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

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: fix browser tests Created 6 years 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"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_enumerator.h" 13 #include "base/files/file_enumerator.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/message_loop/message_loop_proxy.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/prefs/pref_service.h" 20 #include "base/prefs/pref_service.h"
20 #include "base/run_loop.h" 21 #include "base/run_loop.h"
21 #include "base/strings/string16.h" 22 #include "base/strings/string16.h"
22 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
25 #include "base/test/test_file_util.h" 26 #include "base/test/test_file_util.h"
26 #include "base/threading/sequenced_worker_pool.h" 27 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/time/time.h" 28 #include "base/time/time.h"
28 #include "base/values.h" 29 #include "base/values.h"
29 #include "chrome/app/chrome_command_ids.h" 30 #include "chrome/app/chrome_command_ids.h"
30 #include "chrome/browser/autocomplete/autocomplete_controller.h" 31 #include "chrome/browser/autocomplete/autocomplete_controller.h"
31 #include "chrome/browser/background/background_contents_service.h" 32 #include "chrome/browser/background/background_contents_service.h"
32 #include "chrome/browser/browser_process.h" 33 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/chrome_notification_types.h" 34 #include "chrome/browser/chrome_notification_types.h"
34 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 35 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
35 #include "chrome/browser/devtools/devtools_window_testing.h" 36 #include "chrome/browser/devtools/devtools_window_testing.h"
36 #include "chrome/browser/download/download_prefs.h" 37 #include "chrome/browser/download/download_prefs.h"
37 #include "chrome/browser/extensions/api/messaging/message_service.h" 38 #include "chrome/browser/extensions/api/messaging/message_service.h"
38 #include "chrome/browser/extensions/crx_installer.h" 39 #include "chrome/browser/extensions/crx_installer.h"
39 #include "chrome/browser/extensions/extension_management_constants.h" 40 #include "chrome/browser/extensions/extension_management_constants.h"
41 #include "chrome/browser/extensions/extension_management_test_util.h"
40 #include "chrome/browser/extensions/extension_service.h" 42 #include "chrome/browser/extensions/extension_service.h"
41 #include "chrome/browser/extensions/shared_module_service.h" 43 #include "chrome/browser/extensions/shared_module_service.h"
42 #include "chrome/browser/extensions/unpacked_installer.h" 44 #include "chrome/browser/extensions/unpacked_installer.h"
43 #include "chrome/browser/extensions/updater/extension_cache_fake.h" 45 #include "chrome/browser/extensions/updater/extension_cache_fake.h"
44 #include "chrome/browser/extensions/updater/extension_updater.h" 46 #include "chrome/browser/extensions/updater/extension_updater.h"
45 #include "chrome/browser/infobars/infobar_service.h" 47 #include "chrome/browser/infobars/infobar_service.h"
46 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 48 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
47 #include "chrome/browser/media/media_stream_devices_controller.h" 49 #include "chrome/browser/media/media_stream_devices_controller.h"
48 #include "chrome/browser/metrics/variations/variations_service.h" 50 #include "chrome/browser/metrics/variations/variations_service.h"
49 #include "chrome/browser/net/prediction_options.h" 51 #include "chrome/browser/net/prediction_options.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 #include "content/public/common/process_type.h" 124 #include "content/public/common/process_type.h"
123 #include "content/public/common/result_codes.h" 125 #include "content/public/common/result_codes.h"
124 #include "content/public/common/url_constants.h" 126 #include "content/public/common/url_constants.h"
125 #include "content/public/common/webplugininfo.h" 127 #include "content/public/common/webplugininfo.h"
126 #include "content/public/test/browser_test_utils.h" 128 #include "content/public/test/browser_test_utils.h"
127 #include "content/public/test/download_test_observer.h" 129 #include "content/public/test/download_test_observer.h"
128 #include "content/public/test/mock_notification_observer.h" 130 #include "content/public/test/mock_notification_observer.h"
129 #include "content/public/test/test_navigation_observer.h" 131 #include "content/public/test/test_navigation_observer.h"
130 #include "content/public/test/test_utils.h" 132 #include "content/public/test/test_utils.h"
131 #include "extensions/browser/extension_host.h" 133 #include "extensions/browser/extension_host.h"
134 #include "extensions/browser/extension_prefs.h"
132 #include "extensions/browser/extension_registry.h" 135 #include "extensions/browser/extension_registry.h"
133 #include "extensions/browser/extension_system.h" 136 #include "extensions/browser/extension_system.h"
134 #include "extensions/browser/process_manager.h" 137 #include "extensions/browser/process_manager.h"
135 #include "extensions/browser/test_extension_registry_observer.h" 138 #include "extensions/browser/test_extension_registry_observer.h"
136 #include "extensions/browser/uninstall_reason.h" 139 #include "extensions/browser/uninstall_reason.h"
137 #include "extensions/common/constants.h" 140 #include "extensions/common/constants.h"
138 #include "extensions/common/extension.h" 141 #include "extensions/common/extension.h"
139 #include "extensions/common/extension_set.h" 142 #include "extensions/common/extension_set.h"
140 #include "extensions/common/manifest_handlers/shared_module_info.h" 143 #include "extensions/common/manifest_handlers/shared_module_info.h"
141 #include "net/base/net_errors.h" 144 #include "net/base/net_errors.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 FILE_PATH_LITERAL("hosted_app.crx"); 212 FILE_PATH_LITERAL("hosted_app.crx");
210 213
211 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 214 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
212 const char kAdBlockCrxId[] = "dojnnbeimaimaojcialkkgajdnefpgcn"; 215 const char kAdBlockCrxId[] = "dojnnbeimaimaojcialkkgajdnefpgcn";
213 const char kHostedAppCrxId[] = "kbmnembihfiondgfjekmnmcbddelicoi"; 216 const char kHostedAppCrxId[] = "kbmnembihfiondgfjekmnmcbddelicoi";
214 217
215 const base::FilePath::CharType kGood2CrxManifestName[] = 218 const base::FilePath::CharType kGood2CrxManifestName[] =
216 FILE_PATH_LITERAL("good2_update_manifest.xml"); 219 FILE_PATH_LITERAL("good2_update_manifest.xml");
217 const base::FilePath::CharType kGoodV1CrxManifestName[] = 220 const base::FilePath::CharType kGoodV1CrxManifestName[] =
218 FILE_PATH_LITERAL("good_v1_update_manifest.xml"); 221 FILE_PATH_LITERAL("good_v1_update_manifest.xml");
222 const base::FilePath::CharType kGoodV1CrxName[] =
223 FILE_PATH_LITERAL("good_v1.crx");
219 const base::FilePath::CharType kGoodUnpackedExt[] = 224 const base::FilePath::CharType kGoodUnpackedExt[] =
220 FILE_PATH_LITERAL("good_unpacked"); 225 FILE_PATH_LITERAL("good_unpacked");
221 const base::FilePath::CharType kAppUnpackedExt[] = 226 const base::FilePath::CharType kAppUnpackedExt[] =
222 FILE_PATH_LITERAL("app"); 227 FILE_PATH_LITERAL("app");
223 228
224 #if !defined(OS_MACOSX) 229 #if !defined(OS_MACOSX)
225 const base::FilePath::CharType kUnpackedFullscreenAppName[] = 230 const base::FilePath::CharType kUnpackedFullscreenAppName[] =
226 FILE_PATH_LITERAL("fullscreen_app"); 231 FILE_PATH_LITERAL("fullscreen_app");
227 #endif // !defined(OS_MACOSX) 232 #endif // !defined(OS_MACOSX)
228 233
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 observer.Wait(); 1955 observer.Wait();
1951 // Note: Cannot check that the notification details match the expected 1956 // Note: Cannot check that the notification details match the expected
1952 // exception, since the details object has already been freed prior to 1957 // exception, since the details object has already been freed prior to
1953 // the completion of observer.Wait(). 1958 // the completion of observer.Wait().
1954 1959
1955 // The first extension shouldn't be present, the second should be there. 1960 // The first extension shouldn't be present, the second should be there.
1956 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); 1961 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true));
1957 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false)); 1962 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false));
1958 } 1963 }
1959 1964
1965 // Verifies that extensions with version older than minimum version required by
1966 // policy will get disabled, and will be auto-updated and/or re-enabled upon
1967 // policy changes as well as regular auto-updater scheduled updates.
1968 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequired) {
1969 ExtensionService* service = extension_service();
1970 extensions::ExtensionRegistry* registry =
1971 extensions::ExtensionRegistry::Get(browser()->profile());
1972 extensions::ExtensionPrefs* extension_prefs =
1973 extensions::ExtensionPrefs::Get(browser()->profile());
1974
1975 // Explicitly stop the timer to avoid all scheduled extension auto-updates.
1976 service->updater()->StopTimerForTesting();
1977
1978 // Setup interceptor for extension updates.
1979 base::FilePath test_path;
1980 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path));
1981 TestRequestInterceptor interceptor(
1982 "update.extension",
1983 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
1984 interceptor.PushJobCallback(TestRequestInterceptor::BadRequestJob());
1985 interceptor.PushJobCallback(TestRequestInterceptor::FileJob(
1986 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
1987
1988 // Install the extension.
1989 ASSERT_TRUE(InstallExtension(kGoodV1CrxName));
1990 ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
1991
1992 // Update policy to set a minimum version of 1.0.0.0, the extension (with
1993 // version 1.0.0.0) should still be enabled.
1994 {
1995 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
1996 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.0");
1997 }
1998 base::RunLoop().RunUntilIdle();
1999
2000 ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
2001
2002 // Update policy to set a minimum version of 1.0.0.1, the extension (with
2003 // version 1.0.0.0) should now be disabled.
2004 ASSERT_EQ(2u, interceptor.GetPendingSize());
2005 {
2006 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2007 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1");
2008 }
2009 {
2010 // Wait until the first bad request is consumed.
2011 base::RunLoop run_loop;
2012 interceptor.AddRequestServicedCallback(base::Bind(
Joao da Silva 2014/12/03 12:25:45 This must be prepared before the policy is modifie
binjin 2014/12/03 12:40:00 Done.
2013 base::IgnoreResult(&base::MessageLoopProxy::PostTask),
2014 base::MessageLoopProxy::current(), FROM_HERE, run_loop.QuitClosure()));
2015 run_loop.Run();
2016 }
2017 ASSERT_EQ(1u, interceptor.GetPendingSize());
2018
2019 ASSERT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
2020 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
2021 extension_prefs->GetDisableReasons(kGoodCrxId));
2022
2023 // Provide a new version (1.0.0.1) which is expected to be auto updated to
2024 // via update URL in the manifest of the older version.
2025 ASSERT_EQ(1u, interceptor.GetPendingSize());
2026 {
2027 content::WindowedNotificationObserver update_observer(
2028 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2029 content::NotificationService::AllSources());
2030 service->updater()->CheckSoon();
2031 update_observer.Wait();
2032 }
2033 ASSERT_EQ(0u, interceptor.GetPendingSize());
2034
2035 // The extension should be auto-updated to newer version and re-enabled.
2036 EXPECT_EQ("1.0.0.1",
2037 service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
2038 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
2039 }
2040
2041 // Similar to ExtensionMinimumVersionRequired test, but with different settings
2042 // and orders.
2043 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequiredAlt) {
2044 ExtensionService* service = extension_service();
2045 extensions::ExtensionRegistry* registry =
2046 extensions::ExtensionRegistry::Get(browser()->profile());
2047 extensions::ExtensionPrefs* extension_prefs =
2048 extensions::ExtensionPrefs::Get(browser()->profile());
2049
2050 // Explicitly stop the timer to avoid all scheduled extension auto-updates.
2051 service->updater()->StopTimerForTesting();
2052
2053 // Setup interceptor for extension updates.
2054 base::FilePath test_path;
2055 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path));
2056 TestRequestInterceptor interceptor(
2057 "update.extension",
2058 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
2059 interceptor.PushJobCallback(TestRequestInterceptor::FileJob(
2060 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
2061
2062 // Set the policy to require an even higher minimum version this time.
2063 {
2064 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2065 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.2");
2066 }
2067 base::RunLoop().RunUntilIdle();
2068
2069 // Install the 1.0.0.0 version, it should be installed but disabled.
2070 ASSERT_TRUE(InstallExtension(kGoodV1CrxName));
2071 ASSERT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
2072 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
2073 extension_prefs->GetDisableReasons(kGoodCrxId));
2074 EXPECT_EQ("1.0.0.0",
2075 service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
2076
2077 // An extension management policy update should trigger an update as well.
2078 ASSERT_EQ(1u, interceptor.GetPendingSize());
2079 {
2080 content::WindowedNotificationObserver update_observer(
2081 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2082 content::NotificationService::AllSources());
2083 {
2084 // Set a higher minimum version, just intend to trigger an policy update.
2085 extensions::ExtensionManagementPolicyUpdater management_policy(
2086 &provider_);
2087 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.3");
2088 }
2089 base::RunLoop().RunUntilIdle();
2090 update_observer.Wait();
2091 }
2092 ASSERT_EQ(0u, interceptor.GetPendingSize());
2093
2094 // It should be updated to 1.0.0.1 but remain disabled.
2095 EXPECT_EQ("1.0.0.1",
2096 service->GetInstalledExtension(kGoodCrxId)->version()->GetString());
2097 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
2098 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
2099 extension_prefs->GetDisableReasons(kGoodCrxId));
2100
2101 // Remove the minimum version requirement, it should be re-enabled.
2102 {
2103 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2104 management_policy.UnsetMinimumVersionRequired(kGoodCrxId);
2105 }
2106 base::RunLoop().RunUntilIdle();
2107
2108 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
2109 EXPECT_FALSE(extension_prefs->HasDisableReason(
2110 kGoodCrxId, extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY));
2111 }
2112
2113 // Verifies that force installed missing the minimum version requirement is
2114 // handled well.
2115 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) {
2116 extensions::ExtensionRegistry* registry =
2117 extensions::ExtensionRegistry::Get(browser()->profile());
2118 extensions::ExtensionPrefs* extension_prefs =
2119 extensions::ExtensionPrefs::Get(browser()->profile());
2120
2121 // Prepare the update URL for force installing.
2122 base::FilePath path =
2123 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName);
2124 GURL url(URLRequestMockHTTPJob::GetMockUrl(path));
2125
2126 // Set policy to force install the extension, it should be installed and
2127 // enabled.
2128 content::WindowedNotificationObserver install_observer(
2129 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2130 content::NotificationService::AllSources());
2131 ASSERT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId));
2132 {
2133 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2134 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId,
2135 url.spec(), true);
2136 }
2137 base::RunLoop().RunUntilIdle();
2138 install_observer.Wait();
2139
2140 ASSERT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId));
2141
2142 // Set policy a minimum version of "1.0.0.1", the extension now should be
2143 // disabled.
2144 {
2145 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2146 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1");
2147 }
2148 base::RunLoop().RunUntilIdle();
2149 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId));
2150 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId));
2151 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY,
2152 extension_prefs->GetDisableReasons(kGoodCrxId));
2153 }
2154
1960 IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) { 2155 IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) {
1961 #if defined(OS_WIN) && defined(USE_ASH) 2156 #if defined(OS_WIN) && defined(USE_ASH)
1962 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 2157 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
1963 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 2158 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
1964 return; 2159 return;
1965 #endif 2160 #endif
1966 2161
1967 // Verifies that the homepage can be configured with policies. 2162 // Verifies that the homepage can be configured with policies.
1968 // Set a default, and check that the home button navigates there. 2163 // Set a default, and check that the home button navigates there.
1969 browser()->profile()->GetPrefs()->SetString( 2164 browser()->profile()->GetPrefs()->SetString(
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
3428 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 3623 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
3429 browser2->tab_strip_model()->GetActiveWebContents(), 3624 browser2->tab_strip_model()->GetActiveWebContents(),
3430 "domAutomationController.send(window.showModalDialog !== undefined);", 3625 "domAutomationController.send(window.showModalDialog !== undefined);",
3431 &result)); 3626 &result));
3432 EXPECT_TRUE(result); 3627 EXPECT_TRUE(result);
3433 } 3628 }
3434 3629
3435 #endif // !defined(CHROME_OS) 3630 #endif // !defined(CHROME_OS)
3436 3631
3437 } // namespace policy 3632 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | chrome/browser/resources/extensions/extension_list.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698