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