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 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 scripts[1].js_scripts()[0].extension_root(), | 1016 scripts[1].js_scripts()[0].extension_root(), |
1017 scripts[1].js_scripts()[0].relative_path()); | 1017 scripts[1].js_scripts()[0].relative_path()); |
1018 expected_path = | 1018 expected_path = |
1019 extension->path().AppendASCII("js_files").AppendASCII("script3.js"); | 1019 extension->path().AppendASCII("js_files").AppendASCII("script3.js"); |
1020 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); | 1020 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); |
1021 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); | 1021 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); |
1022 | 1022 |
1023 expected_patterns.ClearPatterns(); | 1023 expected_patterns.ClearPatterns(); |
1024 AddPattern(&expected_patterns, "http://*.google.com/*"); | 1024 AddPattern(&expected_patterns, "http://*.google.com/*"); |
1025 AddPattern(&expected_patterns, "https://*.google.com/*"); | 1025 AddPattern(&expected_patterns, "https://*.google.com/*"); |
1026 EXPECT_EQ(expected_patterns, extension->permission_set()->explicit_hosts()); | 1026 EXPECT_EQ(expected_patterns, |
| 1027 extension->GetActivePermissions()->explicit_hosts()); |
1027 | 1028 |
1028 EXPECT_EQ(std::string(good1), loaded_[1]->id()); | 1029 EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
1029 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); | 1030 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
1030 EXPECT_EQ(std::string(""), loaded_[1]->description()); | 1031 EXPECT_EQ(std::string(""), loaded_[1]->description()); |
1031 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), | 1032 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
1032 loaded_[1]->background_url()); | 1033 loaded_[1]->background_url()); |
1033 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); | 1034 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); |
1034 // We don't parse the plugins section on Chrome OS. | 1035 // We don't parse the plugins section on Chrome OS. |
1035 #if defined(OS_CHROMEOS) | 1036 #if defined(OS_CHROMEOS) |
1036 EXPECT_EQ(0u, loaded_[1]->plugins().size()); | 1037 EXPECT_EQ(0u, loaded_[1]->plugins().size()); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 ASSERT_TRUE(file_util::PathExists(pem_path)); | 1358 ASSERT_TRUE(file_util::PathExists(pem_path)); |
1358 ASSERT_TRUE(file_util::PathExists(path)); | 1359 ASSERT_TRUE(file_util::PathExists(path)); |
1359 | 1360 |
1360 ExtensionPrefs* prefs = service_->extension_prefs(); | 1361 ExtensionPrefs* prefs = service_->extension_prefs(); |
1361 | 1362 |
1362 ExtensionAPIPermissionSet expected_api_perms; | 1363 ExtensionAPIPermissionSet expected_api_perms; |
1363 URLPatternSet expected_host_perms; | 1364 URLPatternSet expected_host_perms; |
1364 | 1365 |
1365 // Make sure there aren't any granted permissions before the | 1366 // Make sure there aren't any granted permissions before the |
1366 // extension is installed. | 1367 // extension is installed. |
1367 scoped_ptr<ExtensionPermissionSet> known_perms( | 1368 scoped_refptr<ExtensionPermissionSet> known_perms( |
1368 prefs->GetGrantedPermissions(permissions_crx)); | 1369 prefs->GetGrantedPermissions(permissions_crx)); |
1369 EXPECT_FALSE(known_perms.get()); | 1370 EXPECT_FALSE(known_perms.get()); |
1370 | 1371 |
1371 PackAndInstallCrx(path, pem_path, true); | 1372 PackAndInstallCrx(path, pem_path, true); |
1372 | 1373 |
1373 EXPECT_EQ(0u, GetErrors().size()); | 1374 EXPECT_EQ(0u, GetErrors().size()); |
1374 ASSERT_EQ(1u, service_->extensions()->size()); | 1375 ASSERT_EQ(1u, service_->extensions()->size()); |
1375 std::string extension_id = service_->extensions()->at(0)->id(); | 1376 std::string extension_id = service_->extensions()->at(0)->id(); |
1376 EXPECT_EQ(permissions_crx, extension_id); | 1377 EXPECT_EQ(permissions_crx, extension_id); |
1377 | 1378 |
1378 // Verify that the valid API permissions have been recognized. | 1379 // Verify that the valid API permissions have been recognized. |
1379 expected_api_perms.insert(ExtensionAPIPermission::kTab); | 1380 expected_api_perms.insert(ExtensionAPIPermission::kTab); |
1380 | 1381 |
1381 AddPattern(&expected_host_perms, "http://*.google.com/*"); | 1382 AddPattern(&expected_host_perms, "http://*.google.com/*"); |
1382 AddPattern(&expected_host_perms, "https://*.google.com/*"); | 1383 AddPattern(&expected_host_perms, "https://*.google.com/*"); |
1383 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); | 1384 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
1384 AddPattern(&expected_host_perms, "http://www.example.com/*"); | 1385 AddPattern(&expected_host_perms, "http://www.example.com/*"); |
1385 | 1386 |
1386 known_perms.reset(prefs->GetGrantedPermissions(extension_id)); | 1387 known_perms = prefs->GetGrantedPermissions(extension_id); |
1387 EXPECT_TRUE(known_perms.get()); | 1388 EXPECT_TRUE(known_perms.get()); |
1388 EXPECT_FALSE(known_perms->IsEmpty()); | 1389 EXPECT_FALSE(known_perms->IsEmpty()); |
1389 EXPECT_EQ(expected_api_perms, known_perms->apis()); | 1390 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
1390 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1391 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
1391 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); | 1392 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
1392 } | 1393 } |
1393 | 1394 |
1394 #if !defined(OS_CHROMEOS) | 1395 #if !defined(OS_CHROMEOS) |
1395 // Tests that the granted permissions full_access bit gets set correctly when | 1396 // Tests that the granted permissions full_access bit gets set correctly when |
1396 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS | 1397 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
1397 // since they don't support plugins. | 1398 // since they don't support plugins. |
1398 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { | 1399 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
1399 InitializeEmptyExtensionService(); | 1400 InitializeEmptyExtensionService(); |
1400 | 1401 |
1401 FilePath path = data_dir_ | 1402 FilePath path = data_dir_ |
1402 .AppendASCII("good") | 1403 .AppendASCII("good") |
1403 .AppendASCII("Extensions") | 1404 .AppendASCII("Extensions") |
1404 .AppendASCII(good1) | 1405 .AppendASCII(good1) |
1405 .AppendASCII("2"); | 1406 .AppendASCII("2"); |
1406 | 1407 |
1407 ASSERT_TRUE(file_util::PathExists(path)); | 1408 ASSERT_TRUE(file_util::PathExists(path)); |
1408 PackAndInstallCrx(path, true); | 1409 PackAndInstallCrx(path, true); |
1409 EXPECT_EQ(0u, GetErrors().size()); | 1410 EXPECT_EQ(0u, GetErrors().size()); |
1410 EXPECT_EQ(1u, service_->extensions()->size()); | 1411 EXPECT_EQ(1u, service_->extensions()->size()); |
1411 const Extension* extension = service_->extensions()->at(0); | 1412 const Extension* extension = service_->extensions()->at(0); |
1412 std::string extension_id = extension->id(); | 1413 std::string extension_id = extension->id(); |
1413 ExtensionPrefs* prefs = service_->extension_prefs(); | 1414 ExtensionPrefs* prefs = service_->extension_prefs(); |
1414 | 1415 |
1415 scoped_ptr<ExtensionPermissionSet> permissions( | 1416 scoped_refptr<ExtensionPermissionSet> permissions( |
1416 prefs->GetGrantedPermissions(extension_id)); | 1417 prefs->GetGrantedPermissions(extension_id)); |
1417 EXPECT_FALSE(permissions->IsEmpty()); | 1418 EXPECT_FALSE(permissions->IsEmpty()); |
1418 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); | 1419 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
1419 EXPECT_FALSE(permissions->apis().empty()); | 1420 EXPECT_FALSE(permissions->apis().empty()); |
1420 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin)); | 1421 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin)); |
1421 | 1422 |
1422 // Full access implies full host access too... | 1423 // Full access implies full host access too... |
1423 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); | 1424 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
1424 } | 1425 } |
1425 #endif | 1426 #endif |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); | 1471 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
1471 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1472 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
1472 | 1473 |
1473 // Now grant and re-enable the extension, making sure the prefs are updated. | 1474 // Now grant and re-enable the extension, making sure the prefs are updated. |
1474 service_->GrantPermissionsAndEnableExtension(extension); | 1475 service_->GrantPermissionsAndEnableExtension(extension); |
1475 | 1476 |
1476 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); | 1477 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
1477 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); | 1478 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
1478 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1479 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
1479 | 1480 |
1480 scoped_ptr<ExtensionPermissionSet> current_perms( | 1481 scoped_refptr<ExtensionPermissionSet> current_perms( |
1481 prefs->GetGrantedPermissions(extension_id)); | 1482 prefs->GetGrantedPermissions(extension_id)); |
1482 ASSERT_TRUE(current_perms.get()); | 1483 ASSERT_TRUE(current_perms.get()); |
1483 ASSERT_FALSE(current_perms->IsEmpty()); | 1484 ASSERT_FALSE(current_perms->IsEmpty()); |
1484 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); | 1485 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
1485 ASSERT_EQ(expected_api_permissions, current_perms->apis()); | 1486 ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
1486 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); | 1487 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
1487 | 1488 |
1488 // Tests that the extension is disabled when a host permission is missing from | 1489 // Tests that the extension is disabled when a host permission is missing from |
1489 // the extension's granted host permissions preference. (This simulates | 1490 // the extension's granted host permissions preference. (This simulates |
1490 // updating the browser to a version which recognizes additional host | 1491 // updating the browser to a version which recognizes additional host |
1491 // permissions). | 1492 // permissions). |
1492 host_permissions.clear(); | 1493 host_permissions.clear(); |
1493 current_perms.reset(); | 1494 current_perms = NULL; |
1494 | 1495 |
1495 host_permissions.insert("http://*.google.com/*"); | 1496 host_permissions.insert("http://*.google.com/*"); |
1496 host_permissions.insert("https://*.google.com/*"); | 1497 host_permissions.insert("https://*.google.com/*"); |
1497 host_permissions.insert("http://*.google.com.hk/*"); | 1498 host_permissions.insert("http://*.google.com.hk/*"); |
1498 | 1499 |
1499 ListValue* api_permissions = new ListValue(); | 1500 ListValue* api_permissions = new ListValue(); |
1500 api_permissions->Append( | 1501 api_permissions->Append( |
1501 Value::CreateIntegerValue(ExtensionAPIPermission::kTab)); | 1502 Value::CreateIntegerValue(ExtensionAPIPermission::kTab)); |
1502 SetPref(extension_id, "granted_permissions.api", | 1503 SetPref(extension_id, "granted_permissions.api", |
1503 api_permissions, "granted_permissions.api"); | 1504 api_permissions, "granted_permissions.api"); |
1504 SetPrefStringSet( | 1505 SetPrefStringSet( |
1505 extension_id, "granted_permissions.scriptable_host", host_permissions); | 1506 extension_id, "granted_permissions.scriptable_host", host_permissions); |
1506 | 1507 |
1507 service_->ReloadExtensions(); | 1508 service_->ReloadExtensions(); |
1508 | 1509 |
1509 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 1510 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
1510 extension = service_->disabled_extensions()->at(0); | 1511 extension = service_->disabled_extensions()->at(0); |
1511 | 1512 |
1512 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); | 1513 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); |
1513 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); | 1514 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
1514 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1515 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
1515 | 1516 |
1516 // Now grant and re-enable the extension, making sure the prefs are updated. | 1517 // Now grant and re-enable the extension, making sure the prefs are updated. |
1517 service_->GrantPermissionsAndEnableExtension(extension); | 1518 service_->GrantPermissionsAndEnableExtension(extension); |
1518 | 1519 |
1519 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); | 1520 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
1520 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1521 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
1521 | 1522 |
1522 current_perms.reset(prefs->GetGrantedPermissions(extension_id)); | 1523 current_perms = prefs->GetGrantedPermissions(extension_id); |
1523 ASSERT_TRUE(current_perms.get()); | 1524 ASSERT_TRUE(current_perms.get()); |
1524 ASSERT_FALSE(current_perms->IsEmpty()); | 1525 ASSERT_FALSE(current_perms->IsEmpty()); |
1525 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); | 1526 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
1526 ASSERT_EQ(expected_api_permissions, current_perms->apis()); | 1527 ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
1527 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); | 1528 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
1528 } | 1529 } |
1529 | 1530 |
1530 // Test Packaging and installing an extension. | 1531 // Test Packaging and installing an extension. |
1531 TEST_F(ExtensionServiceTest, PackExtension) { | 1532 TEST_F(ExtensionServiceTest, PackExtension) { |
1532 InitializeEmptyExtensionService(); | 1533 InitializeEmptyExtensionService(); |
(...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3793 ASSERT_FALSE(AddPendingSyncInstall()); | 3794 ASSERT_FALSE(AddPendingSyncInstall()); |
3794 | 3795 |
3795 // Wait for the external source to install. | 3796 // Wait for the external source to install. |
3796 WaitForCrxInstall(crx_path_, true); | 3797 WaitForCrxInstall(crx_path_, true); |
3797 ASSERT_TRUE(IsCrxInstalled()); | 3798 ASSERT_TRUE(IsCrxInstalled()); |
3798 | 3799 |
3799 // Now that the extension is installed, sync request should fail | 3800 // Now that the extension is installed, sync request should fail |
3800 // because the extension is already installed. | 3801 // because the extension is already installed. |
3801 ASSERT_FALSE(AddPendingSyncInstall()); | 3802 ASSERT_FALSE(AddPendingSyncInstall()); |
3802 } | 3803 } |
OLD | NEW |