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

Side by Side 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 unified diff | Download patch
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 19 matching lines...) Expand all
30 #include "chrome/browser/autocomplete/autocomplete_controller.h" 30 #include "chrome/browser/autocomplete/autocomplete_controller.h"
31 #include "chrome/browser/background/background_contents_service.h" 31 #include "chrome/browser/background/background_contents_service.h"
32 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/chrome_notification_types.h" 33 #include "chrome/browser/chrome_notification_types.h"
34 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 34 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
35 #include "chrome/browser/devtools/devtools_window_testing.h" 35 #include "chrome/browser/devtools/devtools_window_testing.h"
36 #include "chrome/browser/download/download_prefs.h" 36 #include "chrome/browser/download/download_prefs.h"
37 #include "chrome/browser/extensions/api/messaging/message_service.h" 37 #include "chrome/browser/extensions/api/messaging/message_service.h"
38 #include "chrome/browser/extensions/crx_installer.h" 38 #include "chrome/browser/extensions/crx_installer.h"
39 #include "chrome/browser/extensions/extension_management_constants.h" 39 #include "chrome/browser/extensions/extension_management_constants.h"
40 #include "chrome/browser/extensions/extension_management_test_util.h"
40 #include "chrome/browser/extensions/extension_service.h" 41 #include "chrome/browser/extensions/extension_service.h"
41 #include "chrome/browser/extensions/shared_module_service.h" 42 #include "chrome/browser/extensions/shared_module_service.h"
42 #include "chrome/browser/extensions/unpacked_installer.h" 43 #include "chrome/browser/extensions/unpacked_installer.h"
43 #include "chrome/browser/extensions/updater/extension_cache_fake.h" 44 #include "chrome/browser/extensions/updater/extension_cache_fake.h"
44 #include "chrome/browser/extensions/updater/extension_updater.h" 45 #include "chrome/browser/extensions/updater/extension_updater.h"
45 #include "chrome/browser/infobars/infobar_service.h" 46 #include "chrome/browser/infobars/infobar_service.h"
46 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 47 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
47 #include "chrome/browser/media/media_stream_devices_controller.h" 48 #include "chrome/browser/media/media_stream_devices_controller.h"
48 #include "chrome/browser/metrics/variations/variations_service.h" 49 #include "chrome/browser/metrics/variations/variations_service.h"
49 #include "chrome/browser/net/prediction_options.h" 50 #include "chrome/browser/net/prediction_options.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 #include "content/public/common/process_type.h" 120 #include "content/public/common/process_type.h"
120 #include "content/public/common/result_codes.h" 121 #include "content/public/common/result_codes.h"
121 #include "content/public/common/url_constants.h" 122 #include "content/public/common/url_constants.h"
122 #include "content/public/common/webplugininfo.h" 123 #include "content/public/common/webplugininfo.h"
123 #include "content/public/test/browser_test_utils.h" 124 #include "content/public/test/browser_test_utils.h"
124 #include "content/public/test/download_test_observer.h" 125 #include "content/public/test/download_test_observer.h"
125 #include "content/public/test/mock_notification_observer.h" 126 #include "content/public/test/mock_notification_observer.h"
126 #include "content/public/test/test_navigation_observer.h" 127 #include "content/public/test/test_navigation_observer.h"
127 #include "content/public/test/test_utils.h" 128 #include "content/public/test/test_utils.h"
128 #include "extensions/browser/extension_host.h" 129 #include "extensions/browser/extension_host.h"
130 #include "extensions/browser/extension_prefs.h"
129 #include "extensions/browser/extension_registry.h" 131 #include "extensions/browser/extension_registry.h"
130 #include "extensions/browser/extension_system.h" 132 #include "extensions/browser/extension_system.h"
131 #include "extensions/browser/process_manager.h" 133 #include "extensions/browser/process_manager.h"
132 #include "extensions/browser/test_extension_registry_observer.h" 134 #include "extensions/browser/test_extension_registry_observer.h"
133 #include "extensions/browser/uninstall_reason.h" 135 #include "extensions/browser/uninstall_reason.h"
134 #include "extensions/common/constants.h" 136 #include "extensions/common/constants.h"
135 #include "extensions/common/extension.h" 137 #include "extensions/common/extension.h"
136 #include "extensions/common/extension_set.h" 138 #include "extensions/common/extension_set.h"
137 #include "extensions/common/manifest_handlers/shared_module_info.h" 139 #include "extensions/common/manifest_handlers/shared_module_info.h"
138 #include "net/base/net_errors.h" 140 #include "net/base/net_errors.h"
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 observer.Wait(); 1949 observer.Wait();
1948 // Note: Cannot check that the notification details match the expected 1950 // Note: Cannot check that the notification details match the expected
1949 // exception, since the details object has already been freed prior to 1951 // exception, since the details object has already been freed prior to
1950 // the completion of observer.Wait(). 1952 // the completion of observer.Wait().
1951 1953
1952 // The first extension shouldn't be present, the second should be there. 1954 // The first extension shouldn't be present, the second should be there.
1953 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); 1955 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true));
1954 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false)); 1956 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false));
1955 } 1957 }
1956 1958
1959 // Verifies that extensions with version older than minimum version required by
1960 // policy will get disabled, and will be auto-updated and/or re-enabled upon
1961 // policy changes as well as regular auto-updater scheduled updates.
1962 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequired) {
1963 ExtensionService* service = extension_service();
1964 extensions::ExtensionRegistry* registry =
1965 extensions::ExtensionRegistry::Get(browser()->profile());
1966 extensions::ExtensionPrefs* extension_prefs =
1967 extensions::ExtensionPrefs::Get(browser()->profile());
1968
1969 // Install the extension.
1970 ASSERT_TRUE(InstallExtension("good_v1.crx"));
1971 ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
1972
1973 // Update policy to set a minimum version of 1.0.0.0, the extension (with
1974 // version 1.0.0.0) should still be enabled.
1975 {
1976 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
1977 management_policy.SetMinimumVersion(kGoodCrxId, "1.0.0.0");
1978 }
1979 base::RunLoop().RunUntilIdle();
1980
1981 ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
1982
1983 // Update policy to set a minimum version of 1.0.0.1, the extension (with
1984 // version 1.0.0.0) should still be disabled.
1985 {
1986 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
1987 management_policy.SetMinimumVersion(kGoodCrxId, "1.0.0.1");
1988 }
1989 base::RunLoop().RunUntilIdle();
1990
1991 ASSERT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
1992 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
1993 extension_prefs->GetDisableReasons(kGoodCrxId));
1994
1995 // 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.
1996 // 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.
1997 base::FilePath test_path;
1998 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path));
1999 TestRequestInterceptor interceptor(
2000 "update.extension",
2001 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
2002 interceptor.PushJobCallback(TestRequestInterceptor::FileJob(
2003 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
2004 ASSERT_EQ(1u, interceptor.GetPendingSize());
2005 {
2006 content::WindowedNotificationObserver update_observer(
2007 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2008 content::NotificationService::AllSources());
2009 service->updater()->CheckSoon();
2010 update_observer.Wait();
2011 }
2012 ASSERT_EQ(0u, interceptor.GetPendingSize());
2013
2014 // The extension should be auto-updated to newer version and re-enabled.
2015 EXPECT_EQ("1.0.0.1",
2016 service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
2017 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
2018
2019 // Set the policy to require even higher minimum version.
2020 {
2021 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2022 management_policy.SetMinimumVersion(kGoodCrxId, "1.0.0.2");
2023 }
2024 base::RunLoop().RunUntilIdle();
2025
2026 // It should be disabled again.
2027 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
2028
2029 // Uninsatll the extension.
pastarmovj 2014/11/11 12:50:55 nit: Uninst_a_ll
binjin 2014/11/11 19:10:37 Done.
2030 UninstallExtension(kGoodCrxId, true);
2031
2032 // Re-install the 1.0.0.0 version, it should be installed but disabled.
2033 ASSERT_TRUE(InstallExtension("good_v1.crx"));
2034 ASSERT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
2035 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
2036 extension_prefs->GetDisableReasons(kGoodCrxId));
2037 EXPECT_EQ("1.0.0.0",
2038 service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
2039
2040 // An extension management policy update should trigger an update as well.
2041 interceptor.PushJobCallback(TestRequestInterceptor::FileJob(
2042 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
2043 ASSERT_EQ(1u, interceptor.GetPendingSize());
2044 {
2045 content::WindowedNotificationObserver update_observer(
2046 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2047 content::NotificationService::AllSources());
2048 {
2049 // Just touch to trigger an extension management policy update.
2050 extensions::ExtensionManagementPolicyUpdater management_policy(
2051 &provider_);
2052 }
2053 base::RunLoop().RunUntilIdle();
2054 update_observer.Wait();
2055 }
2056 ASSERT_EQ(0u, interceptor.GetPendingSize());
2057
2058 // It should be updated to 1.0.0.1 but remain disabled.
2059 EXPECT_EQ("1.0.0.1",
2060 service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
2061 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
2062 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
2063 extension_prefs->GetDisableReasons(kGoodCrxId));
2064 }
2065
2066 // Verifies that force installed missing the minimum version requirement is
2067 // handled well.
2068 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) {
2069 extensions::ExtensionRegistry* registry =
2070 extensions::ExtensionRegistry::Get(browser()->profile());
2071 extensions::ExtensionPrefs* extension_prefs =
2072 extensions::ExtensionPrefs::Get(browser()->profile());
2073
2074 // Prepare the update URL for force installing.
2075 base::FilePath path =
2076 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName);
2077 GURL url(URLRequestMockHTTPJob::GetMockUrl(path));
2078
2079 // Set policy to force install the extension, it should be installed and
2080 // enabled.
2081 content::WindowedNotificationObserver install_observer(
2082 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2083 content::NotificationService::AllSources());
2084 ASSERT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId));
2085 {
2086 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2087 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId,
2088 url.spec(), true);
2089 }
2090 base::RunLoop().RunUntilIdle();
2091 install_observer.Wait();
2092
2093 ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
2094
2095 // Set policy a minimum version of "1.0.0.1", the extension now should be
2096 // disabled.
2097 {
2098 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2099 management_policy.SetMinimumVersion(kGoodCrxId, "1.0.0.1");
2100 }
2101 base::RunLoop().RunUntilIdle();
2102 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId));
2103 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
2104 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
2105 extension_prefs->GetDisableReasons(kGoodCrxId));
2106 }
2107
1957 IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) { 2108 IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) {
1958 #if defined(OS_WIN) && defined(USE_ASH) 2109 #if defined(OS_WIN) && defined(USE_ASH)
1959 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 2110 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
1960 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 2111 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
1961 return; 2112 return;
1962 #endif 2113 #endif
1963 2114
1964 // Verifies that the homepage can be configured with policies. 2115 // Verifies that the homepage can be configured with policies.
1965 // Set a default, and check that the home button navigates there. 2116 // Set a default, and check that the home button navigates there.
1966 browser()->profile()->GetPrefs()->SetString( 2117 browser()->profile()->GetPrefs()->SetString(
(...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after
3426 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 3577 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
3427 browser2->tab_strip_model()->GetActiveWebContents(), 3578 browser2->tab_strip_model()->GetActiveWebContents(),
3428 "domAutomationController.send(window.showModalDialog !== undefined);", 3579 "domAutomationController.send(window.showModalDialog !== undefined);",
3429 &result)); 3580 &result));
3430 EXPECT_TRUE(result); 3581 EXPECT_TRUE(result);
3431 } 3582 }
3432 3583
3433 #endif // !defined(CHROME_OS) 3584 #endif // !defined(CHROME_OS)
3434 3585
3435 } // namespace policy 3586 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698