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 "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | 1831 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
1832 | 1832 |
1833 // Setting the forcelist extension should install "good_v1.crx". | 1833 // Setting the forcelist extension should install "good_v1.crx". |
1834 base::ListValue forcelist; | 1834 base::ListValue forcelist; |
1835 forcelist.Append(new base::StringValue( | 1835 forcelist.Append(new base::StringValue( |
1836 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str()))); | 1836 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str()))); |
1837 PolicyMap policies; | 1837 PolicyMap policies; |
1838 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, | 1838 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
1839 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, forcelist.DeepCopy(), | 1839 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, forcelist.DeepCopy(), |
1840 nullptr); | 1840 nullptr); |
1841 content::WindowedNotificationObserver observer( | 1841 extensions::TestExtensionRegistryObserver observer( |
1842 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 1842 extensions::ExtensionRegistry::Get(browser()->profile())); |
1843 content::NotificationService::AllSources()); | |
1844 UpdateProviderPolicy(policies); | 1843 UpdateProviderPolicy(policies); |
1845 observer.Wait(); | 1844 observer.WaitForExtensionWillBeInstalled(); |
1846 // Note: Cannot check that the notification details match the expected | 1845 // Note: Cannot check that the notification details match the expected |
1847 // exception, since the details object has already been freed prior to | 1846 // exception, since the details object has already been freed prior to |
1848 // the completion of observer.Wait(). | 1847 // the completion of observer.WaitForExtensionWillBeInstalled(). |
1849 | 1848 |
1850 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); | 1849 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); |
1851 | 1850 |
1852 // The user is not allowed to uninstall force-installed extensions. | 1851 // The user is not allowed to uninstall force-installed extensions. |
1853 UninstallExtension(kGoodCrxId, false); | 1852 UninstallExtension(kGoodCrxId, false); |
1854 | 1853 |
1855 // The user is not allowed to load an unpacked extension with the | 1854 // The user is not allowed to load an unpacked extension with the |
1856 // same ID as a force-installed extension. | 1855 // same ID as a force-installed extension. |
1857 LoadUnpackedExtension(kGoodUnpackedExt, false); | 1856 LoadUnpackedExtension(kGoodUnpackedExt, false); |
1858 | 1857 |
(...skipping 10 matching lines...) Expand all Loading... |
1869 "update.extension", | 1868 "update.extension", |
1870 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1869 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
1871 interceptor.PushJobCallback( | 1870 interceptor.PushJobCallback( |
1872 TestRequestInterceptor::FileJob( | 1871 TestRequestInterceptor::FileJob( |
1873 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName))); | 1872 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName))); |
1874 | 1873 |
1875 // Updating the force-installed extension. | 1874 // Updating the force-installed extension. |
1876 extensions::ExtensionUpdater* updater = service->updater(); | 1875 extensions::ExtensionUpdater* updater = service->updater(); |
1877 extensions::ExtensionUpdater::CheckParams params; | 1876 extensions::ExtensionUpdater::CheckParams params; |
1878 params.install_immediately = true; | 1877 params.install_immediately = true; |
1879 content::WindowedNotificationObserver update_observer( | 1878 extensions::TestExtensionRegistryObserver update_observer( |
1880 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 1879 extensions::ExtensionRegistry::Get(browser()->profile())); |
1881 content::NotificationService::AllSources()); | |
1882 updater->CheckNow(params); | 1880 updater->CheckNow(params); |
1883 update_observer.Wait(); | 1881 update_observer.WaitForExtensionWillBeInstalled(); |
1884 | 1882 |
1885 const base::Version* new_version = | 1883 const base::Version* new_version = |
1886 service->GetExtensionById(kGoodCrxId, true)->version(); | 1884 service->GetExtensionById(kGoodCrxId, true)->version(); |
1887 ASSERT_TRUE(new_version->IsValid()); | 1885 ASSERT_TRUE(new_version->IsValid()); |
1888 base::Version old_version(old_version_number); | 1886 base::Version old_version(old_version_number); |
1889 ASSERT_TRUE(old_version.IsValid()); | 1887 ASSERT_TRUE(old_version.IsValid()); |
1890 | 1888 |
1891 EXPECT_EQ(1, new_version->CompareTo(old_version)); | 1889 EXPECT_EQ(1, new_version->CompareTo(old_version)); |
1892 | 1890 |
1893 EXPECT_EQ(0u, interceptor.GetPendingSize()); | 1891 EXPECT_EQ(0u, interceptor.GetPendingSize()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 dict_value.SetString( | 1950 dict_value.SetString( |
1953 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl, | 1951 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl, |
1954 url.spec()); | 1952 url.spec()); |
1955 PolicyMap policies; | 1953 PolicyMap policies; |
1956 policies.Set(key::kExtensionSettings, | 1954 policies.Set(key::kExtensionSettings, |
1957 POLICY_LEVEL_MANDATORY, | 1955 POLICY_LEVEL_MANDATORY, |
1958 POLICY_SCOPE_USER, | 1956 POLICY_SCOPE_USER, |
1959 POLICY_SOURCE_CLOUD, | 1957 POLICY_SOURCE_CLOUD, |
1960 dict_value.DeepCopy(), | 1958 dict_value.DeepCopy(), |
1961 NULL); | 1959 NULL); |
1962 content::WindowedNotificationObserver observer( | 1960 extensions::TestExtensionRegistryObserver observer( |
1963 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 1961 extensions::ExtensionRegistry::Get(browser()->profile())); |
1964 content::NotificationService::AllSources()); | |
1965 UpdateProviderPolicy(policies); | 1962 UpdateProviderPolicy(policies); |
1966 observer.Wait(); | 1963 observer.WaitForExtensionWillBeInstalled(); |
1967 | 1964 |
1968 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); | 1965 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); |
1969 | 1966 |
1970 // The user is not allowed to uninstall recommended-installed extensions. | 1967 // The user is not allowed to uninstall recommended-installed extensions. |
1971 UninstallExtension(kGoodCrxId, false); | 1968 UninstallExtension(kGoodCrxId, false); |
1972 | 1969 |
1973 // Explictly re-enables the extension. | 1970 // Explictly re-enables the extension. |
1974 service->EnableExtension(kGoodCrxId); | 1971 service->EnableExtension(kGoodCrxId); |
1975 | 1972 |
1976 // But the user is allowed to disable them. | 1973 // But the user is allowed to disable them. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 // Install the policy and trigger another download. | 2043 // Install the policy and trigger another download. |
2047 base::ListValue install_sources; | 2044 base::ListValue install_sources; |
2048 install_sources.AppendString(install_source_url.spec()); | 2045 install_sources.AppendString(install_source_url.spec()); |
2049 install_sources.AppendString(referrer_url.spec()); | 2046 install_sources.AppendString(referrer_url.spec()); |
2050 PolicyMap policies; | 2047 PolicyMap policies; |
2051 policies.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY, | 2048 policies.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY, |
2052 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 2049 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
2053 install_sources.DeepCopy(), nullptr); | 2050 install_sources.DeepCopy(), nullptr); |
2054 UpdateProviderPolicy(policies); | 2051 UpdateProviderPolicy(policies); |
2055 | 2052 |
2056 content::WindowedNotificationObserver observer( | 2053 extensions::TestExtensionRegistryObserver observer( |
2057 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 2054 extensions::ExtensionRegistry::Get(browser()->profile())); |
2058 content::NotificationService::AllSources()); | |
2059 PerformClick(1, 0); | 2055 PerformClick(1, 0); |
2060 observer.Wait(); | 2056 observer.WaitForExtensionWillBeInstalled(); |
2061 // Note: Cannot check that the notification details match the expected | 2057 // Note: Cannot check that the notification details match the expected |
2062 // exception, since the details object has already been freed prior to | 2058 // exception, since the details object has already been freed prior to |
2063 // the completion of observer.Wait(). | 2059 // the completion of observer.WaitForExtensionWillBeInstalled(). |
2064 | 2060 |
2065 // The first extension shouldn't be present, the second should be there. | 2061 // The first extension shouldn't be present, the second should be there. |
2066 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); | 2062 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); |
2067 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false)); | 2063 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false)); |
2068 } | 2064 } |
2069 | 2065 |
2070 // Verifies that extensions with version older than the minimum version required | 2066 // Verifies that extensions with version older than the minimum version required |
2071 // by policy will get disabled, and will be auto-updated and/or re-enabled upon | 2067 // by policy will get disabled, and will be auto-updated and/or re-enabled upon |
2072 // policy changes as well as regular auto-updater scheduled updates. | 2068 // policy changes as well as regular auto-updater scheduled updates. |
2073 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequired) { | 2069 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequired) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 EXPECT_EQ(1u, interceptor.GetPendingSize()); | 2114 EXPECT_EQ(1u, interceptor.GetPendingSize()); |
2119 | 2115 |
2120 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); | 2116 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
2121 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, | 2117 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
2122 extension_prefs->GetDisableReasons(kGoodCrxId)); | 2118 extension_prefs->GetDisableReasons(kGoodCrxId)); |
2123 | 2119 |
2124 // Provide a new version (1.0.0.1) which is expected to be auto updated to | 2120 // Provide a new version (1.0.0.1) which is expected to be auto updated to |
2125 // via the update URL in the manifest of the older version. | 2121 // via the update URL in the manifest of the older version. |
2126 EXPECT_EQ(1u, interceptor.GetPendingSize()); | 2122 EXPECT_EQ(1u, interceptor.GetPendingSize()); |
2127 { | 2123 { |
2128 content::WindowedNotificationObserver update_observer( | 2124 extensions::TestExtensionRegistryObserver update_observer( |
2129 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 2125 extensions::ExtensionRegistry::Get(browser()->profile())); |
2130 content::NotificationService::AllSources()); | |
2131 service->updater()->CheckSoon(); | 2126 service->updater()->CheckSoon(); |
2132 update_observer.Wait(); | 2127 update_observer.WaitForExtensionWillBeInstalled(); |
2133 } | 2128 } |
2134 EXPECT_EQ(0u, interceptor.GetPendingSize()); | 2129 EXPECT_EQ(0u, interceptor.GetPendingSize()); |
2135 | 2130 |
2136 // The extension should be auto-updated to newer version and re-enabled. | 2131 // The extension should be auto-updated to newer version and re-enabled. |
2137 EXPECT_EQ("1.0.0.1", | 2132 EXPECT_EQ("1.0.0.1", |
2138 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); | 2133 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); |
2139 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); | 2134 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
2140 } | 2135 } |
2141 | 2136 |
2142 // Similar to ExtensionMinimumVersionRequired test, but with different settings | 2137 // Similar to ExtensionMinimumVersionRequired test, but with different settings |
(...skipping 28 matching lines...) Expand all Loading... |
2171 EXPECT_TRUE(InstallExtension(kGoodV1CrxName)); | 2166 EXPECT_TRUE(InstallExtension(kGoodV1CrxName)); |
2172 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); | 2167 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
2173 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, | 2168 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
2174 extension_prefs->GetDisableReasons(kGoodCrxId)); | 2169 extension_prefs->GetDisableReasons(kGoodCrxId)); |
2175 EXPECT_EQ("1.0.0.0", | 2170 EXPECT_EQ("1.0.0.0", |
2176 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); | 2171 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); |
2177 | 2172 |
2178 // An extension management policy update should trigger an update as well. | 2173 // An extension management policy update should trigger an update as well. |
2179 EXPECT_EQ(1u, interceptor.GetPendingSize()); | 2174 EXPECT_EQ(1u, interceptor.GetPendingSize()); |
2180 { | 2175 { |
2181 content::WindowedNotificationObserver update_observer( | 2176 extensions::TestExtensionRegistryObserver update_observer( |
2182 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 2177 extensions::ExtensionRegistry::Get(browser()->profile())); |
2183 content::NotificationService::AllSources()); | |
2184 { | 2178 { |
2185 // Set a higher minimum version, just intend to trigger a policy update. | 2179 // Set a higher minimum version, just intend to trigger a policy update. |
2186 extensions::ExtensionManagementPolicyUpdater management_policy( | 2180 extensions::ExtensionManagementPolicyUpdater management_policy( |
2187 &provider_); | 2181 &provider_); |
2188 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.3"); | 2182 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.3"); |
2189 } | 2183 } |
2190 base::RunLoop().RunUntilIdle(); | 2184 base::RunLoop().RunUntilIdle(); |
2191 update_observer.Wait(); | 2185 update_observer.WaitForExtensionWillBeInstalled(); |
2192 } | 2186 } |
2193 EXPECT_EQ(0u, interceptor.GetPendingSize()); | 2187 EXPECT_EQ(0u, interceptor.GetPendingSize()); |
2194 | 2188 |
2195 // It should be updated to 1.0.0.1 but remain disabled. | 2189 // It should be updated to 1.0.0.1 but remain disabled. |
2196 EXPECT_EQ("1.0.0.1", | 2190 EXPECT_EQ("1.0.0.1", |
2197 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); | 2191 service->GetInstalledExtension(kGoodCrxId)->version()->GetString()); |
2198 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); | 2192 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
2199 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, | 2193 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
2200 extension_prefs->GetDisableReasons(kGoodCrxId)); | 2194 extension_prefs->GetDisableReasons(kGoodCrxId)); |
2201 | 2195 |
(...skipping 17 matching lines...) Expand all Loading... |
2219 extensions::ExtensionPrefs* extension_prefs = | 2213 extensions::ExtensionPrefs* extension_prefs = |
2220 extensions::ExtensionPrefs::Get(browser()->profile()); | 2214 extensions::ExtensionPrefs::Get(browser()->profile()); |
2221 | 2215 |
2222 // Prepare the update URL for force installing. | 2216 // Prepare the update URL for force installing. |
2223 const base::FilePath path = | 2217 const base::FilePath path = |
2224 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); | 2218 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
2225 const GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | 2219 const GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
2226 | 2220 |
2227 // Set policy to force-install the extension, it should be installed and | 2221 // Set policy to force-install the extension, it should be installed and |
2228 // enabled. | 2222 // enabled. |
2229 content::WindowedNotificationObserver install_observer( | 2223 extensions::TestExtensionRegistryObserver install_observer( |
2230 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 2224 extensions::ExtensionRegistry::Get(browser()->profile())); |
2231 content::NotificationService::AllSources()); | |
2232 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); | 2225 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); |
2233 { | 2226 { |
2234 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); | 2227 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
2235 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId, | 2228 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId, |
2236 url.spec(), true); | 2229 url.spec(), true); |
2237 } | 2230 } |
2238 base::RunLoop().RunUntilIdle(); | 2231 base::RunLoop().RunUntilIdle(); |
2239 install_observer.Wait(); | 2232 install_observer.WaitForExtensionWillBeInstalled(); |
2240 | 2233 |
2241 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); | 2234 EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
2242 | 2235 |
2243 // Set policy a minimum version of "1.0.0.1", the extension now should be | 2236 // Set policy a minimum version of "1.0.0.1", the extension now should be |
2244 // disabled. | 2237 // disabled. |
2245 { | 2238 { |
2246 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); | 2239 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
2247 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1"); | 2240 management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1"); |
2248 } | 2241 } |
2249 base::RunLoop().RunUntilIdle(); | 2242 base::RunLoop().RunUntilIdle(); |
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4000 POLICY_SCOPE_USER, | 3993 POLICY_SCOPE_USER, |
4001 POLICY_SOURCE_CLOUD, | 3994 POLICY_SOURCE_CLOUD, |
4002 new base::FundamentalValue(false), | 3995 new base::FundamentalValue(false), |
4003 NULL); | 3996 NULL); |
4004 UpdateProviderPolicy(policies); | 3997 UpdateProviderPolicy(policies); |
4005 EXPECT_FALSE(display_manager->unified_desktop_enabled()); | 3998 EXPECT_FALSE(display_manager->unified_desktop_enabled()); |
4006 } | 3999 } |
4007 #endif // defined(OS_CHROMEOS) | 4000 #endif // defined(OS_CHROMEOS) |
4008 | 4001 |
4009 } // namespace policy | 4002 } // namespace policy |
OLD | NEW |