| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/stl_util-inl.h" | 6 #include "base/stl_util-inl.h" |
| 7 #include "chrome/browser/extensions/autoupdate_interceptor.h" | 7 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
| 8 #include "chrome/browser/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 #include "chrome/browser/extensions/extension_updater.h" | 12 #include "chrome/browser/extensions/extension_updater.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/test/ui_test_utils.h" | 21 #include "chrome/test/ui_test_utils.h" |
| 21 #include "content/browser/renderer_host/render_view_host.h" | 22 #include "content/browser/renderer_host/render_view_host.h" |
| 22 | 23 |
| 23 class ExtensionManagementTest : public ExtensionBrowserTest { | 24 class ExtensionManagementTest : public ExtensionBrowserTest { |
| 24 protected: | 25 protected: |
| 25 // Helper method that returns whether the extension is at the given version. | 26 // Helper method that returns whether the extension is at the given version. |
| 26 // This calls version(), which must be defined in the extension's bg page, | 27 // This calls version(), which must be defined in the extension's bg page, |
| 27 // as well as asking the extension itself. | 28 // as well as asking the extension itself. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 service->EnableExtension("bjafgdebaacbbbecmhlhpofkepfkgcpa"); | 228 service->EnableExtension("bjafgdebaacbbbecmhlhpofkepfkgcpa"); |
| 228 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 229 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
| 229 EXPECT_EQ(0u, service->disabled_extensions()->size()); | 230 EXPECT_EQ(0u, service->disabled_extensions()->size()); |
| 230 EXPECT_TRUE(manager->GetBackgroundHostForExtension(extension)); | 231 EXPECT_TRUE(manager->GetBackgroundHostForExtension(extension)); |
| 231 } | 232 } |
| 232 | 233 |
| 233 // Used for testing notifications sent during extension updates. | 234 // Used for testing notifications sent during extension updates. |
| 234 class NotificationListener : public NotificationObserver { | 235 class NotificationListener : public NotificationObserver { |
| 235 public: | 236 public: |
| 236 NotificationListener() : started_(false), finished_(false) { | 237 NotificationListener() : started_(false), finished_(false) { |
| 237 NotificationType::Type types[] = { | 238 int types[] = { |
| 238 NotificationType::EXTENSION_UPDATING_STARTED, | 239 chrome::NOTIFICATION_EXTENSION_UPDATING_STARTED, |
| 239 NotificationType::EXTENSION_UPDATING_FINISHED, | 240 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED, |
| 240 NotificationType::EXTENSION_UPDATE_FOUND | 241 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND |
| 241 }; | 242 }; |
| 242 for (size_t i = 0; i < arraysize(types); i++) { | 243 for (size_t i = 0; i < arraysize(types); i++) { |
| 243 registrar_.Add(this, types[i], NotificationService::AllSources()); | 244 registrar_.Add(this, types[i], NotificationService::AllSources()); |
| 244 } | 245 } |
| 245 } | 246 } |
| 246 ~NotificationListener() {} | 247 ~NotificationListener() {} |
| 247 | 248 |
| 248 bool started() { return started_; } | 249 bool started() { return started_; } |
| 249 | 250 |
| 250 bool finished() { return finished_; } | 251 bool finished() { return finished_; } |
| 251 | 252 |
| 252 const std::set<std::string>& updates() { return updates_; } | 253 const std::set<std::string>& updates() { return updates_; } |
| 253 | 254 |
| 254 void Reset() { | 255 void Reset() { |
| 255 started_ = false; | 256 started_ = false; |
| 256 finished_ = false; | 257 finished_ = false; |
| 257 updates_.clear(); | 258 updates_.clear(); |
| 258 } | 259 } |
| 259 | 260 |
| 260 // Implements NotificationObserver interface. | 261 // Implements NotificationObserver interface. |
| 261 virtual void Observe(NotificationType type, | 262 virtual void Observe(int type, |
| 262 const NotificationSource& source, | 263 const NotificationSource& source, |
| 263 const NotificationDetails& details) { | 264 const NotificationDetails& details) { |
| 264 switch (type.value) { | 265 switch (type) { |
| 265 case NotificationType::EXTENSION_UPDATING_STARTED: { | 266 case chrome::NOTIFICATION_EXTENSION_UPDATING_STARTED: { |
| 266 DCHECK(!started_); | 267 DCHECK(!started_); |
| 267 started_ = true; | 268 started_ = true; |
| 268 break; | 269 break; |
| 269 } | 270 } |
| 270 case NotificationType::EXTENSION_UPDATING_FINISHED: { | 271 case chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED: { |
| 271 DCHECK(!finished_); | 272 DCHECK(!finished_); |
| 272 finished_ = true; | 273 finished_ = true; |
| 273 break; | 274 break; |
| 274 } | 275 } |
| 275 case NotificationType::EXTENSION_UPDATE_FOUND: { | 276 case chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND: { |
| 276 const std::string* id = Details<const std::string>(details).ptr(); | 277 const std::string* id = Details<const std::string>(details).ptr(); |
| 277 updates_.insert(*id); | 278 updates_.insert(*id); |
| 278 break; | 279 break; |
| 279 } | 280 } |
| 280 default: | 281 default: |
| 281 NOTREACHED(); | 282 NOTREACHED(); |
| 282 } | 283 } |
| 283 } | 284 } |
| 284 | 285 |
| 285 private: | 286 private: |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 502 |
| 502 // Check that emptying the list triggers uninstall. | 503 // Check that emptying the list triggers uninstall. |
| 503 { | 504 { |
| 504 prefs->ClearPref(prefs::kExtensionInstallForceList); | 505 prefs->ClearPref(prefs::kExtensionInstallForceList); |
| 505 } | 506 } |
| 506 EXPECT_EQ(size_before + 1, extensions->size()); | 507 EXPECT_EQ(size_before + 1, extensions->size()); |
| 507 ExtensionList::const_iterator i; | 508 ExtensionList::const_iterator i; |
| 508 for (i = extensions->begin(); i != extensions->end(); ++i) | 509 for (i = extensions->begin(); i != extensions->end(); ++i) |
| 509 EXPECT_NE(kExtensionId, (*i)->id()); | 510 EXPECT_NE(kExtensionId, (*i)->id()); |
| 510 } | 511 } |
| OLD | NEW |