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/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "chrome/service/service_process_prefs.h" | 10 #include "chrome/service/service_process_prefs.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 class ServiceProcessPrefsTest : public testing::Test { | 14 class ServiceProcessPrefsTest : public testing::Test { |
15 protected: | 15 protected: |
16 void SetUp() override { | 16 void SetUp() override { |
17 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 17 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
18 | 18 |
19 prefs_.reset(new ServiceProcessPrefs( | 19 prefs_.reset(new ServiceProcessPrefs( |
20 temp_dir_.path().AppendASCII("service_process_prefs.txt"), | 20 temp_dir_.path().AppendASCII("service_process_prefs.txt"), |
21 message_loop_.task_runner().get())); | 21 message_loop_.task_runner().get())); |
22 } | 22 } |
23 | 23 |
24 void TearDown() override { prefs_.reset(); } | 24 void TearDown() override { prefs_.reset(); } |
25 | 25 |
26 // The path to temporary directory used to contain the test operations. | 26 // The path to temporary directory used to contain the test operations. |
27 base::ScopedTempDir temp_dir_; | 27 base::ScopedTempDir temp_dir_; |
28 // A message loop that we can use as the file thread message loop. | 28 // A message loop that we can use as the file thread message loop. |
29 base::MessageLoop message_loop_; | 29 base::MessageLoop message_loop_; |
30 scoped_ptr<ServiceProcessPrefs> prefs_; | 30 std::unique_ptr<ServiceProcessPrefs> prefs_; |
31 }; | 31 }; |
32 | 32 |
33 // Test ability to retrieve prefs | 33 // Test ability to retrieve prefs |
34 TEST_F(ServiceProcessPrefsTest, RetrievePrefs) { | 34 TEST_F(ServiceProcessPrefsTest, RetrievePrefs) { |
35 prefs_->SetBoolean("testb", true); | 35 prefs_->SetBoolean("testb", true); |
36 prefs_->SetString("tests", "testvalue"); | 36 prefs_->SetString("tests", "testvalue"); |
37 prefs_->WritePrefs(); | 37 prefs_->WritePrefs(); |
38 message_loop_.RunUntilIdle(); | 38 message_loop_.RunUntilIdle(); |
39 prefs_->SetBoolean("testb", false); // overwrite | 39 prefs_->SetBoolean("testb", false); // overwrite |
40 prefs_->SetString("tests", std::string()); // overwrite | 40 prefs_->SetString("tests", std::string()); // overwrite |
41 prefs_->ReadPrefs(); | 41 prefs_->ReadPrefs(); |
42 EXPECT_EQ(prefs_->GetBoolean("testb", false), true); | 42 EXPECT_EQ(prefs_->GetBoolean("testb", false), true); |
43 EXPECT_EQ(prefs_->GetString("tests", std::string()), "testvalue"); | 43 EXPECT_EQ(prefs_->GetString("tests", std::string()), "testvalue"); |
44 } | 44 } |
OLD | NEW |