Chromium Code Reviews| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1496 ASSERT_TRUE(extension); | 1498 ASSERT_TRUE(extension); |
| 1497 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | 1499 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 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 } |
| 1508 | |
| 1509 // Update to version 5 that removes the kNotifications permission again. | |
| 1510 // The extension should get re-enabled. | |
| 1511 PackCRXAndUpdateExtension(id, path5, pem_path, ENABLED); | |
| 1512 extension = service()->GetInstalledExtension(id); | |
| 1513 ASSERT_TRUE(extension); | |
| 1514 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
| 1515 | |
| 1516 // No new permissions should have been granted. | |
| 1517 { | |
| 1518 std::unique_ptr<const PermissionSet> known_perms = | |
| 1519 prefs->GetGrantedPermissions(id); | |
| 1520 ASSERT_TRUE(known_perms.get()); | |
| 1521 EXPECT_EQ(expected_api_perms, known_perms->apis()); | |
| 1522 } | |
| 1506 } | 1523 } |
| 1507 | 1524 |
| 1525 TEST_F(ExtensionServiceTest, ReenableWithAllPermissionsGranted) { | |
|
Devlin
2016/06/02 16:05:55
How does this differ from the last test?
Marc Treib
2016/06/02 16:36:14
Right - this is essentially the same as the "versi
Marc Treib
2016/06/10 14:12:17
Done. (Removed the added part of the above test ag
| |
| 1526 InitializeEmptyExtensionService(); | |
| 1527 const base::FilePath base_path = data_dir().AppendASCII("permissions"); | |
| 1528 | |
| 1529 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); | |
| 1530 const base::FilePath path1 = base_path.AppendASCII("update_1"); | |
| 1531 const base::FilePath path4 = base_path.AppendASCII("update_4"); | |
| 1532 const base::FilePath path5 = base_path.AppendASCII("update_5"); | |
| 1533 | |
| 1534 ASSERT_TRUE(base::PathExists(pem_path)); | |
| 1535 ASSERT_TRUE(base::PathExists(path1)); | |
| 1536 ASSERT_TRUE(base::PathExists(path4)); | |
| 1537 ASSERT_TRUE(base::PathExists(path5)); | |
| 1538 | |
| 1539 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | |
| 1540 | |
| 1541 // Install version 1, which has the kHistory permission. | |
| 1542 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); | |
| 1543 const std::string id = extension->id(); | |
| 1544 | |
| 1545 EXPECT_EQ(0u, GetErrors().size()); | |
| 1546 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); | |
| 1547 | |
| 1548 // Update to version 4 that adds the kNotifications permission, which has a | |
| 1549 // message and hence is considered a permission increase. The extension | |
| 1550 // should get disabled due to a permissions increase. | |
| 1551 PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED); | |
| 1552 extension = service()->GetInstalledExtension(id); | |
| 1553 ASSERT_TRUE(extension); | |
| 1554 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | |
| 1555 EXPECT_TRUE( | |
| 1556 prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE)); | |
| 1557 | |
| 1558 // Update to version 5 that removes the kNotifications permission again. | |
| 1559 // The extension should get re-enabled. | |
| 1560 PackCRXAndUpdateExtension(id, path5, pem_path, ENABLED); | |
| 1561 extension = service()->GetInstalledExtension(id); | |
| 1562 ASSERT_TRUE(extension); | |
| 1563 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | |
| 1564 } | |
| 1565 | |
| 1566 TEST_F(ExtensionServiceTest, | |
| 1567 DontReenableWithAllPermissionsGrantedButOtherReason) { | |
| 1568 InitializeEmptyExtensionService(); | |
| 1569 const base::FilePath base_path = data_dir().AppendASCII("permissions"); | |
| 1570 | |
| 1571 const base::FilePath pem_path = base_path.AppendASCII("update.pem"); | |
| 1572 const base::FilePath path1 = base_path.AppendASCII("update_1"); | |
| 1573 const base::FilePath path4 = base_path.AppendASCII("update_4"); | |
| 1574 const base::FilePath path5 = base_path.AppendASCII("update_5"); | |
| 1575 | |
| 1576 ASSERT_TRUE(base::PathExists(pem_path)); | |
| 1577 ASSERT_TRUE(base::PathExists(path1)); | |
| 1578 ASSERT_TRUE(base::PathExists(path4)); | |
| 1579 ASSERT_TRUE(base::PathExists(path5)); | |
| 1580 | |
| 1581 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | |
| 1582 | |
| 1583 // Install version 1, which has the kHistory permission. | |
| 1584 const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); | |
| 1585 const std::string id = extension->id(); | |
| 1586 | |
| 1587 EXPECT_EQ(0u, GetErrors().size()); | |
| 1588 ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); | |
| 1589 | |
| 1590 // Disable the extension. | |
| 1591 service()->DisableExtension(id, Extension::DISABLE_USER_ACTION); | |
| 1592 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | |
| 1593 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_USER_ACTION)); | |
| 1594 | |
| 1595 // Update to version 4 that adds the kNotifications permission, which has a | |
| 1596 // message and hence is considered a permission increase. The extension | |
| 1597 // should get disabled due to a permissions increase. | |
| 1598 PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED); | |
| 1599 extension = service()->GetInstalledExtension(id); | |
| 1600 ASSERT_TRUE(extension); | |
| 1601 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | |
| 1602 EXPECT_TRUE( | |
| 1603 prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE)); | |
| 1604 // The USER_ACTION reason should also still be there. | |
| 1605 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_USER_ACTION)); | |
| 1606 | |
| 1607 // Update to version 5 that removes the kNotifications permission again. | |
| 1608 // The PERMISSIONS_INCREASE should be removed, but the extension should stay | |
| 1609 // disabled since USER_ACTION is still there. | |
| 1610 PackCRXAndUpdateExtension(id, path5, pem_path, DISABLED); | |
| 1611 extension = service()->GetInstalledExtension(id); | |
| 1612 ASSERT_TRUE(extension); | |
| 1613 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | |
| 1614 EXPECT_FALSE( | |
| 1615 prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE)); | |
| 1616 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_USER_ACTION)); | |
|
Devlin
2016/06/02 16:05:55
Could even just EXPECT_EQ() here, right?
Marc Treib
2016/06/02 16:36:15
Sure, done.
| |
| 1617 } | |
|
Devlin
2016/06/02 16:05:55
How hard would it be to add a test that checks the
Marc Treib
2016/06/02 16:36:14
Shouldn't be too hard - I guess we can simulate a
| |
| 1618 | |
| 1508 #if !defined(OS_CHROMEOS) | 1619 #if !defined(OS_CHROMEOS) |
| 1509 // This tests that the granted permissions preferences are correctly set for | 1620 // This tests that the granted permissions preferences are correctly set for |
| 1510 // default apps. | 1621 // default apps. |
| 1511 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { | 1622 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
| 1512 InitializeEmptyExtensionService(); | 1623 InitializeEmptyExtensionService(); |
| 1513 base::FilePath path = data_dir().AppendASCII("permissions"); | 1624 base::FilePath path = data_dir().AppendASCII("permissions"); |
| 1514 | 1625 |
| 1515 base::FilePath pem_path = path.AppendASCII("unknown.pem"); | 1626 base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
| 1516 path = path.AppendASCII("unknown"); | 1627 path = path.AppendASCII("unknown"); |
| 1517 | 1628 |
| (...skipping 5133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6651 | 6762 |
| 6652 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6763 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 6653 content::Source<Profile>(profile()), | 6764 content::Source<Profile>(profile()), |
| 6654 content::NotificationService::NoDetails()); | 6765 content::NotificationService::NoDetails()); |
| 6655 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6766 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
| 6656 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6767 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 6657 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6768 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 6658 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6769 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 6659 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6770 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
| 6660 } | 6771 } |
| OLD | NEW |