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