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.
5 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_
6 #define CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_
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"
15 class RenderProcessHost;
17 class WebContentsImpl;
19 // Test class for BrowserPluginGuest.
21 // Provides utilities to wait for certain state/messages in BrowserPluginGuest
22 // to be used in tests.
23 class TestBrowserPluginGuest : public BrowserPluginGuest {
25 TestBrowserPluginGuest(int instance_id, WebContentsImpl* web_contents);
26 virtual ~TestBrowserPluginGuest();
28 WebContentsImpl* web_contents() const;
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;
42 // Overridden from WebContentsObserver.
43 virtual void WasHidden() OVERRIDE;
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
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.
54 // Waits for blur to reach this guest.
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.
62 // Waits until input is observed.
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();
71 void set_guest_hang_timeout(const base::TimeDelta& timeout) {
72 guest_hang_timeout_ = timeout;
75 ui::TextInputType last_text_input_type() {
76 return last_text_input_type_;
80 // Overridden methods from BrowserPluginGuest to intercept in test objects.
81 virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE;
83 int update_rect_count_;
84 int damage_buffer_call_count_;
88 bool advance_focus_observed_;
89 bool was_hidden_observed_;
90 bool set_damage_buffer_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_;
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_;
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_;
114 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest);
117 } // namespace content
119 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_