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