Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 return; 404 return;
405 } 405 }
406 data_dir_ = test_data_dir.AppendASCII("extensions"); 406 data_dir_ = test_data_dir.AppendASCII("extensions");
407 } 407 }
408 408
409 ExtensionServiceTestBase::~ExtensionServiceTestBase() { 409 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
410 // Drop our reference to ExtensionService and TestingProfile, so that they 410 // Drop our reference to ExtensionService and TestingProfile, so that they
411 // can be destroyed while BrowserThreads and MessageLoop are still around 411 // can be destroyed while BrowserThreads and MessageLoop are still around
412 // (they are used in the destruction process). 412 // (they are used in the destruction process).
413 service_ = NULL; 413 service_ = NULL;
414 MessageLoop::current()->RunAllPending(); 414 MessageLoop::current()->RunUntilIdle();
415 profile_.reset(NULL); 415 profile_.reset(NULL);
416 MessageLoop::current()->RunAllPending(); 416 MessageLoop::current()->RunUntilIdle();
417 } 417 }
418 418
419 void ExtensionServiceTestBase::InitializeExtensionService( 419 void ExtensionServiceTestBase::InitializeExtensionService(
420 const FilePath& profile_path, 420 const FilePath& profile_path,
421 const FilePath& pref_file, 421 const FilePath& pref_file,
422 const FilePath& extensions_install_dir, 422 const FilePath& extensions_install_dir,
423 bool autoupdate_enabled) { 423 bool autoupdate_enabled) {
424 TestingProfile::Builder profile_builder; 424 TestingProfile::Builder profile_builder;
425 // Create a PrefService that only contains user defined preference values. 425 // Create a PrefService that only contains user defined preference values.
426 scoped_ptr<PrefService> prefs( 426 scoped_ptr<PrefService> prefs(
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 ASSERT_TRUE(creator->Run(dir_path, 597 ASSERT_TRUE(creator->Run(dir_path,
598 crx_path, 598 crx_path,
599 pem_path, 599 pem_path,
600 pem_output_path, 600 pem_output_path,
601 ExtensionCreator::kOverwriteCRX)); 601 ExtensionCreator::kOverwriteCRX));
602 602
603 ASSERT_TRUE(file_util::PathExists(crx_path)); 603 ASSERT_TRUE(file_util::PathExists(crx_path));
604 } 604 }
605 605
606 // Create a CrxInstaller and start installation. To allow the install 606 // Create a CrxInstaller and start installation. To allow the install
607 // to happen, use loop_.RunAllPending();. Most tests will not use this 607 // to happen, use loop_.RunUntilIdle();. Most tests will not use this
608 // method directly. Instead, use InstallCrx(), which waits for 608 // method directly. Instead, use InstallCrx(), which waits for
609 // the crx to be installed and does extra error checking. 609 // the crx to be installed and does extra error checking.
610 void StartCRXInstall(const FilePath& crx_path) { 610 void StartCRXInstall(const FilePath& crx_path) {
611 StartCRXInstall(crx_path, Extension::NO_FLAGS); 611 StartCRXInstall(crx_path, Extension::NO_FLAGS);
612 } 612 }
613 613
614 void StartCRXInstall(const FilePath& crx_path, int creation_flags) { 614 void StartCRXInstall(const FilePath& crx_path, int creation_flags) {
615 ASSERT_TRUE(file_util::PathExists(crx_path)) 615 ASSERT_TRUE(file_util::PathExists(crx_path))
616 << "Path does not exist: "<< crx_path.value().c_str(); 616 << "Path does not exist: "<< crx_path.value().c_str();
617 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); 617 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 installer->InstallCrx(crx_path); 685 installer->InstallCrx(crx_path);
686 686
687 return WaitForCrxInstall(crx_path, install_state); 687 return WaitForCrxInstall(crx_path, install_state);
688 } 688 }
689 689
690 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the 690 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the
691 // |install_state| to INSTALL_FAILED if the installation is expected to fail. 691 // |install_state| to INSTALL_FAILED if the installation is expected to fail.
692 // Returns an Extension pointer if the install succeeded, NULL otherwise. 692 // Returns an Extension pointer if the install succeeded, NULL otherwise.
693 const Extension* WaitForCrxInstall(const FilePath& path, 693 const Extension* WaitForCrxInstall(const FilePath& path,
694 InstallState install_state) { 694 InstallState install_state) {
695 loop_.RunAllPending(); 695 loop_.RunUntilIdle();
696 std::vector<string16> errors = GetErrors(); 696 std::vector<string16> errors = GetErrors();
697 const Extension* extension = NULL; 697 const Extension* extension = NULL;
698 if (install_state != INSTALL_FAILED) { 698 if (install_state != INSTALL_FAILED) {
699 if (install_state == INSTALL_NEW) 699 if (install_state == INSTALL_NEW)
700 ++expected_extensions_count_; 700 ++expected_extensions_count_;
701 701
702 EXPECT_TRUE(installed_) << path.value(); 702 EXPECT_TRUE(installed_) << path.value();
703 703
704 EXPECT_EQ(1u, loaded_.size()) << path.value(); 704 EXPECT_EQ(1u, loaded_.size()) << path.value();
705 EXPECT_EQ(0u, errors.size()) << path.value(); 705 EXPECT_EQ(0u, errors.size()) << path.value();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 path = path.Append(in_path.BaseName()); 759 path = path.Append(in_path.BaseName());
760 ASSERT_TRUE(file_util::CopyFile(in_path, path)); 760 ASSERT_TRUE(file_util::CopyFile(in_path, path));
761 761
762 int previous_enabled_extension_count = 762 int previous_enabled_extension_count =
763 service_->extensions()->size(); 763 service_->extensions()->size();
764 int previous_installed_extension_count = 764 int previous_installed_extension_count =
765 previous_enabled_extension_count + 765 previous_enabled_extension_count +
766 service_->disabled_extensions()->size(); 766 service_->disabled_extensions()->size();
767 767
768 service_->UpdateExtension(id, path, GURL(), NULL); 768 service_->UpdateExtension(id, path, GURL(), NULL);
769 loop_.RunAllPending(); 769 loop_.RunUntilIdle();
770 770
771 std::vector<string16> errors = GetErrors(); 771 std::vector<string16> errors = GetErrors();
772 int error_count = errors.size(); 772 int error_count = errors.size();
773 int enabled_extension_count = 773 int enabled_extension_count =
774 service_->extensions()->size(); 774 service_->extensions()->size();
775 int installed_extension_count = 775 int installed_extension_count =
776 enabled_extension_count + service_->disabled_extensions()->size(); 776 enabled_extension_count + service_->disabled_extensions()->size();
777 777
778 int expected_error_count = (expected_state == FAILED) ? 1 : 0; 778 int expected_error_count = (expected_state == FAILED) ? 1 : 0;
779 EXPECT_EQ(expected_error_count, error_count) << path.value(); 779 EXPECT_EQ(expected_error_count, error_count) << path.value();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 size_t new_pref_key_count = GetPrefKeyCount(); 841 size_t new_pref_key_count = GetPrefKeyCount();
842 if (new_pref_key_count == pref_key_count) { 842 if (new_pref_key_count == pref_key_count) {
843 ValidateIntegerPref(id, "location", 843 ValidateIntegerPref(id, "location",
844 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 844 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
845 } else { 845 } else {
846 EXPECT_EQ(new_pref_key_count, pref_key_count - 1); 846 EXPECT_EQ(new_pref_key_count, pref_key_count - 1);
847 } 847 }
848 848
849 // The extension should not be in the service anymore. 849 // The extension should not be in the service anymore.
850 EXPECT_FALSE(service_->GetInstalledExtension(id)); 850 EXPECT_FALSE(service_->GetInstalledExtension(id));
851 loop_.RunAllPending(); 851 loop_.RunUntilIdle();
852 852
853 // The directory should be gone. 853 // The directory should be gone.
854 EXPECT_FALSE(file_util::PathExists(extension_path)); 854 EXPECT_FALSE(file_util::PathExists(extension_path));
855 } 855 }
856 856
857 void ValidatePrefKeyCount(size_t count) { 857 void ValidatePrefKeyCount(size_t count) {
858 EXPECT_EQ(count, GetPrefKeyCount()); 858 EXPECT_EQ(count, GetPrefKeyCount());
859 } 859 }
860 860
861 void ValidateBooleanPref(const std::string& extension_id, 861 void ValidateBooleanPref(const std::string& extension_id,
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 1389
1390 // Register and install an external extension. 1390 // Register and install an external extension.
1391 Version version("1.0.0.0"); 1391 Version version("1.0.0.0");
1392 service_->OnExternalExtensionFileFound( 1392 service_->OnExternalExtensionFileFound(
1393 good_crx, 1393 good_crx,
1394 &version, 1394 &version,
1395 path, 1395 path,
1396 Extension::EXTERNAL_PREF, 1396 Extension::EXTERNAL_PREF,
1397 Extension::FROM_BOOKMARK, 1397 Extension::FROM_BOOKMARK,
1398 false /* mark_acknowledged */); 1398 false /* mark_acknowledged */);
1399 loop_.RunAllPending(); 1399 loop_.RunUntilIdle();
1400 1400
1401 const Extension* extension = service_->GetExtensionById(good_crx, false); 1401 const Extension* extension = service_->GetExtensionById(good_crx, false);
1402 ASSERT_TRUE(extension); 1402 ASSERT_TRUE(extension);
1403 ASSERT_TRUE(extension->from_bookmark()); 1403 ASSERT_TRUE(extension->from_bookmark());
1404 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); 1404 ValidateBooleanPref(good_crx, kPrefFromBookmark, true);
1405 1405
1406 // Upgrade to version 2.0, the flag should be preserved. 1406 // Upgrade to version 2.0, the flag should be preserved.
1407 path = data_dir_.AppendASCII("good2.crx"); 1407 path = data_dir_.AppendASCII("good2.crx");
1408 UpdateExtension(good_crx, path, ENABLED); 1408 UpdateExtension(good_crx, path, ENABLED);
1409 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); 1409 ValidateBooleanPref(good_crx, kPrefFromBookmark, true);
1410 extension = service_->GetExtensionById(good_crx, false); 1410 extension = service_->GetExtensionById(good_crx, false);
1411 ASSERT_TRUE(extension); 1411 ASSERT_TRUE(extension);
1412 ASSERT_TRUE(extension->from_bookmark()); 1412 ASSERT_TRUE(extension->from_bookmark());
1413 } 1413 }
1414 1414
1415 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED 1415 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED
1416 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { 1416 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) {
1417 InitializeEmptyExtensionService(); 1417 InitializeEmptyExtensionService();
1418 1418
1419 FilePath path = data_dir_.AppendASCII("good.crx"); 1419 FilePath path = data_dir_.AppendASCII("good.crx");
1420 set_extensions_enabled(true); 1420 set_extensions_enabled(true);
1421 1421
1422 Version version("1.0.0.0"); 1422 Version version("1.0.0.0");
1423 // Install an external extension. 1423 // Install an external extension.
1424 service_->OnExternalExtensionFileFound(good_crx, &version, 1424 service_->OnExternalExtensionFileFound(good_crx, &version,
1425 path, Extension::EXTERNAL_PREF, 1425 path, Extension::EXTERNAL_PREF,
1426 Extension::NO_FLAGS, false); 1426 Extension::NO_FLAGS, false);
1427 loop_.RunAllPending(); 1427 loop_.RunUntilIdle();
1428 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1428 ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
1429 1429
1430 // Uninstall it and check that its killbit gets set. 1430 // Uninstall it and check that its killbit gets set.
1431 UninstallExtension(good_crx, false); 1431 UninstallExtension(good_crx, false);
1432 ValidateIntegerPref(good_crx, "location", 1432 ValidateIntegerPref(good_crx, "location",
1433 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1433 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1434 1434
1435 // Try to re-install it externally. This should fail because of the killbit. 1435 // Try to re-install it externally. This should fail because of the killbit.
1436 service_->OnExternalExtensionFileFound(good_crx, &version, 1436 service_->OnExternalExtensionFileFound(good_crx, &version,
1437 path, Extension::EXTERNAL_PREF, 1437 path, Extension::EXTERNAL_PREF,
1438 Extension::NO_FLAGS, false); 1438 Extension::NO_FLAGS, false);
1439 loop_.RunAllPending(); 1439 loop_.RunUntilIdle();
1440 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1440 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
1441 ValidateIntegerPref(good_crx, "location", 1441 ValidateIntegerPref(good_crx, "location",
1442 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1442 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1443 1443
1444 version = Version("1.0.0.1"); 1444 version = Version("1.0.0.1");
1445 // Repeat the same thing with a newer version of the extension. 1445 // Repeat the same thing with a newer version of the extension.
1446 path = data_dir_.AppendASCII("good2.crx"); 1446 path = data_dir_.AppendASCII("good2.crx");
1447 service_->OnExternalExtensionFileFound(good_crx, &version, 1447 service_->OnExternalExtensionFileFound(good_crx, &version,
1448 path, Extension::EXTERNAL_PREF, 1448 path, Extension::EXTERNAL_PREF,
1449 Extension::NO_FLAGS, false); 1449 Extension::NO_FLAGS, false);
1450 loop_.RunAllPending(); 1450 loop_.RunUntilIdle();
1451 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); 1451 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
1452 ValidateIntegerPref(good_crx, "location", 1452 ValidateIntegerPref(good_crx, "location",
1453 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1453 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1454 1454
1455 // Try adding the same extension from an external update URL. 1455 // Try adding the same extension from an external update URL.
1456 ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( 1456 ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl(
1457 good_crx, 1457 good_crx,
1458 GURL("http:://fake.update/url"), 1458 GURL("http:://fake.update/url"),
1459 Extension::EXTERNAL_PREF_DOWNLOAD)); 1459 Extension::EXTERNAL_PREF_DOWNLOAD));
1460 1460
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 const std::string wrong_id = all_zero; 1500 const std::string wrong_id = all_zero;
1501 const std::string correct_id = good_crx; 1501 const std::string correct_id = good_crx;
1502 ASSERT_NE(correct_id, wrong_id); 1502 ASSERT_NE(correct_id, wrong_id);
1503 1503
1504 // Install an external extension with an ID from the external 1504 // Install an external extension with an ID from the external
1505 // source that is not equal to the ID in the extension manifest. 1505 // source that is not equal to the ID in the extension manifest.
1506 service_->OnExternalExtensionFileFound( 1506 service_->OnExternalExtensionFileFound(
1507 wrong_id, &version, path, Extension::EXTERNAL_PREF, 1507 wrong_id, &version, path, Extension::EXTERNAL_PREF,
1508 Extension::NO_FLAGS, false); 1508 Extension::NO_FLAGS, false);
1509 1509
1510 loop_.RunAllPending(); 1510 loop_.RunUntilIdle();
1511 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); 1511 ASSERT_FALSE(service_->GetExtensionById(good_crx, false));
1512 1512
1513 // Try again with the right ID. Expect success. 1513 // Try again with the right ID. Expect success.
1514 service_->OnExternalExtensionFileFound( 1514 service_->OnExternalExtensionFileFound(
1515 correct_id, &version, path, Extension::EXTERNAL_PREF, 1515 correct_id, &version, path, Extension::EXTERNAL_PREF,
1516 Extension::NO_FLAGS, false); 1516 Extension::NO_FLAGS, false);
1517 loop_.RunAllPending(); 1517 loop_.RunUntilIdle();
1518 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1518 ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
1519 } 1519 }
1520 1520
1521 // Test that external extensions with incorrect versions are not installed. 1521 // Test that external extensions with incorrect versions are not installed.
1522 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { 1522 TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
1523 InitializeEmptyExtensionService(); 1523 InitializeEmptyExtensionService();
1524 FilePath path = data_dir_.AppendASCII("good.crx"); 1524 FilePath path = data_dir_.AppendASCII("good.crx");
1525 set_extensions_enabled(true); 1525 set_extensions_enabled(true);
1526 1526
1527 // Install an external extension with a version from the external 1527 // Install an external extension with a version from the external
1528 // source that is not equal to the version in the extension manifest. 1528 // source that is not equal to the version in the extension manifest.
1529 Version wrong_version("1.2.3.4"); 1529 Version wrong_version("1.2.3.4");
1530 service_->OnExternalExtensionFileFound( 1530 service_->OnExternalExtensionFileFound(
1531 good_crx, &wrong_version, path, Extension::EXTERNAL_PREF, 1531 good_crx, &wrong_version, path, Extension::EXTERNAL_PREF,
1532 Extension::NO_FLAGS, false); 1532 Extension::NO_FLAGS, false);
1533 1533
1534 loop_.RunAllPending(); 1534 loop_.RunUntilIdle();
1535 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); 1535 ASSERT_FALSE(service_->GetExtensionById(good_crx, false));
1536 1536
1537 // Try again with the right version. Expect success. 1537 // Try again with the right version. Expect success.
1538 service_->pending_extension_manager()->Remove(good_crx); 1538 service_->pending_extension_manager()->Remove(good_crx);
1539 Version correct_version("1.0.0.0"); 1539 Version correct_version("1.0.0.0");
1540 service_->OnExternalExtensionFileFound( 1540 service_->OnExternalExtensionFileFound(
1541 good_crx, &correct_version, path, Extension::EXTERNAL_PREF, 1541 good_crx, &correct_version, path, Extension::EXTERNAL_PREF,
1542 Extension::NO_FLAGS, false); 1542 Extension::NO_FLAGS, false);
1543 loop_.RunAllPending(); 1543 loop_.RunUntilIdle();
1544 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1544 ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
1545 } 1545 }
1546 1546
1547 // Install a user script (they get converted automatically to an extension) 1547 // Install a user script (they get converted automatically to an extension)
1548 TEST_F(ExtensionServiceTest, InstallUserScript) { 1548 TEST_F(ExtensionServiceTest, InstallUserScript) {
1549 // The details of script conversion are tested elsewhere, this just tests 1549 // The details of script conversion are tested elsewhere, this just tests
1550 // integration with ExtensionService. 1550 // integration with ExtensionService.
1551 InitializeEmptyExtensionService(); 1551 InitializeEmptyExtensionService();
1552 1552
1553 FilePath path = data_dir_ 1553 FilePath path = data_dir_
1554 .AppendASCII("user_script_basic.user.js"); 1554 .AppendASCII("user_script_basic.user.js");
1555 1555
1556 ASSERT_TRUE(file_util::PathExists(path)); 1556 ASSERT_TRUE(file_util::PathExists(path));
1557 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); 1557 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
1558 installer->set_allow_silent_install(true); 1558 installer->set_allow_silent_install(true);
1559 installer->InstallUserScript( 1559 installer->InstallUserScript(
1560 path, 1560 path,
1561 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); 1561 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"));
1562 1562
1563 loop_.RunAllPending(); 1563 loop_.RunUntilIdle();
1564 std::vector<string16> errors = GetErrors(); 1564 std::vector<string16> errors = GetErrors();
1565 EXPECT_TRUE(installed_) << "Nothing was installed."; 1565 EXPECT_TRUE(installed_) << "Nothing was installed.";
1566 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; 1566 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
1567 EXPECT_EQ(0u, errors.size()) << "There were errors: " 1567 EXPECT_EQ(0u, errors.size()) << "There were errors: "
1568 << JoinString(errors, ','); 1568 << JoinString(errors, ',');
1569 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << 1569 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) <<
1570 path.value(); 1570 path.value();
1571 1571
1572 installed_ = NULL; 1572 installed_ = NULL;
1573 loaded_.clear(); 1573 loaded_.clear();
1574 ExtensionErrorReporter::GetInstance()->ClearErrors(); 1574 ExtensionErrorReporter::GetInstance()->ClearErrors();
1575 } 1575 }
1576 1576
1577 // Extensions don't install during shutdown. 1577 // Extensions don't install during shutdown.
1578 TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) { 1578 TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) {
1579 InitializeEmptyExtensionService(); 1579 InitializeEmptyExtensionService();
1580 1580
1581 // Simulate shutdown. 1581 // Simulate shutdown.
1582 service_->set_browser_terminating_for_test(true); 1582 service_->set_browser_terminating_for_test(true);
1583 1583
1584 FilePath path = data_dir_.AppendASCII("good.crx"); 1584 FilePath path = data_dir_.AppendASCII("good.crx");
1585 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); 1585 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
1586 installer->set_allow_silent_install(true); 1586 installer->set_allow_silent_install(true);
1587 installer->InstallCrx(path); 1587 installer->InstallCrx(path);
1588 loop_.RunAllPending(); 1588 loop_.RunUntilIdle();
1589 1589
1590 EXPECT_FALSE(installed_) << "Extension installed during shutdown."; 1590 EXPECT_FALSE(installed_) << "Extension installed during shutdown.";
1591 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown."; 1591 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown.";
1592 } 1592 }
1593 1593
1594 // This tests that the granted permissions preferences are correctly set when 1594 // This tests that the granted permissions preferences are correctly set when
1595 // installing an extension. 1595 // installing an extension.
1596 TEST_F(ExtensionServiceTest, GrantedPermissions) { 1596 TEST_F(ExtensionServiceTest, GrantedPermissions) {
1597 InitializeEmptyExtensionService(); 1597 InitializeEmptyExtensionService();
1598 FilePath path = data_dir_ 1598 FilePath path = data_dir_
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 ValidatePrefKeyCount(pref_count); 2054 ValidatePrefKeyCount(pref_count);
2055 } 2055 }
2056 2056
2057 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { 2057 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
2058 // Load. 2058 // Load.
2059 InitializeEmptyExtensionService(); 2059 InitializeEmptyExtensionService();
2060 FilePath extension_path = data_dir_ 2060 FilePath extension_path = data_dir_
2061 .AppendASCII("theme_i18n"); 2061 .AppendASCII("theme_i18n");
2062 2062
2063 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2063 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2064 loop_.RunAllPending(); 2064 loop_.RunUntilIdle();
2065 EXPECT_EQ(0u, GetErrors().size()); 2065 EXPECT_EQ(0u, GetErrors().size());
2066 ASSERT_EQ(1u, loaded_.size()); 2066 ASSERT_EQ(1u, loaded_.size());
2067 EXPECT_EQ(1u, service_->extensions()->size()); 2067 EXPECT_EQ(1u, service_->extensions()->size());
2068 const Extension* theme = *service_->extensions()->begin(); 2068 const Extension* theme = *service_->extensions()->begin();
2069 EXPECT_EQ("name", theme->name()); 2069 EXPECT_EQ("name", theme->name());
2070 EXPECT_EQ("description", theme->description()); 2070 EXPECT_EQ("description", theme->description());
2071 } 2071 }
2072 2072
2073 // Tests that we can change the ID of an unpacked extension by adding a key 2073 // Tests that we can change the ID of an unpacked extension by adding a key
2074 // to its manifest. 2074 // to its manifest.
(...skipping 13 matching lines...) Expand all
2088 AppendASCII("unpacked"). 2088 AppendASCII("unpacked").
2089 AppendASCII("manifest_with_key.json"); 2089 AppendASCII("manifest_with_key.json");
2090 2090
2091 ASSERT_TRUE(file_util::PathExists(manifest_no_key)); 2091 ASSERT_TRUE(file_util::PathExists(manifest_no_key));
2092 ASSERT_TRUE(file_util::PathExists(manifest_with_key)); 2092 ASSERT_TRUE(file_util::PathExists(manifest_with_key));
2093 2093
2094 // Load the unpacked extension with no key. 2094 // Load the unpacked extension with no key.
2095 file_util::CopyFile(manifest_no_key, manifest_path); 2095 file_util::CopyFile(manifest_no_key, manifest_path);
2096 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2096 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2097 2097
2098 loop_.RunAllPending(); 2098 loop_.RunUntilIdle();
2099 EXPECT_EQ(0u, GetErrors().size()); 2099 EXPECT_EQ(0u, GetErrors().size());
2100 ASSERT_EQ(1u, loaded_.size()); 2100 ASSERT_EQ(1u, loaded_.size());
2101 EXPECT_EQ(1u, service_->extensions()->size()); 2101 EXPECT_EQ(1u, service_->extensions()->size());
2102 2102
2103 // Add the key to the manifest. 2103 // Add the key to the manifest.
2104 file_util::CopyFile(manifest_with_key, manifest_path); 2104 file_util::CopyFile(manifest_with_key, manifest_path);
2105 loaded_.clear(); 2105 loaded_.clear();
2106 2106
2107 // Reload the extensions. 2107 // Reload the extensions.
2108 service_->ReloadExtensions(); 2108 service_->ReloadExtensions();
(...skipping 22 matching lines...) Expand all
2131 ASSERT_TRUE(temp.CreateUniqueTempDir()); 2131 ASSERT_TRUE(temp.CreateUniqueTempDir());
2132 FilePath extension_path = temp.path(); 2132 FilePath extension_path = temp.path();
2133 FilePath manifest = extension_path.Append(Extension::kManifestFilename); 2133 FilePath manifest = extension_path.Append(Extension::kManifestFilename);
2134 FilePath icon_symlink = extension_path.AppendASCII("icon.png"); 2134 FilePath icon_symlink = extension_path.AppendASCII("icon.png");
2135 file_util::CopyFile(source_manifest, manifest); 2135 file_util::CopyFile(source_manifest, manifest);
2136 file_util::CreateSymbolicLink(source_icon, icon_symlink); 2136 file_util::CreateSymbolicLink(source_icon, icon_symlink);
2137 2137
2138 // Load extension. 2138 // Load extension.
2139 InitializeEmptyExtensionService(); 2139 InitializeEmptyExtensionService();
2140 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2140 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2141 loop_.RunAllPending(); 2141 loop_.RunUntilIdle();
2142 2142
2143 EXPECT_TRUE(GetErrors().empty()); 2143 EXPECT_TRUE(GetErrors().empty());
2144 ASSERT_EQ(1u, loaded_.size()); 2144 ASSERT_EQ(1u, loaded_.size());
2145 EXPECT_EQ(1u, service_->extensions()->size()); 2145 EXPECT_EQ(1u, service_->extensions()->size());
2146 } 2146 }
2147 #endif 2147 #endif
2148 2148
2149 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { 2149 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
2150 InitializeEmptyExtensionService(); 2150 InitializeEmptyExtensionService();
2151 FilePath theme_path = data_dir_ 2151 FilePath theme_path = data_dir_
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2478 service_->GetExtensionById(good_crx, false)-> 2478 service_->GetExtensionById(good_crx, false)->
2479 version()->GetString()); 2479 version()->GetString());
2480 } 2480 }
2481 2481
2482 // Test updating a not-already-installed extension - this should fail 2482 // Test updating a not-already-installed extension - this should fail
2483 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { 2483 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) {
2484 InitializeEmptyExtensionService(); 2484 InitializeEmptyExtensionService();
2485 2485
2486 FilePath path = data_dir_.AppendASCII("good.crx"); 2486 FilePath path = data_dir_.AppendASCII("good.crx");
2487 UpdateExtension(good_crx, path, UPDATED); 2487 UpdateExtension(good_crx, path, UPDATED);
2488 loop_.RunAllPending(); 2488 loop_.RunUntilIdle();
2489 2489
2490 ASSERT_EQ(0u, service_->extensions()->size()); 2490 ASSERT_EQ(0u, service_->extensions()->size());
2491 ASSERT_FALSE(installed_); 2491 ASSERT_FALSE(installed_);
2492 ASSERT_EQ(0u, loaded_.size()); 2492 ASSERT_EQ(0u, loaded_.size());
2493 } 2493 }
2494 2494
2495 // Makes sure you can't downgrade an extension via UpdateExtension 2495 // Makes sure you can't downgrade an extension via UpdateExtension
2496 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { 2496 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) {
2497 InitializeEmptyExtensionService(); 2497 InitializeEmptyExtensionService();
2498 2498
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2582 // Start with version 2.0. 2582 // Start with version 2.0.
2583 DictionaryValue manifest; 2583 DictionaryValue manifest;
2584 manifest.SetString("version", "2.0"); 2584 manifest.SetString("version", "2.0");
2585 manifest.SetString("name", "LOAD Downgrade Test"); 2585 manifest.SetString("name", "LOAD Downgrade Test");
2586 manifest.SetInteger("manifest_version", 2); 2586 manifest.SetInteger("manifest_version", 2);
2587 2587
2588 JSONFileValueSerializer serializer(manifest_path); 2588 JSONFileValueSerializer serializer(manifest_path);
2589 ASSERT_TRUE(serializer.Serialize(manifest)); 2589 ASSERT_TRUE(serializer.Serialize(manifest));
2590 2590
2591 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2591 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2592 loop_.RunAllPending(); 2592 loop_.RunUntilIdle();
2593 2593
2594 EXPECT_EQ(0u, GetErrors().size()); 2594 EXPECT_EQ(0u, GetErrors().size());
2595 ASSERT_EQ(1u, loaded_.size()); 2595 ASSERT_EQ(1u, loaded_.size());
2596 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); 2596 EXPECT_EQ(Extension::LOAD, loaded_[0]->location());
2597 EXPECT_EQ(1u, service_->extensions()->size()); 2597 EXPECT_EQ(1u, service_->extensions()->size());
2598 EXPECT_EQ("2.0", loaded_[0]->VersionString()); 2598 EXPECT_EQ("2.0", loaded_[0]->VersionString());
2599 2599
2600 // Now set the version number to 1.0, reload the extensions and verify that 2600 // Now set the version number to 1.0, reload the extensions and verify that
2601 // the downgrade was accepted. 2601 // the downgrade was accepted.
2602 manifest.SetString("version", "1.0"); 2602 manifest.SetString("version", "1.0");
2603 ASSERT_TRUE(serializer.Serialize(manifest)); 2603 ASSERT_TRUE(serializer.Serialize(manifest));
2604 2604
2605 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2605 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2606 loop_.RunAllPending(); 2606 loop_.RunUntilIdle();
2607 2607
2608 EXPECT_EQ(0u, GetErrors().size()); 2608 EXPECT_EQ(0u, GetErrors().size());
2609 ASSERT_EQ(1u, loaded_.size()); 2609 ASSERT_EQ(1u, loaded_.size());
2610 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); 2610 EXPECT_EQ(Extension::LOAD, loaded_[0]->location());
2611 EXPECT_EQ(1u, service_->extensions()->size()); 2611 EXPECT_EQ(1u, service_->extensions()->size());
2612 EXPECT_EQ("1.0", loaded_[0]->VersionString()); 2612 EXPECT_EQ("1.0", loaded_[0]->VersionString());
2613 } 2613 }
2614 2614
2615 #if !defined(OS_CHROMEOS) 2615 #if !defined(OS_CHROMEOS)
2616 // LOAD extensions with plugins require approval. 2616 // LOAD extensions with plugins require approval.
(...skipping 15 matching lines...) Expand all
2632 service_->set_show_extensions_prompts(true); 2632 service_->set_show_extensions_prompts(true);
2633 2633
2634 // Start by canceling any install prompts. 2634 // Start by canceling any install prompts.
2635 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2635 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2636 switches::kAppsGalleryInstallAutoConfirmForTests, 2636 switches::kAppsGalleryInstallAutoConfirmForTests,
2637 "cancel"); 2637 "cancel");
2638 2638
2639 // The extension that has a plugin should not install. 2639 // The extension that has a plugin should not install.
2640 extensions::UnpackedInstaller::Create(service_)->Load( 2640 extensions::UnpackedInstaller::Create(service_)->Load(
2641 extension_with_plugin_path); 2641 extension_with_plugin_path);
2642 loop_.RunAllPending(); 2642 loop_.RunUntilIdle();
2643 EXPECT_EQ(0u, GetErrors().size()); 2643 EXPECT_EQ(0u, GetErrors().size());
2644 EXPECT_EQ(0u, loaded_.size()); 2644 EXPECT_EQ(0u, loaded_.size());
2645 EXPECT_EQ(0u, service_->extensions()->size()); 2645 EXPECT_EQ(0u, service_->extensions()->size());
2646 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 2646 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2647 2647
2648 // But the extension with no plugin should since there's no prompt. 2648 // But the extension with no plugin should since there's no prompt.
2649 extensions::UnpackedInstaller::Create(service_)->Load( 2649 extensions::UnpackedInstaller::Create(service_)->Load(
2650 extension_no_plugin_path); 2650 extension_no_plugin_path);
2651 loop_.RunAllPending(); 2651 loop_.RunUntilIdle();
2652 EXPECT_EQ(0u, GetErrors().size()); 2652 EXPECT_EQ(0u, GetErrors().size());
2653 EXPECT_EQ(1u, loaded_.size()); 2653 EXPECT_EQ(1u, loaded_.size());
2654 EXPECT_EQ(1u, service_->extensions()->size()); 2654 EXPECT_EQ(1u, service_->extensions()->size());
2655 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 2655 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2656 EXPECT_TRUE(service_->extensions()->Contains(good2)); 2656 EXPECT_TRUE(service_->extensions()->Contains(good2));
2657 2657
2658 // The plugin extension should install if we accept the dialog. 2658 // The plugin extension should install if we accept the dialog.
2659 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2659 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2660 switches::kAppsGalleryInstallAutoConfirmForTests, 2660 switches::kAppsGalleryInstallAutoConfirmForTests,
2661 "accept"); 2661 "accept");
2662 2662
2663 extensions::UnpackedInstaller::Create(service_)->Load( 2663 extensions::UnpackedInstaller::Create(service_)->Load(
2664 extension_with_plugin_path); 2664 extension_with_plugin_path);
2665 loop_.RunAllPending(); 2665 loop_.RunUntilIdle();
2666 EXPECT_EQ(0u, GetErrors().size()); 2666 EXPECT_EQ(0u, GetErrors().size());
2667 EXPECT_EQ(2u, loaded_.size()); 2667 EXPECT_EQ(2u, loaded_.size());
2668 EXPECT_EQ(2u, service_->extensions()->size()); 2668 EXPECT_EQ(2u, service_->extensions()->size());
2669 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 2669 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2670 EXPECT_TRUE(service_->extensions()->Contains(good1)); 2670 EXPECT_TRUE(service_->extensions()->Contains(good1));
2671 EXPECT_TRUE(service_->extensions()->Contains(good2)); 2671 EXPECT_TRUE(service_->extensions()->Contains(good2));
2672 2672
2673 // Make sure the granted permissions have been setup. 2673 // Make sure the granted permissions have been setup.
2674 scoped_refptr<PermissionSet> permissions( 2674 scoped_refptr<PermissionSet> permissions(
2675 service_->extension_prefs()->GetGrantedPermissions(good1)); 2675 service_->extension_prefs()->GetGrantedPermissions(good1));
2676 EXPECT_FALSE(permissions->IsEmpty()); 2676 EXPECT_FALSE(permissions->IsEmpty());
2677 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); 2677 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
2678 EXPECT_FALSE(permissions->apis().empty()); 2678 EXPECT_FALSE(permissions->apis().empty());
2679 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); 2679 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
2680 2680
2681 // We should be able to reload the extension without getting another prompt. 2681 // We should be able to reload the extension without getting another prompt.
2682 loaded_.clear(); 2682 loaded_.clear();
2683 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2683 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2684 switches::kAppsGalleryInstallAutoConfirmForTests, 2684 switches::kAppsGalleryInstallAutoConfirmForTests,
2685 "cancel"); 2685 "cancel");
2686 2686
2687 service_->ReloadExtension(good1); 2687 service_->ReloadExtension(good1);
2688 loop_.RunAllPending(); 2688 loop_.RunUntilIdle();
2689 EXPECT_EQ(1u, loaded_.size()); 2689 EXPECT_EQ(1u, loaded_.size());
2690 EXPECT_EQ(2u, service_->extensions()->size()); 2690 EXPECT_EQ(2u, service_->extensions()->size());
2691 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 2691 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2692 } 2692 }
2693 #endif 2693 #endif
2694 2694
2695 namespace { 2695 namespace {
2696 2696
2697 bool IsExtension(const Extension& extension) { 2697 bool IsExtension(const Extension& extension) {
2698 return extension.GetType() == Extension::TYPE_EXTENSION; 2698 return extension.GetType() == Extension::TYPE_EXTENSION;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2920 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { 2920 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) {
2921 InitializeEmptyExtensionService(); 2921 InitializeEmptyExtensionService();
2922 std::vector<std::string> blacklist; 2922 std::vector<std::string> blacklist;
2923 blacklist.push_back(good0); 2923 blacklist.push_back(good0);
2924 blacklist.push_back("invalid_id"); // an invalid id 2924 blacklist.push_back("invalid_id"); // an invalid id
2925 blacklist.push_back(good1); 2925 blacklist.push_back(good1);
2926 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 2926 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
2927 "v1"); 2927 "v1");
2928 2928
2929 // Make sure pref is updated 2929 // Make sure pref is updated
2930 loop_.RunAllPending(); 2930 loop_.RunUntilIdle();
2931 2931
2932 // blacklist is set for good0,1,2 2932 // blacklist is set for good0,1,2
2933 ValidateBooleanPref(good0, "blacklist", true); 2933 ValidateBooleanPref(good0, "blacklist", true);
2934 ValidateBooleanPref(good1, "blacklist", true); 2934 ValidateBooleanPref(good1, "blacklist", true);
2935 // invalid_id should not be inserted to pref. 2935 // invalid_id should not be inserted to pref.
2936 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); 2936 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist"));
2937 2937
2938 // remove good1, add good2 2938 // remove good1, add good2
2939 blacklist.pop_back(); 2939 blacklist.pop_back();
2940 blacklist.push_back(good2); 2940 blacklist.push_back(good2);
(...skipping 16 matching lines...) Expand all
2957 const Extension* good = InstallCRX(path, INSTALL_NEW); 2957 const Extension* good = InstallCRX(path, INSTALL_NEW);
2958 EXPECT_EQ(good_crx, good->id()); 2958 EXPECT_EQ(good_crx, good->id());
2959 UpdateExtension(good_crx, path, FAILED_SILENTLY); 2959 UpdateExtension(good_crx, path, FAILED_SILENTLY);
2960 2960
2961 std::vector<std::string> blacklist; 2961 std::vector<std::string> blacklist;
2962 blacklist.push_back(good_crx); 2962 blacklist.push_back(good_crx);
2963 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 2963 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
2964 "v1"); 2964 "v1");
2965 2965
2966 // Make sure pref is updated 2966 // Make sure pref is updated
2967 loop_.RunAllPending(); 2967 loop_.RunUntilIdle();
2968 2968
2969 // Now, the good_crx is blacklisted. 2969 // Now, the good_crx is blacklisted.
2970 ValidateBooleanPref(good_crx, "blacklist", true); 2970 ValidateBooleanPref(good_crx, "blacklist", true);
2971 EXPECT_EQ(0u, service_->extensions()->size()); 2971 EXPECT_EQ(0u, service_->extensions()->size());
2972 2972
2973 // Remove good_crx from blacklist 2973 // Remove good_crx from blacklist
2974 blacklist.pop_back(); 2974 blacklist.pop_back();
2975 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 2975 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
2976 "v2"); 2976 "v2");
2977 2977
2978 // Make sure pref is updated 2978 // Make sure pref is updated
2979 loop_.RunAllPending(); 2979 loop_.RunUntilIdle();
2980 // blacklist value should not be set for good_crx 2980 // blacklist value should not be set for good_crx
2981 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist")); 2981 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist"));
2982 } 2982 }
2983 2983
2984 // Unload installed extension from blacklist. 2984 // Unload installed extension from blacklist.
2985 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { 2985 TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) {
2986 InitializeEmptyExtensionService(); 2986 InitializeEmptyExtensionService();
2987 std::vector<std::string> blacklist; 2987 std::vector<std::string> blacklist;
2988 blacklist.push_back(good_crx); 2988 blacklist.push_back(good_crx);
2989 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 2989 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
2990 "v1"); 2990 "v1");
2991 2991
2992 // Make sure pref is updated 2992 // Make sure pref is updated
2993 loop_.RunAllPending(); 2993 loop_.RunUntilIdle();
2994 2994
2995 // Now, the good_crx is blacklisted. 2995 // Now, the good_crx is blacklisted.
2996 ValidateBooleanPref(good_crx, "blacklist", true); 2996 ValidateBooleanPref(good_crx, "blacklist", true);
2997 2997
2998 // We can not install good_crx. 2998 // We can not install good_crx.
2999 FilePath path = data_dir_.AppendASCII("good.crx"); 2999 FilePath path = data_dir_.AppendASCII("good.crx");
3000 InstallCRX(path, INSTALL_FAILED); 3000 InstallCRX(path, INSTALL_FAILED);
3001 EXPECT_EQ(0u, service_->extensions()->size()); 3001 EXPECT_EQ(0u, service_->extensions()->size());
3002 ValidateBooleanPref(good_crx, "blacklist", true); 3002 ValidateBooleanPref(good_crx, "blacklist", true);
3003 } 3003 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3126 .AppendASCII("Preferences"); 3126 .AppendASCII("Preferences");
3127 InitializeInstalledExtensionService(pref_path, source_install_dir); 3127 InitializeInstalledExtensionService(pref_path, source_install_dir);
3128 3128
3129 // Blacklist good1. 3129 // Blacklist good1.
3130 std::vector<std::string> blacklist; 3130 std::vector<std::string> blacklist;
3131 blacklist.push_back(good1); 3131 blacklist.push_back(good1);
3132 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, 3132 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist,
3133 "v1"); 3133 "v1");
3134 3134
3135 // Make sure pref is updated 3135 // Make sure pref is updated
3136 loop_.RunAllPending(); 3136 loop_.RunUntilIdle();
3137 3137
3138 ValidateBooleanPref(good1, "blacklist", true); 3138 ValidateBooleanPref(good1, "blacklist", true);
3139 3139
3140 // Load extensions. 3140 // Load extensions.
3141 service_->Init(); 3141 service_->Init();
3142 3142
3143 std::vector<string16> errors = GetErrors(); 3143 std::vector<string16> errors = GetErrors();
3144 for (std::vector<string16>::iterator err = errors.begin(); 3144 for (std::vector<string16>::iterator err = errors.begin();
3145 err != errors.end(); ++err) { 3145 err != errors.end(); ++err) {
3146 LOG(ERROR) << *err; 3146 LOG(ERROR) << *err;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 PrefService* prefs = profile_->GetPrefs(); 3193 PrefService* prefs = profile_->GetPrefs();
3194 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); 3194 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList);
3195 ListValue* blacklist = update.Get(); 3195 ListValue* blacklist = update.Get();
3196 ASSERT_TRUE(blacklist != NULL); 3196 ASSERT_TRUE(blacklist != NULL);
3197 3197
3198 // Blacklist this extension. 3198 // Blacklist this extension.
3199 blacklist->Append(Value::CreateStringValue(good_crx)); 3199 blacklist->Append(Value::CreateStringValue(good_crx));
3200 } 3200 }
3201 3201
3202 // Extension should not be running now. 3202 // Extension should not be running now.
3203 loop_.RunAllPending(); 3203 loop_.RunUntilIdle();
3204 EXPECT_EQ(0u, service_->extensions()->size()); 3204 EXPECT_EQ(0u, service_->extensions()->size());
3205 } 3205 }
3206 3206
3207 // Tests that component extensions are not blacklisted by policy. 3207 // Tests that component extensions are not blacklisted by policy.
3208 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { 3208 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
3209 InitializeEmptyExtensionService(); 3209 InitializeEmptyExtensionService();
3210 3210
3211 // Blacklist everything. 3211 // Blacklist everything.
3212 { 3212 {
3213 ListPrefUpdate update(profile_->GetPrefs(), 3213 ListPrefUpdate update(profile_->GetPrefs(),
(...skipping 23 matching lines...) Expand all
3237 ASSERT_EQ(1u, service_->extensions()->size()); 3237 ASSERT_EQ(1u, service_->extensions()->size());
3238 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3238 EXPECT_TRUE(service_->GetExtensionById(good0, false));
3239 3239
3240 // Extension should not be uninstalled on blacklist changes. 3240 // Extension should not be uninstalled on blacklist changes.
3241 { 3241 {
3242 ListPrefUpdate update(profile_->GetPrefs(), 3242 ListPrefUpdate update(profile_->GetPrefs(),
3243 prefs::kExtensionInstallDenyList); 3243 prefs::kExtensionInstallDenyList);
3244 ListValue* blacklist = update.Get(); 3244 ListValue* blacklist = update.Get();
3245 blacklist->Append(Value::CreateStringValue(good0)); 3245 blacklist->Append(Value::CreateStringValue(good0));
3246 } 3246 }
3247 loop_.RunAllPending(); 3247 loop_.RunUntilIdle();
3248 ASSERT_EQ(1u, service_->extensions()->size()); 3248 ASSERT_EQ(1u, service_->extensions()->size());
3249 EXPECT_TRUE(service_->GetExtensionById(good0, false)); 3249 EXPECT_TRUE(service_->GetExtensionById(good0, false));
3250 } 3250 }
3251 3251
3252 // Tests that policy-installed extensions are not blacklisted by policy. 3252 // Tests that policy-installed extensions are not blacklisted by policy.
3253 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { 3253 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
3254 InitializeEmptyExtensionService(); 3254 InitializeEmptyExtensionService();
3255 3255
3256 // Blacklist everything. 3256 // Blacklist everything.
3257 { 3257 {
3258 ListPrefUpdate update(profile_->GetPrefs(), 3258 ListPrefUpdate update(profile_->GetPrefs(),
3259 prefs::kExtensionInstallDenyList); 3259 prefs::kExtensionInstallDenyList);
3260 ListValue* blacklist = update.Get(); 3260 ListValue* blacklist = update.Get();
3261 blacklist->Append(Value::CreateStringValue("*")); 3261 blacklist->Append(Value::CreateStringValue("*"));
3262 } 3262 }
3263 3263
3264 // Have policy force-install an extension. 3264 // Have policy force-install an extension.
3265 MockExtensionProvider* provider = 3265 MockExtensionProvider* provider =
3266 new MockExtensionProvider(service_, 3266 new MockExtensionProvider(service_,
3267 Extension::EXTERNAL_POLICY_DOWNLOAD); 3267 Extension::EXTERNAL_POLICY_DOWNLOAD);
3268 AddMockExternalProvider(provider); 3268 AddMockExternalProvider(provider);
3269 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3269 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
3270 data_dir_.AppendASCII("good.crx")); 3270 data_dir_.AppendASCII("good.crx"));
3271 3271
3272 // Reloading extensions should find our externally registered extension 3272 // Reloading extensions should find our externally registered extension
3273 // and install it. 3273 // and install it.
3274 service_->CheckForExternalUpdates(); 3274 service_->CheckForExternalUpdates();
3275 loop_.RunAllPending(); 3275 loop_.RunUntilIdle();
3276 3276
3277 // Extension should be installed despite blacklist. 3277 // Extension should be installed despite blacklist.
3278 ASSERT_EQ(1u, service_->extensions()->size()); 3278 ASSERT_EQ(1u, service_->extensions()->size());
3279 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3279 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3280 3280
3281 // Blacklist update should not uninstall the extension. 3281 // Blacklist update should not uninstall the extension.
3282 { 3282 {
3283 ListPrefUpdate update(profile_->GetPrefs(), 3283 ListPrefUpdate update(profile_->GetPrefs(),
3284 prefs::kExtensionInstallDenyList); 3284 prefs::kExtensionInstallDenyList);
3285 ListValue* blacklist = update.Get(); 3285 ListValue* blacklist = update.Get();
3286 blacklist->Append(Value::CreateStringValue(good0)); 3286 blacklist->Append(Value::CreateStringValue(good0));
3287 } 3287 }
3288 loop_.RunAllPending(); 3288 loop_.RunUntilIdle();
3289 ASSERT_EQ(1u, service_->extensions()->size()); 3289 ASSERT_EQ(1u, service_->extensions()->size());
3290 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3290 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3291 } 3291 }
3292 3292
3293 // Tests that extensions cannot be installed if the policy provider prohibits 3293 // Tests that extensions cannot be installed if the policy provider prohibits
3294 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). 3294 // it. This functionality is implemented in CrxInstaller::ConfirmInstall().
3295 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { 3295 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) {
3296 InitializeEmptyExtensionService(); 3296 InitializeEmptyExtensionService();
3297 3297
3298 management_policy_->UnregisterAllProviders(); 3298 management_policy_->UnregisterAllProviders();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3443 MockExtensionProvider* provider = 3443 MockExtensionProvider* provider =
3444 new MockExtensionProvider(service_, 3444 new MockExtensionProvider(service_,
3445 Extension::EXTERNAL_POLICY_DOWNLOAD); 3445 Extension::EXTERNAL_POLICY_DOWNLOAD);
3446 AddMockExternalProvider(provider); 3446 AddMockExternalProvider(provider);
3447 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 3447 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
3448 data_dir_.AppendASCII("page_action.crx")); 3448 data_dir_.AppendASCII("page_action.crx"));
3449 } 3449 }
3450 3450
3451 // Providers are set up. Let them run. 3451 // Providers are set up. Let them run.
3452 service_->CheckForExternalUpdates(); 3452 service_->CheckForExternalUpdates();
3453 loop_.RunAllPending(); 3453 loop_.RunUntilIdle();
3454 3454
3455 ASSERT_EQ(2u, service_->extensions()->size()); 3455 ASSERT_EQ(2u, service_->extensions()->size());
3456 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3456 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3457 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); 3457 EXPECT_TRUE(service_->GetExtensionById(page_action, false));
3458 ExtensionPrefs* prefs = service_->extension_prefs(); 3458 ExtensionPrefs* prefs = service_->extension_prefs();
3459 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); 3459 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx));
3460 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); 3460 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action));
3461 } 3461 }
3462 3462
3463 #if !defined(OS_CHROMEOS) 3463 #if !defined(OS_CHROMEOS)
(...skipping 19 matching lines...) Expand all
3483 new extensions::ExternalTestingLoader(json_data, data_dir_), 3483 new extensions::ExternalTestingLoader(json_data, data_dir_),
3484 Extension::INTERNAL, 3484 Extension::INTERNAL,
3485 Extension::INVALID, 3485 Extension::INVALID,
3486 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); 3486 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
3487 3487
3488 AddMockExternalProvider(provider); 3488 AddMockExternalProvider(provider);
3489 } 3489 }
3490 3490
3491 ASSERT_EQ(0u, service_->extensions()->size()); 3491 ASSERT_EQ(0u, service_->extensions()->size());
3492 service_->CheckForExternalUpdates(); 3492 service_->CheckForExternalUpdates();
3493 loop_.RunAllPending(); 3493 loop_.RunUntilIdle();
3494 3494
3495 ASSERT_EQ(1u, service_->extensions()->size()); 3495 ASSERT_EQ(1u, service_->extensions()->size());
3496 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3496 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3497 const Extension* extension = service_->GetExtensionById(good_crx, false); 3497 const Extension* extension = service_->GetExtensionById(good_crx, false);
3498 EXPECT_TRUE(extension->from_webstore()); 3498 EXPECT_TRUE(extension->from_webstore());
3499 EXPECT_TRUE(extension->was_installed_by_default()); 3499 EXPECT_TRUE(extension->was_installed_by_default());
3500 3500
3501 } 3501 }
3502 #endif 3502 #endif
3503 3503
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
3724 3724
3725 // Unpacked extensions are not allowed to be installed if they have unsupported 3725 // Unpacked extensions are not allowed to be installed if they have unsupported
3726 // requirements. 3726 // requirements.
3727 TEST_F(ExtensionServiceTest, UnpackedRequirements) { 3727 TEST_F(ExtensionServiceTest, UnpackedRequirements) {
3728 InitializeEmptyExtensionService(); 3728 InitializeEmptyExtensionService();
3729 BlackListWebGL(); 3729 BlackListWebGL();
3730 3730
3731 FilePath path = data_dir_.AppendASCII("requirements") 3731 FilePath path = data_dir_.AppendASCII("requirements")
3732 .AppendASCII("v2_bad_requirements"); 3732 .AppendASCII("v2_bad_requirements");
3733 extensions::UnpackedInstaller::Create(service_)->Load(path); 3733 extensions::UnpackedInstaller::Create(service_)->Load(path);
3734 loop_.RunAllPending(); 3734 loop_.RunUntilIdle();
3735 EXPECT_EQ(1u, GetErrors().size()); 3735 EXPECT_EQ(1u, GetErrors().size());
3736 EXPECT_EQ(0u, service_->extensions()->size()); 3736 EXPECT_EQ(0u, service_->extensions()->size());
3737 } 3737 }
3738 3738
3739 class ExtensionCookieCallback { 3739 class ExtensionCookieCallback {
3740 public: 3740 public:
3741 ExtensionCookieCallback() 3741 ExtensionCookieCallback()
3742 : result_(false), 3742 : result_(false),
3743 weak_factory_(MessageLoop::current()) {} 3743 weak_factory_(MessageLoop::current()) {}
3744 3744
(...skipping 30 matching lines...) Expand all
3775 // Set a cookie for the extension. 3775 // Set a cookie for the extension.
3776 net::CookieMonster* cookie_monster = 3776 net::CookieMonster* cookie_monster =
3777 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> 3777 profile_->GetRequestContextForExtensions()->GetURLRequestContext()->
3778 cookie_store()->GetCookieMonster(); 3778 cookie_store()->GetCookieMonster();
3779 ASSERT_TRUE(cookie_monster); 3779 ASSERT_TRUE(cookie_monster);
3780 net::CookieOptions options; 3780 net::CookieOptions options;
3781 cookie_monster->SetCookieWithOptionsAsync( 3781 cookie_monster->SetCookieWithOptionsAsync(
3782 ext_url, "dummy=value", options, 3782 ext_url, "dummy=value", options,
3783 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 3783 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
3784 base::Unretained(&callback))); 3784 base::Unretained(&callback)));
3785 loop_.RunAllPending(); 3785 loop_.RunUntilIdle();
3786 EXPECT_TRUE(callback.result_); 3786 EXPECT_TRUE(callback.result_);
3787 3787
3788 cookie_monster->GetAllCookiesForURLAsync( 3788 cookie_monster->GetAllCookiesForURLAsync(
3789 ext_url, 3789 ext_url,
3790 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 3790 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
3791 base::Unretained(&callback))); 3791 base::Unretained(&callback)));
3792 loop_.RunAllPending(); 3792 loop_.RunUntilIdle();
3793 EXPECT_EQ(1U, callback.list_.size()); 3793 EXPECT_EQ(1U, callback.list_.size());
3794 3794
3795 // Open a database. 3795 // Open a database.
3796 webkit_database::DatabaseTracker* db_tracker = 3796 webkit_database::DatabaseTracker* db_tracker =
3797 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 3797 BrowserContext::GetDefaultStoragePartition(profile_.get())->
3798 GetDatabaseTracker(); 3798 GetDatabaseTracker();
3799 string16 db_name = UTF8ToUTF16("db"); 3799 string16 db_name = UTF8ToUTF16("db");
3800 string16 description = UTF8ToUTF16("db_description"); 3800 string16 description = UTF8ToUTF16("db_description");
3801 int64 size; 3801 int64 size;
3802 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 3802 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
(...skipping 17 matching lines...) Expand all
3820 // creating the directory on the disk. 3820 // creating the directory on the disk.
3821 IndexedDBContext* idb_context = 3821 IndexedDBContext* idb_context =
3822 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 3822 BrowserContext::GetDefaultStoragePartition(profile_.get())->
3823 GetIndexedDBContext(); 3823 GetIndexedDBContext();
3824 FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); 3824 FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
3825 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); 3825 EXPECT_TRUE(file_util::CreateDirectory(idb_path));
3826 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); 3826 EXPECT_TRUE(file_util::DirectoryExists(idb_path));
3827 3827
3828 // Uninstall the extension. 3828 // Uninstall the extension.
3829 service_->UninstallExtension(good_crx, false, NULL); 3829 service_->UninstallExtension(good_crx, false, NULL);
3830 loop_.RunAllPending(); 3830 loop_.RunUntilIdle();
3831 3831
3832 // Check that the cookie is gone. 3832 // Check that the cookie is gone.
3833 cookie_monster->GetAllCookiesForURLAsync( 3833 cookie_monster->GetAllCookiesForURLAsync(
3834 ext_url, 3834 ext_url,
3835 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 3835 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
3836 base::Unretained(&callback))); 3836 base::Unretained(&callback)));
3837 loop_.RunAllPending(); 3837 loop_.RunUntilIdle();
3838 EXPECT_EQ(0U, callback.list_.size()); 3838 EXPECT_EQ(0U, callback.list_.size());
3839 3839
3840 // The database should have vanished as well. 3840 // The database should have vanished as well.
3841 origins.clear(); 3841 origins.clear();
3842 db_tracker->GetAllOriginsInfo(&origins); 3842 db_tracker->GetAllOriginsInfo(&origins);
3843 EXPECT_EQ(0U, origins.size()); 3843 EXPECT_EQ(0U, origins.size());
3844 3844
3845 // Check that the LSO file has been removed. 3845 // Check that the LSO file has been removed.
3846 EXPECT_FALSE(file_util::PathExists(lso_file_path)); 3846 EXPECT_FALSE(file_util::PathExists(lso_file_path));
3847 3847
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3888 // Set a cookie for the extension. 3888 // Set a cookie for the extension.
3889 net::CookieMonster* cookie_monster = 3889 net::CookieMonster* cookie_monster =
3890 profile_->GetRequestContext()->GetURLRequestContext()-> 3890 profile_->GetRequestContext()->GetURLRequestContext()->
3891 cookie_store()->GetCookieMonster(); 3891 cookie_store()->GetCookieMonster();
3892 ASSERT_TRUE(cookie_monster); 3892 ASSERT_TRUE(cookie_monster);
3893 net::CookieOptions options; 3893 net::CookieOptions options;
3894 cookie_monster->SetCookieWithOptionsAsync( 3894 cookie_monster->SetCookieWithOptionsAsync(
3895 origin1, "dummy=value", options, 3895 origin1, "dummy=value", options,
3896 base::Bind(&ExtensionCookieCallback::SetCookieCallback, 3896 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
3897 base::Unretained(&callback))); 3897 base::Unretained(&callback)));
3898 loop_.RunAllPending(); 3898 loop_.RunUntilIdle();
3899 EXPECT_TRUE(callback.result_); 3899 EXPECT_TRUE(callback.result_);
3900 3900
3901 cookie_monster->GetAllCookiesForURLAsync( 3901 cookie_monster->GetAllCookiesForURLAsync(
3902 origin1, 3902 origin1,
3903 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 3903 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
3904 base::Unretained(&callback))); 3904 base::Unretained(&callback)));
3905 loop_.RunAllPending(); 3905 loop_.RunUntilIdle();
3906 EXPECT_EQ(1U, callback.list_.size()); 3906 EXPECT_EQ(1U, callback.list_.size());
3907 3907
3908 // Open a database. 3908 // Open a database.
3909 webkit_database::DatabaseTracker* db_tracker = 3909 webkit_database::DatabaseTracker* db_tracker =
3910 BrowserContext::GetDefaultStoragePartition(profile_.get())-> 3910 BrowserContext::GetDefaultStoragePartition(profile_.get())->
3911 GetDatabaseTracker(); 3911 GetDatabaseTracker();
3912 string16 db_name = UTF8ToUTF16("db"); 3912 string16 db_name = UTF8ToUTF16("db");
3913 string16 description = UTF8ToUTF16("db_description"); 3913 string16 description = UTF8ToUTF16("db_description");
3914 int64 size; 3914 int64 size;
3915 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 3915 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
(...skipping 27 matching lines...) Expand all
3943 UninstallExtension(id1, false); 3943 UninstallExtension(id1, false);
3944 EXPECT_EQ(1u, service_->extensions()->size()); 3944 EXPECT_EQ(1u, service_->extensions()->size());
3945 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 3945 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
3946 IsStorageUnlimited(origin1)); 3946 IsStorageUnlimited(origin1));
3947 3947
3948 // Check that the cookie is still there. 3948 // Check that the cookie is still there.
3949 cookie_monster->GetAllCookiesForURLAsync( 3949 cookie_monster->GetAllCookiesForURLAsync(
3950 origin1, 3950 origin1,
3951 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 3951 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
3952 base::Unretained(&callback))); 3952 base::Unretained(&callback)));
3953 loop_.RunAllPending(); 3953 loop_.RunUntilIdle();
3954 EXPECT_EQ(1U, callback.list_.size()); 3954 EXPECT_EQ(1U, callback.list_.size());
3955 3955
3956 // Now uninstall the other. Storage should be cleared for the apps. 3956 // Now uninstall the other. Storage should be cleared for the apps.
3957 UninstallExtension(id2, false); 3957 UninstallExtension(id2, false);
3958 EXPECT_EQ(0u, service_->extensions()->size()); 3958 EXPECT_EQ(0u, service_->extensions()->size());
3959 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 3959 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
3960 IsStorageUnlimited(origin1)); 3960 IsStorageUnlimited(origin1));
3961 3961
3962 // Check that the cookie is gone. 3962 // Check that the cookie is gone.
3963 cookie_monster->GetAllCookiesForURLAsync( 3963 cookie_monster->GetAllCookiesForURLAsync(
3964 origin1, 3964 origin1,
3965 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 3965 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
3966 base::Unretained(&callback))); 3966 base::Unretained(&callback)));
3967 loop_.RunAllPending(); 3967 loop_.RunUntilIdle();
3968 EXPECT_EQ(0U, callback.list_.size()); 3968 EXPECT_EQ(0U, callback.list_.size());
3969 3969
3970 // The database should have vanished as well. 3970 // The database should have vanished as well.
3971 origins.clear(); 3971 origins.clear();
3972 db_tracker->GetAllOriginsInfo(&origins); 3972 db_tracker->GetAllOriginsInfo(&origins);
3973 EXPECT_EQ(0U, origins.size()); 3973 EXPECT_EQ(0U, origins.size());
3974 3974
3975 // Check that the LSO file has been removed. 3975 // Check that the LSO file has been removed.
3976 EXPECT_FALSE(file_util::PathExists(lso_file_path)); 3976 EXPECT_FALSE(file_util::PathExists(lso_file_path));
3977 3977
3978 // Check if the indexed db has disappeared too. 3978 // Check if the indexed db has disappeared too.
3979 EXPECT_FALSE(file_util::DirectoryExists(idb_path)); 3979 EXPECT_FALSE(file_util::DirectoryExists(idb_path));
3980 } 3980 }
3981 3981
3982 // Tests loading single extensions (like --load-extension) 3982 // Tests loading single extensions (like --load-extension)
3983 TEST_F(ExtensionServiceTest, LoadExtension) { 3983 TEST_F(ExtensionServiceTest, LoadExtension) {
3984 InitializeEmptyExtensionService(); 3984 InitializeEmptyExtensionService();
3985 3985
3986 FilePath ext1 = data_dir_ 3986 FilePath ext1 = data_dir_
3987 .AppendASCII("good") 3987 .AppendASCII("good")
3988 .AppendASCII("Extensions") 3988 .AppendASCII("Extensions")
3989 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 3989 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
3990 .AppendASCII("1.0.0.0"); 3990 .AppendASCII("1.0.0.0");
3991 extensions::UnpackedInstaller::Create(service_)->Load(ext1); 3991 extensions::UnpackedInstaller::Create(service_)->Load(ext1);
3992 loop_.RunAllPending(); 3992 loop_.RunUntilIdle();
3993 EXPECT_EQ(0u, GetErrors().size()); 3993 EXPECT_EQ(0u, GetErrors().size());
3994 ASSERT_EQ(1u, loaded_.size()); 3994 ASSERT_EQ(1u, loaded_.size());
3995 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); 3995 EXPECT_EQ(Extension::LOAD, loaded_[0]->location());
3996 EXPECT_EQ(1u, service_->extensions()->size()); 3996 EXPECT_EQ(1u, service_->extensions()->size());
3997 3997
3998 ValidatePrefKeyCount(1); 3998 ValidatePrefKeyCount(1);
3999 3999
4000 FilePath no_manifest = data_dir_ 4000 FilePath no_manifest = data_dir_
4001 .AppendASCII("bad") 4001 .AppendASCII("bad")
4002 // .AppendASCII("Extensions") 4002 // .AppendASCII("Extensions")
4003 .AppendASCII("cccccccccccccccccccccccccccccccc") 4003 .AppendASCII("cccccccccccccccccccccccccccccccc")
4004 .AppendASCII("1"); 4004 .AppendASCII("1");
4005 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); 4005 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest);
4006 loop_.RunAllPending(); 4006 loop_.RunUntilIdle();
4007 EXPECT_EQ(1u, GetErrors().size()); 4007 EXPECT_EQ(1u, GetErrors().size());
4008 ASSERT_EQ(1u, loaded_.size()); 4008 ASSERT_EQ(1u, loaded_.size());
4009 EXPECT_EQ(1u, service_->extensions()->size()); 4009 EXPECT_EQ(1u, service_->extensions()->size());
4010 4010
4011 // Test uninstall. 4011 // Test uninstall.
4012 std::string id = loaded_[0]->id(); 4012 std::string id = loaded_[0]->id();
4013 EXPECT_FALSE(unloaded_id_.length()); 4013 EXPECT_FALSE(unloaded_id_.length());
4014 service_->UninstallExtension(id, false, NULL); 4014 service_->UninstallExtension(id, false, NULL);
4015 loop_.RunAllPending(); 4015 loop_.RunUntilIdle();
4016 EXPECT_EQ(id, unloaded_id_); 4016 EXPECT_EQ(id, unloaded_id_);
4017 ASSERT_EQ(0u, loaded_.size()); 4017 ASSERT_EQ(0u, loaded_.size());
4018 EXPECT_EQ(0u, service_->extensions()->size()); 4018 EXPECT_EQ(0u, service_->extensions()->size());
4019 } 4019 }
4020 4020
4021 // Tests that we generate IDs when they are not specified in the manifest for 4021 // Tests that we generate IDs when they are not specified in the manifest for
4022 // --load-extension. 4022 // --load-extension.
4023 TEST_F(ExtensionServiceTest, GenerateID) { 4023 TEST_F(ExtensionServiceTest, GenerateID) {
4024 InitializeEmptyExtensionService(); 4024 InitializeEmptyExtensionService();
4025 4025
4026 FilePath no_id_ext = data_dir_.AppendASCII("no_id"); 4026 FilePath no_id_ext = data_dir_.AppendASCII("no_id");
4027 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4027 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
4028 loop_.RunAllPending(); 4028 loop_.RunUntilIdle();
4029 EXPECT_EQ(0u, GetErrors().size()); 4029 EXPECT_EQ(0u, GetErrors().size());
4030 ASSERT_EQ(1u, loaded_.size()); 4030 ASSERT_EQ(1u, loaded_.size());
4031 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); 4031 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
4032 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); 4032 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD);
4033 4033
4034 ValidatePrefKeyCount(1); 4034 ValidatePrefKeyCount(1);
4035 4035
4036 std::string previous_id = loaded_[0]->id(); 4036 std::string previous_id = loaded_[0]->id();
4037 4037
4038 // If we reload the same path, we should get the same extension ID. 4038 // If we reload the same path, we should get the same extension ID.
4039 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); 4039 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
4040 loop_.RunAllPending(); 4040 loop_.RunUntilIdle();
4041 ASSERT_EQ(1u, loaded_.size()); 4041 ASSERT_EQ(1u, loaded_.size());
4042 ASSERT_EQ(previous_id, loaded_[0]->id()); 4042 ASSERT_EQ(previous_id, loaded_[0]->id());
4043 } 4043 }
4044 4044
4045 void ExtensionServiceTest::TestExternalProvider( 4045 void ExtensionServiceTest::TestExternalProvider(
4046 MockExtensionProvider* provider, Extension::Location location) { 4046 MockExtensionProvider* provider, Extension::Location location) {
4047 // Verify that starting with no providers loads no extensions. 4047 // Verify that starting with no providers loads no extensions.
4048 service_->Init(); 4048 service_->Init();
4049 ASSERT_EQ(0u, loaded_.size()); 4049 ASSERT_EQ(0u, loaded_.size());
4050 4050
4051 provider->set_visit_count(0); 4051 provider->set_visit_count(0);
4052 4052
4053 // Register a test extension externally using the mock registry provider. 4053 // Register a test extension externally using the mock registry provider.
4054 FilePath source_path = data_dir_.AppendASCII("good.crx"); 4054 FilePath source_path = data_dir_.AppendASCII("good.crx");
4055 4055
4056 // Add the extension. 4056 // Add the extension.
4057 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4057 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4058 4058
4059 // Reloading extensions should find our externally registered extension 4059 // Reloading extensions should find our externally registered extension
4060 // and install it. 4060 // and install it.
4061 service_->CheckForExternalUpdates(); 4061 service_->CheckForExternalUpdates();
4062 loop_.RunAllPending(); 4062 loop_.RunUntilIdle();
4063 4063
4064 ASSERT_EQ(0u, GetErrors().size()); 4064 ASSERT_EQ(0u, GetErrors().size());
4065 ASSERT_EQ(1u, loaded_.size()); 4065 ASSERT_EQ(1u, loaded_.size());
4066 ASSERT_EQ(location, loaded_[0]->location()); 4066 ASSERT_EQ(location, loaded_[0]->location());
4067 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4067 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4068 ValidatePrefKeyCount(1); 4068 ValidatePrefKeyCount(1);
4069 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4069 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4070 ValidateIntegerPref(good_crx, "location", location); 4070 ValidateIntegerPref(good_crx, "location", location);
4071 4071
4072 // Reload extensions without changing anything. The extension should be 4072 // Reload extensions without changing anything. The extension should be
4073 // loaded again. 4073 // loaded again.
4074 loaded_.clear(); 4074 loaded_.clear();
4075 service_->ReloadExtensions(); 4075 service_->ReloadExtensions();
4076 loop_.RunAllPending(); 4076 loop_.RunUntilIdle();
4077 ASSERT_EQ(0u, GetErrors().size()); 4077 ASSERT_EQ(0u, GetErrors().size());
4078 ASSERT_EQ(1u, loaded_.size()); 4078 ASSERT_EQ(1u, loaded_.size());
4079 ValidatePrefKeyCount(1); 4079 ValidatePrefKeyCount(1);
4080 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4080 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4081 ValidateIntegerPref(good_crx, "location", location); 4081 ValidateIntegerPref(good_crx, "location", location);
4082 4082
4083 // Now update the extension with a new version. We should get upgraded. 4083 // Now update the extension with a new version. We should get upgraded.
4084 source_path = source_path.DirName().AppendASCII("good2.crx"); 4084 source_path = source_path.DirName().AppendASCII("good2.crx");
4085 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4085 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4086 4086
4087 loaded_.clear(); 4087 loaded_.clear();
4088 service_->CheckForExternalUpdates(); 4088 service_->CheckForExternalUpdates();
4089 loop_.RunAllPending(); 4089 loop_.RunUntilIdle();
4090 ASSERT_EQ(0u, GetErrors().size()); 4090 ASSERT_EQ(0u, GetErrors().size());
4091 ASSERT_EQ(1u, loaded_.size()); 4091 ASSERT_EQ(1u, loaded_.size());
4092 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4092 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4093 ValidatePrefKeyCount(1); 4093 ValidatePrefKeyCount(1);
4094 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4094 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4095 ValidateIntegerPref(good_crx, "location", location); 4095 ValidateIntegerPref(good_crx, "location", location);
4096 4096
4097 // Uninstall the extension and reload. Nothing should happen because the 4097 // Uninstall the extension and reload. Nothing should happen because the
4098 // preference should prevent us from reinstalling. 4098 // preference should prevent us from reinstalling.
4099 std::string id = loaded_[0]->id(); 4099 std::string id = loaded_[0]->id();
4100 service_->UninstallExtension(id, false, NULL); 4100 service_->UninstallExtension(id, false, NULL);
4101 loop_.RunAllPending(); 4101 loop_.RunUntilIdle();
4102 4102
4103 FilePath install_path = extensions_install_dir_.AppendASCII(id); 4103 FilePath install_path = extensions_install_dir_.AppendASCII(id);
4104 if (Extension::IsRequired(location)) { 4104 if (Extension::IsRequired(location)) {
4105 // Policy controlled extensions should not have been touched by uninstall. 4105 // Policy controlled extensions should not have been touched by uninstall.
4106 ASSERT_TRUE(file_util::PathExists(install_path)); 4106 ASSERT_TRUE(file_util::PathExists(install_path));
4107 } else { 4107 } else {
4108 // The extension should also be gone from the install directory. 4108 // The extension should also be gone from the install directory.
4109 ASSERT_FALSE(file_util::PathExists(install_path)); 4109 ASSERT_FALSE(file_util::PathExists(install_path));
4110 loaded_.clear(); 4110 loaded_.clear();
4111 service_->CheckForExternalUpdates(); 4111 service_->CheckForExternalUpdates();
4112 loop_.RunAllPending(); 4112 loop_.RunUntilIdle();
4113 ASSERT_EQ(0u, loaded_.size()); 4113 ASSERT_EQ(0u, loaded_.size());
4114 ValidatePrefKeyCount(1); 4114 ValidatePrefKeyCount(1);
4115 ValidateIntegerPref(good_crx, "state", 4115 ValidateIntegerPref(good_crx, "state",
4116 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 4116 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
4117 ValidateIntegerPref(good_crx, "location", location); 4117 ValidateIntegerPref(good_crx, "location", location);
4118 4118
4119 // Now clear the preference and reinstall. 4119 // Now clear the preference and reinstall.
4120 SetPrefInteg(good_crx, "state", Extension::ENABLED); 4120 SetPrefInteg(good_crx, "state", Extension::ENABLED);
4121 4121
4122 loaded_.clear(); 4122 loaded_.clear();
4123 service_->CheckForExternalUpdates(); 4123 service_->CheckForExternalUpdates();
4124 loop_.RunAllPending(); 4124 loop_.RunUntilIdle();
4125 ASSERT_EQ(1u, loaded_.size()); 4125 ASSERT_EQ(1u, loaded_.size());
4126 } 4126 }
4127 ValidatePrefKeyCount(1); 4127 ValidatePrefKeyCount(1);
4128 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4128 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4129 ValidateIntegerPref(good_crx, "location", location); 4129 ValidateIntegerPref(good_crx, "location", location);
4130 4130
4131 if (Extension::IsRequired(location)) { 4131 if (Extension::IsRequired(location)) {
4132 EXPECT_EQ(2, provider->visit_count()); 4132 EXPECT_EQ(2, provider->visit_count());
4133 } else { 4133 } else {
4134 // Now test an externally triggered uninstall (deleting the registry key or 4134 // Now test an externally triggered uninstall (deleting the registry key or
4135 // the pref entry). 4135 // the pref entry).
4136 provider->RemoveExtension(good_crx); 4136 provider->RemoveExtension(good_crx);
4137 4137
4138 loaded_.clear(); 4138 loaded_.clear();
4139 service_->OnExternalProviderReady(provider); 4139 service_->OnExternalProviderReady(provider);
4140 loop_.RunAllPending(); 4140 loop_.RunUntilIdle();
4141 ASSERT_EQ(0u, loaded_.size()); 4141 ASSERT_EQ(0u, loaded_.size());
4142 ValidatePrefKeyCount(0); 4142 ValidatePrefKeyCount(0);
4143 4143
4144 // The extension should also be gone from the install directory. 4144 // The extension should also be gone from the install directory.
4145 ASSERT_FALSE(file_util::PathExists(install_path)); 4145 ASSERT_FALSE(file_util::PathExists(install_path));
4146 4146
4147 // Now test the case where user uninstalls and then the extension is removed 4147 // Now test the case where user uninstalls and then the extension is removed
4148 // from the external provider. 4148 // from the external provider.
4149 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4149 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4150 service_->CheckForExternalUpdates(); 4150 service_->CheckForExternalUpdates();
4151 loop_.RunAllPending(); 4151 loop_.RunUntilIdle();
4152 4152
4153 ASSERT_EQ(1u, loaded_.size()); 4153 ASSERT_EQ(1u, loaded_.size());
4154 ASSERT_EQ(0u, GetErrors().size()); 4154 ASSERT_EQ(0u, GetErrors().size());
4155 4155
4156 // User uninstalls. 4156 // User uninstalls.
4157 loaded_.clear(); 4157 loaded_.clear();
4158 service_->UninstallExtension(id, false, NULL); 4158 service_->UninstallExtension(id, false, NULL);
4159 loop_.RunAllPending(); 4159 loop_.RunUntilIdle();
4160 ASSERT_EQ(0u, loaded_.size()); 4160 ASSERT_EQ(0u, loaded_.size());
4161 4161
4162 // Then remove the extension from the extension provider. 4162 // Then remove the extension from the extension provider.
4163 provider->RemoveExtension(good_crx); 4163 provider->RemoveExtension(good_crx);
4164 4164
4165 // Should still be at 0. 4165 // Should still be at 0.
4166 loaded_.clear(); 4166 loaded_.clear();
4167 extensions::InstalledLoader(service_).LoadAllExtensions(); 4167 extensions::InstalledLoader(service_).LoadAllExtensions();
4168 loop_.RunAllPending(); 4168 loop_.RunUntilIdle();
4169 ASSERT_EQ(0u, loaded_.size()); 4169 ASSERT_EQ(0u, loaded_.size());
4170 ValidatePrefKeyCount(1); 4170 ValidatePrefKeyCount(1);
4171 4171
4172 EXPECT_EQ(5, provider->visit_count()); 4172 EXPECT_EQ(5, provider->visit_count());
4173 } 4173 }
4174 } 4174 }
4175 4175
4176 // Tests the external installation feature 4176 // Tests the external installation feature
4177 #if defined(OS_WIN) 4177 #if defined(OS_WIN)
4178 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 4178 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4253 set_extensions_enabled(false); 4253 set_extensions_enabled(false);
4254 4254
4255 service_->Init(); 4255 service_->Init();
4256 4256
4257 ASSERT_EQ(0u, GetErrors().size()); 4257 ASSERT_EQ(0u, GetErrors().size());
4258 ASSERT_EQ(0u, loaded_.size()); 4258 ASSERT_EQ(0u, loaded_.size());
4259 4259
4260 // Verify that it's not the disabled extensions flag causing it not to load. 4260 // Verify that it's not the disabled extensions flag causing it not to load.
4261 set_extensions_enabled(true); 4261 set_extensions_enabled(true);
4262 service_->ReloadExtensions(); 4262 service_->ReloadExtensions();
4263 loop_.RunAllPending(); 4263 loop_.RunUntilIdle();
4264 4264
4265 ASSERT_EQ(0u, GetErrors().size()); 4265 ASSERT_EQ(0u, GetErrors().size());
4266 ASSERT_EQ(0u, loaded_.size()); 4266 ASSERT_EQ(0u, loaded_.size());
4267 } 4267 }
4268 4268
4269 // Test that running multiple update checks simultaneously does not 4269 // Test that running multiple update checks simultaneously does not
4270 // keep the update from succeeding. 4270 // keep the update from succeeding.
4271 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { 4271 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
4272 InitializeEmptyExtensionService(); 4272 InitializeEmptyExtensionService();
4273 4273
4274 MockExtensionProvider* provider = 4274 MockExtensionProvider* provider =
4275 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 4275 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
4276 AddMockExternalProvider(provider); 4276 AddMockExternalProvider(provider);
4277 4277
4278 // Verify that starting with no providers loads no extensions. 4278 // Verify that starting with no providers loads no extensions.
4279 service_->Init(); 4279 service_->Init();
4280 ASSERT_EQ(0u, loaded_.size()); 4280 ASSERT_EQ(0u, loaded_.size());
4281 4281
4282 // Start two checks for updates. 4282 // Start two checks for updates.
4283 provider->set_visit_count(0); 4283 provider->set_visit_count(0);
4284 service_->CheckForExternalUpdates(); 4284 service_->CheckForExternalUpdates();
4285 service_->CheckForExternalUpdates(); 4285 service_->CheckForExternalUpdates();
4286 loop_.RunAllPending(); 4286 loop_.RunUntilIdle();
4287 4287
4288 // Two calls should cause two checks for external extensions. 4288 // Two calls should cause two checks for external extensions.
4289 EXPECT_EQ(2, provider->visit_count()); 4289 EXPECT_EQ(2, provider->visit_count());
4290 EXPECT_EQ(0u, GetErrors().size()); 4290 EXPECT_EQ(0u, GetErrors().size());
4291 EXPECT_EQ(0u, loaded_.size()); 4291 EXPECT_EQ(0u, loaded_.size());
4292 4292
4293 // Register a test extension externally using the mock registry provider. 4293 // Register a test extension externally using the mock registry provider.
4294 FilePath source_path = data_dir_.AppendASCII("good.crx"); 4294 FilePath source_path = data_dir_.AppendASCII("good.crx");
4295 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4295 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4296 4296
4297 // Two checks for external updates should find the extension, and install it 4297 // Two checks for external updates should find the extension, and install it
4298 // once. 4298 // once.
4299 provider->set_visit_count(0); 4299 provider->set_visit_count(0);
4300 service_->CheckForExternalUpdates(); 4300 service_->CheckForExternalUpdates();
4301 service_->CheckForExternalUpdates(); 4301 service_->CheckForExternalUpdates();
4302 loop_.RunAllPending(); 4302 loop_.RunUntilIdle();
4303 EXPECT_EQ(2, provider->visit_count()); 4303 EXPECT_EQ(2, provider->visit_count());
4304 ASSERT_EQ(0u, GetErrors().size()); 4304 ASSERT_EQ(0u, GetErrors().size());
4305 ASSERT_EQ(1u, loaded_.size()); 4305 ASSERT_EQ(1u, loaded_.size());
4306 ASSERT_EQ(Extension::EXTERNAL_PREF, loaded_[0]->location()); 4306 ASSERT_EQ(Extension::EXTERNAL_PREF, loaded_[0]->location());
4307 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4307 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4308 ValidatePrefKeyCount(1); 4308 ValidatePrefKeyCount(1);
4309 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4309 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4310 ValidateIntegerPref(good_crx, "location", Extension::EXTERNAL_PREF); 4310 ValidateIntegerPref(good_crx, "location", Extension::EXTERNAL_PREF);
4311 4311
4312 provider->RemoveExtension(good_crx); 4312 provider->RemoveExtension(good_crx);
4313 provider->set_visit_count(0); 4313 provider->set_visit_count(0);
4314 service_->CheckForExternalUpdates(); 4314 service_->CheckForExternalUpdates();
4315 service_->CheckForExternalUpdates(); 4315 service_->CheckForExternalUpdates();
4316 loop_.RunAllPending(); 4316 loop_.RunUntilIdle();
4317 4317
4318 // Two calls should cause two checks for external extensions. 4318 // Two calls should cause two checks for external extensions.
4319 // Because the external source no longer includes good_crx, 4319 // Because the external source no longer includes good_crx,
4320 // good_crx will be uninstalled. So, expect that no extensions 4320 // good_crx will be uninstalled. So, expect that no extensions
4321 // are loaded. 4321 // are loaded.
4322 EXPECT_EQ(2, provider->visit_count()); 4322 EXPECT_EQ(2, provider->visit_count());
4323 EXPECT_EQ(0u, GetErrors().size()); 4323 EXPECT_EQ(0u, GetErrors().size());
4324 EXPECT_EQ(0u, loaded_.size()); 4324 EXPECT_EQ(0u, loaded_.size());
4325 } 4325 }
4326 4326
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
4569 // By default, we are enabled. 4569 // By default, we are enabled.
4570 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 4570 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
4571 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( 4571 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>(
4572 ExtensionSystem::Get(profile.get()))-> 4572 ExtensionSystem::Get(profile.get()))->
4573 CreateExtensionService( 4573 CreateExtensionService(
4574 command_line.get(), 4574 command_line.get(),
4575 install_dir, 4575 install_dir,
4576 false); 4576 false);
4577 EXPECT_TRUE(service->extensions_enabled()); 4577 EXPECT_TRUE(service->extensions_enabled());
4578 service->Init(); 4578 service->Init();
4579 loop.RunAllPending(); 4579 loop.RunUntilIdle();
4580 EXPECT_TRUE(recorder.ready()); 4580 EXPECT_TRUE(recorder.ready());
4581 4581
4582 // If either the command line or pref is set, we are disabled. 4582 // If either the command line or pref is set, we are disabled.
4583 recorder.set_ready(false); 4583 recorder.set_ready(false);
4584 profile.reset(new TestingProfile()); 4584 profile.reset(new TestingProfile());
4585 command_line->AppendSwitch(switches::kDisableExtensions); 4585 command_line->AppendSwitch(switches::kDisableExtensions);
4586 service = static_cast<extensions::TestExtensionSystem*>( 4586 service = static_cast<extensions::TestExtensionSystem*>(
4587 ExtensionSystem::Get(profile.get()))-> 4587 ExtensionSystem::Get(profile.get()))->
4588 CreateExtensionService( 4588 CreateExtensionService(
4589 command_line.get(), 4589 command_line.get(),
4590 install_dir, 4590 install_dir,
4591 false); 4591 false);
4592 EXPECT_FALSE(service->extensions_enabled()); 4592 EXPECT_FALSE(service->extensions_enabled());
4593 service->Init(); 4593 service->Init();
4594 loop.RunAllPending(); 4594 loop.RunUntilIdle();
4595 EXPECT_TRUE(recorder.ready()); 4595 EXPECT_TRUE(recorder.ready());
4596 4596
4597 recorder.set_ready(false); 4597 recorder.set_ready(false);
4598 profile.reset(new TestingProfile()); 4598 profile.reset(new TestingProfile());
4599 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 4599 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
4600 service = static_cast<extensions::TestExtensionSystem*>( 4600 service = static_cast<extensions::TestExtensionSystem*>(
4601 ExtensionSystem::Get(profile.get()))-> 4601 ExtensionSystem::Get(profile.get()))->
4602 CreateExtensionService( 4602 CreateExtensionService(
4603 command_line.get(), 4603 command_line.get(),
4604 install_dir, 4604 install_dir,
4605 false); 4605 false);
4606 EXPECT_FALSE(service->extensions_enabled()); 4606 EXPECT_FALSE(service->extensions_enabled());
4607 service->Init(); 4607 service->Init();
4608 loop.RunAllPending(); 4608 loop.RunUntilIdle();
4609 EXPECT_TRUE(recorder.ready()); 4609 EXPECT_TRUE(recorder.ready());
4610 4610
4611 recorder.set_ready(false); 4611 recorder.set_ready(false);
4612 profile.reset(new TestingProfile()); 4612 profile.reset(new TestingProfile());
4613 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 4613 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
4614 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); 4614 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
4615 service = static_cast<extensions::TestExtensionSystem*>( 4615 service = static_cast<extensions::TestExtensionSystem*>(
4616 ExtensionSystem::Get(profile.get()))-> 4616 ExtensionSystem::Get(profile.get()))->
4617 CreateExtensionService( 4617 CreateExtensionService(
4618 command_line.get(), 4618 command_line.get(),
4619 install_dir, 4619 install_dir,
4620 false); 4620 false);
4621 EXPECT_FALSE(service->extensions_enabled()); 4621 EXPECT_FALSE(service->extensions_enabled());
4622 service->Init(); 4622 service->Init();
4623 loop.RunAllPending(); 4623 loop.RunUntilIdle();
4624 EXPECT_TRUE(recorder.ready()); 4624 EXPECT_TRUE(recorder.ready());
4625 4625
4626 // Explicitly delete all the resources used in this test. 4626 // Explicitly delete all the resources used in this test.
4627 profile.reset(); 4627 profile.reset();
4628 service = NULL; 4628 service = NULL;
4629 // Execute any pending deletion tasks. 4629 // Execute any pending deletion tasks.
4630 loop.RunAllPending(); 4630 loop.RunUntilIdle();
4631 4631
4632 // Ensure that even if the PluginService is re-used for a later test, it 4632 // Ensure that even if the PluginService is re-used for a later test, it
4633 // won't still hold a reference to the stack position of our MockPluginList. 4633 // won't still hold a reference to the stack position of our MockPluginList.
4634 // See crbug.com/159754. 4634 // See crbug.com/159754.
4635 PluginService::GetInstance()->SetPluginListForTesting(NULL); 4635 PluginService::GetInstance()->SetPluginListForTesting(NULL);
4636 } 4636 }
4637 4637
4638 // Test loading extensions that require limited and unlimited storage quotas. 4638 // Test loading extensions that require limited and unlimited storage quotas.
4639 TEST_F(ExtensionServiceTest, StorageQuota) { 4639 TEST_F(ExtensionServiceTest, StorageQuota) {
4640 InitializeEmptyExtensionService(); 4640 InitializeEmptyExtensionService();
4641 4641
4642 FilePath extensions_path = data_dir_ 4642 FilePath extensions_path = data_dir_
4643 .AppendASCII("storage_quota"); 4643 .AppendASCII("storage_quota");
4644 4644
4645 FilePath limited_quota_ext = 4645 FilePath limited_quota_ext =
4646 extensions_path.AppendASCII("limited_quota") 4646 extensions_path.AppendASCII("limited_quota")
4647 .AppendASCII("1.0"); 4647 .AppendASCII("1.0");
4648 4648
4649 // The old permission name for unlimited quota was "unlimited_storage", but 4649 // The old permission name for unlimited quota was "unlimited_storage", but
4650 // we changed it to "unlimitedStorage". This tests both versions. 4650 // we changed it to "unlimitedStorage". This tests both versions.
4651 FilePath unlimited_quota_ext = 4651 FilePath unlimited_quota_ext =
4652 extensions_path.AppendASCII("unlimited_quota") 4652 extensions_path.AppendASCII("unlimited_quota")
4653 .AppendASCII("1.0"); 4653 .AppendASCII("1.0");
4654 FilePath unlimited_quota_ext2 = 4654 FilePath unlimited_quota_ext2 =
4655 extensions_path.AppendASCII("unlimited_quota") 4655 extensions_path.AppendASCII("unlimited_quota")
4656 .AppendASCII("2.0"); 4656 .AppendASCII("2.0");
4657 extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext); 4657 extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext);
4658 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext); 4658 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext);
4659 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2); 4659 extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2);
4660 loop_.RunAllPending(); 4660 loop_.RunUntilIdle();
4661 4661
4662 ASSERT_EQ(3u, loaded_.size()); 4662 ASSERT_EQ(3u, loaded_.size());
4663 EXPECT_TRUE(profile_.get()); 4663 EXPECT_TRUE(profile_.get());
4664 EXPECT_FALSE(profile_->IsOffTheRecord()); 4664 EXPECT_FALSE(profile_->IsOffTheRecord());
4665 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 4665 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4666 loaded_[0]->url())); 4666 loaded_[0]->url()));
4667 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 4667 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4668 loaded_[1]->url())); 4668 loaded_[1]->url()));
4669 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( 4669 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4670 loaded_[2]->url())); 4670 loaded_[2]->url()));
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
5721 // needs to know about. 5721 // needs to know about.
5722 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5722 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5723 5723
5724 // This is a normal extension, installed normally. 5724 // This is a normal extension, installed normally.
5725 // This should NOT trigger an alert. 5725 // This should NOT trigger an alert.
5726 set_extensions_enabled(true); 5726 set_extensions_enabled(true);
5727 FilePath path = data_dir_.AppendASCII("good.crx"); 5727 FilePath path = data_dir_.AppendASCII("good.crx");
5728 InstallCRX(path, INSTALL_NEW); 5728 InstallCRX(path, INSTALL_NEW);
5729 5729
5730 service_->CheckForExternalUpdates(); 5730 service_->CheckForExternalUpdates();
5731 loop_.RunAllPending(); 5731 loop_.RunUntilIdle();
5732 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5732 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5733 5733
5734 // A hosted app, installed externally. 5734 // A hosted app, installed externally.
5735 // This SHOULD trigger an alert. 5735 // This SHOULD trigger an alert.
5736 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5736 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5737 data_dir_.AppendASCII("hosted_app.crx")); 5737 data_dir_.AppendASCII("hosted_app.crx"));
5738 5738
5739 service_->CheckForExternalUpdates(); 5739 service_->CheckForExternalUpdates();
5740 loop_.RunAllPending(); 5740 loop_.RunUntilIdle();
5741 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5741 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5742 service_->EnableExtension(hosted_app); 5742 service_->EnableExtension(hosted_app);
5743 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5743 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5744 5744
5745 // Another normal extension, but installed externally. 5745 // Another normal extension, but installed externally.
5746 // This SHOULD trigger an alert. 5746 // This SHOULD trigger an alert.
5747 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 5747 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5748 data_dir_.AppendASCII("page_action.crx")); 5748 data_dir_.AppendASCII("page_action.crx"));
5749 5749
5750 service_->CheckForExternalUpdates(); 5750 service_->CheckForExternalUpdates();
5751 loop_.RunAllPending(); 5751 loop_.RunUntilIdle();
5752 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5752 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5753 } 5753 }
5754 5754
5755 // Test that external extensions are initially disabled, and that enabling 5755 // Test that external extensions are initially disabled, and that enabling
5756 // them clears the prompt. 5756 // them clears the prompt.
5757 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { 5757 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
5758 FeatureSwitch::ScopedOverride prompt( 5758 FeatureSwitch::ScopedOverride prompt(
5759 FeatureSwitch::prompt_for_external_extensions(), true); 5759 FeatureSwitch::prompt_for_external_extensions(), true);
5760 5760
5761 InitializeEmptyExtensionService(); 5761 InitializeEmptyExtensionService();
5762 MockExtensionProvider* provider = 5762 MockExtensionProvider* provider =
5763 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 5763 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
5764 AddMockExternalProvider(provider); 5764 AddMockExternalProvider(provider);
5765 5765
5766 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 5766 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5767 data_dir_.AppendASCII("page_action.crx")); 5767 data_dir_.AppendASCII("page_action.crx"));
5768 5768
5769 service_->CheckForExternalUpdates(); 5769 service_->CheckForExternalUpdates();
5770 loop_.RunAllPending(); 5770 loop_.RunUntilIdle();
5771 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5771 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5772 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 5772 EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
5773 5773
5774 const Extension* extension = 5774 const Extension* extension =
5775 service_->disabled_extensions()->GetByID(page_action); 5775 service_->disabled_extensions()->GetByID(page_action);
5776 EXPECT_TRUE(extension); 5776 EXPECT_TRUE(extension);
5777 EXPECT_EQ(page_action, extension->id()); 5777 EXPECT_EQ(page_action, extension->id());
5778 5778
5779 service_->EnableExtension(page_action); 5779 service_->EnableExtension(page_action);
5780 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5780 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
(...skipping 11 matching lines...) Expand all
5792 AddMockExternalProvider(provider); 5792 AddMockExternalProvider(provider);
5793 5793
5794 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 5794 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5795 data_dir_.AppendASCII("page_action.crx")); 5795 data_dir_.AppendASCII("page_action.crx"));
5796 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 5796 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
5797 data_dir_.AppendASCII("good.crx")); 5797 data_dir_.AppendASCII("good.crx"));
5798 provider->UpdateOrAddExtension(theme_crx, "2.0", 5798 provider->UpdateOrAddExtension(theme_crx, "2.0",
5799 data_dir_.AppendASCII("theme.crx")); 5799 data_dir_.AppendASCII("theme.crx"));
5800 5800
5801 service_->CheckForExternalUpdates(); 5801 service_->CheckForExternalUpdates();
5802 loop_.RunAllPending(); 5802 loop_.RunUntilIdle();
5803 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5803 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5804 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 5804 EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
5805 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5805 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5806 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); 5806 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx));
5807 5807
5808 service_->EnableExtension(page_action); 5808 service_->EnableExtension(page_action);
5809 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5809 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5810 service_->EnableExtension(theme_crx); 5810 service_->EnableExtension(theme_crx);
5811 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 5811 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5812 service_->EnableExtension(good_crx); 5812 service_->EnableExtension(good_crx);
(...skipping 23 matching lines...) Expand all
5836 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5836 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5837 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5837 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5838 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 5838 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5839 5839
5840 ExtensionPrefs* prefs = service_->extension_prefs(); 5840 ExtensionPrefs* prefs = service_->extension_prefs();
5841 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & 5841 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) &
5842 Extension::DISABLE_SIDELOAD_WIPEOUT); 5842 Extension::DISABLE_SIDELOAD_WIPEOUT);
5843 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & 5843 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) &
5844 Extension::DISABLE_SIDELOAD_WIPEOUT); 5844 Extension::DISABLE_SIDELOAD_WIPEOUT);
5845 } 5845 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_crash_recovery_browsertest.cc ('k') | chrome/browser/extensions/extension_ui_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698