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

Unified Diff: chrome/common/json_pref_store_unittest.cc

Issue 11027070: Moved JsonPrefStore to use SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months 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/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 5b5a5f3328bcb11a73eb43f333a9f563d4bb10b7..8ed94c4b525741ffe27d54618c86b82ded242129 100644
--- a/chrome/common/json_pref_store_unittest.cc
+++ b/chrome/common/json_pref_store_unittest.cc
@@ -5,12 +5,11 @@
#include "base/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop.h"
-#include "base/message_loop_proxy.h"
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
+#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -38,7 +37,7 @@ class MockReadErrorDelegate : public PersistentPrefStore::ReadErrorDelegate {
class JsonPrefStoreTest : public testing::Test {
protected:
virtual void SetUp() {
- message_loop_proxy_ = base::MessageLoopProxy::current();
+ blocking_pool_ = new base::SequencedWorkerPool(1, "TestBlocking");
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
@@ -51,9 +50,8 @@ class JsonPrefStoreTest : public testing::Test {
ScopedTempDir temp_dir_;
// The path to the directory where the test data is stored.
FilePath data_dir_;
- // A message loop that we can use as the file thread message loop.
- MessageLoop message_loop_;
- scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
+ // A blocking pool that we can use for file operations.
+ scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
};
// Test fallback behavior for a nonexistent file.
@@ -61,7 +59,7 @@ TEST_F(JsonPrefStoreTest, NonExistentFile) {
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());
+ JsonPrefStore::Create(bogus_input_file, blocking_pool_.get());
EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE,
pref_store->ReadPrefs());
EXPECT_FALSE(pref_store->ReadOnly());
@@ -73,7 +71,7 @@ TEST_F(JsonPrefStoreTest, InvalidFile) {
FilePath invalid_file = temp_dir_.path().AppendASCII("invalid.json");
ASSERT_TRUE(file_util::CopyFile(invalid_file_original, invalid_file));
scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(invalid_file, message_loop_proxy_.get());
+ JsonPrefStore::Create(invalid_file, blocking_pool_.get());
EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE,
pref_store->ReadPrefs());
EXPECT_FALSE(pref_store->ReadOnly());
@@ -166,7 +164,7 @@ TEST_F(JsonPrefStoreTest, Basic) {
FilePath input_file = temp_dir_.path().AppendASCII("write.json");
ASSERT_TRUE(file_util::PathExists(input_file));
scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(input_file, message_loop_proxy_.get());
+ JsonPrefStore::Create(input_file, blocking_pool_.get());
ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
ASSERT_FALSE(pref_store->ReadOnly());
@@ -193,7 +191,7 @@ TEST_F(JsonPrefStoreTest, BasicAsync) {
FilePath input_file = temp_dir_.path().AppendASCII("write.json");
ASSERT_TRUE(file_util::PathExists(input_file));
scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(input_file, message_loop_proxy_.get());
+ JsonPrefStore::Create(input_file, blocking_pool_.get());
MockPrefStoreObserver mock_observer;
pref_store->AddObserver(&mock_observer);
@@ -204,7 +202,7 @@ TEST_F(JsonPrefStoreTest, BasicAsync) {
EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1);
EXPECT_CALL(*mock_error_delegate,
OnError(PersistentPrefStore::PREF_READ_ERROR_NONE)).Times(0);
- message_loop_.RunAllPending();
+ blocking_pool_->FlushForTesting();
pref_store->RemoveObserver(&mock_observer);
ASSERT_FALSE(pref_store->ReadOnly());
@@ -229,7 +227,7 @@ 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());
+ JsonPrefStore::Create(bogus_input_file, blocking_pool_.get());
MockPrefStoreObserver mock_observer;
pref_store->AddObserver(&mock_observer);
@@ -239,7 +237,7 @@ TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) {
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();
+ blocking_pool_->Shutdown();
pref_store->RemoveObserver(&mock_observer);
EXPECT_FALSE(pref_store->ReadOnly());
@@ -255,7 +253,7 @@ TEST_F(JsonPrefStoreTest, NeedsEmptyValue) {
// Test that the persistent value can be loaded.
ASSERT_TRUE(file_util::PathExists(pref_file));
scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(pref_file, message_loop_proxy_.get());
+ JsonPrefStore::Create(pref_file, blocking_pool_.get());
ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
ASSERT_FALSE(pref_store->ReadOnly());

Powered by Google App Engine
This is Rietveld 408576698