1 // Copyright 2013 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.
6 * TestFixture for kiosk app settings WebUI testing.
7 * @extends {testing.Test}
10 function KioskAppSettingsWebUITest() {}
12 KioskAppSettingsWebUITest
.prototype = {
13 __proto__
: testing
.Test
.prototype,
16 * Browse to the kiosk app settings page.
18 browsePreload
: 'chrome://extensions-frame/',
41 disableBailout
: false,
42 hasAutoLaunchApp
: false
46 * Register a mock dictionary handler.
49 this.makeAndRegisterMockHandler(
50 ['getKioskAppSettings',
53 'enableKioskAutoLaunch',
54 'disableKioskAutoLaunch'
56 this.mockHandler
.stubs().getKioskAppSettings().
57 will(callFunction(function() {
58 extensions
.KioskAppsOverlay
.setSettings(this.settings_
);
60 this.mockHandler
.stubs().addKioskApp(ANYTHING
);
61 this.mockHandler
.stubs().removeKioskApp(ANYTHING
);
62 this.mockHandler
.stubs().enableKioskAutoLaunch(ANYTHING
);
63 this.mockHandler
.stubs().disableKioskAutoLaunch(ANYTHING
);
67 // Shows the kiosk apps management overlay.
68 cr
.dispatchSimpleEvent($('add-kiosk-app'), 'click');
72 // Test opening kiosk app settings has correct location and app items have
74 TEST_F('KioskAppSettingsWebUITest', 'testOpenKioskAppSettings', function() {
75 assertEquals(this.browsePreload
, document
.location
.href
);
77 var appItems
= $('kiosk-app-list').items
;
78 assertEquals(this.settings_
.apps
.length
, appItems
.length
);
79 assertEquals(this.settings_
.apps
[0].name
, appItems
[0].name
.textContent
);
80 assertFalse(appItems
[0].icon
.classList
.contains('spinner'));
81 assertEquals(this.settings_
.apps
[1].id
, appItems
[1].name
.textContent
);
82 assertTrue(appItems
[1].icon
.classList
.contains('spinner'));
85 // Verify that enter key on 'kiosk-app-id-edit' adds an app.
86 TEST_F('KioskAppSettingsWebUITest', 'testAddKioskApp', function() {
87 var testAppId
= 'app_3';
88 var appIdInput
= $('kiosk-app-id-edit');
90 appIdInput
.value
= testAppId
;
92 this.mockHandler
.expects(once()).addKioskApp([testAppId
]);
93 var keypress
= document
.createEvent('KeyboardEvents');
94 keypress
.initKeyboardEvent('keypress', true, true, null, 'Enter', '');
95 appIdInput
.dispatchEvent(keypress
);
98 // Verify that the 'kiosk-app-add' button adds an app.
99 TEST_F('KioskAppSettingsWebUITest', 'testAddKioskAppByAddButton', function() {
100 var testAppId
= 'app_3';
101 $('kiosk-app-id-edit').value
= testAppId
;
103 this.mockHandler
.expects(once()).addKioskApp([testAppId
]);
104 cr
.dispatchSimpleEvent($('kiosk-app-add'), 'click');
107 // Verify that the 'done' button adds an app.
108 TEST_F('KioskAppSettingsWebUITest', 'testAddKioskAppByDoneButton', function() {
109 var testAppId
= 'app_3';
110 $('kiosk-app-id-edit').value
= testAppId
;
112 this.mockHandler
.expects(once()).addKioskApp([testAppId
]);
113 cr
.dispatchSimpleEvent($('kiosk-options-overlay-confirm'), 'click');
116 // Test the row delete button.
117 TEST_F('KioskAppSettingsWebUITest', 'testRemoveKioskApp', function() {
118 var appItem
= $('kiosk-app-list').items
[0];
119 var appId
= appItem
.data
.id
;
121 this.mockHandler
.expects(once()).removeKioskApp([appId
]);
122 appItem
.querySelector('.row-delete-button').click();
125 // Test enable/disable auto launch buttons.
126 TEST_F('KioskAppSettingsWebUITest', 'testEnableDisableAutoLaunch', function() {
127 var appItem
= $('kiosk-app-list').items
[0];
128 var appId
= appItem
.data
.id
;
130 var enableAutoLaunchCalled
= false;
131 this.mockHandler
.expects(once()).enableKioskAutoLaunch([appId
]).
132 will(callFunction(function() {
133 enableAutoLaunchCalled
= true;
135 appItem
.querySelector('.enable-auto-launch-button').click();
136 expectTrue(enableAutoLaunchCalled
);
138 var disableAutoLaunchCalled
= false;
139 this.mockHandler
.expects(once()).disableKioskAutoLaunch([appId
]).
140 will(callFunction(function() {
141 disableAutoLaunchCalled
= true;
143 appItem
.querySelector('.disable-auto-launch-button').click();
144 expectTrue(disableAutoLaunchCalled
);
147 // Verify that updateApp updates app info.
148 TEST_F('KioskAppSettingsWebUITest', 'testUpdateApp', function() {
149 var appItems
= $('kiosk-app-list').items
;
150 assertEquals(appItems
[1].data
.id
, 'app_2');
151 expectEquals(appItems
[1].data
.name
, '');
152 expectTrue(appItems
[1].icon
.classList
.contains('spinner'));
153 expectFalse(appItems
[1].autoLaunch
);
155 // New data changes name, autoLaunch and isLoading.
156 var newName
= 'Name for App2';
164 extensions
.KioskAppsOverlay
.updateApp(newApp2
);
166 assertEquals('app_2', appItems
[1].data
.id
);
167 expectEquals(newName
, appItems
[1].data
.name
, newName
);
168 expectEquals(newName
, appItems
[1].name
.textContent
);
169 expectFalse(appItems
[1].icon
.classList
.contains('spinner'));
170 expectTrue(appItems
[1].autoLaunch
);
173 // Verify that showError makes error banner visible.
174 TEST_F('KioskAppSettingsWebUITest', 'testShowError', function() {
175 extensions
.KioskAppsOverlay
.showError('A bad app');
176 expectTrue($('kiosk-apps-error-banner').classList
.contains('visible'));
179 // Verify that checking disable bailout checkbox brings up confirmation UI and
180 // the check only remains when the confirmation UI is acknowledged.
181 TEST_F('KioskAppSettingsWebUITest', 'testCheckDisableBailout', function() {
182 var checkbox
= $('kiosk-disable-bailout-shortcut');
183 var confirmOverlay
= $('kiosk-disable-bailout-confirm-overlay');
184 expectFalse(confirmOverlay
.classList
.contains('showing'));
186 // Un-checking the box does not trigger confirmation.
187 checkbox
.checked
= false;
188 cr
.dispatchSimpleEvent(checkbox
, 'change');
189 expectFalse(confirmOverlay
.classList
.contains('showing'));
191 // Checking the box trigger confirmation.
192 checkbox
.checked
= true;
193 cr
.dispatchSimpleEvent(checkbox
, 'change');
194 expectTrue(confirmOverlay
.classList
.contains('showing'));
196 // Confirm it and the check remains.
197 cr
.dispatchSimpleEvent($('kiosk-disable-bailout-confirm-button'), 'click');
198 expectTrue(checkbox
.checked
);
199 expectFalse(confirmOverlay
.classList
.contains('showing'));
201 // And canceling resets the check.
202 checkbox
.checked
= true;
203 cr
.dispatchSimpleEvent(checkbox
, 'change');
204 expectTrue(confirmOverlay
.classList
.contains('showing'));
205 cr
.dispatchSimpleEvent($('kiosk-disable-bailout-cancel-button'), 'click');
206 expectFalse(checkbox
.checked
);
207 expectFalse(confirmOverlay
.classList
.contains('showing'));
210 // Verify that disable bailout checkbox is hidden without kiosk auto launch.
211 TEST_F('KioskAppSettingsWebUITest', 'testHideDisableBailout', function() {
212 var checkbox
= $('kiosk-disable-bailout-shortcut');
213 var kioskEnabledSettings
= {
215 autoLaunchEnabled
: true
217 extensions
.KioskAppsOverlay
.enableKiosk(kioskEnabledSettings
);
218 expectFalse(checkbox
.parentNode
.hidden
);
220 kioskEnabledSettings
.autoLaunchEnabled
= false;
221 extensions
.KioskAppsOverlay
.enableKiosk(kioskEnabledSettings
);
222 expectTrue(checkbox
.parentNode
.hidden
);
225 // Verify that disable bailout checkbox is disabled with no auto launch app.
226 TEST_F('KioskAppSettingsWebUITest', 'testAllowDisableBailout', function() {
227 var checkbox
= $('kiosk-disable-bailout-shortcut');
229 this.settings_
.hasAutoLaunchApp
= false;
230 extensions
.KioskAppsOverlay
.setSettings(this.settings_
);
231 expectTrue(checkbox
.disabled
);
233 this.settings_
.hasAutoLaunchApp
= true;
234 extensions
.KioskAppsOverlay
.setSettings(this.settings_
);
235 expectFalse(checkbox
.disabled
);