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..424847a0f7d1ae8c555b4953695a9a8d1677ec9d 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,11 +14,21 @@ |
#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 "content/browser/browser_thread.h" |
Mattias Nissler (ping if slow)
2011/04/26 09:04:26
Are we allowed to include content/browser from chr
altimofeev
2011/04/27 10:32:08
Good point. If I understand correctly, you suggest
|
+#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
Mattias Nissler (ping if slow)
2011/04/26 09:04:26
newline
altimofeev
2011/04/27 10:32:08
Done.
|
+namespace { |
+ |
+class MockPrefStoreObserver: public PrefStore::Observer { |
+ public: |
Mattias Nissler (ping if slow)
2011/04/26 09:04:26
indentation
altimofeev
2011/04/27 10:32:08
Done.
|
+ MOCK_METHOD1(OnPrefValueChanged, void (const std::string&)); |
+ MOCK_METHOD0(OnInitializationCompleted, void ()); |
+}; |
+ |
+} // namespace |
class JsonPrefStoreTest : public testing::Test { |
protected: |
@@ -160,3 +171,34 @@ 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 case when there is no file. |
Mattias Nissler (ping if slow)
2011/04/26 09:04:26
remove "case"
altimofeev
2011/04/27 10:32:08
Done.
|
+TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { |
+ BrowserThread ui_thread(BrowserThread::UI, &message_loop_); |
+ BrowserThread file_thread(BrowserThread::FILE, &message_loop_); |
+ |
+ 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); |
+ |
+ PersistentPrefStore::PrefReadError error; |
+ bool is_fatal; |
+ pref_store->GetErrors(&error, &is_fatal); |
+ EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, error); |
+ EXPECT_FALSE(is_fatal); |
+ |
+ pref_store->ReadPrefsAsync(); |
+ |
+ EXPECT_CALL(mock_observer, OnInitializationCompleted()).Times(1); |
+ message_loop_.RunAllPending(); |
+ pref_store->RemoveObserver(&mock_observer); |
+ |
+ pref_store->GetErrors(&error, &is_fatal); |
+ |
+ EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, error); |
+ EXPECT_FALSE(is_fatal); |
+ EXPECT_FALSE(pref_store->ReadOnly()); |
+} |