OLD | NEW |
| (Empty) |
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. | |
4 | |
5 /** | |
6 * TestFixture for kiosk app settings WebUI testing. | |
7 * @extends {testing.Test} | |
8 * @constructor | |
9 **/ | |
10 function KioskAppSettingsWebUITest() {} | |
11 | |
12 KioskAppSettingsWebUITest.prototype = { | |
13 __proto__: testing.Test.prototype, | |
14 | |
15 /** | |
16 * Browse to the kiosk app settings page. | |
17 */ | |
18 browsePreload: 'chrome://settings-frame/kioskAppsOverlay', | |
19 | |
20 /** | |
21 * Mock apps data. | |
22 */ | |
23 apps_: [ | |
24 { | |
25 id: 'app_1', | |
26 name: 'App1 Name', | |
27 iconURL: '', | |
28 autoLaunch: false, | |
29 isLoading: false, | |
30 }, | |
31 { | |
32 id: 'app_2', | |
33 name: '', // no name | |
34 iconURL: '', | |
35 autoLaunch: false, | |
36 isLoading: true, | |
37 }, | |
38 ], | |
39 | |
40 /** | |
41 * Register a mock dictionary handler. | |
42 */ | |
43 preLoad: function() { | |
44 this.makeAndRegisterMockHandler( | |
45 ['getKioskApps', | |
46 'addKioskApp', | |
47 'removeKioskApp', | |
48 'enableKioskAutoLaunch', | |
49 'disableKioskAutoLaunch' | |
50 ]); | |
51 this.mockHandler.stubs().getKioskApps(). | |
52 will(callFunction(function() { | |
53 KioskAppsOverlay.setApps(this.apps_); | |
54 }.bind(this))); | |
55 this.mockHandler.stubs().addKioskApp(ANYTHING); | |
56 this.mockHandler.stubs().removeKioskApp(ANYTHING); | |
57 this.mockHandler.stubs().enableKioskAutoLaunch(ANYTHING); | |
58 this.mockHandler.stubs().disableKioskAutoLaunch(ANYTHING); | |
59 } | |
60 }; | |
61 | |
62 // Test opening kiosk app settings has correct location and app items have | |
63 // correct label. | |
64 TEST_F('KioskAppSettingsWebUITest', 'testOpenKioskAppSettings', function() { | |
65 assertEquals(this.browsePreload, document.location.href); | |
66 | |
67 var appItems = $('kiosk-app-list').items; | |
68 assertEquals(this.apps_.length, appItems.length); | |
69 assertEquals(this.apps_[0].name, appItems[0].name.textContent); | |
70 assertFalse(appItems[0].icon.classList.contains('spinner')); | |
71 assertEquals(this.apps_[1].id, appItems[1].name.textContent); | |
72 assertTrue(appItems[1].icon.classList.contains('spinner')); | |
73 }); | |
74 | |
75 // Verify that enter key on 'kiosk-app-id-edit' adds an app. | |
76 TEST_F('KioskAppSettingsWebUITest', 'testAddKioskApp', function() { | |
77 var testAppId = 'app_3'; | |
78 var appIdInput = $('kiosk-app-id-edit'); | |
79 | |
80 appIdInput.value = testAppId; | |
81 | |
82 this.mockHandler.expects(once()).addKioskApp([testAppId]); | |
83 var keypress = document.createEvent("KeyboardEvents"); | |
84 keypress.initKeyboardEvent('keypress', true, true, null, 'Enter', ''); | |
85 appIdInput.dispatchEvent(keypress); | |
86 }); | |
87 | |
88 // Test the row delete button. | |
89 TEST_F('KioskAppSettingsWebUITest', 'testRemoveKioskApp', function() { | |
90 var appItem = $('kiosk-app-list').items[0]; | |
91 var appId = appItem.data.id; | |
92 | |
93 this.mockHandler.expects(once()).removeKioskApp([appId]); | |
94 appItem.querySelector('.row-delete-button').click(); | |
95 }); | |
96 | |
97 // Test enable/disable auto launch buttons. | |
98 TEST_F('KioskAppSettingsWebUITest', 'testEnableDisableAutoLaunch', function() { | |
99 var appItem = $('kiosk-app-list').items[0]; | |
100 var appId = appItem.data.id; | |
101 | |
102 var enableAutoLaunchCalled = false; | |
103 this.mockHandler.expects(once()).enableKioskAutoLaunch([appId]). | |
104 will(callFunction(function() { | |
105 enableAutoLaunchCalled = true; | |
106 })); | |
107 appItem.querySelector('.enable-auto-launch-button').click(); | |
108 expectTrue(enableAutoLaunchCalled); | |
109 | |
110 var disableAutoLaunchCalled = false; | |
111 this.mockHandler.expects(once()).disableKioskAutoLaunch([appId]). | |
112 will(callFunction(function() { | |
113 disableAutoLaunchCalled = true; | |
114 })); | |
115 appItem.querySelector('.disable-auto-launch-button').click(); | |
116 expectTrue(disableAutoLaunchCalled); | |
117 }); | |
118 | |
119 // Verify that updateApp updates app info. | |
120 TEST_F('KioskAppSettingsWebUITest', 'testUpdateApp', function() { | |
121 var appItems = $('kiosk-app-list').items; | |
122 assertEquals(appItems[1].data.id, 'app_2'); | |
123 expectEquals(appItems[1].data.name, ''); | |
124 expectTrue(appItems[1].icon.classList.contains('spinner')); | |
125 expectFalse(appItems[1].autoLaunch); | |
126 | |
127 // New data changes name, autoLaunch and isLoading. | |
128 var newName = 'Name for App2'; | |
129 var newApp2 = { | |
130 id: 'app_2', | |
131 name: newName, | |
132 iconURL: '', | |
133 autoLaunch: true, | |
134 isLoading: false, | |
135 }; | |
136 KioskAppsOverlay.updateApp(newApp2); | |
137 | |
138 assertEquals('app_2', appItems[1].data.id); | |
139 expectEquals(newName, appItems[1].data.name, newName); | |
140 expectEquals(newName, appItems[1].name.textContent); | |
141 expectFalse(appItems[1].icon.classList.contains('spinner')); | |
142 expectTrue(appItems[1].autoLaunch); | |
143 }); | |
144 | |
145 // Verify that showError makes error banner visible. | |
146 TEST_F('KioskAppSettingsWebUITest', 'testShowError', function() { | |
147 KioskAppsOverlay.showError('A bad app'); | |
148 expectTrue($('kiosk-apps-error-banner').classList.contains('visible')); | |
149 }); | |
150 | |
151 // Verify that checking disable bailout checkbox brings up confirmation UI and | |
152 // the check only remains when the confirmation UI is acknowledged. | |
153 TEST_F('KioskAppSettingsWebUITest', 'testCheckDisableBailout', function() { | |
154 var checkbox = $('kiosk-disable-bailout-shortcut'); | |
155 var confirmOverlay = KioskDisableBailoutConfirm.getInstance(); | |
156 expectFalse(confirmOverlay.visible); | |
157 | |
158 // Un-checking the box does not trigger confirmation. | |
159 checkbox.checked = false; | |
160 cr.dispatchSimpleEvent(checkbox, 'change'); | |
161 expectFalse(confirmOverlay.visible); | |
162 | |
163 // Checking the box trigger confirmation. | |
164 checkbox.checked = true; | |
165 cr.dispatchSimpleEvent(checkbox, 'change'); | |
166 expectTrue(confirmOverlay.visible); | |
167 | |
168 // Confirm it and the check remains. | |
169 cr.dispatchSimpleEvent($('kiosk-disable-bailout-confirm-button'), 'click'); | |
170 expectTrue(checkbox.checked); | |
171 expectFalse(confirmOverlay.visible); | |
172 | |
173 // And canceling resets the check. | |
174 checkbox.checked = true; | |
175 cr.dispatchSimpleEvent(checkbox, 'change'); | |
176 expectTrue(confirmOverlay.visible); | |
177 cr.dispatchSimpleEvent($('kiosk-disable-bailout-cancel-button'), 'click'); | |
178 expectFalse(checkbox.checked); | |
179 expectFalse(confirmOverlay.visible); | |
180 }); | |
OLD | NEW |