Index: chrome/browser/extensions/settings/testing_settings_storage.cc |
diff --git a/chrome/browser/extensions/settings/in_memory_settings_storage.cc b/chrome/browser/extensions/settings/testing_settings_storage.cc |
similarity index 60% |
rename from chrome/browser/extensions/settings/in_memory_settings_storage.cc |
rename to chrome/browser/extensions/settings/testing_settings_storage.cc |
index d017a692d598a9dbb6c4ca5967b862e081412d85..7b256ec2157095ae3b94d9066124c8cb1bad7dcf 100644 |
--- a/chrome/browser/extensions/settings/in_memory_settings_storage.cc |
+++ b/chrome/browser/extensions/settings/testing_settings_storage.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/extensions/settings/in_memory_settings_storage.h" |
+#include "chrome/browser/extensions/settings/testing_settings_storage.h" |
#include "base/logging.h" |
@@ -10,6 +10,16 @@ namespace extensions { |
namespace { |
+const char* kGenericErrorMessage = "TestingSettingsStorage configured to error"; |
+ |
+SettingsStorage::ReadResult ReadResultError() { |
+ return SettingsStorage::ReadResult(kGenericErrorMessage); |
+} |
+ |
+SettingsStorage::WriteResult WriteResultError() { |
+ return SettingsStorage::WriteResult(kGenericErrorMessage); |
+} |
+ |
std::vector<std::string> CreateVector(const std::string& string) { |
std::vector<std::string> strings; |
strings.push_back(string); |
@@ -18,13 +28,26 @@ std::vector<std::string> CreateVector(const std::string& string) { |
} // namespace |
-SettingsStorage::ReadResult InMemorySettingsStorage::Get( |
+TestingSettingsStorage::TestingSettingsStorage() |
+ : fail_all_requests_(false) {} |
+ |
+TestingSettingsStorage::~TestingSettingsStorage() {} |
+ |
+void TestingSettingsStorage::SetFailAllRequests(bool fail_all_requests) { |
+ fail_all_requests_ = fail_all_requests; |
+} |
+ |
+SettingsStorage::ReadResult TestingSettingsStorage::Get( |
const std::string& key) { |
return Get(CreateVector(key)); |
} |
-SettingsStorage::ReadResult InMemorySettingsStorage::Get( |
+SettingsStorage::ReadResult TestingSettingsStorage::Get( |
const std::vector<std::string>& keys) { |
+ if (fail_all_requests_) { |
+ return ReadResultError(); |
+ } |
+ |
DictionaryValue* settings = new DictionaryValue(); |
for (std::vector<std::string>::const_iterator it = keys.begin(); |
it != keys.end(); ++it) { |
@@ -36,21 +59,27 @@ SettingsStorage::ReadResult InMemorySettingsStorage::Get( |
return ReadResult(settings); |
} |
-SettingsStorage::ReadResult InMemorySettingsStorage::Get() { |
+SettingsStorage::ReadResult TestingSettingsStorage::Get() { |
+ if (fail_all_requests_) { |
+ return ReadResultError(); |
+ } |
return ReadResult(storage_.DeepCopy()); |
} |
-SettingsStorage::WriteResult InMemorySettingsStorage::Set( |
+SettingsStorage::WriteResult TestingSettingsStorage::Set( |
const std::string& key, const Value& value) { |
DictionaryValue settings; |
settings.SetWithoutPathExpansion(key, value.DeepCopy()); |
return Set(settings); |
} |
-SettingsStorage::WriteResult InMemorySettingsStorage::Set( |
+SettingsStorage::WriteResult TestingSettingsStorage::Set( |
const DictionaryValue& settings) { |
- scoped_ptr<SettingChangeList> changes( |
- new SettingChangeList()); |
+ if (fail_all_requests_) { |
+ return WriteResultError(); |
+ } |
+ |
+ scoped_ptr<SettingChangeList> changes(new SettingChangeList()); |
for (DictionaryValue::Iterator it(settings); it.HasNext(); it.Advance()) { |
Value* old_value = NULL; |
storage_.GetWithoutPathExpansion(it.key(), &old_value); |
@@ -66,13 +95,17 @@ SettingsStorage::WriteResult InMemorySettingsStorage::Set( |
return WriteResult(changes.release()); |
} |
-SettingsStorage::WriteResult InMemorySettingsStorage::Remove( |
+SettingsStorage::WriteResult TestingSettingsStorage::Remove( |
const std::string& key) { |
return Remove(CreateVector(key)); |
} |
-SettingsStorage::WriteResult InMemorySettingsStorage::Remove( |
+SettingsStorage::WriteResult TestingSettingsStorage::Remove( |
const std::vector<std::string>& keys) { |
+ if (fail_all_requests_) { |
+ return WriteResultError(); |
+ } |
+ |
scoped_ptr<SettingChangeList> changes( |
new SettingChangeList()); |
for (std::vector<std::string>::const_iterator it = keys.begin(); |
@@ -85,8 +118,11 @@ SettingsStorage::WriteResult InMemorySettingsStorage::Remove( |
return WriteResult(changes.release()); |
} |
-SettingsStorage::WriteResult |
-InMemorySettingsStorage::Clear() { |
+SettingsStorage::WriteResult TestingSettingsStorage::Clear() { |
+ if (fail_all_requests_) { |
+ return WriteResultError(); |
+ } |
+ |
std::vector<std::string> keys; |
for (DictionaryValue::Iterator it(storage_); it.HasNext(); it.Advance()) { |
keys.push_back(it.key()); |