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 15 matching lines...) Expand all Loading... | |
26 #include "chrome/app/chrome_command_ids.h" | 26 #include "chrome/app/chrome_command_ids.h" |
27 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 27 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
29 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 29 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
30 #include "chrome/browser/devtools/devtools_window.h" | 30 #include "chrome/browser/devtools/devtools_window.h" |
31 #include "chrome/browser/download/download_prefs.h" | 31 #include "chrome/browser/download/download_prefs.h" |
32 #include "chrome/browser/extensions/crx_installer.h" | 32 #include "chrome/browser/extensions/crx_installer.h" |
33 #include "chrome/browser/extensions/extension_service.h" | 33 #include "chrome/browser/extensions/extension_service.h" |
34 #include "chrome/browser/extensions/extension_system.h" | 34 #include "chrome/browser/extensions/extension_system.h" |
35 #include "chrome/browser/extensions/unpacked_installer.h" | 35 #include "chrome/browser/extensions/unpacked_installer.h" |
36 #include "chrome/browser/extensions/updater/extension_updater.h" | |
36 #include "chrome/browser/infobars/infobar_service.h" | 37 #include "chrome/browser/infobars/infobar_service.h" |
37 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 38 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
38 #include "chrome/browser/media/media_stream_devices_controller.h" | 39 #include "chrome/browser/media/media_stream_devices_controller.h" |
39 #include "chrome/browser/metrics/variations/variations_service.h" | 40 #include "chrome/browser/metrics/variations/variations_service.h" |
40 #include "chrome/browser/net/url_request_mock_util.h" | 41 #include "chrome/browser/net/url_request_mock_util.h" |
41 #include "chrome/browser/plugins/plugin_prefs.h" | 42 #include "chrome/browser/plugins/plugin_prefs.h" |
42 #include "chrome/browser/policy/browser_policy_connector.h" | 43 #include "chrome/browser/policy/browser_policy_connector.h" |
44 #include "chrome/browser/policy/cloud/test_request_interceptor.h" | |
43 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 45 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
44 #include "chrome/browser/policy/policy_map.h" | 46 #include "chrome/browser/policy/policy_map.h" |
45 #include "chrome/browser/prefs/session_startup_pref.h" | 47 #include "chrome/browser/prefs/session_startup_pref.h" |
46 #include "chrome/browser/profiles/profile.h" | 48 #include "chrome/browser/profiles/profile.h" |
47 #include "chrome/browser/search/search.h" | 49 #include "chrome/browser/search/search.h" |
48 #include "chrome/browser/search_engines/template_url.h" | 50 #include "chrome/browser/search_engines/template_url.h" |
49 #include "chrome/browser/search_engines/template_url_service.h" | 51 #include "chrome/browser/search_engines/template_url_service.h" |
50 #include "chrome/browser/search_engines/template_url_service_factory.h" | 52 #include "chrome/browser/search_engines/template_url_service_factory.h" |
51 #include "chrome/browser/translate/translate_infobar_delegate.h" | 53 #include "chrome/browser/translate/translate_infobar_delegate.h" |
52 #include "chrome/browser/translate/translate_tab_helper.h" | 54 #include "chrome/browser/translate/translate_tab_helper.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 FILE_PATH_LITERAL("adblock.crx"); | 149 FILE_PATH_LITERAL("adblock.crx"); |
148 const base::FilePath::CharType kHostedAppCrxName[] = | 150 const base::FilePath::CharType kHostedAppCrxName[] = |
149 FILE_PATH_LITERAL("hosted_app.crx"); | 151 FILE_PATH_LITERAL("hosted_app.crx"); |
150 | 152 |
151 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 153 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
152 const char kAdBlockCrxId[] = "dojnnbeimaimaojcialkkgajdnefpgcn"; | 154 const char kAdBlockCrxId[] = "dojnnbeimaimaojcialkkgajdnefpgcn"; |
153 const char kHostedAppCrxId[] = "kbmnembihfiondgfjekmnmcbddelicoi"; | 155 const char kHostedAppCrxId[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
154 | 156 |
155 const base::FilePath::CharType kGoodCrxManifestName[] = | 157 const base::FilePath::CharType kGoodCrxManifestName[] = |
156 FILE_PATH_LITERAL("good_update_manifest.xml"); | 158 FILE_PATH_LITERAL("good_update_manifest.xml"); |
159 const base::FilePath::CharType kGood2CrxManifestName[] = | |
160 FILE_PATH_LITERAL("good2_update_manifest.xml"); | |
161 const base::FilePath::CharType kGoodV1CrxManifestName[] = | |
162 FILE_PATH_LITERAL("good_v1_update_manifest.xml"); | |
Joao da Silva
2013/05/28 08:27:31
Use consistent names for the files: "good_v1_*" an
csorba
2013/05/28 12:00:39
I tried to introduce as few new crx files as possi
| |
157 const base::FilePath::CharType kGoodUnpackedExt[] = | 163 const base::FilePath::CharType kGoodUnpackedExt[] = |
158 FILE_PATH_LITERAL("good_unpacked"); | 164 FILE_PATH_LITERAL("good_unpacked"); |
159 const base::FilePath::CharType kAppUnpackedExt[] = | 165 const base::FilePath::CharType kAppUnpackedExt[] = |
160 FILE_PATH_LITERAL("app"); | 166 FILE_PATH_LITERAL("app"); |
161 | 167 |
162 // Filters requests to the hosts in |urls| and redirects them to the test data | 168 // Filters requests to the hosts in |urls| and redirects them to the test data |
163 // dir through URLRequestMockHTTPJobs. | 169 // dir through URLRequestMockHTTPJobs. |
164 void RedirectHostsToTestData(const char* const urls[], size_t size) { | 170 void RedirectHostsToTestData(const char* const urls[], size_t size) { |
165 // Map the given hosts to the test data dir. | 171 // Map the given hosts to the test data dir. |
166 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 172 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1297 } | 1303 } |
1298 | 1304 |
1299 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallForcelist) { | 1305 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallForcelist) { |
1300 // Verifies that extensions that are force-installed by policies are | 1306 // Verifies that extensions that are force-installed by policies are |
1301 // installed and can't be uninstalled. | 1307 // installed and can't be uninstalled. |
1302 ExtensionService* service = extension_service(); | 1308 ExtensionService* service = extension_service(); |
1303 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1309 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1304 | 1310 |
1305 // Extensions that are force-installed come from an update URL, which defaults | 1311 // Extensions that are force-installed come from an update URL, which defaults |
1306 // to the webstore. Use a mock URL for this test with an update manifest | 1312 // to the webstore. Use a mock URL for this test with an update manifest |
1307 // that includes "good.crx". | 1313 // that includes "good_v1.crx". |
1308 base::FilePath path = | 1314 base::FilePath path = |
1309 base::FilePath(kTestExtensionsDir).Append(kGoodCrxManifestName); | 1315 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
1310 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | 1316 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
1311 | 1317 |
1312 // Setting the forcelist extension should install "good.crx". | 1318 // Setting the forcelist extension should install "good_v1.crx". |
1313 base::ListValue forcelist; | 1319 base::ListValue forcelist; |
1314 forcelist.Append(base::Value::CreateStringValue(base::StringPrintf( | 1320 forcelist.Append(base::Value::CreateStringValue(base::StringPrintf( |
1315 "%s;%s", kGoodCrxId, url.spec().c_str()))); | 1321 "%s;%s", kGoodCrxId, url.spec().c_str()))); |
1316 PolicyMap policies; | 1322 PolicyMap policies; |
1317 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, | 1323 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
1318 POLICY_SCOPE_USER, forcelist.DeepCopy()); | 1324 POLICY_SCOPE_USER, forcelist.DeepCopy()); |
1319 content::WindowedNotificationObserver observer( | 1325 content::WindowedNotificationObserver observer( |
1320 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 1326 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
1321 content::NotificationService::AllSources()); | 1327 content::NotificationService::AllSources()); |
1322 UpdateProviderPolicy(policies); | 1328 UpdateProviderPolicy(policies); |
1323 observer.Wait(); | 1329 observer.Wait(); |
1324 // Note: Cannot check that the notification details match the expected | 1330 // Note: Cannot check that the notification details match the expected |
1325 // exception, since the details object has already been freed prior to | 1331 // exception, since the details object has already been freed prior to |
1326 // the completion of observer.Wait(). | 1332 // the completion of observer.Wait(). |
1327 | 1333 |
1328 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); | 1334 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); |
1329 | 1335 |
1330 // The user is not allowed to uninstall force-installed extensions. | 1336 // The user is not allowed to uninstall force-installed extensions. |
1331 UninstallExtension(kGoodCrxId, false); | 1337 UninstallExtension(kGoodCrxId, false); |
1332 | 1338 |
1333 // The user is not allowed to load an unpacked extension with the | 1339 // The user is not allowed to load an unpacked extension with the |
1334 // same ID as a force-installed extension. | 1340 // same ID as a force-installed extension. |
1335 LoadUnpackedExtension(kGoodUnpackedExt, false); | 1341 LoadUnpackedExtension(kGoodUnpackedExt, false); |
1336 | 1342 |
1337 // Loading other unpacked extensions are not blocked. | 1343 // Loading other unpacked extensions are not blocked. |
1338 LoadUnpackedExtension(kAppUnpackedExt, true); | 1344 LoadUnpackedExtension(kAppUnpackedExt, true); |
1345 | |
1346 const std::string old_version_number = | |
1347 service->GetExtensionById(kGoodCrxId, true)->version()->GetString(); | |
1348 | |
1349 base::FilePath test_path; | |
1350 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | |
Joao da Silva
2013/05/28 08:27:31
ASSERT_TRUE( ... )
csorba
2013/05/28 12:00:39
Done.
| |
1351 | |
1352 scoped_ptr<TestRequestInterceptor> interceptor; | |
Joao da Silva
2013/05/28 08:27:31
No need to have this in a scoped_ptr, just use a v
| |
1353 interceptor.reset(new TestRequestInterceptor("update.extension")); | |
1354 interceptor->PushJobCallback( | |
1355 TestRequestInterceptor::MockJob( | |
1356 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName))); | |
1357 | |
1358 // Updating the force-installed extension. | |
1359 extensions::ExtensionUpdater* updater = service->updater(); | |
1360 extensions::ExtensionUpdater::CheckParams params; | |
1361 params.install_immediately = true; | |
1362 content::WindowedNotificationObserver update_observer( | |
1363 chrome::NOTIFICATION_EXTENSION_INSTALLED, | |
1364 content::NotificationService::AllSources()); | |
1365 updater->CheckNow(params); | |
1366 update_observer.Wait(); | |
1367 | |
1368 const base::Version* new_version = | |
1369 service->GetExtensionById(kGoodCrxId, true)->version(); | |
Joao da Silva
2013/05/28 08:27:31
nit: indent
csorba
2013/05/28 12:00:39
Done.
| |
1370 | |
1371 EXPECT_FALSE(new_version->IsOlderThan(old_version_number)); | |
Joao da Silva
2013/05/28 08:27:31
This would pass even if new_version == old_version
csorba
2013/05/28 12:00:39
Done + ASSERT_TRUE(new_version->IsValid()) added.
| |
1339 } | 1372 } |
Joao da Silva
2013/05/28 08:27:31
Verify that the expected callback jobs were used b
csorba
2013/05/28 12:00:39
Done.
| |
1340 | 1373 |
1341 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { | 1374 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { |
1342 // Verifies that extensions are blocked if policy specifies an allowed types | 1375 // Verifies that extensions are blocked if policy specifies an allowed types |
1343 // list and the extension's type is not on that list. | 1376 // list and the extension's type is not on that list. |
1344 ExtensionService* service = extension_service(); | 1377 ExtensionService* service = extension_service(); |
1345 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1378 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1346 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); | 1379 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); |
1347 | 1380 |
1348 base::ListValue allowed_types; | 1381 base::ListValue allowed_types; |
1349 allowed_types.AppendString("hosted_app"); | 1382 allowed_types.AppendString("hosted_app"); |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2114 chrome_variations::VariationsService::GetVariationsServerURL( | 2147 chrome_variations::VariationsService::GetVariationsServerURL( |
2115 g_browser_process->local_state()); | 2148 g_browser_process->local_state()); |
2116 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2149 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
2117 std::string value; | 2150 std::string value; |
2118 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2151 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
2119 EXPECT_EQ("restricted", value); | 2152 EXPECT_EQ("restricted", value); |
2120 } | 2153 } |
2121 #endif | 2154 #endif |
2122 | 2155 |
2123 } // namespace policy | 2156 } // namespace policy |
OLD | NEW |