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

Unified Diff: chrome/browser/extensions/settings/settings_frontend_unittest.cc

Issue 8497065: Extension Settings API: make it so that when leveldb storage areas fail to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/settings/settings_frontend_unittest.cc
diff --git a/chrome/browser/extensions/settings/settings_frontend_unittest.cc b/chrome/browser/extensions/settings/settings_frontend_unittest.cc
index 4c0063a3a602c49f666229cc0bfe9c5d2e7d9475..565dab0de358d08e25060e07da5427de5b73568d 100644
--- a/chrome/browser/extensions/settings/settings_frontend_unittest.cc
+++ b/chrome/browser/extensions/settings/settings_frontend_unittest.cc
@@ -21,16 +21,16 @@ using content::BrowserThread;
using namespace settings_test_util;
-class SettingsFrontendTest : public testing::Test {
+class ExtensionSettingsFrontendTest : public testing::Test {
public:
- SettingsFrontendTest()
+ ExtensionSettingsFrontendTest()
: ui_thread_(BrowserThread::UI, MessageLoop::current()),
file_thread_(BrowserThread::FILE, MessageLoop::current()) {}
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
profile_.reset(new MockProfile(temp_dir_.path()));
- frontend_.reset(new SettingsFrontend(profile_.get()));
+ ResetFrontend();
}
virtual void TearDown() OVERRIDE {
@@ -39,10 +39,20 @@ class SettingsFrontendTest : public testing::Test {
}
protected:
+ void ResetFrontend() {
+ storage_factory_ =
+ new DelegatingSettingsStorageFactory(
+ new SettingsLeveldbStorage::Factory());
+ frontend_.reset(SettingsFrontend::Create(storage_factory_, profile_.get()));
+ }
+
ScopedTempDir temp_dir_;
scoped_ptr<MockProfile> profile_;
scoped_ptr<SettingsFrontend> frontend_;
+ // Owned by |frontend_|.
+ DelegatingSettingsStorageFactory* storage_factory_;
+
private:
MessageLoop message_loop_;
content::TestBrowserThread ui_thread_;
@@ -53,7 +63,7 @@ class SettingsFrontendTest : public testing::Test {
// alternating in each test.
// TODO(kalman): explicitly test the two interact correctly.
-TEST_F(SettingsFrontendTest, SettingsPreservedAcrossReconstruction) {
+TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) {
const std::string id = "ext";
profile_->GetMockExtensionService()->AddExtension(
id, Extension::TYPE_EXTENSION);
@@ -74,7 +84,7 @@ TEST_F(SettingsFrontendTest, SettingsPreservedAcrossReconstruction) {
EXPECT_FALSE(result.settings().empty());
}
- frontend_.reset(new SettingsFrontend(profile_.get()));
+ ResetFrontend();
storage = GetStorage(id, frontend_.get());
{
@@ -84,7 +94,7 @@ TEST_F(SettingsFrontendTest, SettingsPreservedAcrossReconstruction) {
}
}
-TEST_F(SettingsFrontendTest, SettingsClearedOnUninstall) {
+TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) {
const std::string id = "ext";
profile_->GetMockExtensionService()->AddExtension(
id, Extension::TYPE_PACKAGED_APP);
@@ -110,7 +120,7 @@ TEST_F(SettingsFrontendTest, SettingsClearedOnUninstall) {
}
}
-TEST_F(SettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) {
+TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) {
const std::string id = "ext";
profile_->GetMockExtensionService()->AddExtension(
id, Extension::TYPE_EXTENSION);
@@ -140,4 +150,39 @@ TEST_F(SettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) {
//EXPECT_FALSE(file_util::PathExists(temp_dir_.path()));
}
+TEST_F(ExtensionSettingsFrontendTest,
+ LeveldbCreationFailureFailsAllOperations) {
+ const std::string id = "ext";
+ profile_->GetMockExtensionService()->AddExtension(
+ id, Extension::TYPE_EXTENSION);
+
+ storage_factory_->Reset(new NullSettingsStorageFactory());
+
+ SettingsStorage* storage = GetStorage(id, frontend_.get());
+ ASSERT_TRUE(storage != NULL);
+
+ EXPECT_TRUE(storage->Get().HasError());
+ EXPECT_TRUE(storage->Clear().HasError());
+ {
+ StringValue bar("bar");
+ EXPECT_TRUE(storage->Set("foo", bar).HasError());
+ }
+ EXPECT_TRUE(storage->Remove("foo").HasError());
+
+ // For simplicity: just always fail those requests, even if the leveldb
+ // storage areas start working.
+ storage_factory_->Reset(new SettingsLeveldbStorage::Factory());
+
+ storage = GetStorage(id, frontend_.get());
+ ASSERT_TRUE(storage != NULL);
+
+ EXPECT_TRUE(storage->Get().HasError());
+ EXPECT_TRUE(storage->Clear().HasError());
+ {
+ StringValue bar("bar");
+ EXPECT_TRUE(storage->Set("foo", bar).HasError());
+ }
+ EXPECT_TRUE(storage->Remove("foo").HasError());
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698