| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "chrome/service/service_process_prefs.h" | 11 #include "chrome/service/service_process_prefs.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 class ServiceProcessPrefsTest : public testing::Test { | 15 class ServiceProcessPrefsTest : public testing::Test { |
| 15 protected: | 16 protected: |
| 16 virtual void SetUp() { | 17 virtual void SetUp() OVERRIDE { |
| 17 message_loop_proxy_ = base::MessageLoopProxy::current(); | 18 blocking_pool_ = new base::SequencedWorkerPool(1, "TestBlocking"); |
| 18 | 19 |
| 19 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 20 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 20 | 21 |
| 21 prefs_.reset(new ServiceProcessPrefs( | 22 prefs_.reset(new ServiceProcessPrefs( |
| 22 temp_dir_.path().AppendASCII("service_process_prefs.txt"), | 23 temp_dir_.path().AppendASCII("service_process_prefs.txt"), |
| 23 message_loop_proxy_.get())); | 24 blocking_pool_.get())); |
| 25 } |
| 26 |
| 27 virtual void TearDown() OVERRIDE { |
| 28 prefs_.reset(NULL); |
| 29 blocking_pool_->Shutdown(); |
| 24 } | 30 } |
| 25 | 31 |
| 26 // The path to temporary directory used to contain the test operations. | 32 // The path to temporary directory used to contain the test operations. |
| 27 ScopedTempDir temp_dir_; | 33 ScopedTempDir temp_dir_; |
| 28 // A message loop that we can use as the file thread message loop. | 34 // A message loop that we need for timers. |
| 29 MessageLoop message_loop_; | 35 MessageLoop message_loop_; |
| 30 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 36 // A blocking pool that we can use for file operations. |
| 37 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; |
| 31 scoped_ptr<ServiceProcessPrefs> prefs_; | 38 scoped_ptr<ServiceProcessPrefs> prefs_; |
| 32 }; | 39 }; |
| 33 | 40 |
| 34 // Test ability to retrieve prefs | 41 // Test ability to retrieve prefs |
| 35 TEST_F(ServiceProcessPrefsTest, RetrievePrefs) { | 42 TEST_F(ServiceProcessPrefsTest, RetrievePrefs) { |
| 36 prefs_->SetBoolean("testb", true); | 43 prefs_->SetBoolean("testb", true); |
| 37 prefs_->SetString("tests", "testvalue"); | 44 prefs_->SetString("tests", "testvalue"); |
| 38 prefs_->WritePrefs(); | 45 prefs_->WritePrefs(); |
| 39 MessageLoop::current()->RunAllPending(); | 46 blocking_pool_->FlushForTesting(); |
| 40 prefs_->SetBoolean("testb", false); // overwrite | 47 prefs_->SetBoolean("testb", false); // overwrite |
| 41 prefs_->SetString("tests", ""); // overwrite | 48 prefs_->SetString("tests", ""); // overwrite |
| 42 prefs_->ReadPrefs(); | 49 prefs_->ReadPrefs(); |
| 43 EXPECT_EQ(prefs_->GetBoolean("testb", false), true); | 50 EXPECT_EQ(prefs_->GetBoolean("testb", false), true); |
| 44 EXPECT_EQ(prefs_->GetString("tests", ""), "testvalue"); | 51 EXPECT_EQ(prefs_->GetString("tests", ""), "testvalue"); |
| 45 } | 52 } |
| 46 | 53 |
| OLD | NEW |