| 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 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 // escalation. | 1422 // escalation. |
| 1423 TEST_F(ExtensionServiceTest, GrantedPermissionsOnUpdate) { | 1423 TEST_F(ExtensionServiceTest, GrantedPermissionsOnUpdate) { |
| 1424 InitializeEmptyExtensionService(); | 1424 InitializeEmptyExtensionService(); |
| 1425 const base::FilePath base_path = data_dir().AppendASCII("permissions"); | 1425 const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1426 | 1426 |
| 1427 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); | 1427 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1428 const base::FilePath path1 = base_path.AppendASCII("update_1"); | 1428 const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1429 const base::FilePath path2 = base_path.AppendASCII("update_2"); | 1429 const base::FilePath path2 = base_path.AppendASCII("update_2"); |
| 1430 const base::FilePath path3 = base_path.AppendASCII("update_3"); | 1430 const base::FilePath path3 = base_path.AppendASCII("update_3"); |
| 1431 const base::FilePath path4 = base_path.AppendASCII("update_4"); | 1431 const base::FilePath path4 = base_path.AppendASCII("update_4"); |
| 1432 const base::FilePath path5 = base_path.AppendASCII("update_5"); |
| 1432 | 1433 |
| 1433 ASSERT_TRUE(base::PathExists(pem_path)); | 1434 ASSERT_TRUE(base::PathExists(pem_path)); |
| 1434 ASSERT_TRUE(base::PathExists(path1)); | 1435 ASSERT_TRUE(base::PathExists(path1)); |
| 1435 ASSERT_TRUE(base::PathExists(path2)); | 1436 ASSERT_TRUE(base::PathExists(path2)); |
| 1436 ASSERT_TRUE(base::PathExists(path3)); | 1437 ASSERT_TRUE(base::PathExists(path3)); |
| 1437 ASSERT_TRUE(base::PathExists(path4)); | 1438 ASSERT_TRUE(base::PathExists(path4)); |
| 1439 ASSERT_TRUE(base::PathExists(path5)); |
| 1438 | 1440 |
| 1439 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 1441 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1440 | 1442 |
| 1441 // Install version 1, which has the kHistory permission. | 1443 // Install version 1, which has the kHistory permission. |
| 1442 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); | 1444 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1443 const std::string id = extension->id(); | 1445 const std::string id = extension->id(); |
| 1444 | 1446 |
| 1445 EXPECT_EQ(0u, GetErrors().size()); | 1447 EXPECT_EQ(0u, GetErrors().size()); |
| 1446 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); | 1448 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1447 | 1449 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 | 1500 |
| 1499 // No new permissions should have been granted. | 1501 // No new permissions should have been granted. |
| 1500 { | 1502 { |
| 1501 std::unique_ptr<const PermissionSet> known_perms = | 1503 std::unique_ptr<const PermissionSet> known_perms = |
| 1502 prefs->GetGrantedPermissions(id); | 1504 prefs->GetGrantedPermissions(id); |
| 1503 ASSERT_TRUE(known_perms.get()); | 1505 ASSERT_TRUE(known_perms.get()); |
| 1504 EXPECT_EQ(expected_api_perms, known_perms->apis()); | 1506 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1505 } | 1507 } |
| 1506 } | 1508 } |
| 1507 | 1509 |
| 1510 TEST_F(ExtensionServiceTest, ReenableWithAllPermissionsGranted) { |
| 1511 InitializeEmptyExtensionService(); |
| 1512 const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1513 |
| 1514 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1515 const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1516 const base::FilePath path4 = base_path.AppendASCII("update_4"); |
| 1517 const base::FilePath path5 = base_path.AppendASCII("update_5"); |
| 1518 |
| 1519 ASSERT_TRUE(base::PathExists(pem_path)); |
| 1520 ASSERT_TRUE(base::PathExists(path1)); |
| 1521 ASSERT_TRUE(base::PathExists(path4)); |
| 1522 ASSERT_TRUE(base::PathExists(path5)); |
| 1523 |
| 1524 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1525 |
| 1526 // Install version 1, which has the kHistory permission. |
| 1527 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1528 const std::string id = extension->id(); |
| 1529 |
| 1530 EXPECT_EQ(0u, GetErrors().size()); |
| 1531 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1532 |
| 1533 // Update to version 4 that adds the kNotifications permission, which has a |
| 1534 // message and hence is considered a permission increase. The extension |
| 1535 // should get disabled due to a permissions increase. |
| 1536 PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED); |
| 1537 extension = service()->GetInstalledExtension(id); |
| 1538 ASSERT_TRUE(extension); |
| 1539 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1540 EXPECT_TRUE( |
| 1541 prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE)); |
| 1542 |
| 1543 // Update to version 5 that removes the kNotifications permission again. |
| 1544 // The extension should get re-enabled. |
| 1545 PackCRXAndUpdateExtension(id, path5, pem_path, ENABLED); |
| 1546 extension = service()->GetInstalledExtension(id); |
| 1547 ASSERT_TRUE(extension); |
| 1548 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1549 } |
| 1550 |
| 1551 TEST_F(ExtensionServiceTest, ReenableWithAllPermissionsGrantedOnStartup) { |
| 1552 InitializeEmptyExtensionService(); |
| 1553 const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1554 |
| 1555 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1556 const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1557 |
| 1558 ASSERT_TRUE(base::PathExists(pem_path)); |
| 1559 ASSERT_TRUE(base::PathExists(path1)); |
| 1560 |
| 1561 // Install an extension which has the kHistory permission. |
| 1562 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1563 const std::string id = extension->id(); |
| 1564 |
| 1565 EXPECT_EQ(0u, GetErrors().size()); |
| 1566 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1567 |
| 1568 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1569 |
| 1570 // Disable the extension due to a supposed permission increase, but retain its |
| 1571 // granted permissions. |
| 1572 service()->DisableExtension(id, Extension::DISABLE_PERMISSIONS_INCREASE); |
| 1573 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1574 EXPECT_TRUE( |
| 1575 prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE)); |
| 1576 |
| 1577 // Simulate a Chrome restart. Since the extension has all required |
| 1578 // permissions, it should get re-enabled. |
| 1579 service()->ReloadExtensionsForTest(); |
| 1580 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1581 EXPECT_FALSE( |
| 1582 prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE)); |
| 1583 } |
| 1584 |
| 1585 TEST_F(ExtensionServiceTest, |
| 1586 DontReenableWithAllPermissionsGrantedButOtherReason) { |
| 1587 InitializeEmptyExtensionService(); |
| 1588 const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1589 |
| 1590 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1591 const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1592 const base::FilePath path4 = base_path.AppendASCII("update_4"); |
| 1593 const base::FilePath path5 = base_path.AppendASCII("update_5"); |
| 1594 |
| 1595 ASSERT_TRUE(base::PathExists(pem_path)); |
| 1596 ASSERT_TRUE(base::PathExists(path1)); |
| 1597 ASSERT_TRUE(base::PathExists(path4)); |
| 1598 ASSERT_TRUE(base::PathExists(path5)); |
| 1599 |
| 1600 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1601 |
| 1602 // Install version 1, which has the kHistory permission. |
| 1603 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1604 const std::string id = extension->id(); |
| 1605 |
| 1606 EXPECT_EQ(0u, GetErrors().size()); |
| 1607 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1608 |
| 1609 // Disable the extension. |
| 1610 service()->DisableExtension(id, Extension::DISABLE_USER_ACTION); |
| 1611 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1612 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_USER_ACTION)); |
| 1613 |
| 1614 // Update to version 4 that adds the kNotifications permission, which has a |
| 1615 // message and hence is considered a permission increase. The extension |
| 1616 // should get disabled due to a permissions increase. |
| 1617 PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED); |
| 1618 extension = service()->GetInstalledExtension(id); |
| 1619 ASSERT_TRUE(extension); |
| 1620 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1621 EXPECT_TRUE( |
| 1622 prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE)); |
| 1623 // The USER_ACTION reason should also still be there. |
| 1624 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_USER_ACTION)); |
| 1625 |
| 1626 // Update to version 5 that removes the kNotifications permission again. |
| 1627 // The PERMISSIONS_INCREASE should be removed, but the extension should stay |
| 1628 // disabled since USER_ACTION is still there. |
| 1629 PackCRXAndUpdateExtension(id, path5, pem_path, DISABLED); |
| 1630 extension = service()->GetInstalledExtension(id); |
| 1631 ASSERT_TRUE(extension); |
| 1632 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1633 EXPECT_EQ(Extension::DISABLE_USER_ACTION, prefs->GetDisableReasons(id)); |
| 1634 } |
| 1635 |
| 1636 TEST_F(ExtensionServiceTest, |
| 1637 DontReenableWithAllPermissionsGrantedOnStartupButOtherReason) { |
| 1638 InitializeEmptyExtensionService(); |
| 1639 const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1640 |
| 1641 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1642 const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1643 |
| 1644 ASSERT_TRUE(base::PathExists(pem_path)); |
| 1645 ASSERT_TRUE(base::PathExists(path1)); |
| 1646 |
| 1647 // Install an extension which has the kHistory permission. |
| 1648 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1649 const std::string id = extension->id(); |
| 1650 |
| 1651 EXPECT_EQ(0u, GetErrors().size()); |
| 1652 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1653 |
| 1654 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1655 |
| 1656 // Disable the extension due to a supposed permission increase, but retain its |
| 1657 // granted permissions. |
| 1658 service()->DisableExtension( |
| 1659 id, |
| 1660 Extension::DISABLE_PERMISSIONS_INCREASE | Extension::DISABLE_USER_ACTION); |
| 1661 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1662 EXPECT_TRUE( |
| 1663 prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE)); |
| 1664 |
| 1665 // Simulate a Chrome restart. Since the extension has all required |
| 1666 // permissions, the DISABLE_PERMISSIONS_INCREASE should get removed, but it |
| 1667 // should stay disabled due to the remaining DISABLE_USER_ACTION reason. |
| 1668 service()->ReloadExtensionsForTest(); |
| 1669 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1670 EXPECT_EQ(Extension::DISABLE_USER_ACTION, prefs->GetDisableReasons(id)); |
| 1671 } |
| 1672 |
| 1508 #if !defined(OS_CHROMEOS) | 1673 #if !defined(OS_CHROMEOS) |
| 1509 // This tests that the granted permissions preferences are correctly set for | 1674 // This tests that the granted permissions preferences are correctly set for |
| 1510 // default apps. | 1675 // default apps. |
| 1511 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { | 1676 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
| 1512 InitializeEmptyExtensionService(); | 1677 InitializeEmptyExtensionService(); |
| 1513 base::FilePath path = data_dir().AppendASCII("permissions"); | 1678 base::FilePath path = data_dir().AppendASCII("permissions"); |
| 1514 | 1679 |
| 1515 base::FilePath pem_path = path.AppendASCII("unknown.pem"); | 1680 base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
| 1516 path = path.AppendASCII("unknown"); | 1681 path = path.AppendASCII("unknown"); |
| 1517 | 1682 |
| (...skipping 5132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6650 | 6815 |
| 6651 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6816 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 6652 content::Source<Profile>(profile()), | 6817 content::Source<Profile>(profile()), |
| 6653 content::NotificationService::NoDetails()); | 6818 content::NotificationService::NoDetails()); |
| 6654 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6819 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
| 6655 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6820 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 6656 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6821 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 6657 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6822 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 6658 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6823 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
| 6659 } | 6824 } |
| OLD | NEW |