Commit 8f512c76 authored by yoz@chromium.org's avatar yoz@chromium.org

Clean up ExtensionServiceTest.

- Make InstallCrx, PackAndInstallCrx return the installed Extension*.
- Change StartCrxInstall callers to use InstallCrx.
- Fix dubious use of ScopedTempDir in PackAndInstallCrx.
- Add an InstallState enum for the above functions.
- Remove all uses of extensions()->at(), since ExtensionSet won't support it.

BUG=104091
TEST=unit_tests


Review URL: http://codereview.chromium.org/8598028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111213 0039d316-1c4b-4281-b951-d872f2087c98
parent 87377184
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include "base/at_exit.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
...@@ -382,7 +381,7 @@ class ExtensionTestingProfile : public TestingProfile { ...@@ -382,7 +381,7 @@ class ExtensionTestingProfile : public TestingProfile {
ExtensionServiceTestBase::ExtensionServiceTestBase() ExtensionServiceTestBase::ExtensionServiceTestBase()
: loop_(MessageLoop::TYPE_IO), : loop_(MessageLoop::TYPE_IO),
service_(NULL), service_(NULL),
total_successes_(0), expected_extensions_count_(0),
ui_thread_(BrowserThread::UI, &loop_), ui_thread_(BrowserThread::UI, &loop_),
db_thread_(BrowserThread::DB, &loop_), db_thread_(BrowserThread::DB, &loop_),
webkit_thread_(BrowserThread::WEBKIT, &loop_), webkit_thread_(BrowserThread::WEBKIT, &loop_),
...@@ -435,7 +434,7 @@ void ExtensionServiceTestBase::InitializeExtensionService( ...@@ -435,7 +434,7 @@ void ExtensionServiceTestBase::InitializeExtensionService(
// will register one specifically. // will register one specifically.
service_->ClearProvidersForTesting(); service_->ClearProvidersForTesting();
total_successes_ = 0; expected_extensions_count_ = 0;
} }
void ExtensionServiceTestBase::InitializeInstalledExtensionService( void ExtensionServiceTestBase::InitializeInstalledExtensionService(
...@@ -557,19 +556,13 @@ class ExtensionServiceTest ...@@ -557,19 +556,13 @@ class ExtensionServiceTest
void TestExternalProvider(MockExtensionProvider* provider, void TestExternalProvider(MockExtensionProvider* provider,
Extension::Location location); Extension::Location location);
void PackAndInstallCrx(const FilePath& dir_path, void PackCRX(const FilePath& dir_path,
const FilePath& pem_path, const FilePath& pem_path,
bool should_succeed) { const FilePath& crx_path) {
FilePath crx_path;
ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
crx_path = temp_dir_.path().AppendASCII("temp.crx");
// Use the existing pem key, if provided. // Use the existing pem key, if provided.
FilePath pem_output_path; FilePath pem_output_path;
if (pem_path.value().empty()) { if (pem_path.value().empty()) {
pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); pem_output_path = crx_path.DirName().AppendASCII("temp.pem");
ASSERT_TRUE(file_util::Delete(pem_output_path, false));
} else { } else {
ASSERT_TRUE(file_util::PathExists(pem_path)); ASSERT_TRUE(file_util::PathExists(pem_path));
} }
...@@ -583,23 +576,17 @@ class ExtensionServiceTest ...@@ -583,23 +576,17 @@ class ExtensionServiceTest
pem_output_path)); pem_output_path));
ASSERT_TRUE(file_util::PathExists(crx_path)); ASSERT_TRUE(file_util::PathExists(crx_path));
InstallCrx(crx_path, should_succeed);
}
void PackAndInstallCrx(const FilePath& dir_path,
bool should_succeed) {
PackAndInstallCrx(dir_path, FilePath(), should_succeed);
} }
// Create a CrxInstaller and start installation. To allow the install // Create a CrxInstaller and start installation. To allow the install
// to happen, use loop_.RunAllPending();. Most tests will not use this // to happen, use loop_.RunAllPending();. Most tests will not use this
// method directly. Instead, use InstallCrx(), which waits for // method directly. Instead, use InstallCrx(), which waits for
// the crx to be installed and does extra error checking. // the crx to be installed and does extra error checking.
void StartCrxInstall(const FilePath& crx_path) { void StartCRXInstall(const FilePath& crx_path) {
StartCrxInstall(crx_path, false); StartCRXInstall(crx_path, false);
} }
void StartCrxInstall(const FilePath& crx_path, bool from_webstore) { void StartCRXInstall(const FilePath& crx_path, bool from_webstore) {
ASSERT_TRUE(file_util::PathExists(crx_path)) ASSERT_TRUE(file_util::PathExists(crx_path))
<< "Path does not exist: "<< crx_path.value().c_str(); << "Path does not exist: "<< crx_path.value().c_str();
scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
...@@ -608,16 +595,45 @@ class ExtensionServiceTest ...@@ -608,16 +595,45 @@ class ExtensionServiceTest
installer->InstallCrx(crx_path); installer->InstallCrx(crx_path);
} }
void InstallCrx(const FilePath& path, enum InstallState {
bool should_succeed) { INSTALL_FAILED,
StartCrxInstall(path); INSTALL_UPDATED,
WaitForCrxInstall(path, should_succeed); INSTALL_NEW
};
const Extension* PackAndInstallCRX(const FilePath& dir_path,
const FilePath& pem_path,
InstallState install_state) {
FilePath crx_path;
ScopedTempDir temp_dir;
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
crx_path = temp_dir.path().AppendASCII("temp.crx");
PackCRX(dir_path, pem_path, crx_path);
return InstallCRX(crx_path, install_state);
} }
void InstallCrxWithLocation(const FilePath& crx_path, const Extension* PackAndInstallCRX(const FilePath& dir_path,
Extension::Location install_location, InstallState install_state) {
bool should_succeed) { return PackAndInstallCRX(dir_path, FilePath(), install_state);
ASSERT_TRUE(file_util::PathExists(crx_path)) }
const Extension* InstallCRX(const FilePath& path,
InstallState install_state) {
StartCRXInstall(path);
return WaitForCrxInstall(path, install_state);
}
const Extension* InstallCRXFromWebStore(const FilePath& path,
InstallState install_state) {
StartCRXInstall(path, true);
return WaitForCrxInstall(path, install_state);
}
const Extension* InstallCRXWithLocation(const FilePath& crx_path,
Extension::Location install_location,
InstallState install_state) {
EXPECT_TRUE(file_util::PathExists(crx_path))
<< "Path does not exist: "<< crx_path.value().c_str(); << "Path does not exist: "<< crx_path.value().c_str();
// no client (silent install) // no client (silent install)
scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
...@@ -625,24 +641,28 @@ class ExtensionServiceTest ...@@ -625,24 +641,28 @@ class ExtensionServiceTest
installer->set_install_source(install_location); installer->set_install_source(install_location);
installer->InstallCrx(crx_path); installer->InstallCrx(crx_path);
WaitForCrxInstall(crx_path, should_succeed); return WaitForCrxInstall(crx_path, install_state);
} }
// Wait for a CrxInstaller to finish. Used by InstallCrx. // Wait for a CrxInstaller to finish. Used by InstallCRX.
void WaitForCrxInstall(const FilePath& path, // Returns an Extension pointer if the install succeeded, NULL otherwise.
bool should_succeed) { const Extension* WaitForCrxInstall(const FilePath& path,
InstallState install_state) {
loop_.RunAllPending(); loop_.RunAllPending();
std::vector<std::string> errors = GetErrors(); std::vector<std::string> errors = GetErrors();
if (should_succeed) { const Extension* extension = NULL;
++total_successes_; if (install_state != INSTALL_FAILED) {
if (install_state == INSTALL_NEW)
++expected_extensions_count_;
EXPECT_TRUE(installed_) << path.value(); EXPECT_TRUE(installed_) << path.value();
ASSERT_EQ(1u, loaded_.size()) << path.value(); EXPECT_EQ(1u, loaded_.size()) << path.value();
EXPECT_EQ(0u, errors.size()) << path.value(); EXPECT_EQ(0u, errors.size()) << path.value();
EXPECT_EQ(total_successes_, service_->extensions()->size()) << EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) <<
path.value(); path.value();
EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << extension = loaded_[0];
EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) <<
path.value(); path.value();
for (std::vector<std::string>::iterator err = errors.begin(); for (std::vector<std::string>::iterator err = errors.begin();
err != errors.end(); ++err) { err != errors.end(); ++err) {
...@@ -657,6 +677,7 @@ class ExtensionServiceTest ...@@ -657,6 +677,7 @@ class ExtensionServiceTest
installed_ = NULL; installed_ = NULL;
loaded_.clear(); loaded_.clear();
ExtensionErrorReporter::GetInstance()->ClearErrors(); ExtensionErrorReporter::GetInstance()->ClearErrors();
return extension;
} }
enum UpdateState { enum UpdateState {
...@@ -749,7 +770,7 @@ class ExtensionServiceTest ...@@ -749,7 +770,7 @@ class ExtensionServiceTest
} else { } else {
EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); EXPECT_TRUE(service_->UninstallExtension(id, false, NULL));
} }
total_successes_ = 0; --expected_extensions_count_;
// We should get an unload notification. // We should get an unload notification.
EXPECT_FALSE(unloaded_id_.empty()); EXPECT_FALSE(unloaded_id_.empty());
...@@ -1101,7 +1122,6 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { ...@@ -1101,7 +1122,6 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
InitializeInstalledExtensionService(pref_path, source_install_dir); InitializeInstalledExtensionService(pref_path, source_install_dir);
service_->Init(); service_->Init();
loop_.RunAllPending();
ASSERT_EQ(4u, GetErrors().size()); ASSERT_EQ(4u, GetErrors().size());
ASSERT_EQ(0u, loaded_.size()); ASSERT_EQ(0u, loaded_.size());
...@@ -1146,6 +1166,7 @@ TEST_F(ExtensionServiceTest, CleanupOnStartup) { ...@@ -1146,6 +1166,7 @@ TEST_F(ExtensionServiceTest, CleanupOnStartup) {
} }
service_->Init(); service_->Init();
// Wait for GarbageCollectExtensions task to complete.
loop_.RunAllPending(); loop_.RunAllPending();
file_util::FileEnumerator dirs(extensions_install_dir_, false, file_util::FileEnumerator dirs(extensions_install_dir_, false,
...@@ -1172,14 +1193,14 @@ TEST_F(ExtensionServiceTest, InstallExtension) { ...@@ -1172,14 +1193,14 @@ TEST_F(ExtensionServiceTest, InstallExtension) {
// Extensions not enabled. // Extensions not enabled.
set_extensions_enabled(false); set_extensions_enabled(false);
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, false); InstallCRX(path, INSTALL_FAILED);
set_extensions_enabled(true); set_extensions_enabled(true);
ValidatePrefKeyCount(0); ValidatePrefKeyCount(0);
// A simple extension that should install without error. // A simple extension that should install without error.
path = data_dir_.AppendASCII("good.crx"); path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); InstallCRX(path, INSTALL_NEW);
// TODO(erikkay): verify the contents of the installed extension. // TODO(erikkay): verify the contents of the installed extension.
int pref_count = 0; int pref_count = 0;
...@@ -1189,24 +1210,24 @@ TEST_F(ExtensionServiceTest, InstallExtension) { ...@@ -1189,24 +1210,24 @@ TEST_F(ExtensionServiceTest, InstallExtension) {
// An extension with page actions. // An extension with page actions.
path = data_dir_.AppendASCII("page_action.crx"); path = data_dir_.AppendASCII("page_action.crx");
InstallCrx(path, true); InstallCRX(path, INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ValidateIntegerPref(page_action, "state", Extension::ENABLED); ValidateIntegerPref(page_action, "state", Extension::ENABLED);
ValidateIntegerPref(page_action, "location", Extension::INTERNAL); ValidateIntegerPref(page_action, "location", Extension::INTERNAL);
// Bad signature. // Bad signature.
path = data_dir_.AppendASCII("bad_signature.crx"); path = data_dir_.AppendASCII("bad_signature.crx");
InstallCrx(path, false); InstallCRX(path, INSTALL_FAILED);
ValidatePrefKeyCount(pref_count); ValidatePrefKeyCount(pref_count);
// 0-length extension file. // 0-length extension file.
path = data_dir_.AppendASCII("not_an_extension.crx"); path = data_dir_.AppendASCII("not_an_extension.crx");
InstallCrx(path, false); InstallCRX(path, INSTALL_FAILED);
ValidatePrefKeyCount(pref_count); ValidatePrefKeyCount(pref_count);
// Bad magic number. // Bad magic number.
path = data_dir_.AppendASCII("bad_magic.crx"); path = data_dir_.AppendASCII("bad_magic.crx");
InstallCrx(path, false); InstallCRX(path, INSTALL_FAILED);
ValidatePrefKeyCount(pref_count); ValidatePrefKeyCount(pref_count);
// Extensions cannot have folders or files that have underscores except in // Extensions cannot have folders or files that have underscores except in
...@@ -1214,7 +1235,7 @@ TEST_F(ExtensionServiceTest, InstallExtension) { ...@@ -1214,7 +1235,7 @@ TEST_F(ExtensionServiceTest, InstallExtension) {
// class of validation that we do to the directory structure of the extension. // class of validation that we do to the directory structure of the extension.
// We did not used to handle this correctly for installation. // We did not used to handle this correctly for installation.
path = data_dir_.AppendASCII("bad_underscore.crx"); path = data_dir_.AppendASCII("bad_underscore.crx");
InstallCrx(path, false); InstallCRX(path, INSTALL_FAILED);
ValidatePrefKeyCount(pref_count); ValidatePrefKeyCount(pref_count);
// TODO(erikkay): add more tests for many of the failure cases. // TODO(erikkay): add more tests for many of the failure cases.
...@@ -1312,7 +1333,6 @@ TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { ...@@ -1312,7 +1333,6 @@ TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) {
InitializeInstalledExtensionService(pref_path, source_install_dir); InitializeInstalledExtensionService(pref_path, source_install_dir);
service_->Init(); service_->Init();
loop_.RunAllPending();
// Check and try to uninstall it. // Check and try to uninstall it.
// If we don't check whether the extension is loaded before we uninstall it // If we don't check whether the extension is loaded before we uninstall it
...@@ -1433,12 +1453,11 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) { ...@@ -1433,12 +1453,11 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
prefs->GetGrantedPermissions(permissions_crx)); prefs->GetGrantedPermissions(permissions_crx));
EXPECT_FALSE(known_perms.get()); EXPECT_FALSE(known_perms.get());
PackAndInstallCrx(path, pem_path, true); const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW);
EXPECT_EQ(0u, GetErrors().size()); EXPECT_EQ(0u, GetErrors().size());
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
std::string extension_id = service_->extensions()->at(0)->id(); EXPECT_EQ(permissions_crx, extension->id());
EXPECT_EQ(permissions_crx, extension_id);
// Verify that the valid API permissions have been recognized. // Verify that the valid API permissions have been recognized.
expected_api_perms.insert(ExtensionAPIPermission::kTab); expected_api_perms.insert(ExtensionAPIPermission::kTab);
...@@ -1448,7 +1467,7 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) { ...@@ -1448,7 +1467,7 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); AddPattern(&expected_host_perms, "http://*.google.com.hk/*");
AddPattern(&expected_host_perms, "http://www.example.com/*"); AddPattern(&expected_host_perms, "http://www.example.com/*");
known_perms = prefs->GetGrantedPermissions(extension_id); known_perms = prefs->GetGrantedPermissions(extension->id());
EXPECT_TRUE(known_perms.get()); EXPECT_TRUE(known_perms.get());
EXPECT_FALSE(known_perms->IsEmpty()); EXPECT_FALSE(known_perms->IsEmpty());
EXPECT_EQ(expected_api_perms, known_perms->apis()); EXPECT_EQ(expected_api_perms, known_perms->apis());
...@@ -1472,15 +1491,13 @@ TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { ...@@ -1472,15 +1491,13 @@ TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
.AppendASCII("2"); .AppendASCII("2");
ASSERT_TRUE(file_util::PathExists(path)); ASSERT_TRUE(file_util::PathExists(path));
PackAndInstallCrx(path, true); const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW);
EXPECT_EQ(0u, GetErrors().size()); EXPECT_EQ(0u, GetErrors().size());
EXPECT_EQ(1u, service_->extensions()->size()); EXPECT_EQ(1u, service_->extensions()->size());
const Extension* extension = service_->extensions()->at(0);
std::string extension_id = extension->id();
ExtensionPrefs* prefs = service_->extension_prefs(); ExtensionPrefs* prefs = service_->extension_prefs();
scoped_refptr<ExtensionPermissionSet> permissions( scoped_refptr<ExtensionPermissionSet> permissions(
prefs->GetGrantedPermissions(extension_id)); prefs->GetGrantedPermissions(extension->id()));
EXPECT_FALSE(permissions->IsEmpty()); EXPECT_FALSE(permissions->IsEmpty());
EXPECT_TRUE(permissions->HasEffectiveFullAccess()); EXPECT_TRUE(permissions->HasEffectiveFullAccess());
EXPECT_FALSE(permissions->apis().empty()); EXPECT_FALSE(permissions->apis().empty());
...@@ -1503,11 +1520,10 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { ...@@ -1503,11 +1520,10 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
ASSERT_TRUE(file_util::PathExists(path)); ASSERT_TRUE(file_util::PathExists(path));
PackAndInstallCrx(path, true); const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW);
EXPECT_EQ(0u, GetErrors().size()); EXPECT_EQ(0u, GetErrors().size());
EXPECT_EQ(1u, service_->extensions()->size()); EXPECT_EQ(1u, service_->extensions()->size());
const Extension* extension = service_->extensions()->at(0);
std::string extension_id = extension->id(); std::string extension_id = extension->id();
ExtensionPrefs* prefs = service_->extension_prefs(); ExtensionPrefs* prefs = service_->extension_prefs();
...@@ -1531,7 +1547,7 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { ...@@ -1531,7 +1547,7 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
service_->ReloadExtensions(); service_->ReloadExtensions();
EXPECT_EQ(1u, service_->disabled_extensions()->size()); EXPECT_EQ(1u, service_->disabled_extensions()->size());
extension = service_->disabled_extensions()->at(0); extension = *service_->disabled_extensions()->begin();
ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); ASSERT_FALSE(service_->IsExtensionEnabled(extension_id));
...@@ -1574,7 +1590,7 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { ...@@ -1574,7 +1590,7 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
service_->ReloadExtensions(); service_->ReloadExtensions();
EXPECT_EQ(1u, service_->disabled_extensions()->size()); EXPECT_EQ(1u, service_->disabled_extensions()->size());
extension = service_->disabled_extensions()->at(0); extension = *service_->disabled_extensions()->begin();
ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); ASSERT_FALSE(service_->IsExtensionEnabled(extension_id));
...@@ -1615,7 +1631,7 @@ TEST_F(ExtensionServiceTest, PackExtension) { ...@@ -1615,7 +1631,7 @@ TEST_F(ExtensionServiceTest, PackExtension) {
privkey_path)); privkey_path));
ASSERT_TRUE(file_util::PathExists(privkey_path)); ASSERT_TRUE(file_util::PathExists(privkey_path));
InstallCrx(crx_path, true); InstallCRX(crx_path, INSTALL_NEW);
// Try packing with invalid paths. // Try packing with invalid paths.
creator.reset(new ExtensionCreator()); creator.reset(new ExtensionCreator());
...@@ -1706,7 +1722,7 @@ TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { ...@@ -1706,7 +1722,7 @@ TEST_F(ExtensionServiceTest, PackPunctuatedExtension) {
if (HasFatalFailure()) if (HasFatalFailure())
return; return;
InstallCrx(expected_crx_path, true); InstallCRX(expected_crx_path, INSTALL_NEW);
} }
} }
...@@ -1737,7 +1753,7 @@ TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { ...@@ -1737,7 +1753,7 @@ TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) {
ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path,
FilePath())); FilePath()));
InstallCrx(crx_path, true); InstallCRX(crx_path, INSTALL_NEW);
} }
TEST_F(ExtensionServiceTest, InstallTheme) { TEST_F(ExtensionServiceTest, InstallTheme) {
...@@ -1745,7 +1761,7 @@ TEST_F(ExtensionServiceTest, InstallTheme) { ...@@ -1745,7 +1761,7 @@ TEST_F(ExtensionServiceTest, InstallTheme) {
// A theme. // A theme.
FilePath path = data_dir_.AppendASCII("theme.crx"); FilePath path = data_dir_.AppendASCII("theme.crx");
InstallCrx(path, true); InstallCRX(path, INSTALL_NEW);
int pref_count = 0; int pref_count = 0;
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); ValidateIntegerPref(theme_crx, "state", Extension::ENABLED);
...@@ -1755,7 +1771,7 @@ TEST_F(ExtensionServiceTest, InstallTheme) { ...@@ -1755,7 +1771,7 @@ TEST_F(ExtensionServiceTest, InstallTheme) {
// extensions are disabled. // extensions are disabled.
set_extensions_enabled(false); set_extensions_enabled(false);
path = data_dir_.AppendASCII("theme2.crx"); path = data_dir_.AppendASCII("theme2.crx");
InstallCrx(path, true); InstallCRX(path, INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED);
ValidateIntegerPref(theme2_crx, "location", Extension::INTERNAL); ValidateIntegerPref(theme2_crx, "location", Extension::INTERNAL);
...@@ -1764,12 +1780,12 @@ TEST_F(ExtensionServiceTest, InstallTheme) { ...@@ -1764,12 +1780,12 @@ TEST_F(ExtensionServiceTest, InstallTheme) {
// this test should fail. // this test should fail.
set_extensions_enabled(true); set_extensions_enabled(true);
path = data_dir_.AppendASCII("theme_with_extension.crx"); path = data_dir_.AppendASCII("theme_with_extension.crx");
InstallCrx(path, false); InstallCRX(path, INSTALL_FAILED);
ValidatePrefKeyCount(pref_count); ValidatePrefKeyCount(pref_count);
// A theme with image resources missing (misspelt path). // A theme with image resources missing (misspelt path).
path = data_dir_.AppendASCII("theme_missing_image.crx"); path = data_dir_.AppendASCII("theme_missing_image.crx");
InstallCrx(path, false); InstallCRX(path, INSTALL_FAILED);
ValidatePrefKeyCount(pref_count); ValidatePrefKeyCount(pref_count);
} }
...@@ -1784,8 +1800,9 @@ TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { ...@@ -1784,8 +1800,9 @@ TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
EXPECT_EQ(0u, GetErrors().size()); EXPECT_EQ(0u, GetErrors().size());
ASSERT_EQ(1u, loaded_.size()); ASSERT_EQ(1u, loaded_.size());
EXPECT_EQ(1u, service_->extensions()->size()); EXPECT_EQ(1u, service_->extensions()->size());
EXPECT_EQ("name", service_->extensions()->at(0)->name()); const Extension* theme = *service_->extensions()->begin();
EXPECT_EQ("description", service_->extensions()->at(0)->description()); EXPECT_EQ("name", theme->name());
EXPECT_EQ("description", theme->description());
} }
TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
...@@ -1793,45 +1810,46 @@ TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { ...@@ -1793,45 +1810,46 @@ TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
FilePath theme_path = data_dir_ FilePath theme_path = data_dir_
.AppendASCII("theme_i18n"); .AppendASCII("theme_i18n");
PackAndInstallCrx(theme_path, true); const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW);
EXPECT_EQ(0u, GetErrors().size()); EXPECT_EQ(0u, GetErrors().size());
EXPECT_EQ(1u, service_->extensions()->size()); EXPECT_EQ(1u, service_->extensions()->size());
EXPECT_EQ("name", service_->extensions()->at(0)->name()); EXPECT_EQ("name", theme->name());
EXPECT_EQ("description", service_->extensions()->at(0)->description()); EXPECT_EQ("description", theme->description());
} }
TEST_F(ExtensionServiceTest, InstallApps) { TEST_F(ExtensionServiceTest, InstallApps) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
// An empty app. // An empty app.
PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"),
INSTALL_NEW);
int pref_count = 0; int pref_count = 0;
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
std::string id = service_->extensions()->at(0)->id(); ValidateIntegerPref(app->id(), "state", Extension::ENABLED);
ValidateIntegerPref(id, "state", Extension::ENABLED); ValidateIntegerPref(app->id(), "location", Extension::INTERNAL);
ValidateIntegerPref(id, "location", Extension::INTERNAL);
// Another app with non-overlapping extent. Should succeed. // Another app with non-overlapping extent. Should succeed.
PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
// A third app whose extent overlaps the first. Should fail. // A third app whose extent overlaps the first. Should fail.
PackAndInstallCrx(data_dir_.AppendASCII("app3"), false); PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED);
ValidatePrefKeyCount(pref_count); ValidatePrefKeyCount(pref_count);
} }
// Tests that file access is OFF by default. // Tests that file access is OFF by default.
TEST_F(ExtensionServiceTest, DefaultFileAccess) { TEST_F(ExtensionServiceTest, DefaultFileAccess) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
PackAndInstallCrx(data_dir_.AppendASCII("permissions").AppendASCII("files"), const Extension* extension =
true); PackAndInstallCRX(data_dir_
.AppendASCII("permissions")
.AppendASCII("files"),
INSTALL_NEW);
EXPECT_EQ(0u, GetErrors().size()); EXPECT_EQ(0u, GetErrors().size());
EXPECT_EQ(1u, service_->extensions()->size()); EXPECT_EQ(1u, service_->extensions()->size());
std::string id = service_->extensions()->at(0)->id(); EXPECT_FALSE(service_->extension_prefs()->AllowFileAccess(extension->id()));
EXPECT_FALSE(service_->extension_prefs()->AllowFileAccess(id));
} }
TEST_F(ExtensionServiceTest, UpdateApps) { TEST_F(ExtensionServiceTest, UpdateApps) {
...@@ -1839,21 +1857,21 @@ TEST_F(ExtensionServiceTest, UpdateApps) { ...@@ -1839,21 +1857,21 @@ TEST_F(ExtensionServiceTest, UpdateApps) {
FilePath extensions_path = data_dir_.AppendASCII("app_update"); FilePath extensions_path = data_dir_.AppendASCII("app_update");
// First install v1 of a hosted app. // First install v1 of a hosted app.
InstallCrx(extensions_path.AppendASCII("v1.crx"), true); const Extension* extension =
InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW);
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
std::string id = service_->extensions()->at(0)->id(); std::string id = extension->id();
ASSERT_EQ(std::string("1"), ASSERT_EQ(std::string("1"), extension->version()->GetString());
service_->extensions()->at(0)->version()->GetString());
// Now try updating to v2. // Now try updating to v2.
UpdateExtension(id, UpdateExtension(id,
extensions_path.AppendASCII("v2.crx"), extensions_path.AppendASCII("v2.crx"),
ENABLED); ENABLED);
ASSERT_EQ(std::string("2"), ASSERT_EQ(std::string("2"),
service_->extensions()->at(0)->version()->GetString()); service_->GetExtensionById(id, false)->version()->GetString());
} }
TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) { TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InitializeRequestContext(); InitializeRequestContext();
EXPECT_TRUE(service_->extensions()->empty()); EXPECT_TRUE(service_->extensions()->empty());
...@@ -1861,10 +1879,10 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) { ...@@ -1861,10 +1879,10 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) {
int pref_count = 0; int pref_count = 0;
// Install app1 with unlimited storage. // Install app1 with unlimited storage.
PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); const Extension* extension =
PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
const Extension* extension = service_->extensions()->at(0);
const std::string id1 = extension->id(); const std::string id1 = extension->id();
EXPECT_TRUE(extension->HasAPIPermission( EXPECT_TRUE(extension->HasAPIPermission(
ExtensionAPIPermission::kUnlimitedStorage)); ExtensionAPIPermission::kUnlimitedStorage));
...@@ -1875,10 +1893,9 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) { ...@@ -1875,10 +1893,9 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) {
IsStorageUnlimited(origin1)); IsStorageUnlimited(origin1));
// Install app2 from the same origin with unlimited storage. // Install app2 from the same origin with unlimited storage.
PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ASSERT_EQ(2u, service_->extensions()->size()); ASSERT_EQ(2u, service_->extensions()->size());
extension = service_->extensions()->at(1);
const std::string id2 = extension->id(); const std::string id2 = extension->id();
EXPECT_TRUE(extension->HasAPIPermission( EXPECT_TRUE(extension->HasAPIPermission(
ExtensionAPIPermission::kUnlimitedStorage)); ExtensionAPIPermission::kUnlimitedStorage));
...@@ -1912,10 +1929,10 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { ...@@ -1912,10 +1929,10 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
int pref_count = 0; int pref_count = 0;
PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); const Extension* extension =
PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
const Extension* extension = service_->extensions()->at(0);
EXPECT_TRUE(extension->is_app()); EXPECT_TRUE(extension->is_app());
const std::string id1 = extension->id(); const std::string id1 = extension->id();
const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); const GURL origin1(extension->GetFullLaunchURL().GetOrigin());
...@@ -1923,10 +1940,9 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { ...@@ -1923,10 +1940,9 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
IsStorageProtected(origin1)); IsStorageProtected(origin1));
// App 4 has a different origin (maps.google.com). // App 4 has a different origin (maps.google.com).
PackAndInstallCrx(data_dir_.AppendASCII("app4"), true); extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ASSERT_EQ(2u, service_->extensions()->size()); ASSERT_EQ(2u, service_->extensions()->size());
extension = service_->extensions()->at(1);
const std::string id2 = extension->id(); const std::string id2 = extension->id();
const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); const GURL origin2(extension->GetFullLaunchURL().GetOrigin());
ASSERT_NE(origin1, origin2); ASSERT_NE(origin1, origin2);
...@@ -1951,27 +1967,15 @@ TEST_F(ExtensionServiceTest, Reinstall) { ...@@ -1951,27 +1967,15 @@ TEST_F(ExtensionServiceTest, Reinstall) {
// A simple extension that should install without error. // A simple extension that should install without error.
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
StartCrxInstall(path); InstallCRX(path, INSTALL_NEW);
loop_.RunAllPending();
ASSERT_TRUE(installed_);
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ(0u, GetErrors().size());
ValidatePrefKeyCount(1); ValidatePrefKeyCount(1);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED); ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); ValidateIntegerPref(good_crx, "location", Extension::INTERNAL);
installed_ = NULL;
loaded_.clear();
ExtensionErrorReporter::GetInstance()->ClearErrors();
// Reinstall the same version, it should overwrite the previous one. // Reinstall the same version, it should overwrite the previous one.
StartCrxInstall(path); InstallCRX(path, INSTALL_UPDATED);
loop_.RunAllPending();
ASSERT_TRUE(installed_);
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ(0u, GetErrors().size());
ValidatePrefKeyCount(1); ValidatePrefKeyCount(1);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED); ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); ValidateIntegerPref(good_crx, "location", Extension::INTERNAL);
...@@ -1984,35 +1988,23 @@ TEST_F(ExtensionServiceTest, FromWebStore) { ...@@ -1984,35 +1988,23 @@ TEST_F(ExtensionServiceTest, FromWebStore) {
// A simple extension that should install without error. // A simple extension that should install without error.
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
StartCrxInstall(path, false); // Not from web store. // Not from web store.
loop_.RunAllPending(); const Extension* extension = InstallCRX(path, INSTALL_NEW);
std::string id = extension->id();
ASSERT_TRUE(installed_);
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ(0u, GetErrors().size());
ValidatePrefKeyCount(1); ValidatePrefKeyCount(1);
ValidateBooleanPref(good_crx, "from_webstore", false); ValidateBooleanPref(good_crx, "from_webstore", false);
const Extension* extension = service_->extensions()->at(0);
ASSERT_FALSE(extension->from_webstore()); ASSERT_FALSE(extension->from_webstore());
installed_ = NULL;
loaded_.clear();
ExtensionErrorReporter::GetInstance()->ClearErrors();
// Test install from web store. // Test install from web store.
StartCrxInstall(path, true); // From web store. InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store.
loop_.RunAllPending();
ASSERT_TRUE(installed_);
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ(0u, GetErrors().size());
ValidatePrefKeyCount(1); ValidatePrefKeyCount(1);
ValidateBooleanPref(good_crx, "from_webstore", true); ValidateBooleanPref(good_crx, "from_webstore", true);
// Reload so extension gets reinitialized with new value. // Reload so extension gets reinitialized with new value.
service_->ReloadExtensions(); service_->ReloadExtensions();
extension = service_->extensions()->at(0); extension = service_->GetExtensionById(id, false);
ASSERT_TRUE(extension->from_webstore()); ASSERT_TRUE(extension->from_webstore());
// Upgrade to version 2.0 // Upgrade to version 2.0
...@@ -2027,22 +2019,18 @@ TEST_F(ExtensionServiceTest, UpgradeSignedGood) { ...@@ -2027,22 +2019,18 @@ TEST_F(ExtensionServiceTest, UpgradeSignedGood) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
StartCrxInstall(path); const Extension* extension = InstallCRX(path, INSTALL_NEW);
loop_.RunAllPending(); std::string id = extension->id();
ASSERT_TRUE(installed_); ASSERT_EQ("1.0.0.0", extension->version()->GetString());
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
ASSERT_EQ(0u, GetErrors().size()); ASSERT_EQ(0u, GetErrors().size());
// Upgrade to version 2.0 // Upgrade to version 1.0.0.1
path = data_dir_.AppendASCII("good2.crx"); path = data_dir_.AppendASCII("good2.crx");
StartCrxInstall(path); InstallCRX(path, INSTALL_UPDATED);
loop_.RunAllPending(); extension = service_->GetExtensionById(id, false);
ASSERT_TRUE(installed_); ASSERT_EQ("1.0.0.1", extension->version()->GetString());
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
ASSERT_EQ(0u, GetErrors().size()); ASSERT_EQ(0u, GetErrors().size());
} }
...@@ -2051,23 +2039,12 @@ TEST_F(ExtensionServiceTest, UpgradeSignedBad) { ...@@ -2051,23 +2039,12 @@ TEST_F(ExtensionServiceTest, UpgradeSignedBad) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
StartCrxInstall(path); InstallCRX(path, INSTALL_NEW);
loop_.RunAllPending();
ASSERT_TRUE(installed_);
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ(0u, GetErrors().size());
installed_ = NULL;
// Try upgrading with a bad signature. This should fail during the unpack, // Try upgrading with a bad signature. This should fail during the unpack,
// because the key will not match the signature. // because the key will not match the signature.
path = data_dir_.AppendASCII("bad_signature.crx"); path = data_dir_.AppendASCII("bad_signature.crx");
StartCrxInstall(path); InstallCRX(path, INSTALL_FAILED);
loop_.RunAllPending();
ASSERT_FALSE(installed_);
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ(1u, GetErrors().size());
} }
// Test a normal update via the UpdateExtension API // Test a normal update via the UpdateExtension API
...@@ -2076,14 +2053,15 @@ TEST_F(ExtensionServiceTest, UpdateExtension) { ...@@ -2076,14 +2053,15 @@ TEST_F(ExtensionServiceTest, UpdateExtension) {
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); const Extension* good = InstallCRX(path, INSTALL_NEW);
const Extension* good = service_->extensions()->at(0);
ASSERT_EQ("1.0.0.0", good->VersionString()); ASSERT_EQ("1.0.0.0", good->VersionString());
ASSERT_EQ(good_crx, good->id()); ASSERT_EQ(good_crx, good->id());
path = data_dir_.AppendASCII("good2.crx"); path = data_dir_.AppendASCII("good2.crx");
UpdateExtension(good_crx, path, ENABLED); UpdateExtension(good_crx, path, ENABLED);
ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); ASSERT_EQ("1.0.0.1",
service_->GetExtensionById(good_crx, false)->
version()->GetString());
} }
// Test updating a not-already-installed extension - this should fail // Test updating a not-already-installed extension - this should fail
...@@ -2105,15 +2083,16 @@ TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { ...@@ -2105,15 +2083,16 @@ TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) {
FilePath path = data_dir_.AppendASCII("good2.crx"); FilePath path = data_dir_.AppendASCII("good2.crx");
InstallCrx(path, true); const Extension* good = InstallCRX(path, INSTALL_NEW);
const Extension* good = service_->extensions()->at(0);
ASSERT_EQ("1.0.0.1", good->VersionString()); ASSERT_EQ("1.0.0.1", good->VersionString());
ASSERT_EQ(good_crx, good->id()); ASSERT_EQ(good_crx, good->id());
// Change path from good2.crx -> good.crx // Change path from good2.crx -> good.crx
path = data_dir_.AppendASCII("good.crx"); path = data_dir_.AppendASCII("good.crx");
UpdateExtension(good_crx, path, FAILED); UpdateExtension(good_crx, path, FAILED);
ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString()); ASSERT_EQ("1.0.0.1",
service_->GetExtensionById(good_crx, false)->
version()->GetString());
} }
// Make sure calling update with an identical version does nothing // Make sure calling update with an identical version does nothing
...@@ -2122,8 +2101,7 @@ TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { ...@@ -2122,8 +2101,7 @@ TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) {
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); const Extension* good = InstallCRX(path, INSTALL_NEW);
const Extension* good = service_->extensions()->at(0);
ASSERT_EQ(good_crx, good->id()); ASSERT_EQ(good_crx, good->id());
UpdateExtension(good_crx, path, FAILED_SILENTLY); UpdateExtension(good_crx, path, FAILED_SILENTLY);
} }
...@@ -2134,8 +2112,7 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { ...@@ -2134,8 +2112,7 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) {
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); const Extension* good = InstallCRX(path, INSTALL_NEW);
const Extension* good = service_->extensions()->at(0);
ASSERT_EQ("1.0.0.0", good->VersionString()); ASSERT_EQ("1.0.0.0", good->VersionString());
ASSERT_EQ(good_crx, good->id()); ASSERT_EQ(good_crx, good->id());
...@@ -2147,7 +2124,7 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { ...@@ -2147,7 +2124,7 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) {
path = data_dir_.AppendASCII("good2.crx"); path = data_dir_.AppendASCII("good2.crx");
UpdateExtension(good_crx, path, INSTALLED); UpdateExtension(good_crx, path, INSTALLED);
ASSERT_EQ(1u, service_->disabled_extensions()->size()); ASSERT_EQ(1u, service_->disabled_extensions()->size());
const Extension* good2 = service_->disabled_extensions()->at(0); const Extension* good2 = service_->GetExtensionById(good_crx, true);
ASSERT_EQ("1.0.0.1", good2->version()->GetString()); ASSERT_EQ("1.0.0.1", good2->version()->GetString());
EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id()));
} }
...@@ -2158,8 +2135,7 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { ...@@ -2158,8 +2135,7 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) {
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); const Extension* good = InstallCRX(path, INSTALL_NEW);
const Extension* good = service_->extensions()->at(0);
ASSERT_EQ("1.0.0.0", good->VersionString()); ASSERT_EQ("1.0.0.0", good->VersionString());
ASSERT_EQ(good_crx, good->id()); ASSERT_EQ(good_crx, good->id());
...@@ -2169,7 +2145,7 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { ...@@ -2169,7 +2145,7 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) {
path = data_dir_.AppendASCII("good2.crx"); path = data_dir_.AppendASCII("good2.crx");
UpdateExtension(good_crx, path, ENABLED); UpdateExtension(good_crx, path, ENABLED);
const Extension* good2 = service_->extensions()->at(0); const Extension* good2 = service_->GetExtensionById(good_crx, false);
ASSERT_EQ("1.0.0.1", good2->version()->GetString()); ASSERT_EQ("1.0.0.1", good2->version()->GetString());
EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF); EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF);
} }
...@@ -2428,9 +2404,8 @@ TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { ...@@ -2428,9 +2404,8 @@ TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); const Extension* good = InstallCRX(path, INSTALL_NEW);
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
const Extension* good = service_->extensions()->at(0);
EXPECT_FALSE(good->is_theme()); EXPECT_FALSE(good->is_theme());
...@@ -2478,8 +2453,7 @@ TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) { ...@@ -2478,8 +2453,7 @@ TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) {
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); const Extension* good = InstallCRX(path, INSTALL_NEW);
const Extension* good = service_->extensions()->at(0);
EXPECT_EQ(good_crx, good->id()); EXPECT_EQ(good_crx, good->id());
UpdateExtension(good_crx, path, FAILED_SILENTLY); UpdateExtension(good_crx, path, FAILED_SILENTLY);
...@@ -2516,8 +2490,7 @@ TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { ...@@ -2516,8 +2490,7 @@ TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) {
// We can not install good_crx. // We can not install good_crx.
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
StartCrxInstall(path); InstallCRX(path, INSTALL_FAILED);
loop_.RunAllPending();
EXPECT_EQ(0u, service_->extensions()->size()); EXPECT_EQ(0u, service_->extensions()->size());
ValidateBooleanPref(good_crx, "blacklist", true); ValidateBooleanPref(good_crx, "blacklist", true);
} }
...@@ -2545,7 +2518,6 @@ TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { ...@@ -2545,7 +2518,6 @@ TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
// Load extensions. // Load extensions.
service_->Init(); service_->Init();
loop_.RunAllPending();
std::vector<std::string> errors = GetErrors(); std::vector<std::string> errors = GetErrors();
for (std::vector<std::string>::iterator err = errors.begin(); for (std::vector<std::string>::iterator err = errors.begin();
...@@ -2554,8 +2526,7 @@ TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { ...@@ -2554,8 +2526,7 @@ TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
} }
ASSERT_EQ(2u, loaded_.size()); ASSERT_EQ(2u, loaded_.size());
EXPECT_NE(std::string(good1), loaded_[0]->id()); EXPECT_FALSE(service_->GetExtensionById(good1, true));
EXPECT_NE(std::string(good1), loaded_[1]->id());
} }
// Will not install extension blacklisted by policy. // Will not install extension blacklisted by policy.
...@@ -2572,8 +2543,7 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { ...@@ -2572,8 +2543,7 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
// Blacklist prevents us from installing good_crx. // Blacklist prevents us from installing good_crx.
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
StartCrxInstall(path); InstallCRX(path, INSTALL_FAILED);
loop_.RunAllPending();
EXPECT_EQ(0u, service_->extensions()->size()); EXPECT_EQ(0u, service_->extensions()->size());
// Now whitelist this particular extension. // Now whitelist this particular extension.
...@@ -2584,10 +2554,8 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { ...@@ -2584,10 +2554,8 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
whitelist->Append(Value::CreateStringValue(good_crx)); whitelist->Append(Value::CreateStringValue(good_crx));
} }
// Ensure we can now install good_crx. // Ensure we can now install good_crx.
StartCrxInstall(path); InstallCRX(path, INSTALL_NEW);
loop_.RunAllPending();
EXPECT_EQ(1u, service_->extensions()->size()); EXPECT_EQ(1u, service_->extensions()->size());
} }
...@@ -2597,8 +2565,7 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { ...@@ -2597,8 +2565,7 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) {
// Install good_crx. // Install good_crx.
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
StartCrxInstall(path); InstallCRX(path, INSTALL_NEW);
loop_.RunAllPending();
EXPECT_EQ(1u, service_->extensions()->size()); EXPECT_EQ(1u, service_->extensions()->size());
{ // Scope for pref update notification. { // Scope for pref update notification.
...@@ -2643,12 +2610,12 @@ TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { ...@@ -2643,12 +2610,12 @@ TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
// Extension should be installed despite blacklist. // Extension should be installed despite blacklist.
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(good0, service_->extensions()->at(0)->id()); EXPECT_TRUE(service_->GetExtensionById(good0, false));
// Poke external providers and make sure the extension is still present. // Poke external providers and make sure the extension is still present.
service_->CheckForExternalUpdates(); service_->CheckForExternalUpdates();
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(good0, service_->extensions()->at(0)->id()); EXPECT_TRUE(service_->GetExtensionById(good0, false));
// Extension should not be uninstalled on blacklist changes. // Extension should not be uninstalled on blacklist changes.
{ {
...@@ -2659,7 +2626,7 @@ TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { ...@@ -2659,7 +2626,7 @@ TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
} }
loop_.RunAllPending(); loop_.RunAllPending();
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(good0, service_->extensions()->at(0)->id()); EXPECT_TRUE(service_->GetExtensionById(good0, false));
} }
// Tests that policy-installed extensions are not blacklisted by policy. // Tests that policy-installed extensions are not blacklisted by policy.
...@@ -2689,7 +2656,7 @@ TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { ...@@ -2689,7 +2656,7 @@ TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
// Extension should be installed despite blacklist. // Extension should be installed despite blacklist.
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(good_crx, service_->extensions()->at(0)->id()); EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
// Blacklist update should not uninstall the extension. // Blacklist update should not uninstall the extension.
{ {
...@@ -2700,32 +2667,32 @@ TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { ...@@ -2700,32 +2667,32 @@ TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
} }
loop_.RunAllPending(); loop_.RunAllPending();
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(good_crx, service_->extensions()->at(0)->id()); EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
} }
// Tests disabling extensions // Tests disabling extensions
TEST_F(ExtensionServiceTest, DisableExtension) { TEST_F(ExtensionServiceTest, DisableExtension) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
EXPECT_FALSE(service_->extensions()->empty()); EXPECT_FALSE(service_->extensions()->empty());
EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
EXPECT_TRUE(service_->GetExtensionById(good_crx, false) != NULL); EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
EXPECT_TRUE(service_->disabled_extensions()->empty()); EXPECT_TRUE(service_->disabled_extensions()->empty());
// Disable it. // Disable it.
service_->DisableExtension(good_crx); service_->DisableExtension(good_crx);
EXPECT_TRUE(service_->extensions()->empty()); EXPECT_TRUE(service_->extensions()->empty());
EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
EXPECT_FALSE(service_->GetExtensionById(good_crx, false) != NULL); EXPECT_FALSE(service_->GetExtensionById(good_crx, false));
EXPECT_FALSE(service_->disabled_extensions()->empty()); EXPECT_FALSE(service_->disabled_extensions()->empty());
} }
TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
TerminateExtension(good_crx); TerminateExtension(good_crx);
EXPECT_TRUE(service_->GetTerminatedExtension(good_crx)); EXPECT_TRUE(service_->GetTerminatedExtension(good_crx));
...@@ -2733,7 +2700,7 @@ TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { ...@@ -2733,7 +2700,7 @@ TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
service_->DisableExtension(good_crx); service_->DisableExtension(good_crx);
EXPECT_FALSE(service_->GetTerminatedExtension(good_crx)); EXPECT_FALSE(service_->GetTerminatedExtension(good_crx));
EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
EXPECT_FALSE(service_->disabled_extensions()->empty()); EXPECT_FALSE(service_->disabled_extensions()->empty());
} }
...@@ -2741,9 +2708,8 @@ TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { ...@@ -2741,9 +2708,8 @@ TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
TEST_F(ExtensionServiceTest, DisableAllExtensions) { TEST_F(ExtensionServiceTest, DisableAllExtensions) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); InstallCRX(path, INSTALL_NEW);
EXPECT_EQ(1u, service_->extensions()->size()); EXPECT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(0u, service_->disabled_extensions()->size()); EXPECT_EQ(0u, service_->disabled_extensions()->size());
...@@ -2772,13 +2738,13 @@ TEST_F(ExtensionServiceTest, DisableAllExtensions) { ...@@ -2772,13 +2738,13 @@ TEST_F(ExtensionServiceTest, DisableAllExtensions) {
EXPECT_EQ(0u, service_->disabled_extensions()->size()); EXPECT_EQ(0u, service_->disabled_extensions()->size());
} }
// Tests reloading extensions // Tests reloading extensions.
TEST_F(ExtensionServiceTest, ReloadExtensions) { TEST_F(ExtensionServiceTest, ReloadExtensions) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
// Simple extension that should install without error. // Simple extension that should install without error.
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); InstallCRX(path, INSTALL_NEW);
const char* extension_id = good_crx; const char* extension_id = good_crx;
service_->DisableExtension(extension_id); service_->DisableExtension(extension_id);
...@@ -2816,13 +2782,13 @@ TEST_F(ExtensionServiceTest, ReloadExtensions) { ...@@ -2816,13 +2782,13 @@ TEST_F(ExtensionServiceTest, ReloadExtensions) {
#endif #endif
TEST_F(ExtensionServiceTest, MAYBE_UninstallExtension) { TEST_F(ExtensionServiceTest, MAYBE_UninstallExtension) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
UninstallExtension(good_crx, false); UninstallExtension(good_crx, false);
} }
TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
TerminateExtension(good_crx); TerminateExtension(good_crx);
UninstallExtension(good_crx, false); UninstallExtension(good_crx, false);
} }
...@@ -2830,13 +2796,13 @@ TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { ...@@ -2830,13 +2796,13 @@ TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
// Tests the uninstaller helper. // Tests the uninstaller helper.
TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { TEST_F(ExtensionServiceTest, UninstallExtensionHelper) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
UninstallExtension(good_crx, true); UninstallExtension(good_crx, true);
} }
TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
TerminateExtension(good_crx); TerminateExtension(good_crx);
UninstallExtension(good_crx, true); UninstallExtension(good_crx, true);
} }
...@@ -2873,8 +2839,7 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) { ...@@ -2873,8 +2839,7 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) {
// Load a test extension. // Load a test extension.
FilePath path = data_dir_; FilePath path = data_dir_;
path = path.AppendASCII("good.crx"); path = path.AppendASCII("good.crx");
InstallCrx(path, true); const Extension* extension = InstallCRX(path, INSTALL_NEW);
const Extension* extension = service_->GetExtensionById(good_crx, false);
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
GURL ext_url(extension->url()); GURL ext_url(extension->url());
string16 origin_id = string16 origin_id =
...@@ -2962,10 +2927,10 @@ TEST_F(ExtensionServiceTest, ClearAppData) { ...@@ -2962,10 +2927,10 @@ TEST_F(ExtensionServiceTest, ClearAppData) {
int pref_count = 0; int pref_count = 0;
// Install app1 with unlimited storage. // Install app1 with unlimited storage.
PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); const Extension* extension =
PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
const Extension* extension = service_->extensions()->at(0);
const std::string id1 = extension->id(); const std::string id1 = extension->id();
EXPECT_TRUE(extension->HasAPIPermission( EXPECT_TRUE(extension->HasAPIPermission(
ExtensionAPIPermission::kUnlimitedStorage)); ExtensionAPIPermission::kUnlimitedStorage));
...@@ -2976,10 +2941,9 @@ TEST_F(ExtensionServiceTest, ClearAppData) { ...@@ -2976,10 +2941,9 @@ TEST_F(ExtensionServiceTest, ClearAppData) {
webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); webkit_database::DatabaseUtil::GetOriginIdentifier(origin1);
// Install app2 from the same origin with unlimited storage. // Install app2 from the same origin with unlimited storage.
PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
ValidatePrefKeyCount(++pref_count); ValidatePrefKeyCount(++pref_count);
ASSERT_EQ(2u, service_->extensions()->size()); ASSERT_EQ(2u, service_->extensions()->size());
extension = service_->extensions()->at(1);
const std::string id2 = extension->id(); const std::string id2 = extension->id();
EXPECT_TRUE(extension->HasAPIPermission( EXPECT_TRUE(extension->HasAPIPermission(
ExtensionAPIPermission::kUnlimitedStorage)); ExtensionAPIPermission::kUnlimitedStorage));
...@@ -3124,7 +3088,6 @@ TEST_F(ExtensionServiceTest, LoadExtension) { ...@@ -3124,7 +3088,6 @@ TEST_F(ExtensionServiceTest, LoadExtension) {
TEST_F(ExtensionServiceTest, GenerateID) { TEST_F(ExtensionServiceTest, GenerateID) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
FilePath no_id_ext = data_dir_.AppendASCII("no_id"); FilePath no_id_ext = data_dir_.AppendASCII("no_id");
extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
loop_.RunAllPending(); loop_.RunAllPending();
...@@ -3148,7 +3111,6 @@ void ExtensionServiceTest::TestExternalProvider( ...@@ -3148,7 +3111,6 @@ void ExtensionServiceTest::TestExternalProvider(
MockExtensionProvider* provider, Extension::Location location) { MockExtensionProvider* provider, Extension::Location location) {
// Verify that starting with no providers loads no extensions. // Verify that starting with no providers loads no extensions.
service_->Init(); service_->Init();
loop_.RunAllPending();
ASSERT_EQ(0u, loaded_.size()); ASSERT_EQ(0u, loaded_.size());
provider->set_visit_count(0); provider->set_visit_count(0);
...@@ -3358,7 +3320,6 @@ TEST_F(ExtensionServiceTest, ExternalUninstall) { ...@@ -3358,7 +3320,6 @@ TEST_F(ExtensionServiceTest, ExternalUninstall) {
set_extensions_enabled(false); set_extensions_enabled(false);
service_->Init(); service_->Init();
loop_.RunAllPending();
ASSERT_EQ(0u, GetErrors().size()); ASSERT_EQ(0u, GetErrors().size());
ASSERT_EQ(0u, loaded_.size()); ASSERT_EQ(0u, loaded_.size());
...@@ -3383,7 +3344,6 @@ TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { ...@@ -3383,7 +3344,6 @@ TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
// Verify that starting with no providers loads no extensions. // Verify that starting with no providers loads no extensions.
service_->Init(); service_->Init();
loop_.RunAllPending();
ASSERT_EQ(0u, loaded_.size()); ASSERT_EQ(0u, loaded_.size());
// Start two checks for updates. // Start two checks for updates.
...@@ -3584,7 +3544,6 @@ TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { ...@@ -3584,7 +3544,6 @@ TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) {
InitializeInstalledExtensionService(pref_path, source_install_dir); InitializeInstalledExtensionService(pref_path, source_install_dir);
service_->Init(); service_->Init();
loop_.RunAllPending();
ASSERT_EQ(3u, loaded_.size()); ASSERT_EQ(3u, loaded_.size());
...@@ -3766,11 +3725,11 @@ TEST_F(ExtensionServiceTest, ComponentExtensions) { ...@@ -3766,11 +3725,11 @@ TEST_F(ExtensionServiceTest, ComponentExtensions) {
ValidatePrefKeyCount(0); ValidatePrefKeyCount(0);
// Reload all extensions, and make sure it comes back. // Reload all extensions, and make sure it comes back.
std::string extension_id = service_->extensions()->at(0)->id(); std::string extension_id = (*service_->extensions()->begin())->id();
loaded_.clear(); loaded_.clear();
service_->ReloadExtensions(); service_->ReloadExtensions();
ASSERT_EQ(1u, service_->extensions()->size()); ASSERT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); EXPECT_EQ(extension_id, (*service_->extensions()->begin())->id());
} }
namespace { namespace {
...@@ -3785,7 +3744,7 @@ namespace { ...@@ -3785,7 +3744,7 @@ namespace {
TEST_F(ExtensionServiceTest, GetSyncData) { TEST_F(ExtensionServiceTest, GetSyncData) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
const Extension* extension = service_->GetInstalledExtension(good_crx); const Extension* extension = service_->GetInstalledExtension(good_crx);
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
...@@ -3807,7 +3766,7 @@ TEST_F(ExtensionServiceTest, GetSyncData) { ...@@ -3807,7 +3766,7 @@ TEST_F(ExtensionServiceTest, GetSyncData) {
TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { TEST_F(ExtensionServiceTest, GetSyncDataTerminated) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
TerminateExtension(good_crx); TerminateExtension(good_crx);
const Extension* extension = service_->GetInstalledExtension(good_crx); const Extension* extension = service_->GetInstalledExtension(good_crx);
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
...@@ -3830,7 +3789,7 @@ TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { ...@@ -3830,7 +3789,7 @@ TEST_F(ExtensionServiceTest, GetSyncDataTerminated) {
TEST_F(ExtensionServiceTest, GetSyncDataFilter) { TEST_F(ExtensionServiceTest, GetSyncDataFilter) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
const Extension* extension = service_->GetInstalledExtension(good_crx); const Extension* extension = service_->GetInstalledExtension(good_crx);
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
...@@ -3844,7 +3803,7 @@ TEST_F(ExtensionServiceTest, GetSyncDataFilter) { ...@@ -3844,7 +3803,7 @@ TEST_F(ExtensionServiceTest, GetSyncDataFilter) {
TEST_F(ExtensionServiceTest, GetSyncDataUserSettings) { TEST_F(ExtensionServiceTest, GetSyncDataUserSettings) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
const Extension* extension = service_->GetInstalledExtension(good_crx); const Extension* extension = service_->GetInstalledExtension(good_crx);
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
...@@ -3890,10 +3849,10 @@ TEST_F(ExtensionServiceTest, GetSyncDataUserSettings) { ...@@ -3890,10 +3849,10 @@ TEST_F(ExtensionServiceTest, GetSyncDataUserSettings) {
TEST_F(ExtensionServiceTest, GetSyncDataList) { TEST_F(ExtensionServiceTest, GetSyncDataList) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
InstallCrx(data_dir_.AppendASCII("page_action.crx"), true); InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW);
InstallCrx(data_dir_.AppendASCII("theme.crx"), true); InstallCRX(data_dir_.AppendASCII("theme.crx"), INSTALL_NEW);
InstallCrx(data_dir_.AppendASCII("theme2.crx"), true); InstallCRX(data_dir_.AppendASCII("theme2.crx"), INSTALL_NEW);
TestSyncProcessorStub processor; TestSyncProcessorStub processor;
service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(),
...@@ -3930,7 +3889,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { ...@@ -3930,7 +3889,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) {
// Install the extension. // Install the extension.
FilePath extension_path = data_dir_.AppendASCII("good.crx"); FilePath extension_path = data_dir_.AppendASCII("good.crx");
InstallCrx(extension_path, true); InstallCRX(extension_path, INSTALL_NEW);
EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
// Should uninstall the extension. // Should uninstall the extension.
...@@ -3947,7 +3906,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { ...@@ -3947,7 +3906,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) {
// Install the extension. // Install the extension.
FilePath extension_path = data_dir_.AppendASCII("good.crx"); FilePath extension_path = data_dir_.AppendASCII("good.crx");
InstallCrx(extension_path, true); InstallCRX(extension_path, INSTALL_NEW);
EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
sync_pb::EntitySpecifics specifics; sync_pb::EntitySpecifics specifics;
...@@ -3991,7 +3950,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { ...@@ -3991,7 +3950,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) {
service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(),
&processor); &processor);
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
...@@ -4046,7 +4005,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { ...@@ -4046,7 +4005,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) {
service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(),
&processor); &processor);
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
TerminateExtension(good_crx); TerminateExtension(good_crx);
EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
...@@ -4077,7 +4036,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { ...@@ -4077,7 +4036,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) {
service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(),
&processor); &processor);
InstallCrx(data_dir_.AppendASCII("good.crx"), true); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); EXPECT_TRUE(service_->IsExtensionEnabled(good_crx));
EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx));
...@@ -4169,7 +4128,7 @@ TEST_F(ExtensionServiceTest, HigherPriorityInstall) { ...@@ -4169,7 +4128,7 @@ TEST_F(ExtensionServiceTest, HigherPriorityInstall) {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
FilePath path = data_dir_.AppendASCII("good.crx"); FilePath path = data_dir_.AppendASCII("good.crx");
InstallCrx(path, true); InstallCRX(path, INSTALL_NEW);
ValidatePrefKeyCount(1u); ValidatePrefKeyCount(1u);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED); ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); ValidateIntegerPref(good_crx, "location", Extension::INTERNAL);
...@@ -4294,7 +4253,7 @@ TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) { ...@@ -4294,7 +4253,7 @@ TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) {
ASSERT_EQ(Extension::EXTERNAL_PREF, GetPendingLocation()); ASSERT_EQ(Extension::EXTERNAL_PREF, GetPendingLocation());
ASSERT_FALSE(IsCrxInstalled()); ASSERT_FALSE(IsCrxInstalled());
WaitForCrxInstall(crx_path_, true); WaitForCrxInstall(crx_path_, INSTALL_NEW);
ASSERT_TRUE(IsCrxInstalled()); ASSERT_TRUE(IsCrxInstalled());
} }
...@@ -4337,7 +4296,7 @@ TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) { ...@@ -4337,7 +4296,7 @@ TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) {
ASSERT_FALSE(AddPendingSyncInstall()); ASSERT_FALSE(AddPendingSyncInstall());
// Wait for the external source to install. // Wait for the external source to install.
WaitForCrxInstall(crx_path_, true); WaitForCrxInstall(crx_path_, INSTALL_NEW);
ASSERT_TRUE(IsCrxInstalled()); ASSERT_TRUE(IsCrxInstalled());
// Now that the extension is installed, sync request should fail // Now that the extension is installed, sync request should fail
......
...@@ -57,7 +57,7 @@ class ExtensionServiceTestBase : public testing::Test { ...@@ -57,7 +57,7 @@ class ExtensionServiceTestBase : public testing::Test {
FilePath data_dir_; FilePath data_dir_;
// Owned by |profile_|. // Owned by |profile_|.
ExtensionService* service_; ExtensionService* service_;
size_t total_successes_; size_t expected_extensions_count_;
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_; content::TestBrowserThread db_thread_;
content::TestBrowserThread webkit_thread_; content::TestBrowserThread webkit_thread_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment