| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 EXPECT_TRUE(extension->plugins().empty()); | 1025 EXPECT_TRUE(extension->plugins().empty()); |
| 1027 EXPECT_EQ(1u, scripts[1].url_patterns().size()); | 1026 EXPECT_EQ(1u, scripts[1].url_patterns().size()); |
| 1028 EXPECT_EQ("http://*.news.com/*", scripts[1].url_patterns()[0].GetAsString()); | 1027 EXPECT_EQ("http://*.news.com/*", scripts[1].url_patterns()[0].GetAsString()); |
| 1029 ExtensionResource resource10(extension->id(), | 1028 ExtensionResource resource10(extension->id(), |
| 1030 scripts[1].js_scripts()[0].extension_root(), | 1029 scripts[1].js_scripts()[0].extension_root(), |
| 1031 scripts[1].js_scripts()[0].relative_path()); | 1030 scripts[1].js_scripts()[0].relative_path()); |
| 1032 expected_path = | 1031 expected_path = |
| 1033 extension->path().AppendASCII("js_files").AppendASCII("script3.js"); | 1032 extension->path().AppendASCII("js_files").AppendASCII("script3.js"); |
| 1034 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); | 1033 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); |
| 1035 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); | 1034 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); |
| 1036 const URLPatternList permissions = extension->host_permissions(); | 1035 const URLPatternList permissions = |
| 1036 extension->permission_set()->explicit_hosts().patterns(); |
| 1037 ASSERT_EQ(2u, permissions.size()); | 1037 ASSERT_EQ(2u, permissions.size()); |
| 1038 EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString()); | 1038 EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString()); |
| 1039 EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString()); | 1039 EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString()); |
| 1040 | 1040 |
| 1041 EXPECT_EQ(std::string(good1), loaded_[1]->id()); | 1041 EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
| 1042 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); | 1042 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
| 1043 EXPECT_EQ(std::string(""), loaded_[1]->description()); | 1043 EXPECT_EQ(std::string(""), loaded_[1]->description()); |
| 1044 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), | 1044 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
| 1045 loaded_[1]->background_url()); | 1045 loaded_[1]->background_url()); |
| 1046 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); | 1046 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 .AppendASCII("permissions"); | 1364 .AppendASCII("permissions"); |
| 1365 | 1365 |
| 1366 FilePath pem_path = path.AppendASCII("unknown.pem"); | 1366 FilePath pem_path = path.AppendASCII("unknown.pem"); |
| 1367 path = path.AppendASCII("unknown"); | 1367 path = path.AppendASCII("unknown"); |
| 1368 | 1368 |
| 1369 ASSERT_TRUE(file_util::PathExists(pem_path)); | 1369 ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 1370 ASSERT_TRUE(file_util::PathExists(path)); | 1370 ASSERT_TRUE(file_util::PathExists(path)); |
| 1371 | 1371 |
| 1372 ExtensionPrefs* prefs = service_->extension_prefs(); | 1372 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1373 | 1373 |
| 1374 std::set<std::string> expected_api_perms; | 1374 ExtensionAPIPermissionSet expected_api_perms; |
| 1375 std::set<std::string> known_api_perms; | |
| 1376 bool full_access; | |
| 1377 URLPatternSet expected_host_perms; | 1375 URLPatternSet expected_host_perms; |
| 1378 URLPatternSet known_host_perms; | |
| 1379 | 1376 |
| 1380 // Make sure there aren't any granted permissions before the | 1377 // Make sure there aren't any granted permissions before the |
| 1381 // extension is installed. | 1378 // extension is installed. |
| 1382 EXPECT_FALSE(prefs->GetGrantedPermissions( | 1379 scoped_ptr<ExtensionPermissionSet> known_perms( |
| 1383 permissions_crx, &full_access, &known_api_perms, &known_host_perms)); | 1380 prefs->GetGrantedPermissions(permissions_crx)); |
| 1384 EXPECT_TRUE(known_api_perms.empty()); | 1381 EXPECT_FALSE(known_perms.get()); |
| 1385 EXPECT_TRUE(known_host_perms.is_empty()); | |
| 1386 | 1382 |
| 1387 PackAndInstallCrx(path, pem_path, true); | 1383 PackAndInstallCrx(path, pem_path, true); |
| 1388 | 1384 |
| 1389 EXPECT_EQ(0u, GetErrors().size()); | 1385 EXPECT_EQ(0u, GetErrors().size()); |
| 1390 ASSERT_EQ(1u, service_->extensions()->size()); | 1386 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1391 std::string extension_id = service_->extensions()->at(0)->id(); | 1387 std::string extension_id = service_->extensions()->at(0)->id(); |
| 1392 EXPECT_EQ(permissions_crx, extension_id); | 1388 EXPECT_EQ(permissions_crx, extension_id); |
| 1393 | 1389 |
| 1394 | |
| 1395 // Verify that the valid API permissions have been recognized. | 1390 // Verify that the valid API permissions have been recognized. |
| 1396 expected_api_perms.insert("tabs"); | 1391 expected_api_perms.insert(ExtensionAPIPermission::kTab); |
| 1397 | 1392 |
| 1398 AddPattern(&expected_host_perms, "http://*.google.com/*"); | 1393 AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 1399 AddPattern(&expected_host_perms, "https://*.google.com/*"); | 1394 AddPattern(&expected_host_perms, "https://*.google.com/*"); |
| 1400 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); | 1395 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
| 1401 AddPattern(&expected_host_perms, "http://www.example.com/*"); | 1396 AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 1402 | 1397 |
| 1403 EXPECT_TRUE(prefs->GetGrantedPermissions(extension_id, | 1398 known_perms.reset(prefs->GetGrantedPermissions(extension_id)); |
| 1404 &full_access, | 1399 EXPECT_TRUE(known_perms.get()); |
| 1405 &known_api_perms, | 1400 EXPECT_FALSE(known_perms->IsDefault()); |
| 1406 &known_host_perms)); | 1401 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1407 | 1402 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
| 1408 EXPECT_EQ(expected_api_perms, known_api_perms); | 1403 AssertEqualExtents(expected_host_perms, known_perms->effective_hosts()); |
| 1409 EXPECT_FALSE(full_access); | |
| 1410 AssertEqualExtents(&expected_host_perms, &known_host_perms); | |
| 1411 } | 1404 } |
| 1412 | 1405 |
| 1413 #if !defined(OS_CHROMEOS) | 1406 #if !defined(OS_CHROMEOS) |
| 1414 // Tests that the granted permissions full_access bit gets set correctly when | 1407 // 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 | 1408 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
| 1416 // since they don't support plugins. | 1409 // since they don't support plugins. |
| 1417 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { | 1410 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
| 1418 InitializeEmptyExtensionService(); | 1411 InitializeEmptyExtensionService(); |
| 1419 | 1412 |
| 1420 FilePath path = data_dir_ | 1413 FilePath path = data_dir_ |
| 1421 .AppendASCII("good") | 1414 .AppendASCII("good") |
| 1422 .AppendASCII("Extensions") | 1415 .AppendASCII("Extensions") |
| 1423 .AppendASCII(good1) | 1416 .AppendASCII(good1) |
| 1424 .AppendASCII("2"); | 1417 .AppendASCII("2"); |
| 1425 | 1418 |
| 1426 ASSERT_TRUE(file_util::PathExists(path)); | 1419 ASSERT_TRUE(file_util::PathExists(path)); |
| 1427 | |
| 1428 PackAndInstallCrx(path, true); | 1420 PackAndInstallCrx(path, true); |
| 1429 | |
| 1430 EXPECT_EQ(0u, GetErrors().size()); | 1421 EXPECT_EQ(0u, GetErrors().size()); |
| 1431 EXPECT_EQ(1u, service_->extensions()->size()); | 1422 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1432 const Extension* extension = service_->extensions()->at(0); | 1423 const Extension* extension = service_->extensions()->at(0); |
| 1433 std::string extension_id = extension->id(); | 1424 std::string extension_id = extension->id(); |
| 1434 ExtensionPrefs* prefs = service_->extension_prefs(); | 1425 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1435 | 1426 |
| 1436 bool full_access; | 1427 scoped_ptr<ExtensionPermissionSet> permissions( |
| 1437 std::set<std::string> api_permissions; | 1428 prefs->GetGrantedPermissions(extension_id)); |
| 1438 URLPatternSet host_permissions; | 1429 EXPECT_FALSE(permissions->IsDefault()); |
| 1439 EXPECT_TRUE(prefs->GetGrantedPermissions( | 1430 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 1440 extension_id, &full_access, &api_permissions, &host_permissions)); | 1431 EXPECT_FALSE(permissions->apis().empty()); |
| 1432 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin)); |
| 1441 | 1433 |
| 1442 EXPECT_TRUE(full_access); | 1434 // Full access implies full host access too... |
| 1443 EXPECT_TRUE(api_permissions.empty()); | 1435 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
| 1444 EXPECT_TRUE(host_permissions.is_empty()); | |
| 1445 } | 1436 } |
| 1446 #endif | 1437 #endif |
| 1447 | 1438 |
| 1448 // Tests that the extension is disabled when permissions are missing from | 1439 // Tests that the extension is disabled when permissions are missing from |
| 1449 // the extension's granted permissions preferences. (This simulates updating | 1440 // the extension's granted permissions preferences. (This simulates updating |
| 1450 // the browser to a version which recognizes more permissions). | 1441 // the browser to a version which recognizes more permissions). |
| 1451 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { | 1442 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { |
| 1452 InitializeEmptyExtensionService(); | 1443 InitializeEmptyExtensionService(); |
| 1453 | 1444 |
| 1454 FilePath path = data_dir_ | 1445 FilePath path = data_dir_ |
| 1455 .AppendASCII("permissions") | 1446 .AppendASCII("permissions") |
| 1456 .AppendASCII("unknown"); | 1447 .AppendASCII("unknown"); |
| 1457 | 1448 |
| 1458 ASSERT_TRUE(file_util::PathExists(path)); | 1449 ASSERT_TRUE(file_util::PathExists(path)); |
| 1459 | 1450 |
| 1460 PackAndInstallCrx(path, true); | 1451 PackAndInstallCrx(path, true); |
| 1461 | 1452 |
| 1462 EXPECT_EQ(0u, GetErrors().size()); | 1453 EXPECT_EQ(0u, GetErrors().size()); |
| 1463 EXPECT_EQ(1u, service_->extensions()->size()); | 1454 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1464 const Extension* extension = service_->extensions()->at(0); | 1455 const Extension* extension = service_->extensions()->at(0); |
| 1465 std::string extension_id = extension->id(); | 1456 std::string extension_id = extension->id(); |
| 1466 | 1457 |
| 1467 ExtensionPrefs* prefs = service_->extension_prefs(); | 1458 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1468 | 1459 |
| 1469 std::set<std::string> expected_api_permissions; | 1460 ExtensionAPIPermissionSet expected_api_permissions; |
| 1470 URLPatternSet expected_host_permissions; | 1461 URLPatternSet expected_host_permissions; |
| 1471 | 1462 |
| 1472 expected_api_permissions.insert("tabs"); | 1463 expected_api_permissions.insert(ExtensionAPIPermission::kTab); |
| 1473 AddPattern(&expected_host_permissions, "http://*.google.com/*"); | 1464 AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 1474 AddPattern(&expected_host_permissions, "https://*.google.com/*"); | 1465 AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
| 1475 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); | 1466 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); |
| 1476 AddPattern(&expected_host_permissions, "http://www.example.com/*"); | 1467 AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 1477 | 1468 |
| 1478 std::set<std::string> api_permissions; | |
| 1479 std::set<std::string> host_permissions; | 1469 std::set<std::string> host_permissions; |
| 1480 | 1470 |
| 1481 // Test that the extension is disabled when an API permission is missing from | 1471 // Test that the extension is disabled when an API permission is missing from |
| 1482 // the extension's granted api permissions preference. (This simulates | 1472 // the extension's granted api permissions preference. (This simulates |
| 1483 // updating the browser to a version which recognizes a new API permission). | 1473 // updating the browser to a version which recognizes a new API permission). |
| 1484 SetPrefStringSet(extension_id, "granted_permissions.api", api_permissions); | 1474 SetPref(extension_id, "granted_permissions.api", |
| 1485 | 1475 new ListValue(), "granted_permissions.api"); |
| 1486 service_->ReloadExtensions(); | 1476 service_->ReloadExtensions(); |
| 1487 | 1477 |
| 1488 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 1478 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 1489 extension = service_->disabled_extensions()->at(0); | 1479 extension = service_->disabled_extensions()->at(0); |
| 1490 | 1480 |
| 1491 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); | 1481 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); |
| 1492 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1482 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1493 | 1483 |
| 1494 // Now grant and re-enable the extension, making sure the prefs are updated. | 1484 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1495 service_->GrantPermissionsAndEnableExtension(extension); | 1485 service_->GrantPermissionsAndEnableExtension(extension); |
| 1496 | 1486 |
| 1497 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); | 1487 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
| 1498 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1488 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1499 | 1489 |
| 1500 std::set<std::string> current_api_permissions; | 1490 scoped_ptr<ExtensionPermissionSet> current_perms( |
| 1501 URLPatternSet current_host_permissions; | 1491 prefs->GetGrantedPermissions(extension_id)); |
| 1502 bool current_full_access; | 1492 ASSERT_TRUE(current_perms.get()); |
| 1503 | 1493 ASSERT_FALSE(current_perms->IsDefault()); |
| 1504 ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id, | 1494 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
| 1505 ¤t_full_access, | 1495 ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
| 1506 ¤t_api_permissions, | 1496 AssertEqualExtents(expected_host_permissions, |
| 1507 ¤t_host_permissions)); | 1497 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, ¤t_host_permissions); | |
| 1512 | 1498 |
| 1513 // Tests that the extension is disabled when a host permission is missing from | 1499 // Tests that the extension is disabled when a host permission is missing from |
| 1514 // the extension's granted host permissions preference. (This simulates | 1500 // the extension's granted host permissions preference. (This simulates |
| 1515 // updating the browser to a version which recognizes additional host | 1501 // updating the browser to a version which recognizes additional host |
| 1516 // permissions). | 1502 // permissions). |
| 1517 api_permissions.clear(); | |
| 1518 host_permissions.clear(); | 1503 host_permissions.clear(); |
| 1519 current_api_permissions.clear(); | 1504 current_perms.reset(); |
| 1520 current_host_permissions.ClearPatterns(); | |
| 1521 | 1505 |
| 1522 api_permissions.insert("tabs"); | |
| 1523 host_permissions.insert("http://*.google.com/*"); | 1506 host_permissions.insert("http://*.google.com/*"); |
| 1524 host_permissions.insert("https://*.google.com/*"); | 1507 host_permissions.insert("https://*.google.com/*"); |
| 1525 host_permissions.insert("http://*.google.com.hk/*"); | 1508 host_permissions.insert("http://*.google.com.hk/*"); |
| 1526 | 1509 |
| 1527 SetPrefStringSet(extension_id, "granted_permissions.api", api_permissions); | 1510 ListValue* api_permissions = new ListValue(); |
| 1528 SetPrefStringSet(extension_id, "granted_permissions.host", host_permissions); | 1511 api_permissions->Append( |
| 1512 Value::CreateIntegerValue(ExtensionAPIPermission::kTab)); |
| 1513 SetPref(extension_id, "granted_permissions.api", |
| 1514 api_permissions, "granted_permissions.api"); |
| 1515 SetPrefStringSet( |
| 1516 extension_id, "granted_permissions.scriptable_host", host_permissions); |
| 1529 | 1517 |
| 1530 service_->ReloadExtensions(); | 1518 service_->ReloadExtensions(); |
| 1531 | 1519 |
| 1532 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 1520 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 1533 extension = service_->disabled_extensions()->at(0); | 1521 extension = service_->disabled_extensions()->at(0); |
| 1534 | 1522 |
| 1535 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); | 1523 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); |
| 1536 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1524 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1537 | 1525 |
| 1538 // Now grant and re-enable the extension, making sure the prefs are updated. | 1526 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1539 service_->GrantPermissionsAndEnableExtension(extension); | 1527 service_->GrantPermissionsAndEnableExtension(extension); |
| 1540 | 1528 |
| 1541 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); | 1529 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
| 1542 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1530 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1543 | 1531 |
| 1544 ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id, | 1532 current_perms.reset(prefs->GetGrantedPermissions(extension_id)); |
| 1545 ¤t_full_access, | 1533 ASSERT_TRUE(current_perms.get()); |
| 1546 ¤t_api_permissions, | 1534 ASSERT_FALSE(current_perms->IsDefault()); |
| 1547 ¤t_host_permissions)); | 1535 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
| 1548 | 1536 ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
| 1549 ASSERT_FALSE(current_full_access); | 1537 AssertEqualExtents(expected_host_permissions, |
| 1550 ASSERT_EQ(expected_api_permissions, current_api_permissions); | 1538 current_perms->effective_hosts()); |
| 1551 AssertEqualExtents(&expected_host_permissions, ¤t_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 ¤t_full_access, | |
| 1570 ¤t_api_permissions, | |
| 1571 ¤t_host_permissions)); | |
| 1572 | |
| 1573 ASSERT_FALSE(current_full_access); | |
| 1574 ASSERT_EQ(expected_api_permissions, current_api_permissions); | |
| 1575 AssertEqualExtents(&expected_host_permissions, ¤t_host_permissions); | |
| 1576 } | 1539 } |
| 1577 | 1540 |
| 1578 // Test Packaging and installing an extension. | 1541 // Test Packaging and installing an extension. |
| 1579 TEST_F(ExtensionServiceTest, PackExtension) { | 1542 TEST_F(ExtensionServiceTest, PackExtension) { |
| 1580 InitializeEmptyExtensionService(); | 1543 InitializeEmptyExtensionService(); |
| 1581 FilePath input_directory = data_dir_ | 1544 FilePath input_directory = data_dir_ |
| 1582 .AppendASCII("good") | 1545 .AppendASCII("good") |
| 1583 .AppendASCII("Extensions") | 1546 .AppendASCII("Extensions") |
| 1584 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 1547 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 1585 .AppendASCII("1.0.0.0"); | 1548 .AppendASCII("1.0.0.0"); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 | 1791 |
| 1829 int pref_count = 0; | 1792 int pref_count = 0; |
| 1830 | 1793 |
| 1831 // Install app1 with unlimited storage. | 1794 // Install app1 with unlimited storage. |
| 1832 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 1795 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); |
| 1833 ValidatePrefKeyCount(++pref_count); | 1796 ValidatePrefKeyCount(++pref_count); |
| 1834 ASSERT_EQ(1u, service_->extensions()->size()); | 1797 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1835 const Extension* extension = service_->extensions()->at(0); | 1798 const Extension* extension = service_->extensions()->at(0); |
| 1836 const std::string id1 = extension->id(); | 1799 const std::string id1 = extension->id(); |
| 1837 EXPECT_TRUE(extension->HasApiPermission( | 1800 EXPECT_TRUE(extension->HasApiPermission( |
| 1838 Extension::kUnlimitedStoragePermission)); | 1801 ExtensionAPIPermission::kUnlimitedStorage)); |
| 1839 EXPECT_TRUE(extension->web_extent().MatchesURL( | 1802 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 1840 extension->GetFullLaunchURL())); | 1803 extension->GetFullLaunchURL())); |
| 1841 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 1804 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 1842 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1805 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1843 IsStorageUnlimited(origin1)); | 1806 IsStorageUnlimited(origin1)); |
| 1844 | 1807 |
| 1845 // Install app2 from the same origin with unlimited storage. | 1808 // Install app2 from the same origin with unlimited storage. |
| 1846 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); | 1809 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); |
| 1847 ValidatePrefKeyCount(++pref_count); | 1810 ValidatePrefKeyCount(++pref_count); |
| 1848 ASSERT_EQ(2u, service_->extensions()->size()); | 1811 ASSERT_EQ(2u, service_->extensions()->size()); |
| 1849 extension = service_->extensions()->at(1); | 1812 extension = service_->extensions()->at(1); |
| 1850 const std::string id2 = extension->id(); | 1813 const std::string id2 = extension->id(); |
| 1851 EXPECT_TRUE(extension->HasApiPermission( | 1814 EXPECT_TRUE(extension->HasApiPermission( |
| 1852 Extension::kUnlimitedStoragePermission)); | 1815 ExtensionAPIPermission::kUnlimitedStorage)); |
| 1853 EXPECT_TRUE(extension->web_extent().MatchesURL( | 1816 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 1854 extension->GetFullLaunchURL())); | 1817 extension->GetFullLaunchURL())); |
| 1855 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 1818 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 1856 EXPECT_EQ(origin1, origin2); | 1819 EXPECT_EQ(origin1, origin2); |
| 1857 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1820 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1858 IsStorageUnlimited(origin2)); | 1821 IsStorageUnlimited(origin2)); |
| 1859 | 1822 |
| 1860 | 1823 |
| 1861 // Uninstall one of them, unlimited storage should still be granted | 1824 // Uninstall one of them, unlimited storage should still be granted |
| 1862 // to the origin. | 1825 // to the origin. |
| (...skipping 1937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3800 ASSERT_FALSE(AddPendingSyncInstall()); | 3763 ASSERT_FALSE(AddPendingSyncInstall()); |
| 3801 | 3764 |
| 3802 // Wait for the external source to install. | 3765 // Wait for the external source to install. |
| 3803 WaitForCrxInstall(crx_path_, true); | 3766 WaitForCrxInstall(crx_path_, true); |
| 3804 ASSERT_TRUE(IsCrxInstalled()); | 3767 ASSERT_TRUE(IsCrxInstalled()); |
| 3805 | 3768 |
| 3806 // Now that the extension is installed, sync request should fail | 3769 // Now that the extension is installed, sync request should fail |
| 3807 // because the extension is already installed. | 3770 // because the extension is already installed. |
| 3808 ASSERT_FALSE(AddPendingSyncInstall()); | 3771 ASSERT_FALSE(AddPendingSyncInstall()); |
| 3809 } | 3772 } |
| OLD | NEW |