Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/stub_cros_settings_provider.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chrome/browser/chromeos/cros_settings_names.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const Value* kTrueValue = base::Value::CreateBooleanValue(true); | |
| 19 const Value* kFalseValue = base::Value::CreateBooleanValue(false); | |
| 20 | |
| 21 void Fail() { | |
| 22 // Should never be called. | |
| 23 FAIL(); | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 class StubCrosSettingsProviderTest : public testing::Test { | |
| 29 protected: | |
| 30 StubCrosSettingsProviderTest() | |
| 31 : provider_(new StubCrosSettingsProvider( | |
| 32 base::Bind(&StubCrosSettingsProviderTest::FireObservers, | |
| 33 base::Unretained(this)))) { | |
| 34 } | |
| 35 | |
| 36 virtual ~StubCrosSettingsProviderTest() { | |
| 37 } | |
| 38 | |
| 39 virtual void SetUp() OVERRIDE { | |
| 40 // Reset the observer notification count. | |
| 41 observer_count_.clear(); | |
| 42 } | |
| 43 | |
| 44 void AssertPref(const std::string& prefName, const Value* value) { | |
| 45 const Value* pref = provider_->Get(prefName); | |
| 46 ASSERT_TRUE(pref); | |
| 47 ASSERT_TRUE(pref->Equals(value)); | |
| 48 } | |
| 49 | |
| 50 void ExpectObservers(const std::string& prefName, int count) { | |
| 51 EXPECT_EQ(observer_count_[prefName], count); | |
| 52 } | |
| 53 | |
| 54 void FireObservers(const std::string& path) { | |
| 55 observer_count_[path]++; | |
| 56 } | |
| 57 | |
| 58 StubCrosSettingsProvider* provider_; | |
| 59 std::map<std::string, int> observer_count_; | |
| 60 }; | |
| 61 | |
| 62 TEST_F(StubCrosSettingsProviderTest, Defaults) { | |
| 63 // Verify default values. | |
| 64 AssertPref(kAccountsPrefAllowGuest, kTrueValue); | |
| 65 AssertPref(kAccountsPrefAllowNewUser, kTrueValue); | |
| 66 AssertPref(kAccountsPrefShowUserNamesOnSignIn, kTrueValue); | |
| 67 } | |
| 68 | |
| 69 TEST_F(StubCrosSettingsProviderTest, Set) { | |
| 70 // Setting value and reading it afterwards returns the same value. | |
| 71 base::StringValue owner_value("me@owner"); | |
| 72 provider_->Set(kDeviceOwner, owner_value); | |
| 73 AssertPref(kDeviceOwner, &owner_value); | |
| 74 ExpectObservers(kDeviceOwner, 1); | |
| 75 } | |
| 76 | |
| 77 TEST_F(StubCrosSettingsProviderTest, GetTrusted) { | |
| 78 // Should return immediately without invoking the callback. | |
| 79 bool trusted = provider_->GetTrusted(kDeviceOwner, base::Bind(&Fail)); | |
| 80 EXPECT_TRUE(trusted); | |
| 81 } | |
| 82 | |
|
pastarmovj
2011/12/13 13:41:07
Maybe one more test for Get would be good where yo
Ivan Korotkov
2011/12/13 14:46:16
Done.
| |
| 83 } // namespace chromeos | |
| OLD | NEW |