OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/location_bar/location_bar.h" | 15 #include "chrome/browser/ui/location_bar/location_bar.h" |
16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 class WindowedNotificationObserver; | 21 class WindowedNotificationObserver; |
22 } | 22 } |
23 | 23 |
24 // Test helper class for observing extension-related events. | 24 // Test helper class for observing extension-related events. |
25 class ExtensionTestNotificationObserver | 25 class ExtensionTestNotificationObserver |
26 : public content::NotificationObserver, | 26 : public content::NotificationObserver, |
27 public extensions::ExtensionActionAPI::Observer { | 27 public extensions::ExtensionActionAPI::Observer { |
28 public: | 28 public: |
29 explicit ExtensionTestNotificationObserver(Browser* browser); | 29 explicit ExtensionTestNotificationObserver(Browser* browser); |
30 virtual ~ExtensionTestNotificationObserver(); | 30 ~ExtensionTestNotificationObserver() override; |
31 | 31 |
32 // Wait for the number of visible page actions to change to |count|. | 32 // Wait for the number of visible page actions to change to |count|. |
33 bool WaitForPageActionVisibilityChangeTo(int count); | 33 bool WaitForPageActionVisibilityChangeTo(int count); |
34 | 34 |
35 // Waits until an extension is installed and loaded. Returns true if an | 35 // Waits until an extension is installed and loaded. Returns true if an |
36 // install happened before timeout. | 36 // install happened before timeout. |
37 bool WaitForExtensionInstall(); | 37 bool WaitForExtensionInstall(); |
38 | 38 |
39 // Wait for an extension install error to be raised. Returns true if an | 39 // Wait for an extension install error to be raised. Returns true if an |
40 // error was raised. | 40 // error was raised. |
(...skipping 30 matching lines...) Expand all Loading... |
71 | 71 |
72 const std::string& last_loaded_extension_id() { | 72 const std::string& last_loaded_extension_id() { |
73 return last_loaded_extension_id_; | 73 return last_loaded_extension_id_; |
74 } | 74 } |
75 void set_last_loaded_extension_id( | 75 void set_last_loaded_extension_id( |
76 const std::string& last_loaded_extension_id) { | 76 const std::string& last_loaded_extension_id) { |
77 last_loaded_extension_id_ = last_loaded_extension_id; | 77 last_loaded_extension_id_ = last_loaded_extension_id; |
78 } | 78 } |
79 | 79 |
80 // content::NotificationObserver | 80 // content::NotificationObserver |
81 virtual void Observe(int type, | 81 void Observe(int type, |
82 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
83 const content::NotificationDetails& details) override; | 83 const content::NotificationDetails& details) override; |
84 | 84 |
85 private: | 85 private: |
86 class NotificationSet; | 86 class NotificationSet; |
87 | 87 |
88 Profile* GetProfile(); | 88 Profile* GetProfile(); |
89 | 89 |
90 void WaitForNotification(int notification_type); | 90 void WaitForNotification(int notification_type); |
91 | 91 |
92 // Wait for |condition_| to be met. |notification_set| is the set of | 92 // Wait for |condition_| to be met. |notification_set| is the set of |
93 // notifications to wait for and to check |condition| when observing. This | 93 // notifications to wait for and to check |condition| when observing. This |
94 // can be NULL if we are instead waiting for a different observer method, like | 94 // can be NULL if we are instead waiting for a different observer method, like |
95 // OnPageActionsUpdated(). | 95 // OnPageActionsUpdated(). |
96 void WaitForCondition(const base::Callback<bool(void)>& condition, | 96 void WaitForCondition(const base::Callback<bool(void)>& condition, |
97 NotificationSet* notification_set); | 97 NotificationSet* notification_set); |
98 | 98 |
99 // Quits the message loop if |condition_| is met. | 99 // Quits the message loop if |condition_| is met. |
100 void MaybeQuit(); | 100 void MaybeQuit(); |
101 | 101 |
102 // extensions::ExtensionActionAPI::Observer: | 102 // extensions::ExtensionActionAPI::Observer: |
103 virtual void OnPageActionsUpdated(content::WebContents* contents) override; | 103 void OnPageActionsUpdated(content::WebContents* contents) override; |
104 | 104 |
105 Browser* browser_; | 105 Browser* browser_; |
106 Profile* profile_; | 106 Profile* profile_; |
107 | 107 |
108 content::NotificationRegistrar registrar_; | 108 content::NotificationRegistrar registrar_; |
109 scoped_ptr<content::WindowedNotificationObserver> observer_; | 109 scoped_ptr<content::WindowedNotificationObserver> observer_; |
110 | 110 |
111 std::string last_loaded_extension_id_; | 111 std::string last_loaded_extension_id_; |
112 int extension_installs_observed_; | 112 int extension_installs_observed_; |
113 int extension_load_errors_observed_; | 113 int extension_load_errors_observed_; |
114 int crx_installers_done_observed_; | 114 int crx_installers_done_observed_; |
115 | 115 |
116 // The condition for which we are waiting. This should be checked in any | 116 // The condition for which we are waiting. This should be checked in any |
117 // observing methods that could trigger it. | 117 // observing methods that could trigger it. |
118 base::Callback<bool(void)> condition_; | 118 base::Callback<bool(void)> condition_; |
119 | 119 |
120 // The closure to quit the currently-running message loop. | 120 // The closure to quit the currently-running message loop. |
121 base::Closure quit_closure_; | 121 base::Closure quit_closure_; |
122 }; | 122 }; |
123 | 123 |
124 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ | 124 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ |
OLD | NEW |