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