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 */ 10function KioskAppSettingsWebUITest() {} 11 12KioskAppSettingsWebUITest.prototype = { 13 __proto__: testing.Test.prototype, 14 15 /** 16 * Browse to the kiosk app settings page. 17 */ 18 browsePreload: 'chrome://extensions-frame/', 19 20 /** 21 * Mock settings data. 22 * @private 23 */ 24 settings_: { 25 apps: [ 26 { 27 id: 'app_1', 28 name: 'App1 Name', 29 iconURL: '', 30 autoLaunch: false, 31 isLoading: false, 32 }, 33 { 34 id: 'app_2', 35 name: '', // no name 36 iconURL: '', 37 autoLaunch: false, 38 isLoading: true, 39 }, 40 ], 41 disableBailout: false, 42 hasAutoLaunchApp: false 43 }, 44 45 /** 46 * Register a mock dictionary handler. 47 */ 48 preLoad: function() { 49 this.makeAndRegisterMockHandler( 50 ['getKioskAppSettings', 51 'addKioskApp', 52 'removeKioskApp', 53 'enableKioskAutoLaunch', 54 'disableKioskAutoLaunch' 55 ]); 56 this.mockHandler.stubs().getKioskAppSettings(). 57 will(callFunction(function() { 58 extensions.KioskAppsOverlay.setSettings(this.settings_); 59 }.bind(this))); 60 this.mockHandler.stubs().addKioskApp(ANYTHING); 61 this.mockHandler.stubs().removeKioskApp(ANYTHING); 62 this.mockHandler.stubs().enableKioskAutoLaunch(ANYTHING); 63 this.mockHandler.stubs().disableKioskAutoLaunch(ANYTHING); 64 }, 65 66 setUp: function() { 67 // Shows the kiosk apps management overlay. 68 cr.dispatchSimpleEvent($('add-kiosk-app'), 'click'); 69 } 70}; 71 72// Test opening kiosk app settings has correct location and app items have 73// correct label. 74TEST_F('KioskAppSettingsWebUITest', 'testOpenKioskAppSettings', function() { 75 assertEquals(this.browsePreload, document.location.href); 76 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')); 83}); 84 85// Verify that enter key on 'kiosk-app-id-edit' adds an app. 86TEST_F('KioskAppSettingsWebUITest', 'testAddKioskApp', function() { 87 var testAppId = 'app_3'; 88 var appIdInput = $('kiosk-app-id-edit'); 89 90 appIdInput.value = testAppId; 91 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); 96}); 97 98// Verify that the 'kiosk-app-add' button adds an app. 99TEST_F('KioskAppSettingsWebUITest', 'testAddKioskAppByAddButton', function() { 100 var testAppId = 'app_3'; 101 $('kiosk-app-id-edit').value = testAppId; 102 103 this.mockHandler.expects(once()).addKioskApp([testAppId]); 104 cr.dispatchSimpleEvent($('kiosk-app-add'), 'click'); 105}); 106 107// Verify that the 'done' button adds an app. 108TEST_F('KioskAppSettingsWebUITest', 'testAddKioskAppByDoneButton', function() { 109 var testAppId = 'app_3'; 110 $('kiosk-app-id-edit').value = testAppId; 111 112 this.mockHandler.expects(once()).addKioskApp([testAppId]); 113 cr.dispatchSimpleEvent($('kiosk-options-overlay-confirm'), 'click'); 114}); 115 116// Test the row delete button. 117TEST_F('KioskAppSettingsWebUITest', 'testRemoveKioskApp', function() { 118 var appItem = $('kiosk-app-list').items[0]; 119 var appId = appItem.data.id; 120 121 this.mockHandler.expects(once()).removeKioskApp([appId]); 122 appItem.querySelector('.row-delete-button').click(); 123}); 124 125// Test enable/disable auto launch buttons. 126TEST_F('KioskAppSettingsWebUITest', 'testEnableDisableAutoLaunch', function() { 127 var appItem = $('kiosk-app-list').items[0]; 128 var appId = appItem.data.id; 129 130 var enableAutoLaunchCalled = false; 131 this.mockHandler.expects(once()).enableKioskAutoLaunch([appId]). 132 will(callFunction(function() { 133 enableAutoLaunchCalled = true; 134 })); 135 appItem.querySelector('.enable-auto-launch-button').click(); 136 expectTrue(enableAutoLaunchCalled); 137 138 var disableAutoLaunchCalled = false; 139 this.mockHandler.expects(once()).disableKioskAutoLaunch([appId]). 140 will(callFunction(function() { 141 disableAutoLaunchCalled = true; 142 })); 143 appItem.querySelector('.disable-auto-launch-button').click(); 144 expectTrue(disableAutoLaunchCalled); 145}); 146 147// Verify that updateApp updates app info. 148TEST_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); 154 155 // New data changes name, autoLaunch and isLoading. 156 var newName = 'Name for App2'; 157 var newApp2 = { 158 id: 'app_2', 159 name: newName, 160 iconURL: '', 161 autoLaunch: true, 162 isLoading: false, 163 }; 164 extensions.KioskAppsOverlay.updateApp(newApp2); 165 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); 171}); 172 173// Verify that showError makes error banner visible. 174TEST_F('KioskAppSettingsWebUITest', 'testShowError', function() { 175 extensions.KioskAppsOverlay.showError('A bad app'); 176 expectTrue($('kiosk-apps-error-banner').classList.contains('visible')); 177}); 178 179// Verify that checking disable bailout checkbox brings up confirmation UI and 180// the check only remains when the confirmation UI is acknowledged. 181TEST_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')); 185 186 // Un-checking the box does not trigger confirmation. 187 checkbox.checked = false; 188 cr.dispatchSimpleEvent(checkbox, 'change'); 189 expectFalse(confirmOverlay.classList.contains('showing')); 190 191 // Checking the box trigger confirmation. 192 checkbox.checked = true; 193 cr.dispatchSimpleEvent(checkbox, 'change'); 194 expectTrue(confirmOverlay.classList.contains('showing')); 195 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')); 200 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')); 208}); 209 210// Verify that disable bailout checkbox is hidden without kiosk auto launch. 211TEST_F('KioskAppSettingsWebUITest', 'testHideDisableBailout', function() { 212 var checkbox = $('kiosk-disable-bailout-shortcut'); 213 var kioskEnabledSettings = { 214 kioskEnabled: true, 215 autoLaunchEnabled: true 216 }; 217 extensions.KioskAppsOverlay.enableKiosk(kioskEnabledSettings); 218 expectFalse(checkbox.parentNode.hidden); 219 220 kioskEnabledSettings.autoLaunchEnabled = false; 221 extensions.KioskAppsOverlay.enableKiosk(kioskEnabledSettings); 222 expectTrue(checkbox.parentNode.hidden); 223}); 224 225// Verify that disable bailout checkbox is disabled with no auto launch app. 226TEST_F('KioskAppSettingsWebUITest', 'testAllowDisableBailout', function() { 227 var checkbox = $('kiosk-disable-bailout-shortcut'); 228 229 this.settings_.hasAutoLaunchApp = false; 230 extensions.KioskAppsOverlay.setSettings(this.settings_); 231 expectTrue(checkbox.disabled); 232 233 this.settings_.hasAutoLaunchApp = true; 234 extensions.KioskAppsOverlay.setSettings(this.settings_); 235 expectFalse(checkbox.disabled); 236}); 237