| 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_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 16 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
| 17 #include "extensions/browser/process_manager.h" | 17 #include "extensions/browser/process_manager.h" |
| 18 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
| 19 | 19 |
| 20 using extensions::Extension; | 20 using extensions::Extension; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 bool HasExtensionPageActionCountReachedTarget(LocationBarTesting* location_bar, | |
| 25 int target_page_action_count) { | |
| 26 VLOG(1) << "Number of page actions: " << location_bar->PageActionCount(); | |
| 27 return location_bar->PageActionCount() == target_page_action_count; | |
| 28 } | |
| 29 | |
| 30 bool HasExtensionPageActionVisibilityReachedTarget( | 24 bool HasExtensionPageActionVisibilityReachedTarget( |
| 31 LocationBarTesting* location_bar, | 25 LocationBarTesting* location_bar, |
| 32 int target_visible_page_action_count) { | 26 int target_visible_page_action_count) { |
| 33 VLOG(1) << "Number of visible page actions: " | 27 VLOG(1) << "Number of visible page actions: " |
| 34 << location_bar->PageActionVisibleCount(); | 28 << location_bar->PageActionVisibleCount(); |
| 35 return location_bar->PageActionVisibleCount() == | 29 return location_bar->PageActionVisibleCount() == |
| 36 target_visible_page_action_count; | 30 target_visible_page_action_count; |
| 37 } | 31 } |
| 38 | 32 |
| 39 bool HaveAllExtensionRenderViewHostsFinishedLoading( | 33 bool HaveAllExtensionRenderViewHostsFinishedLoading( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // TODO(bauerb): Using a WindowedNotificationObserver like this can break | 136 // TODO(bauerb): Using a WindowedNotificationObserver like this can break |
| 143 // easily, if the notification we're waiting for is sent before this method. | 137 // easily, if the notification we're waiting for is sent before this method. |
| 144 // Change it so that the WindowedNotificationObserver is constructed earlier. | 138 // Change it so that the WindowedNotificationObserver is constructed earlier. |
| 145 content::NotificationRegistrar registrar; | 139 content::NotificationRegistrar registrar; |
| 146 registrar.Add( | 140 registrar.Add( |
| 147 this, notification_type, content::NotificationService::AllSources()); | 141 this, notification_type, content::NotificationService::AllSources()); |
| 148 content::WindowedNotificationObserver( | 142 content::WindowedNotificationObserver( |
| 149 notification_type, content::NotificationService::AllSources()).Wait(); | 143 notification_type, content::NotificationService::AllSources()).Wait(); |
| 150 } | 144 } |
| 151 | 145 |
| 152 bool ExtensionTestNotificationObserver::WaitForPageActionCountChangeTo( | |
| 153 int count) { | |
| 154 LocationBarTesting* location_bar = | |
| 155 browser_->window()->GetLocationBar()->GetLocationBarForTesting(); | |
| 156 WaitForCondition( | |
| 157 base::Bind( | |
| 158 &HasExtensionPageActionCountReachedTarget, location_bar, count), | |
| 159 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED); | |
| 160 return true; | |
| 161 } | |
| 162 | |
| 163 bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo( | 146 bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo( |
| 164 int count) { | 147 int count) { |
| 165 LocationBarTesting* location_bar = | 148 LocationBarTesting* location_bar = |
| 166 browser_->window()->GetLocationBar()->GetLocationBarForTesting(); | 149 browser_->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 167 WaitForCondition( | 150 WaitForCondition( |
| 168 base::Bind( | 151 base::Bind( |
| 169 &HasExtensionPageActionVisibilityReachedTarget, location_bar, count), | 152 &HasExtensionPageActionVisibilityReachedTarget, location_bar, count), |
| 170 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED); | 153 extensions::NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED); |
| 171 return true; | 154 return true; |
| 172 } | 155 } |
| 173 | 156 |
| 174 bool ExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() { | 157 bool ExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() { |
| 175 extensions::ProcessManager* manager = | 158 extensions::ProcessManager* manager = |
| 176 extensions::ExtensionSystem::Get(GetProfile())->process_manager(); | 159 extensions::ExtensionSystem::Get(GetProfile())->process_manager(); |
| 177 NotificationSet notification_set; | 160 NotificationSet notification_set; |
| 178 notification_set.Add(content::NOTIFICATION_WEB_CONTENTS_DESTROYED); | 161 notification_set.Add(content::NOTIFICATION_WEB_CONTENTS_DESTROYED); |
| 179 notification_set.Add(content::NOTIFICATION_LOAD_STOP); | 162 notification_set.Add(content::NOTIFICATION_LOAD_STOP); |
| 180 WaitForCondition( | 163 WaitForCondition( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 case extensions::NOTIFICATION_EXTENSION_LOAD_ERROR: | 264 case extensions::NOTIFICATION_EXTENSION_LOAD_ERROR: |
| 282 VLOG(1) << "Got EXTENSION_LOAD_ERROR notification."; | 265 VLOG(1) << "Got EXTENSION_LOAD_ERROR notification."; |
| 283 ++extension_load_errors_observed_; | 266 ++extension_load_errors_observed_; |
| 284 break; | 267 break; |
| 285 | 268 |
| 286 default: | 269 default: |
| 287 NOTREACHED(); | 270 NOTREACHED(); |
| 288 break; | 271 break; |
| 289 } | 272 } |
| 290 } | 273 } |
| OLD | NEW |