Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / browser_plugin / test_browser_plugin_guest.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_
6 #define CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_
7
8 #include "base/compiler_specific.h"
9 #include "content/browser/browser_plugin/browser_plugin_guest.h"
10 #include "content/public/test/test_utils.h"
11 #include "ui/gfx/size.h"
12
13 namespace content {
14
15 class RenderProcessHost;
16 class RenderViewHost;
17 class WebContentsImpl;
18
19 // Test class for BrowserPluginGuest.
20 //
21 // Provides utilities to wait for certain state/messages in BrowserPluginGuest
22 // to be used in tests.
23 class TestBrowserPluginGuest : public BrowserPluginGuest {
24  public:
25   TestBrowserPluginGuest(int instance_id, WebContentsImpl* web_contents);
26   virtual ~TestBrowserPluginGuest();
27
28   WebContentsImpl* web_contents() const;
29
30   // Overridden methods from BrowserPluginGuest to intercept in test objects.
31   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
32   virtual void OnHandleInputEvent(int instance_id,
33                                   const gfx::Rect& guest_window_rect,
34                                   const blink::WebInputEvent* event) OVERRIDE;
35   virtual void OnSetFocus(int instance_id, bool focused) OVERRIDE;
36   virtual void OnTakeFocus(bool reverse) OVERRIDE;
37   virtual void SetDamageBuffer(
38       const BrowserPluginHostMsg_ResizeGuest_Params& params) OVERRIDE;
39   virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE;
40   virtual void OnImeCancelComposition() OVERRIDE;
41
42   // Overridden from WebContentsObserver.
43   virtual void WasHidden() OVERRIDE;
44
45   // Test utilities to wait for a event we are interested in.
46   // Waits until UpdateRect message is sent from the guest, meaning it is
47   // ready/rendered.
48   void WaitForUpdateRectMsg();
49   void ResetUpdateRectCount();
50   // Waits until a guest receives a damage buffer of the specified |size|.
51   void WaitForDamageBufferWithSize(const gfx::Size& size);
52   // Waits for focus to reach this guest.
53   void WaitForFocus();
54   // Waits for blur to reach this guest.
55   void WaitForBlur();
56   // Waits for focus to move out of this guest.
57   void WaitForAdvanceFocus();
58   // Waits until the guest is hidden.
59   void WaitUntilHidden();
60   // Waits until guest exits.
61   void WaitForExit();
62   // Waits until input is observed.
63   void WaitForInput();
64   // Waits until 'loadstop' is observed.
65   void WaitForLoadStop();
66   // Waits until UpdateRect with a particular |view_size| is observed.
67   void WaitForViewSize(const gfx::Size& view_size);
68   // Waits until IME cancellation is observed.
69   void WaitForImeCancel();
70
71   void set_guest_hang_timeout(const base::TimeDelta& timeout) {
72     guest_hang_timeout_ = timeout;
73   }
74
75   ui::TextInputType last_text_input_type() {
76     return last_text_input_type_;
77   }
78
79  private:
80   // Overridden methods from BrowserPluginGuest to intercept in test objects.
81   virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE;
82
83   int update_rect_count_;
84   int damage_buffer_call_count_;
85   bool exit_observed_;
86   bool focus_observed_;
87   bool blur_observed_;
88   bool advance_focus_observed_;
89   bool was_hidden_observed_;
90   bool set_damage_buffer_observed_;
91   bool input_observed_;
92   bool load_stop_observed_;
93   bool ime_cancel_observed_;
94   gfx::Size last_view_size_observed_;
95   gfx::Size expected_auto_view_size_;
96
97   // For WaitForDamageBufferWithSize().
98   bool waiting_for_damage_buffer_with_size_;
99   gfx::Size expected_damage_buffer_size_;
100   gfx::Size last_damage_buffer_size_;
101
102   scoped_refptr<MessageLoopRunner> send_message_loop_runner_;
103   scoped_refptr<MessageLoopRunner> crash_message_loop_runner_;
104   scoped_refptr<MessageLoopRunner> focus_message_loop_runner_;
105   scoped_refptr<MessageLoopRunner> blur_message_loop_runner_;
106   scoped_refptr<MessageLoopRunner> advance_focus_message_loop_runner_;
107   scoped_refptr<MessageLoopRunner> was_hidden_message_loop_runner_;
108   scoped_refptr<MessageLoopRunner> damage_buffer_message_loop_runner_;
109   scoped_refptr<MessageLoopRunner> input_message_loop_runner_;
110   scoped_refptr<MessageLoopRunner> load_stop_message_loop_runner_;
111   scoped_refptr<MessageLoopRunner> auto_view_size_message_loop_runner_;
112   scoped_refptr<MessageLoopRunner> ime_cancel_message_loop_runner_;
113
114   DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest);
115 };
116
117 }  // namespace content
118
119 #endif  // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_