Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Unified Diff: chrome/browser/policy/policy_browsertest.cc

Issue 706623004: Add minimum version to extension management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-update-url
Patch Set: WIP Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/policy_browsertest.cc
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index 6aa46a90c6ec0d32891b7b3da81641f7495c271e..231fa63e243c66e1a1a1f4b9af3e4679ea688b8c 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/extensions/api/messaging/message_service.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_management_constants.h"
+#include "chrome/browser/extensions/extension_management_test_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/shared_module_service.h"
#include "chrome/browser/extensions/unpacked_installer.h"
@@ -126,6 +127,7 @@
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_host.h"
+#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
@@ -1954,6 +1956,155 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallSources) {
EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false));
}
+// Verifies that extensions with version older than minimum version required by
+// policy will get disabled, and will be auto-updated and/or re-enabled upon
+// policy changes as well as regular auto-updater scheduled updates.
+IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequired) {
+ ExtensionService* service = extension_service();
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(browser()->profile());
+ extensions::ExtensionPrefs* extension_prefs =
+ extensions::ExtensionPrefs::Get(browser()->profile());
+
+ // Install the extension.
+ ASSERT_TRUE(InstallExtension("good_v1.crx"));
+ ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
+
+ // Update policy to set a minimum version of 1.0.0.0, the extension (with
+ // version 1.0.0.0) should still be enabled.
+ {
+ extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
+ management_policy.SetMinimumVersion(kGoodCrxId, "1.0.0.0");
+ }
+ base::RunLoop().RunUntilIdle();
+
+ ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
+
+ // Update policy to set a minimum version of 1.0.0.1, the extension (with
+ // version 1.0.0.0) should still be disabled.
+ {
+ extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
+ management_policy.SetMinimumVersion(kGoodCrxId, "1.0.0.1");
+ }
+ base::RunLoop().RunUntilIdle();
+
+ ASSERT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
+ EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
+ extension_prefs->GetDisableReasons(kGoodCrxId));
+
+ // Provide a new version (1.0.0.1) which are expect to be auto updated to
pastarmovj 2014/11/11 12:50:55 s/are expect/is expected/
binjin 2014/11/11 19:10:37 Done.
+ // via update URL in manifest of older version.
pastarmovj 2014/11/11 12:50:55 nit: _the_ manifest and _the_ older version
binjin 2014/11/11 19:10:37 Done.
+ base::FilePath test_path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path));
+ TestRequestInterceptor interceptor(
+ "update.extension",
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
+ interceptor.PushJobCallback(TestRequestInterceptor::FileJob(
+ test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
+ ASSERT_EQ(1u, interceptor.GetPendingSize());
+ {
+ content::WindowedNotificationObserver update_observer(
+ extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
+ content::NotificationService::AllSources());
+ service->updater()->CheckSoon();
+ update_observer.Wait();
+ }
+ ASSERT_EQ(0u, interceptor.GetPendingSize());
+
+ // The extension should be auto-updated to newer version and re-enabled.
+ EXPECT_EQ("1.0.0.1",
+ service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
+ EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
+
+ // Set the policy to require even higher minimum version.
+ {
+ extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
+ management_policy.SetMinimumVersion(kGoodCrxId, "1.0.0.2");
+ }
+ base::RunLoop().RunUntilIdle();
+
+ // It should be disabled again.
+ EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
+
+ // Uninsatll the extension.
pastarmovj 2014/11/11 12:50:55 nit: Uninst_a_ll
binjin 2014/11/11 19:10:37 Done.
+ UninstallExtension(kGoodCrxId, true);
+
+ // Re-install the 1.0.0.0 version, it should be installed but disabled.
+ ASSERT_TRUE(InstallExtension("good_v1.crx"));
+ ASSERT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
+ EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
+ extension_prefs->GetDisableReasons(kGoodCrxId));
+ EXPECT_EQ("1.0.0.0",
+ service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
+
+ // An extension management policy update should trigger an update as well.
+ interceptor.PushJobCallback(TestRequestInterceptor::FileJob(
+ test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
+ ASSERT_EQ(1u, interceptor.GetPendingSize());
+ {
+ content::WindowedNotificationObserver update_observer(
+ extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
+ content::NotificationService::AllSources());
+ {
+ // Just touch to trigger an extension management policy update.
+ extensions::ExtensionManagementPolicyUpdater management_policy(
+ &provider_);
+ }
+ base::RunLoop().RunUntilIdle();
+ update_observer.Wait();
+ }
+ ASSERT_EQ(0u, interceptor.GetPendingSize());
+
+ // It should be updated to 1.0.0.1 but remain disabled.
+ EXPECT_EQ("1.0.0.1",
+ service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
+ EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
+ EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
+ extension_prefs->GetDisableReasons(kGoodCrxId));
+}
+
+// Verifies that force installed missing the minimum version requirement is
+// handled well.
+IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) {
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(browser()->profile());
+ extensions::ExtensionPrefs* extension_prefs =
+ extensions::ExtensionPrefs::Get(browser()->profile());
+
+ // Prepare the update URL for force installing.
+ base::FilePath path =
+ base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName);
+ GURL url(URLRequestMockHTTPJob::GetMockUrl(path));
+
+ // Set policy to force install the extension, it should be installed and
+ // enabled.
+ content::WindowedNotificationObserver install_observer(
+ extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
+ content::NotificationService::AllSources());
+ ASSERT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId));
+ {
+ extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
+ management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId,
+ url.spec(), true);
+ }
+ base::RunLoop().RunUntilIdle();
+ install_observer.Wait();
+
+ ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
+
+ // Set policy a minimum version of "1.0.0.1", the extension now should be
+ // disabled.
+ {
+ extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
+ management_policy.SetMinimumVersion(kGoodCrxId, "1.0.0.1");
+ }
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId));
+ EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
+ EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
+ extension_prefs->GetDisableReasons(kGoodCrxId));
+}
+
IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) {
#if defined(OS_WIN) && defined(USE_ASH)
// Disable this test in Metro+Ash for now (http://crbug.com/262796).

Powered by Google App Engine
This is Rietveld 408576698