Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 16102004: Adding browsertest to verify that updating forced-installed extensions is possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/policy/cloud/test_request_interceptor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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");
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
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 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path));
1351
1352 TestRequestInterceptor interceptor("update.extension");
1353 interceptor.PushJobCallback(
1354 TestRequestInterceptor::FileJob(
1355 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
1356
1357 // Updating the force-installed extension.
1358 extensions::ExtensionUpdater* updater = service->updater();
1359 extensions::ExtensionUpdater::CheckParams params;
1360 params.install_immediately = true;
1361 content::WindowedNotificationObserver update_observer(
1362 chrome::NOTIFICATION_EXTENSION_INSTALLED,
1363 content::NotificationService::AllSources());
1364 updater->CheckNow(params);
1365 update_observer.Wait();
1366
1367 const base::Version* new_version =
1368 service->GetExtensionById(kGoodCrxId, true)->version();
1369 ASSERT_TRUE(new_version->IsValid());
1370 base::Version old_version(old_version_number);
1371 ASSERT_TRUE(old_version.IsValid());
1372
1373 EXPECT_EQ(1, new_version->CompareTo(old_version));
1374
1375 EXPECT_EQ(0u, interceptor.GetPendingSize());
1339 } 1376 }
1340 1377
1341 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { 1378 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) {
1342 // Verifies that extensions are blocked if policy specifies an allowed types 1379 // Verifies that extensions are blocked if policy specifies an allowed types
1343 // list and the extension's type is not on that list. 1380 // list and the extension's type is not on that list.
1344 ExtensionService* service = extension_service(); 1381 ExtensionService* service = extension_service();
1345 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1382 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true));
1346 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); 1383 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true));
1347 1384
1348 base::ListValue allowed_types; 1385 base::ListValue allowed_types;
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 chrome_variations::VariationsService::GetVariationsServerURL( 2151 chrome_variations::VariationsService::GetVariationsServerURL(
2115 g_browser_process->local_state()); 2152 g_browser_process->local_state());
2116 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); 2153 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true));
2117 std::string value; 2154 std::string value;
2118 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); 2155 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
2119 EXPECT_EQ("restricted", value); 2156 EXPECT_EQ("restricted", value);
2120 } 2157 }
2121 #endif 2158 #endif
2122 2159
2123 } // namespace policy 2160 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud/test_request_interceptor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698