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/',
45 * Register a mock dictionary handler.
48 this.makeAndRegisterMockHandler(
49 ['getKioskAppSettings',
52 'enableKioskAutoLaunch',
53 'disableKioskAutoLaunch'
55 this.mockHandler
.stubs().getKioskAppSettings().
56 will(callFunction(function() {
57 extensions
.KioskAppsOverlay
.setSettings(this.settings_
);
59 this.mockHandler
.stubs().addKioskApp(ANYTHING
);
60 this.mockHandler
.stubs().removeKioskApp(ANYTHING
);
61 this.mockHandler
.stubs().enableKioskAutoLaunch(ANYTHING
);
62 this.mockHandler
.stubs().disableKioskAutoLaunch(ANYTHING
);
66 // Shows the kiosk apps management overlay.
67 cr
.dispatchSimpleEvent($('add-kiosk-app'), 'click');
71 // Test opening kiosk app settings has correct location and app items have
73 TEST_F('KioskAppSettingsWebUITest', 'testOpenKioskAppSettings', function() {
74 assertEquals(this.browsePreload
, document
.location
.href
);
76 var appItems
= $('kiosk-app-list').items
;
77 assertEquals(this.settings_
.apps
.length
, appItems
.length
);
78 assertEquals(this.settings_
.apps
[0].name
, appItems
[0].name
.textContent
);
79 assertFalse(appItems
[0].icon
.classList
.contains('spinner'));
80 assertEquals(this.settings_
.apps
[1].id
, appItems
[1].name
.textContent
);
81 assertTrue(appItems
[1].icon
.classList
.contains('spinner'));
84 // Verify that enter key on 'kiosk-app-id-edit' adds an app.
85 TEST_F('KioskAppSettingsWebUITest', 'testAddKioskApp', function() {
86 var testAppId
= 'app_3';
87 var appIdInput
= $('kiosk-app-id-edit');
89 appIdInput
.value
= testAppId
;
91 this.mockHandler
.expects(once()).addKioskApp([testAppId
]);
92 var keypress
= document
.createEvent("KeyboardEvents");
93 keypress
.initKeyboardEvent('keypress', true, true, null, 'Enter', '');
94 appIdInput
.dispatchEvent(keypress
);
97 // Verify that the 'kiosk-app-add' button adds an app.
98 TEST_F('KioskAppSettingsWebUITest', 'testAddKioskAppByAddButton', function() {
99 var testAppId
= 'app_3';
100 $('kiosk-app-id-edit').value
= testAppId
;
102 this.mockHandler
.expects(once()).addKioskApp([testAppId
]);
103 cr
.dispatchSimpleEvent($('kiosk-app-add'), 'click');
106 // Verify that the 'done' button adds an app.
107 TEST_F('KioskAppSettingsWebUITest', 'testAddKioskAppByDoneButton', function() {
108 var testAppId
= 'app_3';
109 $('kiosk-app-id-edit').value
= testAppId
;
111 this.mockHandler
.expects(once()).addKioskApp([testAppId
]);
112 cr
.dispatchSimpleEvent($('kiosk-options-overlay-confirm'), 'click');
115 // Test the row delete button.
116 TEST_F('KioskAppSettingsWebUITest', 'testRemoveKioskApp', function() {
117 var appItem
= $('kiosk-app-list').items
[0];
118 var appId
= appItem
.data
.id
;
120 this.mockHandler
.expects(once()).removeKioskApp([appId
]);
121 appItem
.querySelector('.row-delete-button').click();
124 // Test enable/disable auto launch buttons.
125 TEST_F('KioskAppSettingsWebUITest', 'testEnableDisableAutoLaunch', function() {
126 var appItem
= $('kiosk-app-list').items
[0];
127 var appId
= appItem
.data
.id
;
129 var enableAutoLaunchCalled
= false;
130 this.mockHandler
.expects(once()).enableKioskAutoLaunch([appId
]).
131 will(callFunction(function() {
132 enableAutoLaunchCalled
= true;
134 appItem
.querySelector('.enable-auto-launch-button').click();
135 expectTrue(enableAutoLaunchCalled
);
137 var disableAutoLaunchCalled
= false;
138 this.mockHandler
.expects(once()).disableKioskAutoLaunch([appId
]).
139 will(callFunction(function() {
140 disableAutoLaunchCalled
= true;
142 appItem
.querySelector('.disable-auto-launch-button').click();
143 expectTrue(disableAutoLaunchCalled
);
146 // Verify that updateApp updates app info.
147 TEST_F('KioskAppSettingsWebUITest', 'testUpdateApp', function() {
148 var appItems
= $('kiosk-app-list').items
;
149 assertEquals(appItems
[1].data
.id
, 'app_2');
150 expectEquals(appItems
[1].data
.name
, '');
151 expectTrue(appItems
[1].icon
.classList
.contains('spinner'));
152 expectFalse(appItems
[1].autoLaunch
);
154 // New data changes name, autoLaunch and isLoading.
155 var newName
= 'Name for App2';
163 extensions
.KioskAppsOverlay
.updateApp(newApp2
);
165 assertEquals('app_2', appItems
[1].data
.id
);
166 expectEquals(newName
, appItems
[1].data
.name
, newName
);
167 expectEquals(newName
, appItems
[1].name
.textContent
);
168 expectFalse(appItems
[1].icon
.classList
.contains('spinner'));
169 expectTrue(appItems
[1].autoLaunch
);
172 // Verify that showError makes error banner visible.
173 TEST_F('KioskAppSettingsWebUITest', 'testShowError', function() {
174 extensions
.KioskAppsOverlay
.showError('A bad app');
175 expectTrue($('kiosk-apps-error-banner').classList
.contains('visible'));
178 // Verify that checking disable bailout checkbox brings up confirmation UI and
179 // the check only remains when the confirmation UI is acknowledged.
180 TEST_F('KioskAppSettingsWebUITest', 'testCheckDisableBailout', function() {
181 var checkbox
= $('kiosk-disable-bailout-shortcut');
182 var confirmOverlay
= $('kiosk-disable-bailout-confirm-overlay');
183 expectFalse(confirmOverlay
.classList
.contains('showing'));
185 // Un-checking the box does not trigger confirmation.
186 checkbox
.checked
= false;
187 cr
.dispatchSimpleEvent(checkbox
, 'change');
188 expectFalse(confirmOverlay
.classList
.contains('showing'));
190 // Checking the box trigger confirmation.
191 checkbox
.checked
= true;
192 cr
.dispatchSimpleEvent(checkbox
, 'change');
193 expectTrue(confirmOverlay
.classList
.contains('showing'));
195 // Confirm it and the check remains.
196 cr
.dispatchSimpleEvent($('kiosk-disable-bailout-confirm-button'), 'click');
197 expectTrue(checkbox
.checked
);
198 expectFalse(confirmOverlay
.classList
.contains('showing'));
200 // And canceling resets the check.
201 checkbox
.checked
= true;
202 cr
.dispatchSimpleEvent(checkbox
, 'change');
203 expectTrue(confirmOverlay
.classList
.contains('showing'));
204 cr
.dispatchSimpleEvent($('kiosk-disable-bailout-cancel-button'), 'click');
205 expectFalse(checkbox
.checked
);
206 expectFalse(confirmOverlay
.classList
.contains('showing'));