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"
16 class WebContentsImpl;
18 // Test class for BrowserPluginGuest.
20 // Provides utilities to wait for certain state/messages in BrowserPluginGuest
21 // to be used in tests.
22 class TestBrowserPluginGuest : public BrowserPluginGuest {
24 TestBrowserPluginGuest(int instance_id, WebContentsImpl* web_contents);
25 virtual ~TestBrowserPluginGuest();
27 WebContentsImpl* web_contents() const;
29 // Overridden methods from BrowserPluginGuest to intercept in test objects.
30 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
31 virtual void OnHandleInputEvent(int instance_id,
32 const gfx::Rect& guest_window_rect,
33 const blink::WebInputEvent* event) OVERRIDE;
34 virtual void OnSetFocus(int instance_id, bool focused) OVERRIDE;
35 virtual void OnTakeFocus(bool reverse) OVERRIDE;
36 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE;
37 virtual void OnImeCancelComposition() OVERRIDE;
38 virtual void OnResizeGuest(
40 const BrowserPluginHostMsg_ResizeGuest_Params& params) OVERRIDE;
42 // Test utilities to wait for a event we are interested in.
43 // Waits until UpdateRect message is sent from the guest, meaning it is
45 void WaitForUpdateRectMsg();
46 void ResetUpdateRectCount();
47 // Waits for focus to reach this guest.
49 // Waits for blur to reach this guest.
51 // Waits for focus to move out of this guest.
52 void WaitForAdvanceFocus();
53 // Waits until guest exits.
55 // Waits until input is observed.
57 // Waits until 'loadstop' is observed.
58 void WaitForLoadStop();
59 // Waits until UpdateRect with a particular |view_size| is observed.
60 void WaitForViewSize(const gfx::Size& view_size);
61 // Waits until IME cancellation is observed.
62 void WaitForImeCancel();
63 // Waits until we have seen a resize guest of size |view_size|.
64 void WaitForResizeGuest(const gfx::Size& view_size);
66 void set_guest_hang_timeout(const base::TimeDelta& timeout) {
67 guest_hang_timeout_ = timeout;
70 ui::TextInputType last_text_input_type() {
71 return last_text_input_type_;
75 // Overridden methods from BrowserPluginGuest to intercept in test objects.
76 virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE;
78 int update_rect_count_;
82 bool advance_focus_observed_;
84 bool load_stop_observed_;
85 bool ime_cancel_observed_;
86 gfx::Size last_view_size_observed_;
87 gfx::Size expected_auto_view_size_;
88 gfx::Size last_size_observed_in_resize_;
89 gfx::Size expected_view_size_in_resize_;
91 scoped_refptr<MessageLoopRunner> send_message_loop_runner_;
92 scoped_refptr<MessageLoopRunner> crash_message_loop_runner_;
93 scoped_refptr<MessageLoopRunner> focus_message_loop_runner_;
94 scoped_refptr<MessageLoopRunner> blur_message_loop_runner_;
95 scoped_refptr<MessageLoopRunner> advance_focus_message_loop_runner_;
96 scoped_refptr<MessageLoopRunner> input_message_loop_runner_;
97 scoped_refptr<MessageLoopRunner> load_stop_message_loop_runner_;
98 scoped_refptr<MessageLoopRunner> auto_view_size_message_loop_runner_;
99 scoped_refptr<MessageLoopRunner> ime_cancel_message_loop_runner_;
100 scoped_refptr<MessageLoopRunner> resize_guest_message_loop_runner_;
102 DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest);
105 } // namespace content
107 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_