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 <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 Loading... |
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 #include "content/public/common/process_type.h" | 123 #include "content/public/common/process_type.h" |
123 #include "content/public/common/result_codes.h" | 124 #include "content/public/common/result_codes.h" |
124 #include "content/public/common/url_constants.h" | 125 #include "content/public/common/url_constants.h" |
125 #include "content/public/common/webplugininfo.h" | 126 #include "content/public/common/webplugininfo.h" |
126 #include "content/public/test/browser_test_utils.h" | 127 #include "content/public/test/browser_test_utils.h" |
127 #include "content/public/test/download_test_observer.h" | 128 #include "content/public/test/download_test_observer.h" |
128 #include "content/public/test/mock_notification_observer.h" | 129 #include "content/public/test/mock_notification_observer.h" |
129 #include "content/public/test/test_navigation_observer.h" | 130 #include "content/public/test/test_navigation_observer.h" |
130 #include "content/public/test/test_utils.h" | 131 #include "content/public/test/test_utils.h" |
131 #include "extensions/browser/extension_host.h" | 132 #include "extensions/browser/extension_host.h" |
| 133 #include "extensions/browser/extension_prefs.h" |
132 #include "extensions/browser/extension_registry.h" | 134 #include "extensions/browser/extension_registry.h" |
133 #include "extensions/browser/extension_system.h" | 135 #include "extensions/browser/extension_system.h" |
134 #include "extensions/browser/process_manager.h" | 136 #include "extensions/browser/process_manager.h" |
135 #include "extensions/browser/test_extension_registry_observer.h" | 137 #include "extensions/browser/test_extension_registry_observer.h" |
136 #include "extensions/browser/uninstall_reason.h" | 138 #include "extensions/browser/uninstall_reason.h" |
137 #include "extensions/common/constants.h" | 139 #include "extensions/common/constants.h" |
138 #include "extensions/common/extension.h" | 140 #include "extensions/common/extension.h" |
139 #include "extensions/common/extension_set.h" | 141 #include "extensions/common/extension_set.h" |
140 #include "extensions/common/manifest_handlers/shared_module_info.h" | 142 #include "extensions/common/manifest_handlers/shared_module_info.h" |
141 #include "net/base/net_errors.h" | 143 #include "net/base/net_errors.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 FILE_PATH_LITERAL("hosted_app.crx"); | 211 FILE_PATH_LITERAL("hosted_app.crx"); |
210 | 212 |
211 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 213 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
212 const char kAdBlockCrxId[] = "dojnnbeimaimaojcialkkgajdnefpgcn"; | 214 const char kAdBlockCrxId[] = "dojnnbeimaimaojcialkkgajdnefpgcn"; |
213 const char kHostedAppCrxId[] = "kbmnembihfiondgfjekmnmcbddelicoi"; | 215 const char kHostedAppCrxId[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
214 | 216 |
215 const base::FilePath::CharType kGood2CrxManifestName[] = | 217 const base::FilePath::CharType kGood2CrxManifestName[] = |
216 FILE_PATH_LITERAL("good2_update_manifest.xml"); | 218 FILE_PATH_LITERAL("good2_update_manifest.xml"); |
217 const base::FilePath::CharType kGoodV1CrxManifestName[] = | 219 const base::FilePath::CharType kGoodV1CrxManifestName[] = |
218 FILE_PATH_LITERAL("good_v1_update_manifest.xml"); | 220 FILE_PATH_LITERAL("good_v1_update_manifest.xml"); |
| 221 const base::FilePath::CharType kGoodV1CrxName[] = |
| 222 FILE_PATH_LITERAL("good_v1.crx"); |
219 const base::FilePath::CharType kGoodUnpackedExt[] = | 223 const base::FilePath::CharType kGoodUnpackedExt[] = |
220 FILE_PATH_LITERAL("good_unpacked"); | 224 FILE_PATH_LITERAL("good_unpacked"); |
221 const base::FilePath::CharType kAppUnpackedExt[] = | 225 const base::FilePath::CharType kAppUnpackedExt[] = |
222 FILE_PATH_LITERAL("app"); | 226 FILE_PATH_LITERAL("app"); |
223 | 227 |
224 #if !defined(OS_MACOSX) | 228 #if !defined(OS_MACOSX) |
225 const base::FilePath::CharType kUnpackedFullscreenAppName[] = | 229 const base::FilePath::CharType kUnpackedFullscreenAppName[] = |
226 FILE_PATH_LITERAL("fullscreen_app"); | 230 FILE_PATH_LITERAL("fullscreen_app"); |
227 #endif // !defined(OS_MACOSX) | 231 #endif // !defined(OS_MACOSX) |
228 | 232 |
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 observer.Wait(); | 1954 observer.Wait(); |
1951 // Note: Cannot check that the notification details match the expected | 1955 // Note: Cannot check that the notification details match the expected |
1952 // exception, since the details object has already been freed prior to | 1956 // exception, since the details object has already been freed prior to |
1953 // the completion of observer.Wait(). | 1957 // the completion of observer.Wait(). |
1954 | 1958 |
1955 // The first extension shouldn't be present, the second should be there. | 1959 // The first extension shouldn't be present, the second should be there. |
1956 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); | 1960 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); |
1957 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false)); | 1961 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false)); |
1958 } | 1962 } |
1959 | 1963 |
| 1964 // Verifies that extensions with version older than the minimum version required |
| 1965 // by policy will get disabled, and will be auto-updated and/or re-enabled upon |
| 1966 // policy changes as well as regular auto-updater scheduled updates. |
| 1967 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequired) { |
| 1968 ExtensionService* service = extension_service(); |
| 1969 extensions::ExtensionRegistry* registry = |
| 1970 extensions::ExtensionRegistry::Get(browser()->profile()); |
| 1971 extensions::ExtensionPrefs* extension_prefs = |
| 1972 extensions::ExtensionPrefs::Get(browser()->profile()); |
| 1973 |
| 1974 // Explicitly stop the timer to avoid all scheduled extension auto-updates. |
| 1975 service->updater()->StopTimerForTesting(); |
| 1976 |
| 1977 // Setup interceptor for extension updates. |
| 1978 base::FilePath test_path; |
| 1979 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path)); |
| 1980 TestRequestInterceptor interceptor( |
| 1981 "update.extension", |
| 1982 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 1983 interceptor.PushJobCallback(TestRequestInterceptor::BadRequestJob()); |
| 1984 interceptor.PushJobCallback(TestRequestInterceptor::FileJob( |
| 1985 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName))); |
| 1986 |
| 1987 // Install the extension. |
| 1988 EXPECT_TRUE(InstallExtension(kGoodV1CrxName)); |
| 1989 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 1990 |
| 1991 // Update policy to set a minimum version of 1.0.0.0, the extension (with |
| 1992 // version 1.0.0.0) should still be enabled. |
| 1993 { |
| 1994 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 1995 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.0"); |
| 1996 } |
| 1997 base::RunLoop().RunUntilIdle(); |
| 1998 |
| 1999 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2000 |
| 2001 // Update policy to set a minimum version of 1.0.0.1, the extension (with |
| 2002 // version 1.0.0.0) should now be disabled. |
| 2003 EXPECT_EQ(2u, interceptor.GetPendingSize()); |
| 2004 base::RunLoop service_request_run_loop; |
| 2005 interceptor.AddRequestServicedCallback( |
| 2006 service_request_run_loop.QuitClosure()); |
| 2007 { |
| 2008 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2009 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1"); |
| 2010 } |
| 2011 service_request_run_loop.Run(); |
| 2012 EXPECT_EQ(1u, interceptor.GetPendingSize()); |
| 2013 |
| 2014 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
| 2015 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
| 2016 extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 2017 |
| 2018 // Provide a new version (1.0.0.1) which is expected to be auto updated to |
| 2019 // via the update URL in the manifest of the older version. |
| 2020 EXPECT_EQ(1u, interceptor.GetPendingSize()); |
| 2021 { |
| 2022 content::WindowedNotificationObserver update_observer( |
| 2023 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 2024 content::NotificationService::AllSources()); |
| 2025 service->updater()->CheckSoon(); |
| 2026 update_observer.Wait(); |
| 2027 } |
| 2028 EXPECT_EQ(0u, interceptor.GetPendingSize()); |
| 2029 |
| 2030 // The extension should be auto-updated to newer version and re-enabled. |
| 2031 EXPECT_EQ("1.0.0.1", |
| 2032 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); |
| 2033 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2034 } |
| 2035 |
| 2036 // Similar to ExtensionMinimumVersionRequired test, but with different settings |
| 2037 // and orders. |
| 2038 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequiredAlt) { |
| 2039 ExtensionService* service = extension_service(); |
| 2040 extensions::ExtensionRegistry* registry = |
| 2041 extensions::ExtensionRegistry::Get(browser()->profile()); |
| 2042 extensions::ExtensionPrefs* extension_prefs = |
| 2043 extensions::ExtensionPrefs::Get(browser()->profile()); |
| 2044 |
| 2045 // Explicitly stop the timer to avoid all scheduled extension auto-updates. |
| 2046 service->updater()->StopTimerForTesting(); |
| 2047 |
| 2048 // Setup interceptor for extension updates. |
| 2049 base::FilePath test_path; |
| 2050 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path)); |
| 2051 TestRequestInterceptor interceptor( |
| 2052 "update.extension", |
| 2053 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 2054 interceptor.PushJobCallback(TestRequestInterceptor::FileJob( |
| 2055 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName))); |
| 2056 |
| 2057 // Set the policy to require an even higher minimum version this time. |
| 2058 { |
| 2059 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2060 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.2"); |
| 2061 } |
| 2062 base::RunLoop().RunUntilIdle(); |
| 2063 |
| 2064 // Install the 1.0.0.0 version, it should be installed but disabled. |
| 2065 EXPECT_TRUE(InstallExtension(kGoodV1CrxName)); |
| 2066 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
| 2067 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
| 2068 extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 2069 EXPECT_EQ("1.0.0.0", |
| 2070 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); |
| 2071 |
| 2072 // An extension management policy update should trigger an update as well. |
| 2073 EXPECT_EQ(1u, interceptor.GetPendingSize()); |
| 2074 { |
| 2075 content::WindowedNotificationObserver update_observer( |
| 2076 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 2077 content::NotificationService::AllSources()); |
| 2078 { |
| 2079 // Set a higher minimum version, just intend to trigger a policy update. |
| 2080 extensions::ExtensionManagementPolicyUpdater management_policy( |
| 2081 &provider_); |
| 2082 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.3"); |
| 2083 } |
| 2084 base::RunLoop().RunUntilIdle(); |
| 2085 update_observer.Wait(); |
| 2086 } |
| 2087 EXPECT_EQ(0u, interceptor.GetPendingSize()); |
| 2088 |
| 2089 // It should be updated to 1.0.0.1 but remain disabled. |
| 2090 EXPECT_EQ("1.0.0.1", |
| 2091 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); |
| 2092 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
| 2093 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
| 2094 extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 2095 |
| 2096 // Remove the minimum version requirement. The extension should be re-enabled. |
| 2097 { |
| 2098 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2099 management_policy.UnsetMinimumVersionRequired(kGoodCrxId); |
| 2100 } |
| 2101 base::RunLoop().RunUntilIdle(); |
| 2102 |
| 2103 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2104 EXPECT_FALSE(extension_prefs->HasDisableReason( |
| 2105 kGoodCrxId, extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)); |
| 2106 } |
| 2107 |
| 2108 // Verifies that a force-installed extension which does not meet a subsequently |
| 2109 // set minimum version requirement is handled well. |
| 2110 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) { |
| 2111 extensions::ExtensionRegistry* registry = |
| 2112 extensions::ExtensionRegistry::Get(browser()->profile()); |
| 2113 extensions::ExtensionPrefs* extension_prefs = |
| 2114 extensions::ExtensionPrefs::Get(browser()->profile()); |
| 2115 |
| 2116 // Prepare the update URL for force installing. |
| 2117 const base::FilePath path = |
| 2118 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
| 2119 const GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
| 2120 |
| 2121 // Set policy to force-install the extension, it should be installed and |
| 2122 // enabled. |
| 2123 content::WindowedNotificationObserver install_observer( |
| 2124 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 2125 content::NotificationService::AllSources()); |
| 2126 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2127 { |
| 2128 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2129 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId, |
| 2130 url.spec(), true); |
| 2131 } |
| 2132 base::RunLoop().RunUntilIdle(); |
| 2133 install_observer.Wait(); |
| 2134 |
| 2135 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2136 |
| 2137 // Set policy a minimum version of "1.0.0.1", the extension now should be |
| 2138 // disabled. |
| 2139 { |
| 2140 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2141 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1"); |
| 2142 } |
| 2143 base::RunLoop().RunUntilIdle(); |
| 2144 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2145 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
| 2146 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
| 2147 extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 2148 } |
| 2149 |
1960 IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) { | 2150 IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) { |
1961 #if defined(OS_WIN) && defined(USE_ASH) | 2151 #if defined(OS_WIN) && defined(USE_ASH) |
1962 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 2152 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
1963 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 2153 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
1964 return; | 2154 return; |
1965 #endif | 2155 #endif |
1966 | 2156 |
1967 // Verifies that the homepage can be configured with policies. | 2157 // Verifies that the homepage can be configured with policies. |
1968 // Set a default, and check that the home button navigates there. | 2158 // Set a default, and check that the home button navigates there. |
1969 browser()->profile()->GetPrefs()->SetString( | 2159 browser()->profile()->GetPrefs()->SetString( |
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3428 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 3618 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
3429 browser2->tab_strip_model()->GetActiveWebContents(), | 3619 browser2->tab_strip_model()->GetActiveWebContents(), |
3430 "domAutomationController.send(window.showModalDialog !== undefined);", | 3620 "domAutomationController.send(window.showModalDialog !== undefined);", |
3431 &result)); | 3621 &result)); |
3432 EXPECT_TRUE(result); | 3622 EXPECT_TRUE(result); |
3433 } | 3623 } |
3434 | 3624 |
3435 #endif // !defined(CHROME_OS) | 3625 #endif // !defined(CHROME_OS) |
3436 | 3626 |
3437 } // namespace policy | 3627 } // namespace policy |
OLD | NEW |