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.
5 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h"
12 #include "chromeos/settings/cros_settings_names.h"
13 #include "testing/gtest/include/gtest/gtest.h"
20 // Should never be called.
26 class StubCrosSettingsProviderTest
: public testing::Test
{
28 StubCrosSettingsProviderTest()
29 : provider_(new StubCrosSettingsProvider(
30 base::Bind(&StubCrosSettingsProviderTest::FireObservers
,
31 base::Unretained(this)))) {
34 virtual ~StubCrosSettingsProviderTest() {
37 virtual void SetUp() OVERRIDE
{
38 // Reset the observer notification count.
39 observer_count_
.clear();
42 void AssertPref(const std::string
& prefName
, const base::Value
* value
) {
43 const base::Value
* pref
= provider_
->Get(prefName
);
45 ASSERT_TRUE(pref
->Equals(value
));
48 void ExpectObservers(const std::string
& prefName
, int count
) {
49 EXPECT_EQ(observer_count_
[prefName
], count
);
52 void FireObservers(const std::string
& path
) {
53 observer_count_
[path
]++;
56 scoped_ptr
<StubCrosSettingsProvider
> provider_
;
57 std::map
<std::string
, int> observer_count_
;
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"));
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
);
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);
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);
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
);
98 } // namespace chromeos