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_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 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 std::string("Could not load extension from '*'. ") + | 1458 std::string("Could not load extension from '*'. ") + |
1459 extensions::manifest_errors::kMissingFile)) << | 1459 extensions::manifest_errors::kMissingFile)) << |
1460 base::UTF16ToUTF8(GetErrors()[2]); | 1460 base::UTF16ToUTF8(GetErrors()[2]); |
1461 | 1461 |
1462 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]), | 1462 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]), |
1463 std::string("Could not load extension from '*'. ") + | 1463 std::string("Could not load extension from '*'. ") + |
1464 extensions::manifest_errors::kManifestUnreadable)) << | 1464 extensions::manifest_errors::kManifestUnreadable)) << |
1465 base::UTF16ToUTF8(GetErrors()[3]); | 1465 base::UTF16ToUTF8(GetErrors()[3]); |
1466 }; | 1466 }; |
1467 | 1467 |
1468 // Test that partially deleted extensions are cleaned up during startup | |
1469 // Test loading bad extensions from the profile directory. | |
1470 TEST_F(ExtensionServiceTest, CleanupOnStartup) { | |
1471 InitPluginService(); | |
1472 InitializeGoodInstalledExtensionService(); | |
1473 | |
1474 // Simulate that one of them got partially deleted by clearing its pref. | |
1475 { | |
1476 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); | |
1477 base::DictionaryValue* dict = update.Get(); | |
1478 ASSERT_TRUE(dict != NULL); | |
1479 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); | |
1480 } | |
1481 | |
1482 service_->Init(); | |
1483 // A delayed task to call GarbageCollectExtensions is posted by | |
1484 // ExtensionService::Init. As the test won't wait for the delayed task to | |
1485 // be called, call it manually instead. | |
1486 service_->GarbageCollectExtensions(); | |
1487 // Wait for GarbageCollectExtensions task to complete. | |
1488 base::RunLoop().RunUntilIdle(); | |
1489 | |
1490 base::FileEnumerator dirs(extensions_install_dir_, false, | |
1491 base::FileEnumerator::DIRECTORIES); | |
1492 size_t count = 0; | |
1493 while (!dirs.Next().empty()) | |
1494 count++; | |
1495 | |
1496 // We should have only gotten two extensions now. | |
1497 EXPECT_EQ(2u, count); | |
1498 | |
1499 // And extension1 dir should now be toast. | |
1500 base::FilePath extension_dir = extensions_install_dir_ | |
1501 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); | |
1502 ASSERT_FALSE(base::PathExists(extension_dir)); | |
1503 } | |
1504 | |
1505 // Test that GarbageCollectExtensions deletes the right versions of an | |
1506 // extension. | |
1507 TEST_F(ExtensionServiceTest, GarbageCollectWithPendingUpdates) { | |
1508 InitPluginService(); | |
1509 | |
1510 base::FilePath source_install_dir = data_dir_ | |
1511 .AppendASCII("pending_updates") | |
1512 .AppendASCII("Extensions"); | |
1513 base::FilePath pref_path = | |
1514 source_install_dir.DirName().Append(chrome::kPreferencesFilename); | |
1515 | |
1516 InitializeInstalledExtensionService(pref_path, source_install_dir); | |
1517 | |
1518 // This is the directory that is going to be deleted, so make sure it actually | |
1519 // is there before the garbage collection. | |
1520 ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1521 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); | |
1522 | |
1523 service_->GarbageCollectExtensions(); | |
1524 // Wait for GarbageCollectExtensions task to complete. | |
1525 base::RunLoop().RunUntilIdle(); | |
1526 | |
1527 // Verify that the pending update for the first extension didn't get | |
1528 // deleted. | |
1529 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1530 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); | |
1531 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1532 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); | |
1533 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1534 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); | |
1535 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1536 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); | |
1537 } | |
1538 | |
1539 // Test that pending updates are properly handled on startup. | |
1540 TEST_F(ExtensionServiceTest, UpdateOnStartup) { | |
1541 InitPluginService(); | |
1542 | |
1543 base::FilePath source_install_dir = data_dir_ | |
1544 .AppendASCII("pending_updates") | |
1545 .AppendASCII("Extensions"); | |
1546 base::FilePath pref_path = | |
1547 source_install_dir.DirName().Append(chrome::kPreferencesFilename); | |
1548 | |
1549 InitializeInstalledExtensionService(pref_path, source_install_dir); | |
1550 | |
1551 // This is the directory that is going to be deleted, so make sure it actually | |
1552 // is there before the garbage collection. | |
1553 ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1554 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); | |
1555 | |
1556 service_->Init(); | |
1557 // A delayed task to call GarbageCollectExtensions is posted by | |
1558 // ExtensionService::Init. As the test won't wait for the delayed task to | |
1559 // be called, call it manually instead. | |
1560 service_->GarbageCollectExtensions(); | |
1561 // Wait for GarbageCollectExtensions task to complete. | |
1562 base::RunLoop().RunUntilIdle(); | |
1563 | |
1564 // Verify that the pending update for the first extension got installed. | |
1565 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1566 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); | |
1567 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1568 "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); | |
1569 EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1570 "hpiknbiabeeppbpihjehijgoemciehgk/2"))); | |
1571 EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( | |
1572 "hpiknbiabeeppbpihjehijgoemciehgk/3"))); | |
1573 | |
1574 // Make sure update information got deleted. | |
1575 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); | |
1576 EXPECT_FALSE( | |
1577 prefs->GetDelayedInstallInfo("bjafgdebaacbbbecmhlhpofkepfkgcpa")); | |
1578 } | |
1579 | |
1580 // Test various cases for delayed install because of missing imports. | 1468 // Test various cases for delayed install because of missing imports. |
1581 TEST_F(ExtensionServiceTest, PendingImports) { | 1469 TEST_F(ExtensionServiceTest, PendingImports) { |
1582 InitPluginService(); | 1470 InitPluginService(); |
1583 | 1471 |
1584 base::FilePath source_install_dir = data_dir_ | 1472 base::FilePath source_install_dir = data_dir_ |
1585 .AppendASCII("pending_updates_with_imports") | 1473 .AppendASCII("pending_updates_with_imports") |
1586 .AppendASCII("Extensions"); | 1474 .AppendASCII("Extensions"); |
1587 base::FilePath pref_path = | 1475 base::FilePath pref_path = |
1588 source_install_dir.DirName().Append(chrome::kPreferencesFilename); | 1476 source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
1589 | 1477 |
(...skipping 5412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7002 // ReconcileKnownDisabled(). | 6890 // ReconcileKnownDisabled(). |
7003 service_->EnableExtension(good2); | 6891 service_->EnableExtension(good2); |
7004 service_->ReconcileKnownDisabled(); | 6892 service_->ReconcileKnownDisabled(); |
7005 expected_extensions.insert(good2); | 6893 expected_extensions.insert(good2); |
7006 expected_disabled_extensions.erase(good2); | 6894 expected_disabled_extensions.erase(good2); |
7007 | 6895 |
7008 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); | 6896 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); |
7009 EXPECT_EQ(expected_disabled_extensions, | 6897 EXPECT_EQ(expected_disabled_extensions, |
7010 registry_->disabled_extensions().GetIDs()); | 6898 registry_->disabled_extensions().GetIDs()); |
7011 } | 6899 } |
OLD | NEW |