| 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.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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 307 |
| 308 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 308 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 309 basedir.AppendASCII("manifest_v2.xml")); | 309 basedir.AppendASCII("manifest_v2.xml")); |
| 310 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 310 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 311 basedir.AppendASCII("v2.crx")); | 311 basedir.AppendASCII("v2.crx")); |
| 312 | 312 |
| 313 // Install version 1 of the extension. | 313 // Install version 1 of the extension. |
| 314 ExtensionTestMessageListener listener1("v1 installed", false); | 314 ExtensionTestMessageListener listener1("v1 installed", false); |
| 315 ExtensionService* service = browser()->profile()->GetExtensionService(); | 315 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 316 const size_t size_before = service->extensions()->size(); | 316 const size_t size_before = service->extensions()->size(); |
| 317 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 317 ASSERT_TRUE(service->disabled_extensions()->empty()); |
| 318 const Extension* extension = | 318 const Extension* extension = |
| 319 InstallExtension(basedir.AppendASCII("v1.crx"), 1); | 319 InstallExtension(basedir.AppendASCII("v1.crx"), 1); |
| 320 ASSERT_TRUE(extension); | 320 ASSERT_TRUE(extension); |
| 321 listener1.WaitUntilSatisfied(); | 321 listener1.WaitUntilSatisfied(); |
| 322 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 322 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 323 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", extension->id()); | 323 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", extension->id()); |
| 324 ASSERT_EQ("1.0", extension->VersionString()); | 324 ASSERT_EQ("1.0", extension->VersionString()); |
| 325 | 325 |
| 326 // We don't want autoupdate blacklist checks. | 326 // We don't want autoupdate blacklist checks. |
| 327 service->updater()->set_blacklist_checks_enabled(false); | 327 service->updater()->set_blacklist_checks_enabled(false); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // Note: This interceptor gets requests on the IO thread. | 375 // Note: This interceptor gets requests on the IO thread. |
| 376 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 376 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 377 content::URLFetcher::SetEnableInterceptionForTests(true); | 377 content::URLFetcher::SetEnableInterceptionForTests(true); |
| 378 | 378 |
| 379 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 379 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 380 basedir.AppendASCII("manifest_v2.xml")); | 380 basedir.AppendASCII("manifest_v2.xml")); |
| 381 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 381 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 382 basedir.AppendASCII("v2.crx")); | 382 basedir.AppendASCII("v2.crx")); |
| 383 | 383 |
| 384 const size_t size_before = service->extensions()->size(); | 384 const size_t size_before = service->extensions()->size(); |
| 385 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 385 ASSERT_TRUE(service->disabled_extensions()->empty()); |
| 386 | 386 |
| 387 PendingExtensionManager* pending_extension_manager = | 387 PendingExtensionManager* pending_extension_manager = |
| 388 service->pending_extension_manager(); | 388 service->pending_extension_manager(); |
| 389 | 389 |
| 390 // The code that reads external_extensions.json uses this method to inform | 390 // The code that reads external_extensions.json uses this method to inform |
| 391 // the ExtensionService of an extension to download. Using the real code | 391 // the ExtensionService of an extension to download. Using the real code |
| 392 // is race-prone, because instantating the ExtensionService starts a read | 392 // is race-prone, because instantating the ExtensionService starts a read |
| 393 // of external_extensions.json before this test function starts. | 393 // of external_extensions.json before this test function starts. |
| 394 | 394 |
| 395 pending_extension_manager->AddFromExternalUpdateUrl( | 395 pending_extension_manager->AddFromExternalUpdateUrl( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 // Note: This interceptor gets requests on the IO thread. | 458 // Note: This interceptor gets requests on the IO thread. |
| 459 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 459 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 460 content::URLFetcher::SetEnableInterceptionForTests(true); | 460 content::URLFetcher::SetEnableInterceptionForTests(true); |
| 461 | 461 |
| 462 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 462 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 463 basedir.AppendASCII("manifest_v2.xml")); | 463 basedir.AppendASCII("manifest_v2.xml")); |
| 464 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 464 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 465 basedir.AppendASCII("v2.crx")); | 465 basedir.AppendASCII("v2.crx")); |
| 466 | 466 |
| 467 const size_t size_before = service->extensions()->size(); | 467 const size_t size_before = service->extensions()->size(); |
| 468 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 468 ASSERT_TRUE(service->disabled_extensions()->empty()); |
| 469 | 469 |
| 470 PrefService* prefs = browser()->profile()->GetPrefs(); | 470 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 471 const ListValue* forcelist = | 471 const ListValue* forcelist = |
| 472 prefs->GetList(prefs::kExtensionInstallForceList); | 472 prefs->GetList(prefs::kExtensionInstallForceList); |
| 473 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 473 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 474 | 474 |
| 475 { | 475 { |
| 476 // Set the policy as a user preference and fire notification observers. | 476 // Set the policy as a user preference and fire notification observers. |
| 477 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 477 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
| 478 ListValue* forcelist = pref_update.Get(); | 478 ListValue* forcelist = pref_update.Get(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 513 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
| 514 EXPECT_FALSE(service->GetExtensionById(kExtensionId, true)); | 514 EXPECT_FALSE(service->GetExtensionById(kExtensionId, true)); |
| 515 } | 515 } |
| 516 | 516 |
| 517 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, PolicyOverridesUserInstall) { | 517 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, PolicyOverridesUserInstall) { |
| 518 ExtensionService* service = browser()->profile()->GetExtensionService(); | 518 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 519 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 519 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 520 service->updater()->set_blacklist_checks_enabled(false); | 520 service->updater()->set_blacklist_checks_enabled(false); |
| 521 const size_t size_before = service->extensions()->size(); | 521 const size_t size_before = service->extensions()->size(); |
| 522 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 522 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 523 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 523 ASSERT_TRUE(service->disabled_extensions()->empty()); |
| 524 | 524 |
| 525 // Note: This interceptor gets requests on the IO thread. | 525 // Note: This interceptor gets requests on the IO thread. |
| 526 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 526 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 527 content::URLFetcher::SetEnableInterceptionForTests(true); | 527 content::URLFetcher::SetEnableInterceptionForTests(true); |
| 528 | 528 |
| 529 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 529 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 530 basedir.AppendASCII("manifest_v2.xml")); | 530 basedir.AppendASCII("manifest_v2.xml")); |
| 531 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 531 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 532 basedir.AppendASCII("v2.crx")); | 532 basedir.AppendASCII("v2.crx")); |
| 533 | 533 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 extension = service->GetExtensionById(kExtensionId, true); | 574 extension = service->GetExtensionById(kExtensionId, true); |
| 575 EXPECT_FALSE(extension); | 575 EXPECT_FALSE(extension); |
| 576 | 576 |
| 577 // User install again, but have it disabled too before setting the policy. | 577 // User install again, but have it disabled too before setting the policy. |
| 578 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 578 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| 579 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 579 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 580 extension = service->GetExtensionById(kExtensionId, false); | 580 extension = service->GetExtensionById(kExtensionId, false); |
| 581 ASSERT_TRUE(extension); | 581 ASSERT_TRUE(extension); |
| 582 EXPECT_EQ(Extension::INTERNAL, extension->location()); | 582 EXPECT_EQ(Extension::INTERNAL, extension->location()); |
| 583 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 583 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 584 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 584 EXPECT_TRUE(service->disabled_extensions()->empty()); |
| 585 | 585 |
| 586 service->DisableExtension(kExtensionId); | 586 service->DisableExtension(kExtensionId); |
| 587 EXPECT_EQ(1u, service->disabled_extensions()->size()); | 587 EXPECT_EQ(1u, service->disabled_extensions()->size()); |
| 588 extension = service->GetExtensionById(kExtensionId, true); | 588 extension = service->GetExtensionById(kExtensionId, true); |
| 589 EXPECT_TRUE(extension); | 589 EXPECT_TRUE(extension); |
| 590 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); | 590 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); |
| 591 | 591 |
| 592 // Install the policy again. It should overwrite the extension's location, | 592 // Install the policy again. It should overwrite the extension's location, |
| 593 // and force enable it too. | 593 // and force enable it too. |
| 594 { | 594 { |
| 595 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 595 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
| 596 ListValue* forcelist = pref_update.Get(); | 596 ListValue* forcelist = pref_update.Get(); |
| 597 ASSERT_TRUE(forcelist->empty()); | 597 ASSERT_TRUE(forcelist->empty()); |
| 598 forcelist->Append(Value::CreateStringValue( | 598 forcelist->Append(Value::CreateStringValue( |
| 599 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); | 599 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); |
| 600 } | 600 } |
| 601 ASSERT_TRUE(WaitForExtensionInstall()); | 601 ASSERT_TRUE(WaitForExtensionInstall()); |
| 602 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 602 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 603 extension = service->GetExtensionById(kExtensionId, false); | 603 extension = service->GetExtensionById(kExtensionId, false); |
| 604 ASSERT_TRUE(extension); | 604 ASSERT_TRUE(extension); |
| 605 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 605 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 606 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 606 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 607 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 607 EXPECT_TRUE(service->disabled_extensions()->empty()); |
| 608 } | 608 } |
| OLD | NEW |