OLD | NEW |
| (Empty) |
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 "chrome/browser/chromeos/stub_cros_settings_provider.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/values.h" | |
12 #include "chrome/browser/chromeos/cros_settings_names.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace chromeos { | |
16 | |
17 namespace { | |
18 | |
19 void Fail() { | |
20 // Should never be called. | |
21 FAIL(); | |
22 } | |
23 | |
24 } // namespace | |
25 | |
26 class StubCrosSettingsProviderTest : public testing::Test { | |
27 protected: | |
28 StubCrosSettingsProviderTest() | |
29 : provider_(new StubCrosSettingsProvider( | |
30 base::Bind(&StubCrosSettingsProviderTest::FireObservers, | |
31 base::Unretained(this)))) { | |
32 } | |
33 | |
34 virtual ~StubCrosSettingsProviderTest() { | |
35 } | |
36 | |
37 virtual void SetUp() OVERRIDE { | |
38 // Reset the observer notification count. | |
39 observer_count_.clear(); | |
40 } | |
41 | |
42 void AssertPref(const std::string& prefName, const Value* value) { | |
43 const Value* pref = provider_->Get(prefName); | |
44 ASSERT_TRUE(pref); | |
45 ASSERT_TRUE(pref->Equals(value)); | |
46 } | |
47 | |
48 void ExpectObservers(const std::string& prefName, int count) { | |
49 EXPECT_EQ(observer_count_[prefName], count); | |
50 } | |
51 | |
52 void FireObservers(const std::string& path) { | |
53 observer_count_[path]++; | |
54 } | |
55 | |
56 scoped_ptr<StubCrosSettingsProvider> provider_; | |
57 std::map<std::string, int> observer_count_; | |
58 }; | |
59 | |
60 TEST_F(StubCrosSettingsProviderTest, HandlesSettings) { | |
61 // HandlesSettings should return false for unknown settings. | |
62 ASSERT_TRUE(provider_->HandlesSetting(kDeviceOwner)); | |
63 ASSERT_FALSE(provider_->HandlesSetting("no.such.setting")); | |
64 } | |
65 | |
66 TEST_F(StubCrosSettingsProviderTest, Defaults) { | |
67 // Verify default values. | |
68 const base::FundamentalValue kTrueValue(true); | |
69 AssertPref(kAccountsPrefAllowGuest, &kTrueValue); | |
70 AssertPref(kAccountsPrefAllowNewUser, &kTrueValue); | |
71 AssertPref(kAccountsPrefShowUserNamesOnSignIn, &kTrueValue); | |
72 } | |
73 | |
74 TEST_F(StubCrosSettingsProviderTest, Set) { | |
75 // Setting value and reading it afterwards returns the same value. | |
76 base::StringValue owner_value("me@owner"); | |
77 provider_->Set(kDeviceOwner, owner_value); | |
78 AssertPref(kDeviceOwner, &owner_value); | |
79 ExpectObservers(kDeviceOwner, 1); | |
80 } | |
81 | |
82 TEST_F(StubCrosSettingsProviderTest, SetMissing) { | |
83 // Setting is missing initially but is added by |Set|. | |
84 base::StringValue pref_value("testing"); | |
85 ASSERT_FALSE(provider_->Get(kReleaseChannel)); | |
86 provider_->Set(kReleaseChannel, pref_value); | |
87 AssertPref(kReleaseChannel, &pref_value); | |
88 ExpectObservers(kReleaseChannel, 1); | |
89 } | |
90 | |
91 TEST_F(StubCrosSettingsProviderTest, PrepareTrustedValues) { | |
92 // Should return immediately without invoking the callback. | |
93 CrosSettingsProvider::TrustedStatus trusted = | |
94 provider_->PrepareTrustedValues(base::Bind(&Fail)); | |
95 EXPECT_EQ(CrosSettingsProvider::TRUSTED, trusted); | |
96 } | |
97 | |
98 } // namespace chromeos | |
OLD | NEW |