Home | History | Annotate | Download | only in test
      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 UI_WEB_DIALOGS_TEST_TEST_WEB_DIALOG_OBSERVER_H_
      6 #define UI_WEB_DIALOGS_TEST_TEST_WEB_DIALOG_OBSERVER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "content/public/browser/notification_observer.h"
     12 #include "content/public/browser/notification_registrar.h"
     13 #include "ui/web_dialogs/web_dialog_observer.h"
     14 
     15 
     16 namespace content {
     17 class JsInjectionReadyObserver;
     18 class MessageLoopRunner;
     19 class RenderViewHost;
     20 class WebUI;
     21 }
     22 
     23 namespace ui {
     24 namespace test {
     25 
     26 // For browser_tests, which run on the UI thread, run a second message
     27 // MessageLoop to detect WebDialog creation and quit when the constructed
     28 // WebUI instance is captured and ready.
     29 class TestWebDialogObserver : public content::NotificationObserver,
     30                               public WebDialogObserver {
     31  public:
     32   // Create and register a new TestWebDialogObserver. If
     33   // |js_injection_ready_observer| is non-NULL, notify it as soon as the RVH is
     34   // available.
     35   explicit TestWebDialogObserver(
     36       content::JsInjectionReadyObserver* js_injection_ready_observer);
     37   virtual ~TestWebDialogObserver();
     38 
     39   // Overridden from WebDialogObserver:
     40   virtual void OnDialogShown(
     41       content::WebUI* webui,
     42       content::RenderViewHost* render_view_host) OVERRIDE;
     43 
     44   // Waits for an WebDialog to be created. The WebUI instance is captured
     45   // and the method returns it when the navigation on the dialog is complete.
     46   content::WebUI* GetWebUI();
     47 
     48  private:
     49   // content::NotificationObserver:
     50   virtual void Observe(int type,
     51                        const content::NotificationSource& source,
     52                        const content::NotificationDetails& details) OVERRIDE;
     53 
     54   content::NotificationRegistrar registrar_;
     55 
     56   // Observer to take some action when the dialog is ready for JavaScript
     57   // injection.
     58   content::JsInjectionReadyObserver* js_injection_ready_observer_;
     59   content::WebUI* web_ui_;
     60   bool done_;
     61   bool running_;
     62   scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
     63 
     64   DISALLOW_COPY_AND_ASSIGN(TestWebDialogObserver);
     65 };
     66 
     67 }  // namespace test
     68 }  // namespace ui
     69 
     70 #endif  // UI_WEB_DIALOGS_TEST_TEST_WEB_DIALOG_OBSERVER_H_
     71