Index: chrome/common/json_pref_store_unittest.cc |
diff --git a/chrome/common/json_pref_store_unittest.cc b/chrome/common/json_pref_store_unittest.cc |
index e7f34f520331b8fb37e80bd874a1874da1ae3da0..f27ab97218eaac990e3b0c2267fe4347cbb8106a 100644 |
--- a/chrome/common/json_pref_store_unittest.cc |
+++ b/chrome/common/json_pref_store_unittest.cc |
@@ -5,6 +5,7 @@ |
#include "base/file_util.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/scoped_temp_dir.h" |
#include "base/message_loop.h" |
#include "base/message_loop_proxy.h" |
#include "base/path_service.h" |
@@ -13,12 +14,27 @@ |
#include "base/threading/thread.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
-#include "base/memory/scoped_temp_dir.h" |
-#include "chrome/common/json_pref_store.h" |
#include "chrome/common/chrome_paths.h" |
+#include "chrome/common/json_pref_store.h" |
#include "chrome/common/pref_names.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+namespace { |
+ |
+class MockPrefStoreObserver : public PrefStore::Observer { |
+ public: |
+ MOCK_METHOD1(OnPrefValueChanged, void (const std::string&)); |
+ MOCK_METHOD1(OnInitializationCompleted, void (bool)); |
+}; |
+ |
+class MockReadErrorDelegate : public PersistentPrefStore::ReadErrorDelegate { |
+ public: |
+ MOCK_METHOD1(OnError, void(PersistentPrefStore::PrefReadError)); |
+}; |
+ |
+} // namespace |
+ |
class JsonPrefStoreTest : public testing::Test { |
protected: |
virtual void SetUp() { |
@@ -160,3 +176,24 @@ TEST_F(JsonPrefStoreTest, Basic) { |
EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file)); |
ASSERT_TRUE(file_util::Delete(output_file, false)); |
} |
+ |
+// Tests asynchronous reading of the file when there is no file. |
Mattias Nissler (ping if slow)
2011/05/04 23:33:08
Can you please also add a test case for the positi
altimofeev
2011/05/05 12:59:28
Done.
|
+TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { |
+ FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); |
+ ASSERT_FALSE(file_util::PathExists(bogus_input_file)); |
+ scoped_refptr<JsonPrefStore> pref_store = |
+ new JsonPrefStore(bogus_input_file, message_loop_proxy_.get()); |
+ MockPrefStoreObserver mock_observer; |
+ pref_store->AddObserver(&mock_observer); |
+ |
+ MockReadErrorDelegate *mock_error_delegate = new MockReadErrorDelegate; |
+ pref_store->ReadPrefsAsync(mock_error_delegate); |
+ |
+ EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1); |
+ EXPECT_CALL(*mock_error_delegate, |
+ OnError(PersistentPrefStore::PREF_READ_ERROR_NO_FILE)).Times(1); |
+ message_loop_.RunAllPending(); |
+ pref_store->RemoveObserver(&mock_observer); |
+ |
+ EXPECT_FALSE(pref_store->ReadOnly()); |
+} |