| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 // Verify that the valid API permissions have been recognized. | 1403 // Verify that the valid API permissions have been recognized. |
| 1404 expected_api_perms.insert(APIPermission::kTab); | 1404 expected_api_perms.insert(APIPermission::kTab); |
| 1405 | 1405 |
| 1406 AddPattern(&expected_host_perms, "http://*.google.com/*"); | 1406 AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 1407 AddPattern(&expected_host_perms, "https://*.google.com/*"); | 1407 AddPattern(&expected_host_perms, "https://*.google.com/*"); |
| 1408 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); | 1408 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
| 1409 AddPattern(&expected_host_perms, "http://www.example.com/*"); | 1409 AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 1410 | 1410 |
| 1411 std::unique_ptr<const PermissionSet> known_perms = | 1411 std::unique_ptr<const PermissionSet> known_perms = |
| 1412 prefs->GetGrantedPermissions(extension->id()); | 1412 prefs->GetGrantedPermissions(extension->id()); |
| 1413 EXPECT_TRUE(known_perms.get()); | 1413 ASSERT_TRUE(known_perms.get()); |
| 1414 EXPECT_FALSE(known_perms->IsEmpty()); | 1414 EXPECT_FALSE(known_perms->IsEmpty()); |
| 1415 EXPECT_EQ(expected_api_perms, known_perms->apis()); | 1415 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1416 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1416 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
| 1417 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); | 1417 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
| 1418 } | 1418 } |
| 1419 | 1419 |
| 1420 // This tests that the granted permissions preferences are correctly set when |
| 1421 // updating an extension, and the extension is disabled in case of a permission |
| 1422 // escalation. |
| 1423 TEST_F(ExtensionServiceTest, GrantedPermissionsOnUpdate) { |
| 1424 InitializeEmptyExtensionService(); |
| 1425 const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1426 |
| 1427 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1428 const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1429 const base::FilePath path2 = base_path.AppendASCII("update_2"); |
| 1430 const base::FilePath path3 = base_path.AppendASCII("update_3"); |
| 1431 const base::FilePath path4 = base_path.AppendASCII("update_4"); |
| 1432 |
| 1433 ASSERT_TRUE(base::PathExists(pem_path)); |
| 1434 ASSERT_TRUE(base::PathExists(path1)); |
| 1435 ASSERT_TRUE(base::PathExists(path2)); |
| 1436 ASSERT_TRUE(base::PathExists(path3)); |
| 1437 ASSERT_TRUE(base::PathExists(path4)); |
| 1438 |
| 1439 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1440 |
| 1441 // Install version 1, which has the kHistory permission. |
| 1442 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1443 const std::string id = extension->id(); |
| 1444 |
| 1445 EXPECT_EQ(0u, GetErrors().size()); |
| 1446 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1447 |
| 1448 // Verify that the history permission has been recognized. |
| 1449 APIPermissionSet expected_api_perms; |
| 1450 expected_api_perms.insert(APIPermission::kHistory); |
| 1451 { |
| 1452 std::unique_ptr<const PermissionSet> known_perms = |
| 1453 prefs->GetGrantedPermissions(id); |
| 1454 ASSERT_TRUE(known_perms.get()); |
| 1455 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1456 } |
| 1457 |
| 1458 // Update to version 2 that adds the kTopSites permission, which has a |
| 1459 // separate message, but is implied by kHistory. The extension should remain |
| 1460 // enabled. |
| 1461 PackCRXAndUpdateExtension(id, path2, pem_path, ENABLED); |
| 1462 extension = service()->GetInstalledExtension(id); |
| 1463 ASSERT_TRUE(extension); |
| 1464 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1465 |
| 1466 // The extra permission should have been granted automatically. |
| 1467 expected_api_perms.insert(APIPermission::kTopSites); |
| 1468 { |
| 1469 std::unique_ptr<const PermissionSet> known_perms = |
| 1470 prefs->GetGrantedPermissions(id); |
| 1471 ASSERT_TRUE(known_perms.get()); |
| 1472 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1473 } |
| 1474 |
| 1475 // Update to version 3 that adds the kStorage permission, which does not have |
| 1476 // a message. The extension should remain enabled. |
| 1477 PackCRXAndUpdateExtension(id, path3, pem_path, ENABLED); |
| 1478 extension = service()->GetInstalledExtension(id); |
| 1479 ASSERT_TRUE(extension); |
| 1480 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1481 |
| 1482 // The extra permission should have been granted automatically. |
| 1483 expected_api_perms.insert(APIPermission::kStorage); |
| 1484 { |
| 1485 std::unique_ptr<const PermissionSet> known_perms = |
| 1486 prefs->GetGrantedPermissions(id); |
| 1487 ASSERT_TRUE(known_perms.get()); |
| 1488 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1489 } |
| 1490 |
| 1491 // Update to version 4 that adds the kNotifications permission, which has a |
| 1492 // message and hence is considered a permission increase. Now the extension |
| 1493 // should get disabled. |
| 1494 PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED); |
| 1495 extension = service()->GetInstalledExtension(id); |
| 1496 ASSERT_TRUE(extension); |
| 1497 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1498 |
| 1499 // No new permissions should have been granted. |
| 1500 { |
| 1501 std::unique_ptr<const PermissionSet> known_perms = |
| 1502 prefs->GetGrantedPermissions(id); |
| 1503 ASSERT_TRUE(known_perms.get()); |
| 1504 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1505 } |
| 1506 } |
| 1420 | 1507 |
| 1421 #if !defined(OS_CHROMEOS) | 1508 #if !defined(OS_CHROMEOS) |
| 1422 // This tests that the granted permissions preferences are correctly set for | 1509 // This tests that the granted permissions preferences are correctly set for |
| 1423 // default apps. | 1510 // default apps. |
| 1424 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { | 1511 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
| 1425 InitializeEmptyExtensionService(); | 1512 InitializeEmptyExtensionService(); |
| 1426 base::FilePath path = data_dir().AppendASCII("permissions"); | 1513 base::FilePath path = data_dir().AppendASCII("permissions"); |
| 1427 | 1514 |
| 1428 base::FilePath pem_path = path.AppendASCII("unknown.pem"); | 1515 base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
| 1429 path = path.AppendASCII("unknown"); | 1516 path = path.AppendASCII("unknown"); |
| (...skipping 5093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6523 | 6610 |
| 6524 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6611 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 6525 content::Source<Profile>(profile()), | 6612 content::Source<Profile>(profile()), |
| 6526 content::NotificationService::NoDetails()); | 6613 content::NotificationService::NoDetails()); |
| 6527 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6614 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
| 6528 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6615 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 6529 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6616 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 6530 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6617 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 6531 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6618 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
| 6532 } | 6619 } |
| OLD | NEW |