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"
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"
20 const int kFudgeInt
= 100;
26 class KioskModeSettingsTest
: public testing::Test
{
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
);
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();
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)));
59 virtual void TearDown() OVERRIDE
{
60 KioskModeSettings::Get()->set_initialized(false);
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(
98 KioskModeSettings::kMaxIdleLogoutTimeout
+ kFudgeInt
);
100 EXPECT_EQ(KioskModeSettings::Get()->GetIdleLogoutTimeout(),
101 base::TimeDelta::FromMilliseconds(
102 KioskModeSettings::kMaxIdleLogoutTimeout
));
104 // Check if we go under min.
105 cros_settings
->SetInteger(
107 KioskModeSettings::kMinIdleLogoutTimeout
- kFudgeInt
);
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(
116 KioskModeSettings::kMaxIdleLogoutTimeout
- kFudgeInt
);
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
);
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
);
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
);
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(),
160 EXPECT_LT(KioskModeSettings::Get()->GetIdleLogoutTimeout(),
162 EXPECT_LT(KioskModeSettings::Get()->GetIdleLogoutWarningDuration(),
166 } // namespace chromeos