Chromium Code Reviews| Index: chrome/browser/policy/policy_browsertest.cc |
| diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc |
| index 5e9dd5e9933cefeacb47c9ee523deb723945eced..8e38436574558c7b03c9099155d403d6116a917a 100644 |
| --- a/chrome/browser/policy/policy_browsertest.cc |
| +++ b/chrome/browser/policy/policy_browsertest.cc |
| @@ -15,6 +15,7 @@ |
| #include "base/files/file_util.h" |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
|
bartfab (slow)
2014/12/04 13:53:01
Nit: You do not need this include. You never deref
binjin
2014/12/04 15:43:15
Done. It's needed in previous patchset and I forge
|
| #include "base/path_service.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/run_loop.h" |
| @@ -37,6 +38,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" |
| @@ -129,6 +131,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" |
| @@ -216,6 +219,8 @@ const base::FilePath::CharType kGood2CrxManifestName[] = |
| FILE_PATH_LITERAL("good2_update_manifest.xml"); |
| const base::FilePath::CharType kGoodV1CrxManifestName[] = |
| FILE_PATH_LITERAL("good_v1_update_manifest.xml"); |
| +const base::FilePath::CharType kGoodV1CrxName[] = |
| + FILE_PATH_LITERAL("good_v1.crx"); |
| const base::FilePath::CharType kGoodUnpackedExt[] = |
| FILE_PATH_LITERAL("good_unpacked"); |
| const base::FilePath::CharType kAppUnpackedExt[] = |
| @@ -1957,6 +1962,192 @@ 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 |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/than/than the/
binjin
2014/12/04 15:43:15
Done.
|
| +// 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()); |
| + |
| + // Explicitly stop the timer to avoid all scheduled extension auto-updates. |
| + service->updater()->StopTimerForTesting(); |
| + |
| + // Setup interceptor for extension updates. |
| + 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::BadRequestJob()); |
| + interceptor.PushJobCallback(TestRequestInterceptor::FileJob( |
| + test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName))); |
| + |
| + // Install the extension. |
| + ASSERT_TRUE(InstallExtension(kGoodV1CrxName)); |
|
bartfab (slow)
2014/12/04 13:53:01
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:14
Done.
|
| + ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + |
| + // 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.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.0"); |
| + } |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + |
| + // Update policy to set a minimum version of 1.0.0.1, the extension (with |
| + // version 1.0.0.0) should now be disabled. |
| + ASSERT_EQ(2u, interceptor.GetPendingSize()); |
|
bartfab (slow)
2014/12/04 13:53:01
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + base::RunLoop service_request_run_loop; |
| + interceptor.AddRequestServicedCallback( |
| + service_request_run_loop.QuitClosure()); |
| + { |
| + extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| + management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1"); |
| + } |
| + service_request_run_loop.Run(); |
| + ASSERT_EQ(1u, interceptor.GetPendingSize()); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + |
| + ASSERT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
|
bartfab (slow)
2014/12/04 13:53:01
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
| + extension_prefs->GetDisableReasons(kGoodCrxId)); |
| + |
| + // Provide a new version (1.0.0.1) which is expected to be auto updated to |
| + // via update URL in the manifest of the older version. |
|
bartfab (slow)
2014/12/04 13:53:01
Nit: s/via/via the/
binjin
2014/12/04 15:43:15
Done.
|
| + ASSERT_EQ(1u, interceptor.GetPendingSize()); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + { |
| + 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()); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + |
| + // 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)); |
| +} |
| + |
| +// Similar to ExtensionMinimumVersionRequired test, but with different settings |
| +// and orders. |
| +IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequiredAlt) { |
| + ExtensionService* service = extension_service(); |
| + extensions::ExtensionRegistry* registry = |
| + extensions::ExtensionRegistry::Get(browser()->profile()); |
| + extensions::ExtensionPrefs* extension_prefs = |
| + extensions::ExtensionPrefs::Get(browser()->profile()); |
| + |
| + // Explicitly stop the timer to avoid all scheduled extension auto-updates. |
| + service->updater()->StopTimerForTesting(); |
| + |
| + // Setup interceptor for extension updates. |
| + 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))); |
| + |
| + // Set the policy to require an even higher minimum version this time. |
| + { |
| + extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| + management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.2"); |
| + } |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Install the 1.0.0.0 version, it should be installed but disabled. |
| + ASSERT_TRUE(InstallExtension(kGoodV1CrxName)); |
|
bartfab (slow)
2014/12/04 13:53:01
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + ASSERT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:14
Done.
|
| + 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. |
| + ASSERT_EQ(1u, interceptor.GetPendingSize()); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
|
| + { |
| + content::WindowedNotificationObserver update_observer( |
| + extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| + content::NotificationService::AllSources()); |
| + { |
| + // Set a higher minimum version, just intend to trigger an policy update. |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/an/a/
binjin
2014/12/04 15:43:14
Done.
|
| + extensions::ExtensionManagementPolicyUpdater management_policy( |
| + &provider_); |
| + management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.3"); |
| + } |
| + base::RunLoop().RunUntilIdle(); |
| + update_observer.Wait(); |
| + } |
| + ASSERT_EQ(0u, interceptor.GetPendingSize()); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:14
Done.
|
| + |
| + // 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)); |
| + |
| + // Remove the minimum version requirement, it should be re-enabled. |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/, it/. The extension/
binjin
2014/12/04 15:43:15
Done.
|
| + { |
| + extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| + management_policy.UnsetMinimumVersionRequired(kGoodCrxId); |
| + } |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| + EXPECT_FALSE(extension_prefs->HasDisableReason( |
| + kGoodCrxId, extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)); |
| +} |
| + |
| +// Verifies that force installed missing the minimum version requirement is |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/force installed missing the/a force-install
|
| +// 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 = |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: const.
binjin
2014/12/04 15:43:14
Done.
|
| + base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
| + GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: const.
binjin
2014/12/04 15:43:15
Done.
|
| + |
| + // Set policy to force install the extension, it should be installed and |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/force /force-/
binjin
2014/12/04 15:43:15
Done.
|
| + // enabled. |
| + content::WindowedNotificationObserver install_observer( |
| + extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| + content::NotificationService::AllSources()); |
| + ASSERT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:15
Done.
binjin
2014/12/04 15:43:15
Done.
|
| + { |
| + 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)); |
|
bartfab (slow)
2014/12/04 13:53:00
Nit: s/ASSERT/EXPECT/
binjin
2014/12/04 15:43:14
Done.
|
| + |
| + // Set policy a minimum version of "1.0.0.1", the extension now should be |
| + // disabled. |
| + { |
| + extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| + management_policy.SetMinimumVersionRequired(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). |