Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / settings / stub_cros_settings_provider_unittest.cc
blobca5ccd1d7675e60341398092ff2c308c01727639
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"
7 #include <string>
9 #include "base/bind.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"
15 namespace chromeos {
17 namespace {
19 void Fail() {
20 // Should never be called.
21 FAIL();
24 } // namespace
26 class StubCrosSettingsProviderTest : public testing::Test {
27 protected:
28 StubCrosSettingsProviderTest()
29 : provider_(new StubCrosSettingsProvider(
30 base::Bind(&StubCrosSettingsProviderTest::FireObservers,
31 base::Unretained(this)))) {
34 ~StubCrosSettingsProviderTest() override {}
36 void SetUp() override {
37 // Reset the observer notification count.
38 observer_count_.clear();
41 void AssertPref(const std::string& prefName, const base::Value* value) {
42 const base::Value* pref = provider_->Get(prefName);
43 ASSERT_TRUE(pref);
44 ASSERT_TRUE(pref->Equals(value));
47 void ExpectObservers(const std::string& prefName, int count) {
48 EXPECT_EQ(observer_count_[prefName], count);
51 void FireObservers(const std::string& path) {
52 observer_count_[path]++;
55 scoped_ptr<StubCrosSettingsProvider> provider_;
56 std::map<std::string, int> observer_count_;
59 TEST_F(StubCrosSettingsProviderTest, HandlesSettings) {
60 // HandlesSettings should return false for unknown settings.
61 ASSERT_TRUE(provider_->HandlesSetting(kDeviceOwner));
62 ASSERT_FALSE(provider_->HandlesSetting("no.such.setting"));
65 TEST_F(StubCrosSettingsProviderTest, Defaults) {
66 // Verify default values.
67 const base::FundamentalValue kTrueValue(true);
68 AssertPref(kAccountsPrefAllowGuest, &kTrueValue);
69 AssertPref(kAccountsPrefAllowNewUser, &kTrueValue);
70 AssertPref(kAccountsPrefShowUserNamesOnSignIn, &kTrueValue);
71 AssertPref(kAccountsPrefSupervisedUsersEnabled, &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