Upstream version 7.36.149.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 RenderViewHost;
16 class WebContentsImpl;
17
18 // Test class for BrowserPluginGuest.
19 //
20 // Provides utilities to wait for certain state/messages in BrowserPluginGuest
21 // to be used in tests.
22 class TestBrowserPluginGuest : public BrowserPluginGuest {
23  public:
24   TestBrowserPluginGuest(int instance_id, WebContentsImpl* web_contents);
25   virtual ~TestBrowserPluginGuest();
26
27   WebContentsImpl* web_contents() const;
28
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(
39       int instance_id,
40       const BrowserPluginHostMsg_ResizeGuest_Params& params) OVERRIDE;
41
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
44   // ready/rendered.
45   void WaitForUpdateRectMsg();
46   void ResetUpdateRectCount();
47   // Waits for focus to reach this guest.
48   void WaitForFocus();
49   // Waits for blur to reach this guest.
50   void WaitForBlur();
51   // Waits for focus to move out of this guest.
52   void WaitForAdvanceFocus();
53   // Waits until guest exits.
54   void WaitForExit();
55   // Waits until input is observed.
56   void WaitForInput();
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);
65
66   void set_guest_hang_timeout(const base::TimeDelta& timeout) {
67     guest_hang_timeout_ = timeout;
68   }
69
70   ui::TextInputType last_text_input_type() {
71     return last_text_input_type_;
72   }
73
74  private:
75   // Overridden methods from BrowserPluginGuest to intercept in test objects.
76   virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE;
77
78   int update_rect_count_;
79   bool exit_observed_;
80   bool focus_observed_;
81   bool blur_observed_;
82   bool advance_focus_observed_;
83   bool input_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_;
90
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_;
101
102   DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest);
103 };
104
105 }  // namespace content
106
107 #endif  // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_