• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
7 
8 #include <string>
9 
10 #include "base/compiler_specific.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/omnibox/location_bar.h"
14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_types.h"
17 
18 namespace content {
19 class WindowedNotificationObserver;
20 }
21 
22 // Test helper class for observing extension-related events.
23 class ExtensionTestNotificationObserver : public content::NotificationObserver {
24  public:
25   explicit ExtensionTestNotificationObserver(Browser* browser);
26   virtual ~ExtensionTestNotificationObserver();
27 
28   // Wait for the total number of page actions to change to |count|.
29   bool WaitForPageActionCountChangeTo(int count);
30 
31   // Wait for the number of visible page actions to change to |count|.
32   bool WaitForPageActionVisibilityChangeTo(int count);
33 
34   // Waits until an extension is installed and loaded. Returns true if an
35   // install happened before timeout.
36   bool WaitForExtensionInstall();
37 
38   // Wait for an extension install error to be raised. Returns true if an
39   // error was raised.
40   bool WaitForExtensionInstallError();
41 
42   // Waits until an extension is loaded and all view have loaded.
43   void WaitForExtensionAndViewLoad();
44 
45   // Waits until an extension is loaded.
46   void WaitForExtensionLoad();
47 
48   // Waits for an extension load error. Returns true if the error really
49   // happened.
50   bool WaitForExtensionLoadError();
51 
52   // Wait for the specified extension to crash. Returns true if it really
53   // crashed.
54   bool WaitForExtensionCrash(const std::string& extension_id);
55 
56   // Wait for the crx installer to be done. Returns true if it really is done.
57   bool WaitForCrxInstallerDone();
58 
59   // Wait for all extension views to load.
60   bool WaitForExtensionViewsToLoad();
61 
62   // Watch for the given event type from the given source.
63   // After calling this method, call Wait() to ensure that RunMessageLoop() is
64   // called appropriately and cleanup is performed.
65   void Watch(int type, const content::NotificationSource& source);
66 
67   // After registering one or more event types with Watch(), call
68   // this method to run the message loop and perform cleanup.
69   void Wait();
70 
last_loaded_extension_id()71   const std::string& last_loaded_extension_id() {
72     return last_loaded_extension_id_;
73   }
set_last_loaded_extension_id(std::string last_loaded_extension_id)74   void set_last_loaded_extension_id(std::string last_loaded_extension_id) {
75     last_loaded_extension_id_ = last_loaded_extension_id;
76   }
77 
78   // content::NotificationObserver
79   virtual void Observe(int type,
80                        const content::NotificationSource& source,
81                        const content::NotificationDetails& details) OVERRIDE;
82 
83  private:
84   Profile* GetProfile();
85 
86   void WaitForNotification(int notification_type);
87 
88   Browser* browser_;
89   Profile* profile_;
90 
91   content::NotificationRegistrar registrar_;
92   scoped_ptr<content::WindowedNotificationObserver> observer_;
93 
94   std::string last_loaded_extension_id_;
95   int extension_installs_observed_;
96   int extension_load_errors_observed_;
97   int crx_installers_done_observed_;
98 };
99 
100 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
101