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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
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/location_bar/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"
19 class WindowedNotificationObserver;
22 // Test helper class for observing extension-related events.
23 class ExtensionTestNotificationObserver : public content::NotificationObserver {
25 explicit ExtensionTestNotificationObserver(Browser* browser);
26 virtual ~ExtensionTestNotificationObserver();
28 // Wait for the total number of page actions to change to |count|.
29 bool WaitForPageActionCountChangeTo(int count);
31 // Wait for the number of visible page actions to change to |count|.
32 bool WaitForPageActionVisibilityChangeTo(int count);
34 // Waits until an extension is installed and loaded. Returns true if an
35 // install happened before timeout.
36 bool WaitForExtensionInstall();
38 // Wait for an extension install error to be raised. Returns true if an
40 bool WaitForExtensionInstallError();
42 // Waits until an extension is loaded and all view have loaded.
43 void WaitForExtensionAndViewLoad();
45 // Waits until an extension is loaded.
46 void WaitForExtensionLoad();
48 // Waits for an extension load error. Returns true if the error really
50 bool WaitForExtensionLoadError();
52 // Wait for the specified extension to crash. Returns true if it really
54 bool WaitForExtensionCrash(const std::string& extension_id);
56 // Wait for the crx installer to be done. Returns true if it really is done.
57 bool WaitForCrxInstallerDone();
59 // Wait for all extension views to load.
60 bool WaitForExtensionViewsToLoad();
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);
67 // After registering one or more event types with Watch(), call
68 // this method to run the message loop and perform cleanup.
71 const std::string& last_loaded_extension_id() {
72 return last_loaded_extension_id_;
74 void set_last_loaded_extension_id(
75 const std::string& last_loaded_extension_id) {
76 last_loaded_extension_id_ = last_loaded_extension_id;
79 // content::NotificationObserver
80 virtual void Observe(int type,
81 const content::NotificationSource& source,
82 const content::NotificationDetails& details) OVERRIDE;
85 Profile* GetProfile();
87 void WaitForNotification(int notification_type);
92 content::NotificationRegistrar registrar_;
93 scoped_ptr<content::WindowedNotificationObserver> observer_;
95 std::string last_loaded_extension_id_;
96 int extension_installs_observed_;
97 int extension_load_errors_observed_;
98 int crx_installers_done_observed_;
101 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_