| 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" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 notification_type, content::NotificationService::AllSources()).Wait(); | 149 notification_type, content::NotificationService::AllSources()).Wait(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool ExtensionTestNotificationObserver::WaitForPageActionCountChangeTo( | 152 bool ExtensionTestNotificationObserver::WaitForPageActionCountChangeTo( |
| 153 int count) { | 153 int count) { |
| 154 LocationBarTesting* location_bar = | 154 LocationBarTesting* location_bar = |
| 155 browser_->window()->GetLocationBar()->GetLocationBarForTesting(); | 155 browser_->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 156 WaitForCondition( | 156 WaitForCondition( |
| 157 base::Bind( | 157 base::Bind( |
| 158 &HasExtensionPageActionCountReachedTarget, location_bar, count), | 158 &HasExtensionPageActionCountReachedTarget, location_bar, count), |
| 159 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED); | 159 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED); |
| 160 return true; | 160 return true; |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo( | 163 bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo( |
| 164 int count) { | 164 int count) { |
| 165 LocationBarTesting* location_bar = | 165 LocationBarTesting* location_bar = |
| 166 browser_->window()->GetLocationBar()->GetLocationBarForTesting(); | 166 browser_->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 167 WaitForCondition( | 167 WaitForCondition( |
| 168 base::Bind( | 168 base::Bind( |
| 169 &HasExtensionPageActionVisibilityReachedTarget, location_bar, count), | 169 &HasExtensionPageActionVisibilityReachedTarget, location_bar, count), |
| 170 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED); | 170 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED); |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool ExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() { | 174 bool ExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() { |
| 175 extensions::ProcessManager* manager = | 175 extensions::ProcessManager* manager = |
| 176 extensions::ExtensionSystem::Get(GetProfile())->process_manager(); | 176 extensions::ExtensionSystem::Get(GetProfile())->process_manager(); |
| 177 NotificationSet notification_set; | 177 NotificationSet notification_set; |
| 178 notification_set.Add(content::NOTIFICATION_WEB_CONTENTS_DESTROYED); | 178 notification_set.Add(content::NOTIFICATION_WEB_CONTENTS_DESTROYED); |
| 179 notification_set.Add(content::NOTIFICATION_LOAD_STOP); | 179 notification_set.Add(content::NOTIFICATION_LOAD_STOP); |
| 180 WaitForCondition( | 180 WaitForCondition( |
| 181 base::Bind(&HaveAllExtensionRenderViewHostsFinishedLoading, manager), | 181 base::Bind(&HaveAllExtensionRenderViewHostsFinishedLoading, manager), |
| 182 ¬ification_set); | 182 ¬ification_set); |
| 183 return true; | 183 return true; |
| 184 } | 184 } |
| 185 | 185 |
| 186 bool ExtensionTestNotificationObserver::WaitForExtensionInstall() { | 186 bool ExtensionTestNotificationObserver::WaitForExtensionInstall() { |
| 187 int before = extension_installs_observed_; | 187 int before = extension_installs_observed_; |
| 188 WaitForNotification( | 188 WaitForNotification( |
| 189 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED); | 189 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED); |
| 190 return extension_installs_observed_ == (before + 1); | 190 return extension_installs_observed_ == (before + 1); |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool ExtensionTestNotificationObserver::WaitForExtensionInstallError() { | 193 bool ExtensionTestNotificationObserver::WaitForExtensionInstallError() { |
| 194 int before = extension_installs_observed_; | 194 int before = extension_installs_observed_; |
| 195 content::WindowedNotificationObserver( | 195 content::WindowedNotificationObserver( |
| 196 chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 196 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| 197 content::NotificationService::AllSources()).Wait(); | 197 content::NotificationService::AllSources()).Wait(); |
| 198 return extension_installs_observed_ == before; | 198 return extension_installs_observed_ == before; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void ExtensionTestNotificationObserver::WaitForExtensionLoad() { | 201 void ExtensionTestNotificationObserver::WaitForExtensionLoad() { |
| 202 WaitForNotification(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED); | 202 WaitForNotification(extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void ExtensionTestNotificationObserver::WaitForExtensionAndViewLoad() { | 205 void ExtensionTestNotificationObserver::WaitForExtensionAndViewLoad() { |
| 206 this->WaitForExtensionLoad(); | 206 this->WaitForExtensionLoad(); |
| 207 WaitForExtensionViewsToLoad(); | 207 WaitForExtensionViewsToLoad(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool ExtensionTestNotificationObserver::WaitForExtensionLoadError() { | 210 bool ExtensionTestNotificationObserver::WaitForExtensionLoadError() { |
| 211 int before = extension_load_errors_observed_; | 211 int before = extension_load_errors_observed_; |
| 212 WaitForNotification(chrome::NOTIFICATION_EXTENSION_LOAD_ERROR); | 212 WaitForNotification(extensions::NOTIFICATION_EXTENSION_LOAD_ERROR); |
| 213 return extension_load_errors_observed_ != before; | 213 return extension_load_errors_observed_ != before; |
| 214 } | 214 } |
| 215 | 215 |
| 216 bool ExtensionTestNotificationObserver::WaitForExtensionCrash( | 216 bool ExtensionTestNotificationObserver::WaitForExtensionCrash( |
| 217 const std::string& extension_id) { | 217 const std::string& extension_id) { |
| 218 ExtensionService* service = extensions::ExtensionSystem::Get( | 218 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 219 GetProfile())->extension_service(); | 219 GetProfile())->extension_service(); |
| 220 | 220 |
| 221 if (!service->GetExtensionById(extension_id, true)) { | 221 if (!service->GetExtensionById(extension_id, true)) { |
| 222 // The extension is already unloaded, presumably due to a crash. | 222 // The extension is already unloaded, presumably due to a crash. |
| 223 return true; | 223 return true; |
| 224 } | 224 } |
| 225 content::WindowedNotificationObserver( | 225 content::WindowedNotificationObserver( |
| 226 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 226 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 227 content::NotificationService::AllSources()).Wait(); | 227 content::NotificationService::AllSources()).Wait(); |
| 228 return (service->GetExtensionById(extension_id, true) == NULL); | 228 return (service->GetExtensionById(extension_id, true) == NULL); |
| 229 } | 229 } |
| 230 | 230 |
| 231 bool ExtensionTestNotificationObserver::WaitForCrxInstallerDone() { | 231 bool ExtensionTestNotificationObserver::WaitForCrxInstallerDone() { |
| 232 int before = crx_installers_done_observed_; | 232 int before = crx_installers_done_observed_; |
| 233 WaitForNotification(chrome::NOTIFICATION_CRX_INSTALLER_DONE); | 233 WaitForNotification(extensions::NOTIFICATION_CRX_INSTALLER_DONE); |
| 234 return crx_installers_done_observed_ == (before + 1); | 234 return crx_installers_done_observed_ == (before + 1); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void ExtensionTestNotificationObserver::Watch( | 237 void ExtensionTestNotificationObserver::Watch( |
| 238 int type, | 238 int type, |
| 239 const content::NotificationSource& source) { | 239 const content::NotificationSource& source) { |
| 240 CHECK(!observer_); | 240 CHECK(!observer_); |
| 241 observer_.reset(new content::WindowedNotificationObserver(type, source)); | 241 observer_.reset(new content::WindowedNotificationObserver(type, source)); |
| 242 registrar_.Add(this, type, source); | 242 registrar_.Add(this, type, source); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void ExtensionTestNotificationObserver::Wait() { | 245 void ExtensionTestNotificationObserver::Wait() { |
| 246 observer_->Wait(); | 246 observer_->Wait(); |
| 247 | 247 |
| 248 registrar_.RemoveAll(); | 248 registrar_.RemoveAll(); |
| 249 observer_.reset(); | 249 observer_.reset(); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void ExtensionTestNotificationObserver::Observe( | 252 void ExtensionTestNotificationObserver::Observe( |
| 253 int type, | 253 int type, |
| 254 const content::NotificationSource& source, | 254 const content::NotificationSource& source, |
| 255 const content::NotificationDetails& details) { | 255 const content::NotificationDetails& details) { |
| 256 switch (type) { | 256 switch (type) { |
| 257 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: | 257 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: |
| 258 last_loaded_extension_id_ = | 258 last_loaded_extension_id_ = |
| 259 content::Details<const Extension>(details).ptr()->id(); | 259 content::Details<const Extension>(details).ptr()->id(); |
| 260 VLOG(1) << "Got EXTENSION_LOADED notification."; | 260 VLOG(1) << "Got EXTENSION_LOADED notification."; |
| 261 break; | 261 break; |
| 262 | 262 |
| 263 case chrome::NOTIFICATION_CRX_INSTALLER_DONE: | 263 case extensions::NOTIFICATION_CRX_INSTALLER_DONE: |
| 264 VLOG(1) << "Got CRX_INSTALLER_DONE notification."; | 264 VLOG(1) << "Got CRX_INSTALLER_DONE notification."; |
| 265 { | 265 { |
| 266 const Extension* extension = | 266 const Extension* extension = |
| 267 content::Details<const Extension>(details).ptr(); | 267 content::Details<const Extension>(details).ptr(); |
| 268 if (extension) | 268 if (extension) |
| 269 last_loaded_extension_id_ = extension->id(); | 269 last_loaded_extension_id_ = extension->id(); |
| 270 else | 270 else |
| 271 last_loaded_extension_id_.clear(); | 271 last_loaded_extension_id_.clear(); |
| 272 } | 272 } |
| 273 ++crx_installers_done_observed_; | 273 ++crx_installers_done_observed_; |
| 274 break; | 274 break; |
| 275 | 275 |
| 276 case chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: | 276 case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: |
| 277 VLOG(1) << "Got EXTENSION_INSTALLED notification."; | 277 VLOG(1) << "Got EXTENSION_INSTALLED notification."; |
| 278 ++extension_installs_observed_; | 278 ++extension_installs_observed_; |
| 279 break; | 279 break; |
| 280 | 280 |
| 281 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: | 281 case extensions::NOTIFICATION_EXTENSION_LOAD_ERROR: |
| 282 VLOG(1) << "Got EXTENSION_LOAD_ERROR notification."; | 282 VLOG(1) << "Got EXTENSION_LOAD_ERROR notification."; |
| 283 ++extension_load_errors_observed_; | 283 ++extension_load_errors_observed_; |
| 284 break; | 284 break; |
| 285 | 285 |
| 286 default: | 286 default: |
| 287 NOTREACHED(); | 287 NOTREACHED(); |
| 288 break; | 288 break; |
| 289 } | 289 } |
| 290 } | 290 } |
| OLD | NEW |