Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / kiosk_mode / kiosk_mode_settings_unittest.cc
blob587aacf402b8d749815ca99ddcac45e8617c2809
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/kiosk_mode/kiosk_mode_settings.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/values.h"
11 #include "chrome/browser/chromeos/settings/cros_settings.h"
12 #include "chrome/browser/chromeos/settings/device_settings_service.h"
13 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
14 #include "chromeos/settings/cros_settings_names.h"
15 #include "content/public/test/test_browser_thread.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace {
20 const int kFudgeInt = 100;
24 namespace chromeos {
26 class KioskModeSettingsTest : public testing::Test {
27 protected:
28 KioskModeSettingsTest()
29 : ui_thread_(content::BrowserThread::UI, &message_loop_),
30 file_thread_(content::BrowserThread::FILE, &message_loop_) {
31 CrosSettings* cros_settings = CrosSettings::Get();
33 // Remove the real DeviceSettingsProvider and replace it with a stub.
34 device_settings_provider_ =
35 cros_settings->GetProvider(chromeos::kReportDeviceVersionInfo);
36 EXPECT_TRUE(device_settings_provider_ != NULL);
37 EXPECT_TRUE(
38 cros_settings->RemoveSettingsProvider(device_settings_provider_));
39 cros_settings->AddSettingsProvider(&stub_settings_provider_);
42 virtual ~KioskModeSettingsTest() {
43 // Restore the real DeviceSettingsProvider.
44 CrosSettings* cros_settings = CrosSettings::Get();
45 EXPECT_TRUE(
46 cros_settings->RemoveSettingsProvider(&stub_settings_provider_));
47 cros_settings->AddSettingsProvider(device_settings_provider_);
50 virtual void SetUp() OVERRIDE {
51 if (!KioskModeSettings::Get()->is_initialized()) {
52 KioskModeSettings::Get()->Initialize(
53 base::Bind(&KioskModeSettingsTest::SetUp,
54 base::Unretained(this)));
55 return;
59 virtual void TearDown() OVERRIDE {
60 KioskModeSettings::Get()->set_initialized(false);
63 void ReInitialize() {
64 KioskModeSettings::Get()->set_initialized(false);
65 KioskModeSettings::Get()->Initialize(base::Bind(&base::DoNothing));
68 void DisableKioskModeSettings() {
69 KioskModeSettings::Get()->set_initialized(false);
72 base::MessageLoopForUI message_loop_;
73 content::TestBrowserThread ui_thread_;
74 content::TestBrowserThread file_thread_;
76 ScopedTestDeviceSettingsService test_device_settings_service_;
77 ScopedTestCrosSettings test_cros_settings_;
79 CrosSettingsProvider* device_settings_provider_;
80 StubCrosSettingsProvider stub_settings_provider_;
83 TEST_F(KioskModeSettingsTest, DisabledByDefault) {
84 EXPECT_FALSE(KioskModeSettings::Get()->IsKioskModeEnabled());
87 TEST_F(KioskModeSettingsTest, InstanceAvailable) {
88 EXPECT_TRUE(KioskModeSettings::Get() != NULL);
89 EXPECT_TRUE(KioskModeSettings::Get()->is_initialized());
92 TEST_F(KioskModeSettingsTest, CheckLogoutTimeoutBounds) {
93 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get();
95 // Check if we go over max.
96 cros_settings->SetInteger(
97 kIdleLogoutTimeout,
98 KioskModeSettings::kMaxIdleLogoutTimeout + kFudgeInt);
99 ReInitialize();
100 EXPECT_EQ(KioskModeSettings::Get()->GetIdleLogoutTimeout(),
101 base::TimeDelta::FromMilliseconds(
102 KioskModeSettings::kMaxIdleLogoutTimeout));
104 // Check if we go under min.
105 cros_settings->SetInteger(
106 kIdleLogoutTimeout,
107 KioskModeSettings::kMinIdleLogoutTimeout - kFudgeInt);
108 ReInitialize();
109 EXPECT_EQ(KioskModeSettings::Get()->GetIdleLogoutTimeout(),
110 base::TimeDelta::FromMilliseconds(
111 KioskModeSettings::kMinIdleLogoutTimeout));
113 // Check if we are between max and min.
114 cros_settings->SetInteger(
115 kIdleLogoutTimeout,
116 KioskModeSettings::kMaxIdleLogoutTimeout - kFudgeInt);
117 ReInitialize();
118 EXPECT_EQ(KioskModeSettings::Get()->GetIdleLogoutTimeout(),
119 base::TimeDelta::FromMilliseconds(
120 KioskModeSettings::kMaxIdleLogoutTimeout - kFudgeInt));
123 TEST_F(KioskModeSettingsTest, CheckLogoutWarningDurationBounds) {
124 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get();
126 // Check if we go over max.
127 cros_settings->SetInteger(
128 kIdleLogoutWarningDuration,
129 KioskModeSettings::kMaxIdleLogoutWarningDuration + kFudgeInt);
130 ReInitialize();
131 EXPECT_EQ(KioskModeSettings::Get()->GetIdleLogoutWarningDuration(),
132 base::TimeDelta::FromMilliseconds(
133 KioskModeSettings::kMaxIdleLogoutWarningDuration));
135 // Check if we go under min.
136 cros_settings->SetInteger(
137 kIdleLogoutWarningDuration,
138 KioskModeSettings::kMinIdleLogoutWarningDuration - kFudgeInt);
139 ReInitialize();
140 EXPECT_EQ(KioskModeSettings::Get()->GetIdleLogoutWarningDuration(),
141 base::TimeDelta::FromMilliseconds(
142 KioskModeSettings::kMinIdleLogoutWarningDuration));
144 // Check if we are between max and min.
145 cros_settings->SetInteger(
146 kIdleLogoutWarningDuration,
147 KioskModeSettings::kMaxIdleLogoutWarningDuration - kFudgeInt);
148 ReInitialize();
149 EXPECT_EQ(KioskModeSettings::Get()->GetIdleLogoutWarningDuration(),
150 base::TimeDelta::FromMilliseconds(
151 KioskModeSettings::kMaxIdleLogoutWarningDuration - kFudgeInt));
154 TEST_F(KioskModeSettingsTest, UnitializedValues) {
155 DisableKioskModeSettings();
157 // Time delta initializes to '0' microseconds.
158 EXPECT_LT(KioskModeSettings::Get()->GetScreensaverTimeout(),
159 base::TimeDelta());
160 EXPECT_LT(KioskModeSettings::Get()->GetIdleLogoutTimeout(),
161 base::TimeDelta());
162 EXPECT_LT(KioskModeSettings::Get()->GetIdleLogoutWarningDuration(),
163 base::TimeDelta());
166 } // namespace chromeos