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

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 7003098: Start refractoring extension permissions into ExtensionPermissionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: See if rebasing fixes the tests... Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 std::stable_sort(ret_val.begin(), ret_val.end()); 107 std::stable_sort(ret_val.begin(), ret_val.end());
108 108
109 return ret_val; 109 return ret_val;
110 } 110 }
111 111
112 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { 112 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
113 int schemes = URLPattern::SCHEME_ALL; 113 int schemes = URLPattern::SCHEME_ALL;
114 extent->AddPattern(URLPattern(schemes, pattern)); 114 extent->AddPattern(URLPattern(schemes, pattern));
115 } 115 }
116 116
117 static void AssertEqualExtents(URLPatternSet* extent1, 117 static void AssertEqualExtents(const URLPatternSet& extent1,
118 URLPatternSet* extent2) { 118 const URLPatternSet& extent2) {
119 URLPatternList patterns1 = extent1->patterns(); 119 URLPatternList patterns1 = extent1.patterns();
120 URLPatternList patterns2 = extent2->patterns(); 120 URLPatternList patterns2 = extent2.patterns();
121 std::set<std::string> strings1; 121 std::set<std::string> strings1;
122 EXPECT_EQ(patterns1.size(), patterns2.size()); 122 EXPECT_EQ(patterns1.size(), patterns2.size());
123 123
124 for (size_t i = 0; i < patterns1.size(); ++i) 124 for (size_t i = 0; i < patterns1.size(); ++i)
125 strings1.insert(patterns1.at(i).GetAsString()); 125 strings1.insert(patterns1.at(i).GetAsString());
126 126
127 std::set<std::string> strings2; 127 std::set<std::string> strings2;
128 for (size_t i = 0; i < patterns2.size(); ++i) 128 for (size_t i = 0; i < patterns2.size(); ++i)
129 strings2.insert(patterns2.at(i).GetAsString()); 129 strings2.insert(patterns2.at(i).GetAsString());
130 130
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 562
563 ASSERT_TRUE(file_util::Delete(crx_path, false)); 563 ASSERT_TRUE(file_util::Delete(crx_path, false));
564 564
565 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 565 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
566 ASSERT_TRUE(creator->Run(dir_path, 566 ASSERT_TRUE(creator->Run(dir_path,
567 crx_path, 567 crx_path,
568 pem_path, 568 pem_path,
569 pem_output_path)); 569 pem_output_path));
570 570
571 ASSERT_TRUE(file_util::PathExists(crx_path)); 571 ASSERT_TRUE(file_util::PathExists(crx_path));
572
573 InstallCrx(crx_path, should_succeed); 572 InstallCrx(crx_path, should_succeed);
574 } 573 }
575 574
576 void PackAndInstallCrx(const FilePath& dir_path, 575 void PackAndInstallCrx(const FilePath& dir_path,
577 bool should_succeed) { 576 bool should_succeed) {
578 PackAndInstallCrx(dir_path, FilePath(), should_succeed); 577 PackAndInstallCrx(dir_path, FilePath(), should_succeed);
579 } 578 }
580 579
581 // Create a CrxInstaller and start installation. To allow the install 580 // Create a CrxInstaller and start installation. To allow the install
582 // to happen, use loop_.RunAllPending();. Most tests will not use this 581 // to happen, use loop_.RunAllPending();. Most tests will not use this
583 // method directly. Instead, use InstallCrx(), which waits for 582 // method directly. Instead, use InstallCrx(), which waits for
584 // the crx to be installed and does extra error checking. 583 // the crx to be installed and does extra error checking.
585 void StartCrxInstall(const FilePath& crx_path) { 584 void StartCrxInstall(const FilePath& crx_path) {
586 ASSERT_TRUE(file_util::PathExists(crx_path)) 585 ASSERT_TRUE(file_util::PathExists(crx_path))
587 << "Path does not exist: "<< crx_path.value().c_str(); 586 << "Path does not exist: "<< crx_path.value().c_str();
588 // no client (silent install) 587 scoped_refptr<CrxInstaller> installer(
589 scoped_refptr<CrxInstaller> installer(service_->MakeCrxInstaller(NULL)); 588 service_->MakeCrxInstaller(NULL));
589 installer->set_allow_silent_install(true);
590 installer->InstallCrx(crx_path); 590 installer->InstallCrx(crx_path);
591 } 591 }
592 592
593 void InstallCrx(const FilePath& path, 593 void InstallCrx(const FilePath& path,
594 bool should_succeed) { 594 bool should_succeed) {
595 StartCrxInstall(path); 595 StartCrxInstall(path);
596 WaitForCrxInstall(path, should_succeed); 596 WaitForCrxInstall(path, should_succeed);
597 } 597 }
598 598
599 void InstallCrxWithLocation(const FilePath& crx_path, 599 void InstallCrxWithLocation(const FilePath& crx_path,
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 EXPECT_TRUE(extension->plugins().empty()); 1026 EXPECT_TRUE(extension->plugins().empty());
1027 EXPECT_EQ(1u, scripts[1].url_patterns().size()); 1027 EXPECT_EQ(1u, scripts[1].url_patterns().size());
1028 EXPECT_EQ("http://*.news.com/*", scripts[1].url_patterns()[0].GetAsString()); 1028 EXPECT_EQ("http://*.news.com/*", scripts[1].url_patterns()[0].GetAsString());
1029 ExtensionResource resource10(extension->id(), 1029 ExtensionResource resource10(extension->id(),
1030 scripts[1].js_scripts()[0].extension_root(), 1030 scripts[1].js_scripts()[0].extension_root(),
1031 scripts[1].js_scripts()[0].relative_path()); 1031 scripts[1].js_scripts()[0].relative_path());
1032 expected_path = 1032 expected_path =
1033 extension->path().AppendASCII("js_files").AppendASCII("script3.js"); 1033 extension->path().AppendASCII("js_files").AppendASCII("script3.js");
1034 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); 1034 ASSERT_TRUE(file_util::AbsolutePath(&expected_path));
1035 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); 1035 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path));
1036 const URLPatternList permissions = extension->host_permissions(); 1036 const URLPatternList permissions =
1037 extension->permission_set()->explicit_hosts().patterns();
1037 ASSERT_EQ(2u, permissions.size()); 1038 ASSERT_EQ(2u, permissions.size());
1038 EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString()); 1039 EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString());
1039 EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString()); 1040 EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString());
1040 1041
1041 EXPECT_EQ(std::string(good1), loaded_[1]->id()); 1042 EXPECT_EQ(std::string(good1), loaded_[1]->id());
1042 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); 1043 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name());
1043 EXPECT_EQ(std::string(""), loaded_[1]->description()); 1044 EXPECT_EQ(std::string(""), loaded_[1]->description());
1044 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), 1045 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"),
1045 loaded_[1]->background_url()); 1046 loaded_[1]->background_url());
1046 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); 1047 EXPECT_EQ(0u, loaded_[1]->content_scripts().size());
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 // Install a user script (they get converted automatically to an extension) 1330 // Install a user script (they get converted automatically to an extension)
1330 TEST_F(ExtensionServiceTest, InstallUserScript) { 1331 TEST_F(ExtensionServiceTest, InstallUserScript) {
1331 // The details of script conversion are tested elsewhere, this just tests 1332 // The details of script conversion are tested elsewhere, this just tests
1332 // integration with ExtensionService. 1333 // integration with ExtensionService.
1333 InitializeEmptyExtensionService(); 1334 InitializeEmptyExtensionService();
1334 1335
1335 FilePath path = data_dir_ 1336 FilePath path = data_dir_
1336 .AppendASCII("user_script_basic.user.js"); 1337 .AppendASCII("user_script_basic.user.js");
1337 1338
1338 ASSERT_TRUE(file_util::PathExists(path)); 1339 ASSERT_TRUE(file_util::PathExists(path));
1339 // Pass NULL to install silently. 1340 scoped_refptr<CrxInstaller> installer(
1340 scoped_refptr<CrxInstaller> installer(service_->MakeCrxInstaller(NULL)); 1341 service_->MakeCrxInstaller(NULL));
1342 installer->set_allow_silent_install(true);
1341 installer->InstallUserScript( 1343 installer->InstallUserScript(
1342 path, 1344 path,
1343 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); 1345 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"));
1344 1346
1345 loop_.RunAllPending(); 1347 loop_.RunAllPending();
1346 std::vector<std::string> errors = GetErrors(); 1348 std::vector<std::string> errors = GetErrors();
1347 EXPECT_TRUE(installed_) << "Nothing was installed."; 1349 EXPECT_TRUE(installed_) << "Nothing was installed.";
1348 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; 1350 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
1349 EXPECT_EQ(0u, errors.size()) << "There were errors: " 1351 EXPECT_EQ(0u, errors.size()) << "There were errors: "
1350 << JoinString(errors, ','); 1352 << JoinString(errors, ',');
(...skipping 13 matching lines...) Expand all
1364 .AppendASCII("permissions"); 1366 .AppendASCII("permissions");
1365 1367
1366 FilePath pem_path = path.AppendASCII("unknown.pem"); 1368 FilePath pem_path = path.AppendASCII("unknown.pem");
1367 path = path.AppendASCII("unknown"); 1369 path = path.AppendASCII("unknown");
1368 1370
1369 ASSERT_TRUE(file_util::PathExists(pem_path)); 1371 ASSERT_TRUE(file_util::PathExists(pem_path));
1370 ASSERT_TRUE(file_util::PathExists(path)); 1372 ASSERT_TRUE(file_util::PathExists(path));
1371 1373
1372 ExtensionPrefs* prefs = service_->extension_prefs(); 1374 ExtensionPrefs* prefs = service_->extension_prefs();
1373 1375
1374 std::set<std::string> expected_api_perms; 1376 ExtensionAPIPermissionSet expected_api_perms;
1375 std::set<std::string> known_api_perms;
1376 bool full_access;
1377 URLPatternSet expected_host_perms; 1377 URLPatternSet expected_host_perms;
1378 URLPatternSet known_host_perms;
1379 1378
1380 // Make sure there aren't any granted permissions before the 1379 // Make sure there aren't any granted permissions before the
1381 // extension is installed. 1380 // extension is installed.
1382 EXPECT_FALSE(prefs->GetGrantedPermissions( 1381 scoped_ptr<ExtensionPermissionSet> known_perms(
1383 permissions_crx, &full_access, &known_api_perms, &known_host_perms)); 1382 prefs->GetGrantedPermissions(permissions_crx));
1384 EXPECT_TRUE(known_api_perms.empty()); 1383 EXPECT_FALSE(known_perms.get());
1385 EXPECT_TRUE(known_host_perms.is_empty());
1386 1384
1387 PackAndInstallCrx(path, pem_path, true); 1385 PackAndInstallCrx(path, pem_path, true);
1388 1386
1389 EXPECT_EQ(0u, GetErrors().size()); 1387 EXPECT_EQ(0u, GetErrors().size());
1390 ASSERT_EQ(1u, service_->extensions()->size()); 1388 ASSERT_EQ(1u, service_->extensions()->size());
1391 std::string extension_id = service_->extensions()->at(0)->id(); 1389 std::string extension_id = service_->extensions()->at(0)->id();
1392 EXPECT_EQ(permissions_crx, extension_id); 1390 EXPECT_EQ(permissions_crx, extension_id);
1393 1391
1394
1395 // Verify that the valid API permissions have been recognized. 1392 // Verify that the valid API permissions have been recognized.
1396 expected_api_perms.insert("tabs"); 1393 expected_api_perms.insert(ExtensionAPIPermission::kTab);
1397 1394
1398 AddPattern(&expected_host_perms, "http://*.google.com/*"); 1395 AddPattern(&expected_host_perms, "http://*.google.com/*");
1399 AddPattern(&expected_host_perms, "https://*.google.com/*"); 1396 AddPattern(&expected_host_perms, "https://*.google.com/*");
1400 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); 1397 AddPattern(&expected_host_perms, "http://*.google.com.hk/*");
1401 AddPattern(&expected_host_perms, "http://www.example.com/*"); 1398 AddPattern(&expected_host_perms, "http://www.example.com/*");
1402 1399
1403 EXPECT_TRUE(prefs->GetGrantedPermissions(extension_id, 1400 known_perms.reset(prefs->GetGrantedPermissions(extension_id));
1404 &full_access, 1401 EXPECT_TRUE(known_perms.get());
1405 &known_api_perms, 1402 EXPECT_FALSE(known_perms->IsEmpty());
1406 &known_host_perms)); 1403 EXPECT_EQ(expected_api_perms, known_perms->apis());
1407 1404 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1408 EXPECT_EQ(expected_api_perms, known_api_perms); 1405 AssertEqualExtents(expected_host_perms, known_perms->effective_hosts());
1409 EXPECT_FALSE(full_access);
1410 AssertEqualExtents(&expected_host_perms, &known_host_perms);
1411 } 1406 }
1412 1407
1413 #if !defined(OS_CHROMEOS) 1408 #if !defined(OS_CHROMEOS)
1414 // Tests that the granted permissions full_access bit gets set correctly when 1409 // Tests that the granted permissions full_access bit gets set correctly when
1415 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS 1410 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS
1416 // since they don't support plugins. 1411 // since they don't support plugins.
1417 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { 1412 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
1418 InitializeEmptyExtensionService(); 1413 InitializeEmptyExtensionService();
1419 1414
1420 FilePath path = data_dir_ 1415 FilePath path = data_dir_
1421 .AppendASCII("good") 1416 .AppendASCII("good")
1422 .AppendASCII("Extensions") 1417 .AppendASCII("Extensions")
1423 .AppendASCII(good1) 1418 .AppendASCII(good1)
1424 .AppendASCII("2"); 1419 .AppendASCII("2");
1425 1420
1426 ASSERT_TRUE(file_util::PathExists(path)); 1421 ASSERT_TRUE(file_util::PathExists(path));
1427
1428 PackAndInstallCrx(path, true); 1422 PackAndInstallCrx(path, true);
1429
1430 EXPECT_EQ(0u, GetErrors().size()); 1423 EXPECT_EQ(0u, GetErrors().size());
1431 EXPECT_EQ(1u, service_->extensions()->size()); 1424 EXPECT_EQ(1u, service_->extensions()->size());
1432 const Extension* extension = service_->extensions()->at(0); 1425 const Extension* extension = service_->extensions()->at(0);
1433 std::string extension_id = extension->id(); 1426 std::string extension_id = extension->id();
1434 ExtensionPrefs* prefs = service_->extension_prefs(); 1427 ExtensionPrefs* prefs = service_->extension_prefs();
1435 1428
1436 bool full_access; 1429 scoped_ptr<ExtensionPermissionSet> permissions(
1437 std::set<std::string> api_permissions; 1430 prefs->GetGrantedPermissions(extension_id));
1438 URLPatternSet host_permissions; 1431 EXPECT_FALSE(permissions->IsEmpty());
1439 EXPECT_TRUE(prefs->GetGrantedPermissions( 1432 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
1440 extension_id, &full_access, &api_permissions, &host_permissions)); 1433 EXPECT_FALSE(permissions->apis().empty());
1434 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin));
1441 1435
1442 EXPECT_TRUE(full_access); 1436 // Full access implies full host access too...
1443 EXPECT_TRUE(api_permissions.empty()); 1437 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
1444 EXPECT_TRUE(host_permissions.is_empty());
1445 } 1438 }
1446 #endif 1439 #endif
1447 1440
1448 // Tests that the extension is disabled when permissions are missing from 1441 // Tests that the extension is disabled when permissions are missing from
1449 // the extension's granted permissions preferences. (This simulates updating 1442 // the extension's granted permissions preferences. (This simulates updating
1450 // the browser to a version which recognizes more permissions). 1443 // the browser to a version which recognizes more permissions).
1451 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { 1444 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
1452 InitializeEmptyExtensionService(); 1445 InitializeEmptyExtensionService();
1453 1446
1454 FilePath path = data_dir_ 1447 FilePath path = data_dir_
1455 .AppendASCII("permissions") 1448 .AppendASCII("permissions")
1456 .AppendASCII("unknown"); 1449 .AppendASCII("unknown");
1457 1450
1458 ASSERT_TRUE(file_util::PathExists(path)); 1451 ASSERT_TRUE(file_util::PathExists(path));
1459 1452
1460 PackAndInstallCrx(path, true); 1453 PackAndInstallCrx(path, true);
1461 1454
1462 EXPECT_EQ(0u, GetErrors().size()); 1455 EXPECT_EQ(0u, GetErrors().size());
1463 EXPECT_EQ(1u, service_->extensions()->size()); 1456 EXPECT_EQ(1u, service_->extensions()->size());
1464 const Extension* extension = service_->extensions()->at(0); 1457 const Extension* extension = service_->extensions()->at(0);
1465 std::string extension_id = extension->id(); 1458 std::string extension_id = extension->id();
1466 1459
1467 ExtensionPrefs* prefs = service_->extension_prefs(); 1460 ExtensionPrefs* prefs = service_->extension_prefs();
1468 1461
1469 std::set<std::string> expected_api_permissions; 1462 ExtensionAPIPermissionSet expected_api_permissions;
1470 URLPatternSet expected_host_permissions; 1463 URLPatternSet expected_host_permissions;
1471 1464
1472 expected_api_permissions.insert("tabs"); 1465 expected_api_permissions.insert(ExtensionAPIPermission::kTab);
1473 AddPattern(&expected_host_permissions, "http://*.google.com/*"); 1466 AddPattern(&expected_host_permissions, "http://*.google.com/*");
1474 AddPattern(&expected_host_permissions, "https://*.google.com/*"); 1467 AddPattern(&expected_host_permissions, "https://*.google.com/*");
1475 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); 1468 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*");
1476 AddPattern(&expected_host_permissions, "http://www.example.com/*"); 1469 AddPattern(&expected_host_permissions, "http://www.example.com/*");
1477 1470
1478 std::set<std::string> api_permissions;
1479 std::set<std::string> host_permissions; 1471 std::set<std::string> host_permissions;
1480 1472
1481 // Test that the extension is disabled when an API permission is missing from 1473 // Test that the extension is disabled when an API permission is missing from
1482 // the extension's granted api permissions preference. (This simulates 1474 // the extension's granted api permissions preference. (This simulates
1483 // updating the browser to a version which recognizes a new API permission). 1475 // updating the browser to a version which recognizes a new API permission).
1484 SetPrefStringSet(extension_id, "granted_permissions.api", api_permissions); 1476 SetPref(extension_id, "granted_permissions.api",
1485 1477 new ListValue(), "granted_permissions.api");
1486 service_->ReloadExtensions(); 1478 service_->ReloadExtensions();
1487 1479
1488 EXPECT_EQ(1u, service_->disabled_extensions()->size()); 1480 EXPECT_EQ(1u, service_->disabled_extensions()->size());
1489 extension = service_->disabled_extensions()->at(0); 1481 extension = service_->disabled_extensions()->at(0);
1490 1482
1491 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); 1483 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED);
1492 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1484 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
1493 1485
1494 // Now grant and re-enable the extension, making sure the prefs are updated. 1486 // Now grant and re-enable the extension, making sure the prefs are updated.
1495 service_->GrantPermissionsAndEnableExtension(extension); 1487 service_->GrantPermissionsAndEnableExtension(extension);
1496 1488
1497 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); 1489 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED);
1498 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1490 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
1499 1491
1500 std::set<std::string> current_api_permissions; 1492 scoped_ptr<ExtensionPermissionSet> current_perms(
1501 URLPatternSet current_host_permissions; 1493 prefs->GetGrantedPermissions(extension_id));
1502 bool current_full_access; 1494 ASSERT_TRUE(current_perms.get());
1503 1495 ASSERT_FALSE(current_perms->IsEmpty());
1504 ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id, 1496 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
1505 &current_full_access, 1497 ASSERT_EQ(expected_api_permissions, current_perms->apis());
1506 &current_api_permissions, 1498 AssertEqualExtents(expected_host_permissions,
1507 &current_host_permissions)); 1499 current_perms->effective_hosts());
1508
1509 ASSERT_FALSE(current_full_access);
1510 ASSERT_EQ(expected_api_permissions, current_api_permissions);
1511 AssertEqualExtents(&expected_host_permissions, &current_host_permissions);
1512 1500
1513 // Tests that the extension is disabled when a host permission is missing from 1501 // Tests that the extension is disabled when a host permission is missing from
1514 // the extension's granted host permissions preference. (This simulates 1502 // the extension's granted host permissions preference. (This simulates
1515 // updating the browser to a version which recognizes additional host 1503 // updating the browser to a version which recognizes additional host
1516 // permissions). 1504 // permissions).
1517 api_permissions.clear();
1518 host_permissions.clear(); 1505 host_permissions.clear();
1519 current_api_permissions.clear(); 1506 current_perms.reset();
1520 current_host_permissions.ClearPatterns();
1521 1507
1522 api_permissions.insert("tabs");
1523 host_permissions.insert("http://*.google.com/*"); 1508 host_permissions.insert("http://*.google.com/*");
1524 host_permissions.insert("https://*.google.com/*"); 1509 host_permissions.insert("https://*.google.com/*");
1525 host_permissions.insert("http://*.google.com.hk/*"); 1510 host_permissions.insert("http://*.google.com.hk/*");
1526 1511
1527 SetPrefStringSet(extension_id, "granted_permissions.api", api_permissions); 1512 ListValue* api_permissions = new ListValue();
1528 SetPrefStringSet(extension_id, "granted_permissions.host", host_permissions); 1513 api_permissions->Append(
1514 Value::CreateIntegerValue(ExtensionAPIPermission::kTab));
1515 SetPref(extension_id, "granted_permissions.api",
1516 api_permissions, "granted_permissions.api");
1517 SetPrefStringSet(
1518 extension_id, "granted_permissions.scriptable_host", host_permissions);
1529 1519
1530 service_->ReloadExtensions(); 1520 service_->ReloadExtensions();
1531 1521
1532 EXPECT_EQ(1u, service_->disabled_extensions()->size()); 1522 EXPECT_EQ(1u, service_->disabled_extensions()->size());
1533 extension = service_->disabled_extensions()->at(0); 1523 extension = service_->disabled_extensions()->at(0);
1534 1524
1535 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); 1525 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED);
1536 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1526 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
1537 1527
1538 // Now grant and re-enable the extension, making sure the prefs are updated. 1528 // Now grant and re-enable the extension, making sure the prefs are updated.
1539 service_->GrantPermissionsAndEnableExtension(extension); 1529 service_->GrantPermissionsAndEnableExtension(extension);
1540 1530
1541 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); 1531 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED);
1542 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1532 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
1543 1533
1544 ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id, 1534 current_perms.reset(prefs->GetGrantedPermissions(extension_id));
1545 &current_full_access, 1535 ASSERT_TRUE(current_perms.get());
1546 &current_api_permissions, 1536 ASSERT_FALSE(current_perms->IsEmpty());
1547 &current_host_permissions)); 1537 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
1548 1538 ASSERT_EQ(expected_api_permissions, current_perms->apis());
1549 ASSERT_FALSE(current_full_access); 1539 AssertEqualExtents(expected_host_permissions,
1550 ASSERT_EQ(expected_api_permissions, current_api_permissions); 1540 current_perms->effective_hosts());
1551 AssertEqualExtents(&expected_host_permissions, &current_host_permissions);
1552
1553 // Tests that the granted permissions preferences are initialized when
1554 // migrating from the old pref schema.
1555 current_api_permissions.clear();
1556 current_host_permissions.ClearPatterns();
1557
1558 ClearPref(extension_id, "granted_permissions");
1559
1560 service_->ReloadExtensions();
1561
1562 EXPECT_EQ(1u, service_->extensions()->size());
1563 extension = service_->extensions()->at(0);
1564
1565 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED);
1566 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
1567
1568 ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id,
1569 &current_full_access,
1570 &current_api_permissions,
1571 &current_host_permissions));
1572
1573 ASSERT_FALSE(current_full_access);
1574 ASSERT_EQ(expected_api_permissions, current_api_permissions);
1575 AssertEqualExtents(&expected_host_permissions, &current_host_permissions);
1576 } 1541 }
1577 1542
1578 // Test Packaging and installing an extension. 1543 // Test Packaging and installing an extension.
1579 TEST_F(ExtensionServiceTest, PackExtension) { 1544 TEST_F(ExtensionServiceTest, PackExtension) {
1580 InitializeEmptyExtensionService(); 1545 InitializeEmptyExtensionService();
1581 FilePath input_directory = data_dir_ 1546 FilePath input_directory = data_dir_
1582 .AppendASCII("good") 1547 .AppendASCII("good")
1583 .AppendASCII("Extensions") 1548 .AppendASCII("Extensions")
1584 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 1549 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
1585 .AppendASCII("1.0.0.0"); 1550 .AppendASCII("1.0.0.0");
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 EXPECT_TRUE(service_->extensions()->empty()); 1792 EXPECT_TRUE(service_->extensions()->empty());
1828 1793
1829 int pref_count = 0; 1794 int pref_count = 0;
1830 1795
1831 // Install app1 with unlimited storage. 1796 // Install app1 with unlimited storage.
1832 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); 1797 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true);
1833 ValidatePrefKeyCount(++pref_count); 1798 ValidatePrefKeyCount(++pref_count);
1834 ASSERT_EQ(1u, service_->extensions()->size()); 1799 ASSERT_EQ(1u, service_->extensions()->size());
1835 const Extension* extension = service_->extensions()->at(0); 1800 const Extension* extension = service_->extensions()->at(0);
1836 const std::string id1 = extension->id(); 1801 const std::string id1 = extension->id();
1837 EXPECT_TRUE(extension->HasApiPermission( 1802 EXPECT_TRUE(extension->HasAPIPermission(
1838 Extension::kUnlimitedStoragePermission)); 1803 ExtensionAPIPermission::kUnlimitedStorage));
1839 EXPECT_TRUE(extension->web_extent().MatchesURL( 1804 EXPECT_TRUE(extension->web_extent().MatchesURL(
1840 extension->GetFullLaunchURL())); 1805 extension->GetFullLaunchURL()));
1841 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); 1806 const GURL origin1(extension->GetFullLaunchURL().GetOrigin());
1842 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 1807 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
1843 IsStorageUnlimited(origin1)); 1808 IsStorageUnlimited(origin1));
1844 1809
1845 // Install app2 from the same origin with unlimited storage. 1810 // Install app2 from the same origin with unlimited storage.
1846 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); 1811 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true);
1847 ValidatePrefKeyCount(++pref_count); 1812 ValidatePrefKeyCount(++pref_count);
1848 ASSERT_EQ(2u, service_->extensions()->size()); 1813 ASSERT_EQ(2u, service_->extensions()->size());
1849 extension = service_->extensions()->at(1); 1814 extension = service_->extensions()->at(1);
1850 const std::string id2 = extension->id(); 1815 const std::string id2 = extension->id();
1851 EXPECT_TRUE(extension->HasApiPermission( 1816 EXPECT_TRUE(extension->HasAPIPermission(
1852 Extension::kUnlimitedStoragePermission)); 1817 ExtensionAPIPermission::kUnlimitedStorage));
1853 EXPECT_TRUE(extension->web_extent().MatchesURL( 1818 EXPECT_TRUE(extension->web_extent().MatchesURL(
1854 extension->GetFullLaunchURL())); 1819 extension->GetFullLaunchURL()));
1855 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); 1820 const GURL origin2(extension->GetFullLaunchURL().GetOrigin());
1856 EXPECT_EQ(origin1, origin2); 1821 EXPECT_EQ(origin1, origin2);
1857 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 1822 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
1858 IsStorageUnlimited(origin2)); 1823 IsStorageUnlimited(origin2));
1859 1824
1860 1825
1861 // Uninstall one of them, unlimited storage should still be granted 1826 // Uninstall one of them, unlimited storage should still be granted
1862 // to the origin. 1827 // to the origin.
(...skipping 1937 matching lines...) Expand 10 before | Expand all | Expand 10 after
3800 ASSERT_FALSE(AddPendingSyncInstall()); 3765 ASSERT_FALSE(AddPendingSyncInstall());
3801 3766
3802 // Wait for the external source to install. 3767 // Wait for the external source to install.
3803 WaitForCrxInstall(crx_path_, true); 3768 WaitForCrxInstall(crx_path_, true);
3804 ASSERT_TRUE(IsCrxInstalled()); 3769 ASSERT_TRUE(IsCrxInstalled());
3805 3770
3806 // Now that the extension is installed, sync request should fail 3771 // Now that the extension is installed, sync request should fail
3807 // because the extension is already installed. 3772 // because the extension is already installed.
3808 ASSERT_FALSE(AddPendingSyncInstall()); 3773 ASSERT_FALSE(AddPendingSyncInstall());
3809 } 3774 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_special_storage_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698