| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 28 #include "content/test/net/url_request_prepackaged_interceptor.h" | 28 #include "content/test/net/url_request_prepackaged_interceptor.h" |
| 29 #include "net/url_request/url_fetcher.h" | 29 #include "net/url_request/url_fetcher.h" |
| 30 | 30 |
| 31 using extensions::Extension; | 31 using extensions::Extension; |
| 32 using extensions::Manifest; |
| 32 | 33 |
| 33 class ExtensionManagementTest : public ExtensionBrowserTest { | 34 class ExtensionManagementTest : public ExtensionBrowserTest { |
| 34 protected: | 35 protected: |
| 35 // Helper method that returns whether the extension is at the given version. | 36 // Helper method that returns whether the extension is at the given version. |
| 36 // This calls version(), which must be defined in the extension's bg page, | 37 // This calls version(), which must be defined in the extension's bg page, |
| 37 // as well as asking the extension itself. | 38 // as well as asking the extension itself. |
| 38 // | 39 // |
| 39 // Note that 'version' here means something different than the version field | 40 // Note that 'version' here means something different than the version field |
| 40 // in the extension's manifest. We use the version as reported by the | 41 // in the extension's manifest. We use the version as reported by the |
| 41 // background page to test how overinstalling crx files with the same | 42 // background page to test how overinstalling crx files with the same |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 extensions::PendingExtensionManager* pending_extension_manager = | 427 extensions::PendingExtensionManager* pending_extension_manager = |
| 427 service->pending_extension_manager(); | 428 service->pending_extension_manager(); |
| 428 | 429 |
| 429 // The code that reads external_extensions.json uses this method to inform | 430 // The code that reads external_extensions.json uses this method to inform |
| 430 // the ExtensionService of an extension to download. Using the real code | 431 // the ExtensionService of an extension to download. Using the real code |
| 431 // is race-prone, because instantating the ExtensionService starts a read | 432 // is race-prone, because instantating the ExtensionService starts a read |
| 432 // of external_extensions.json before this test function starts. | 433 // of external_extensions.json before this test function starts. |
| 433 | 434 |
| 434 EXPECT_TRUE(pending_extension_manager->AddFromExternalUpdateUrl( | 435 EXPECT_TRUE(pending_extension_manager->AddFromExternalUpdateUrl( |
| 435 kExtensionId, GURL("http://localhost/autoupdate/manifest"), | 436 kExtensionId, GURL("http://localhost/autoupdate/manifest"), |
| 436 Extension::EXTERNAL_PREF_DOWNLOAD)); | 437 Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 437 | 438 |
| 438 // Run autoupdate and make sure version 2 of the extension was installed. | 439 // Run autoupdate and make sure version 2 of the extension was installed. |
| 439 service->updater()->CheckNow(params); | 440 service->updater()->CheckNow(params); |
| 440 ASSERT_TRUE(WaitForExtensionInstall()); | 441 ASSERT_TRUE(WaitForExtensionInstall()); |
| 441 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 442 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 442 const Extension* extension = service->GetExtensionById(kExtensionId, false); | 443 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
| 443 ASSERT_TRUE(extension); | 444 ASSERT_TRUE(extension); |
| 444 ASSERT_EQ("2.0", extension->VersionString()); | 445 ASSERT_EQ("2.0", extension->VersionString()); |
| 445 | 446 |
| 446 // Uninstalling the extension should set a pref that keeps the extension from | 447 // Uninstalling the extension should set a pref that keeps the extension from |
| 447 // being installed again the next time external_extensions.json is read. | 448 // being installed again the next time external_extensions.json is read. |
| 448 | 449 |
| 449 UninstallExtension(kExtensionId); | 450 UninstallExtension(kExtensionId); |
| 450 | 451 |
| 451 extensions::ExtensionPrefs* extension_prefs = service->extension_prefs(); | 452 extensions::ExtensionPrefs* extension_prefs = service->extension_prefs(); |
| 452 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) | 453 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) |
| 453 << "Uninstalling should set kill bit on externaly installed extension."; | 454 << "Uninstalling should set kill bit on externaly installed extension."; |
| 454 | 455 |
| 455 // Try to install the extension again from an external source. It should fail | 456 // Try to install the extension again from an external source. It should fail |
| 456 // because of the killbit. | 457 // because of the killbit. |
| 457 EXPECT_FALSE(pending_extension_manager->AddFromExternalUpdateUrl( | 458 EXPECT_FALSE(pending_extension_manager->AddFromExternalUpdateUrl( |
| 458 kExtensionId, GURL("http://localhost/autoupdate/manifest"), | 459 kExtensionId, GURL("http://localhost/autoupdate/manifest"), |
| 459 Extension::EXTERNAL_PREF_DOWNLOAD)); | 460 Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 460 EXPECT_FALSE(pending_extension_manager->IsIdPending(kExtensionId)) | 461 EXPECT_FALSE(pending_extension_manager->IsIdPending(kExtensionId)) |
| 461 << "External reinstall of a killed extension shouldn't work."; | 462 << "External reinstall of a killed extension shouldn't work."; |
| 462 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) | 463 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) |
| 463 << "External reinstall of a killed extension should leave it killed."; | 464 << "External reinstall of a killed extension should leave it killed."; |
| 464 | 465 |
| 465 // Installing from non-external source. | 466 // Installing from non-external source. |
| 466 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 467 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| 467 | 468 |
| 468 EXPECT_FALSE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) | 469 EXPECT_FALSE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) |
| 469 << "Reinstalling should clear the kill bit."; | 470 << "Reinstalling should clear the kill bit."; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 extensions::ExternalPolicyLoader::AddExtension( | 522 extensions::ExternalPolicyLoader::AddExtension( |
| 522 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 523 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
| 523 } | 524 } |
| 524 | 525 |
| 525 // Check if the extension got installed. | 526 // Check if the extension got installed. |
| 526 ASSERT_TRUE(WaitForExtensionInstall()); | 527 ASSERT_TRUE(WaitForExtensionInstall()); |
| 527 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 528 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 528 const Extension* extension = service->GetExtensionById(kExtensionId, false); | 529 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
| 529 ASSERT_TRUE(extension); | 530 ASSERT_TRUE(extension); |
| 530 ASSERT_EQ("2.0", extension->VersionString()); | 531 ASSERT_EQ("2.0", extension->VersionString()); |
| 531 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 532 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 532 | 533 |
| 533 // Try to disable and uninstall the extension which should fail. | 534 // Try to disable and uninstall the extension which should fail. |
| 534 DisableExtension(kExtensionId); | 535 DisableExtension(kExtensionId); |
| 535 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 536 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
| 536 EXPECT_EQ(0u, service->disabled_extensions()->size()); | 537 EXPECT_EQ(0u, service->disabled_extensions()->size()); |
| 537 UninstallExtension(kExtensionId); | 538 UninstallExtension(kExtensionId); |
| 538 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 539 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
| 539 EXPECT_EQ(0u, service->disabled_extensions()->size()); | 540 EXPECT_EQ(0u, service->disabled_extensions()->size()); |
| 540 | 541 |
| 541 // Now try to disable it through the management api, again failing. | 542 // Now try to disable it through the management api, again failing. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 PrefService* prefs = browser()->profile()->GetPrefs(); | 586 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 586 const DictionaryValue* forcelist = | 587 const DictionaryValue* forcelist = |
| 587 prefs->GetDictionary(prefs::kExtensionInstallForceList); | 588 prefs->GetDictionary(prefs::kExtensionInstallForceList); |
| 588 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 589 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 589 | 590 |
| 590 // User install of the extension. | 591 // User install of the extension. |
| 591 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 592 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| 592 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 593 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 593 const Extension* extension = service->GetExtensionById(kExtensionId, false); | 594 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
| 594 ASSERT_TRUE(extension); | 595 ASSERT_TRUE(extension); |
| 595 EXPECT_EQ(Extension::INTERNAL, extension->location()); | 596 EXPECT_EQ(Manifest::INTERNAL, extension->location()); |
| 596 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 597 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 597 | 598 |
| 598 // Setup the force install policy. It should override the location. | 599 // Setup the force install policy. It should override the location. |
| 599 { | 600 { |
| 600 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 601 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
| 601 extensions::ExternalPolicyLoader::AddExtension( | 602 extensions::ExternalPolicyLoader::AddExtension( |
| 602 pref_update.Get(), kExtensionId, | 603 pref_update.Get(), kExtensionId, |
| 603 "http://localhost/autoupdate/manifest"); | 604 "http://localhost/autoupdate/manifest"); |
| 604 } | 605 } |
| 605 ASSERT_TRUE(WaitForExtensionInstall()); | 606 ASSERT_TRUE(WaitForExtensionInstall()); |
| 606 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 607 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 607 extension = service->GetExtensionById(kExtensionId, false); | 608 extension = service->GetExtensionById(kExtensionId, false); |
| 608 ASSERT_TRUE(extension); | 609 ASSERT_TRUE(extension); |
| 609 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 610 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 610 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 611 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 611 | 612 |
| 612 // Remove the policy, and verify that the extension was uninstalled. | 613 // Remove the policy, and verify that the extension was uninstalled. |
| 613 // TODO(joaodasilva): it would be nicer if the extension was kept instead, | 614 // TODO(joaodasilva): it would be nicer if the extension was kept instead, |
| 614 // and reverted location to INTERNAL or whatever it was before the policy | 615 // and reverted location to INTERNAL or whatever it was before the policy |
| 615 // was applied. | 616 // was applied. |
| 616 prefs->ClearPref(prefs::kExtensionInstallForceList); | 617 prefs->ClearPref(prefs::kExtensionInstallForceList); |
| 617 ASSERT_EQ(size_before, service->extensions()->size()); | 618 ASSERT_EQ(size_before, service->extensions()->size()); |
| 618 extension = service->GetExtensionById(kExtensionId, true); | 619 extension = service->GetExtensionById(kExtensionId, true); |
| 619 EXPECT_FALSE(extension); | 620 EXPECT_FALSE(extension); |
| 620 | 621 |
| 621 // User install again, but have it disabled too before setting the policy. | 622 // User install again, but have it disabled too before setting the policy. |
| 622 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 623 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| 623 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 624 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 624 extension = service->GetExtensionById(kExtensionId, false); | 625 extension = service->GetExtensionById(kExtensionId, false); |
| 625 ASSERT_TRUE(extension); | 626 ASSERT_TRUE(extension); |
| 626 EXPECT_EQ(Extension::INTERNAL, extension->location()); | 627 EXPECT_EQ(Manifest::INTERNAL, extension->location()); |
| 627 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 628 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 628 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 629 EXPECT_TRUE(service->disabled_extensions()->is_empty()); |
| 629 | 630 |
| 630 DisableExtension(kExtensionId); | 631 DisableExtension(kExtensionId); |
| 631 EXPECT_EQ(1u, service->disabled_extensions()->size()); | 632 EXPECT_EQ(1u, service->disabled_extensions()->size()); |
| 632 extension = service->GetExtensionById(kExtensionId, true); | 633 extension = service->GetExtensionById(kExtensionId, true); |
| 633 EXPECT_TRUE(extension); | 634 EXPECT_TRUE(extension); |
| 634 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); | 635 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); |
| 635 | 636 |
| 636 // Install the policy again. It should overwrite the extension's location, | 637 // Install the policy again. It should overwrite the extension's location, |
| 637 // and force enable it too. | 638 // and force enable it too. |
| 638 { | 639 { |
| 639 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 640 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
| 640 DictionaryValue* forcelist = pref_update.Get(); | 641 DictionaryValue* forcelist = pref_update.Get(); |
| 641 extensions::ExternalPolicyLoader::AddExtension( | 642 extensions::ExternalPolicyLoader::AddExtension( |
| 642 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 643 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
| 643 } | 644 } |
| 644 ASSERT_TRUE(WaitForExtensionInstall()); | 645 ASSERT_TRUE(WaitForExtensionInstall()); |
| 645 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 646 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 646 extension = service->GetExtensionById(kExtensionId, false); | 647 extension = service->GetExtensionById(kExtensionId, false); |
| 647 ASSERT_TRUE(extension); | 648 ASSERT_TRUE(extension); |
| 648 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 649 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 649 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 650 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 650 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 651 EXPECT_TRUE(service->disabled_extensions()->is_empty()); |
| 651 } | 652 } |
| OLD | NEW |