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 #include "chrome/browser/extensions/extension_test_notification_observer.h" | 5 #include "chrome/browser/extensions/extension_test_notification_observer.h" |
6 | 6 |
7 #include "base/callback_list.h" | 7 #include "base/callback_list.h" |
| 8 #include "chrome/browser/extensions/extension_action_test_util.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
13 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
15 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
16 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
17 #include "extensions/browser/process_manager.h" | 19 #include "extensions/browser/process_manager.h" |
18 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
19 | 21 |
20 using extensions::Extension; | 22 using extensions::Extension; |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 // A callback that returns true if the condition has been met and takes no | 26 // A callback that returns true if the condition has been met and takes no |
25 // arguments. | 27 // arguments. |
26 typedef base::Callback<bool(void)> ConditionCallback; | 28 typedef base::Callback<bool(void)> ConditionCallback; |
27 | 29 |
28 bool HasPageActionVisibilityReachedTarget( | 30 bool HasPageActionVisibilityReachedTarget( |
29 LocationBarTesting* location_bar, int target_visible_page_action_count) { | 31 Browser* browser, size_t target_visible_page_action_count) { |
30 return location_bar->PageActionVisibleCount() == | 32 return extensions::extension_action_test_util::GetVisiblePageActionCount( |
31 target_visible_page_action_count; | 33 browser->tab_strip_model()->GetActiveWebContents()) == |
| 34 target_visible_page_action_count; |
32 } | 35 } |
33 | 36 |
34 bool HaveAllExtensionRenderViewHostsFinishedLoading( | 37 bool HaveAllExtensionRenderViewHostsFinishedLoading( |
35 extensions::ProcessManager* manager) { | 38 extensions::ProcessManager* manager) { |
36 extensions::ProcessManager::ViewSet all_views = manager->GetAllViews(); | 39 extensions::ProcessManager::ViewSet all_views = manager->GetAllViews(); |
37 for (extensions::ProcessManager::ViewSet::const_iterator iter = | 40 for (extensions::ProcessManager::ViewSet::const_iterator iter = |
38 all_views.begin(); | 41 all_views.begin(); |
39 iter != all_views.end(); ++iter) { | 42 iter != all_views.end(); ++iter) { |
40 if ((*iter)->IsLoading()) | 43 if ((*iter)->IsLoading()) |
41 return false; | 44 return false; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Change it so that the WindowedNotificationObserver is constructed earlier. | 121 // Change it so that the WindowedNotificationObserver is constructed earlier. |
119 content::NotificationRegistrar registrar; | 122 content::NotificationRegistrar registrar; |
120 registrar.Add( | 123 registrar.Add( |
121 this, notification_type, content::NotificationService::AllSources()); | 124 this, notification_type, content::NotificationService::AllSources()); |
122 content::WindowedNotificationObserver( | 125 content::WindowedNotificationObserver( |
123 notification_type, content::NotificationService::AllSources()).Wait(); | 126 notification_type, content::NotificationService::AllSources()).Wait(); |
124 } | 127 } |
125 | 128 |
126 bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo( | 129 bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo( |
127 int count) { | 130 int count) { |
128 LocationBarTesting* location_bar = | |
129 browser_->window()->GetLocationBar()->GetLocationBarForTesting(); | |
130 extensions::ExtensionActionAPI::Get(GetProfile())->AddObserver(this); | 131 extensions::ExtensionActionAPI::Get(GetProfile())->AddObserver(this); |
131 WaitForCondition( | 132 WaitForCondition( |
132 base::Bind(&HasPageActionVisibilityReachedTarget, location_bar, count), | 133 base::Bind(&HasPageActionVisibilityReachedTarget, browser_, count), |
133 NULL); | 134 NULL); |
134 extensions::ExtensionActionAPI::Get(GetProfile())-> | 135 extensions::ExtensionActionAPI::Get(GetProfile())-> |
135 RemoveObserver(this); | 136 RemoveObserver(this); |
136 return true; | 137 return true; |
137 } | 138 } |
138 | 139 |
139 bool ExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() { | 140 bool ExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() { |
140 extensions::ProcessManager* manager = | 141 extensions::ProcessManager* manager = |
141 extensions::ExtensionSystem::Get(GetProfile())->process_manager(); | 142 extensions::ExtensionSystem::Get(GetProfile())->process_manager(); |
142 NotificationSet notification_set; | 143 NotificationSet notification_set; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 runner->Run(); | 280 runner->Run(); |
280 | 281 |
281 condition_.Reset(); | 282 condition_.Reset(); |
282 quit_closure_.Reset(); | 283 quit_closure_.Reset(); |
283 } | 284 } |
284 | 285 |
285 void ExtensionTestNotificationObserver::MaybeQuit() { | 286 void ExtensionTestNotificationObserver::MaybeQuit() { |
286 if (condition_.Run()) | 287 if (condition_.Run()) |
287 quit_closure_.Run(); | 288 quit_closure_.Run(); |
288 } | 289 } |
OLD | NEW |