OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 6 #include "base/stl_util.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" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 "ogjcoiohnmldgjemafoockdghcjciccf")); | 278 "ogjcoiohnmldgjemafoockdghcjciccf")); |
279 | 279 |
280 // Make sure the extension state is the same as before. | 280 // Make sure the extension state is the same as before. |
281 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 281 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
282 extension = service->GetExtensionById( | 282 extension = service->GetExtensionById( |
283 "ogjcoiohnmldgjemafoockdghcjciccf", false); | 283 "ogjcoiohnmldgjemafoockdghcjciccf", false); |
284 ASSERT_TRUE(extension); | 284 ASSERT_TRUE(extension); |
285 ASSERT_EQ("2.0", extension->VersionString()); | 285 ASSERT_EQ("2.0", extension->VersionString()); |
286 } | 286 } |
287 | 287 |
| 288 // Tests extension autoupdate. |
| 289 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, AutoUpdateDisabledExtensions) { |
| 290 NotificationListener notification_listener; |
| 291 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 292 // Note: This interceptor gets requests on the IO thread. |
| 293 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 294 content::URLFetcher::SetEnableInterceptionForTests(true); |
| 295 |
| 296 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 297 basedir.AppendASCII("manifest_v2.xml")); |
| 298 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 299 basedir.AppendASCII("v2.crx")); |
| 300 |
| 301 // Install version 1 of the extension. |
| 302 ExtensionTestMessageListener listener1("v1 installed", false); |
| 303 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 304 const size_t enabled_size_before = service->extensions()->size(); |
| 305 const size_t disabled_size_before = service->disabled_extensions()->size(); |
| 306 const Extension* extension = |
| 307 InstallExtension(basedir.AppendASCII("v1.crx"), 1); |
| 308 ASSERT_TRUE(extension); |
| 309 listener1.WaitUntilSatisfied(); |
| 310 service->DisableExtension(extension->id()); |
| 311 ASSERT_EQ(disabled_size_before + 1, service->disabled_extensions()->size()); |
| 312 ASSERT_EQ(enabled_size_before, service->extensions()->size()); |
| 313 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", extension->id()); |
| 314 ASSERT_EQ("1.0", extension->VersionString()); |
| 315 |
| 316 // We don't want autoupdate blacklist checks. |
| 317 service->updater()->set_blacklist_checks_enabled(false); |
| 318 |
| 319 ExtensionTestMessageListener listener2("v2 installed", false); |
| 320 // Run autoupdate and make sure version 2 of the extension was installed but |
| 321 // is still disabled. |
| 322 service->updater()->CheckNow(); |
| 323 ASSERT_TRUE(WaitForExtensionInstall()); |
| 324 ASSERT_EQ(disabled_size_before + 1, service->disabled_extensions()->size()); |
| 325 ASSERT_EQ(enabled_size_before, service->extensions()->size()); |
| 326 extension = service->GetExtensionById( |
| 327 "ogjcoiohnmldgjemafoockdghcjciccf", true); |
| 328 ASSERT_TRUE(extension); |
| 329 ASSERT_FALSE(service->GetExtensionById( |
| 330 "ogjcoiohnmldgjemafoockdghcjciccf", false)); |
| 331 ASSERT_EQ("2.0", extension->VersionString()); |
| 332 |
| 333 // The extension should have not made the callback because it is disabled. |
| 334 // When we enabled it, it should then make the callback. |
| 335 ASSERT_FALSE(listener2.was_satisfied()); |
| 336 service->EnableExtension(extension->id()); |
| 337 listener2.WaitUntilSatisfied(); |
| 338 ASSERT_TRUE(notification_listener.started()); |
| 339 ASSERT_TRUE(notification_listener.finished()); |
| 340 ASSERT_TRUE(ContainsKey(notification_listener.updates(), |
| 341 "ogjcoiohnmldgjemafoockdghcjciccf")); |
| 342 notification_listener.Reset(); |
| 343 } |
| 344 |
288 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { | 345 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { |
289 ExtensionService* service = browser()->profile()->GetExtensionService(); | 346 ExtensionService* service = browser()->profile()->GetExtensionService(); |
290 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 347 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
291 // We don't want autoupdate blacklist checks. | 348 // We don't want autoupdate blacklist checks. |
292 service->updater()->set_blacklist_checks_enabled(false); | 349 service->updater()->set_blacklist_checks_enabled(false); |
293 | 350 |
294 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 351 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
295 | 352 |
296 // Note: This interceptor gets requests on the IO thread. | 353 // Note: This interceptor gets requests on the IO thread. |
297 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 354 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); | 577 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); |
521 } | 578 } |
522 ASSERT_TRUE(WaitForExtensionInstall()); | 579 ASSERT_TRUE(WaitForExtensionInstall()); |
523 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 580 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
524 extension = service->GetExtensionById(kExtensionId, false); | 581 extension = service->GetExtensionById(kExtensionId, false); |
525 ASSERT_TRUE(extension); | 582 ASSERT_TRUE(extension); |
526 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 583 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
527 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 584 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
528 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 585 EXPECT_TRUE(service->disabled_extensions()->is_empty()); |
529 } | 586 } |
OLD | NEW |