Home | History | Annotate | Download | only in browser_plugin
      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   // NotificationObserver method override.
     31   virtual void Observe(int type,
     32                        const NotificationSource& source,
     33                        const NotificationDetails& details) OVERRIDE;
     34 
     35   // Overridden methods from BrowserPluginGuest to intercept in test objects.
     36   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
     37   virtual void OnHandleInputEvent(int instance_id,
     38                                   const gfx::Rect& guest_window_rect,
     39                                   const WebKit::WebInputEvent* event) OVERRIDE;
     40   virtual void OnSetFocus(int instance_id, bool focused) OVERRIDE;
     41   virtual void OnTakeFocus(bool reverse) OVERRIDE;
     42   virtual void SetDamageBuffer(
     43       const BrowserPluginHostMsg_ResizeGuest_Params& params) OVERRIDE;
     44   virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE;
     45 
     46   // Test utilities to wait for a event we are interested in.
     47   // Waits until UpdateRect message is sent from the guest, meaning it is
     48   // ready/rendered.
     49   void WaitForUpdateRectMsg();
     50   void ResetUpdateRectCount();
     51   // Waits until a guest receives a damage buffer of the specified |size|.
     52   void WaitForDamageBufferWithSize(const gfx::Size& size);
     53   // Waits for focus to reach this guest.
     54   void WaitForFocus();
     55   // Waits for blur to reach this guest.
     56   void WaitForBlur();
     57   // Waits for focus to move out of this guest.
     58   void WaitForAdvanceFocus();
     59   // Waits until the guest is hidden.
     60   void WaitUntilHidden();
     61   // Waits until guest exits.
     62   void WaitForExit();
     63   // Waits until input is observed.
     64   void WaitForInput();
     65   // Waits until 'loadstop' is observed.
     66   void WaitForLoadStop();
     67   // Waits until UpdateRect with a particular |view_size| is observed.
     68   void WaitForViewSize(const gfx::Size& view_size);
     69 
     70  private:
     71   // Overridden methods from BrowserPluginGuest to intercept in test objects.
     72   virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE;
     73 
     74   int update_rect_count_;
     75   int damage_buffer_call_count_;
     76   bool exit_observed_;
     77   bool focus_observed_;
     78   bool blur_observed_;
     79   bool advance_focus_observed_;
     80   bool was_hidden_observed_;
     81   bool set_damage_buffer_observed_;
     82   bool input_observed_;
     83   bool load_stop_observed_;
     84   gfx::Size last_view_size_observed_;
     85   gfx::Size expected_auto_view_size_;
     86 
     87   // For WaitForDamageBufferWithSize().
     88   bool waiting_for_damage_buffer_with_size_;
     89   gfx::Size expected_damage_buffer_size_;
     90   gfx::Size last_damage_buffer_size_;
     91 
     92   scoped_refptr<MessageLoopRunner> send_message_loop_runner_;
     93   scoped_refptr<MessageLoopRunner> crash_message_loop_runner_;
     94   scoped_refptr<MessageLoopRunner> focus_message_loop_runner_;
     95   scoped_refptr<MessageLoopRunner> blur_message_loop_runner_;
     96   scoped_refptr<MessageLoopRunner> advance_focus_message_loop_runner_;
     97   scoped_refptr<MessageLoopRunner> was_hidden_message_loop_runner_;
     98   scoped_refptr<MessageLoopRunner> damage_buffer_message_loop_runner_;
     99   scoped_refptr<MessageLoopRunner> input_message_loop_runner_;
    100   scoped_refptr<MessageLoopRunner> load_stop_message_loop_runner_;
    101   scoped_refptr<MessageLoopRunner> auto_view_size_message_loop_runner_;
    102 
    103   DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest);
    104 };
    105 
    106 }  // namespace content
    107 
    108 #endif  // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_H_
    109