Home | History | Annotate | Download | only in chromeos
      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://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   },
     43 
     44   /**
     45    * Register a mock dictionary handler.
     46    */
     47   preLoad: function() {
     48     this.makeAndRegisterMockHandler(
     49         ['getKioskAppSettings',
     50          'addKioskApp',
     51          'removeKioskApp',
     52          'enableKioskAutoLaunch',
     53          'disableKioskAutoLaunch'
     54         ]);
     55     this.mockHandler.stubs().getKioskAppSettings().
     56         will(callFunction(function() {
     57           extensions.KioskAppsOverlay.setSettings(this.settings_);
     58         }.bind(this)));
     59     this.mockHandler.stubs().addKioskApp(ANYTHING);
     60     this.mockHandler.stubs().removeKioskApp(ANYTHING);
     61     this.mockHandler.stubs().enableKioskAutoLaunch(ANYTHING);
     62     this.mockHandler.stubs().disableKioskAutoLaunch(ANYTHING);
     63   },
     64 
     65   setUp: function() {
     66     // Shows the kiosk apps management overlay.
     67     cr.dispatchSimpleEvent($('add-kiosk-app'), 'click');
     68   }
     69 };
     70 
     71 // Test opening kiosk app settings has correct location and app items have
     72 // correct label.
     73 TEST_F('KioskAppSettingsWebUITest', 'testOpenKioskAppSettings', function() {
     74   assertEquals(this.browsePreload, document.location.href);
     75 
     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'));
     82 });
     83 
     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');
     88 
     89   appIdInput.value = testAppId;
     90 
     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);
     95 });
     96 
     97 // Test the row delete button.
     98 TEST_F('KioskAppSettingsWebUITest', 'testRemoveKioskApp', function() {
     99   var appItem = $('kiosk-app-list').items[0];
    100   var appId = appItem.data.id;
    101 
    102   this.mockHandler.expects(once()).removeKioskApp([appId]);
    103   appItem.querySelector('.row-delete-button').click();
    104 });
    105 
    106 // Test enable/disable auto launch buttons.
    107 TEST_F('KioskAppSettingsWebUITest', 'testEnableDisableAutoLaunch', function() {
    108   var appItem = $('kiosk-app-list').items[0];
    109   var appId = appItem.data.id;
    110 
    111   var enableAutoLaunchCalled = false;
    112   this.mockHandler.expects(once()).enableKioskAutoLaunch([appId]).
    113       will(callFunction(function() {
    114         enableAutoLaunchCalled = true;
    115       }));
    116   appItem.querySelector('.enable-auto-launch-button').click();
    117   expectTrue(enableAutoLaunchCalled);
    118 
    119   var disableAutoLaunchCalled = false;
    120   this.mockHandler.expects(once()).disableKioskAutoLaunch([appId]).
    121       will(callFunction(function() {
    122         disableAutoLaunchCalled = true;
    123       }));
    124   appItem.querySelector('.disable-auto-launch-button').click();
    125   expectTrue(disableAutoLaunchCalled);
    126 });
    127 
    128 // Verify that updateApp updates app info.
    129 TEST_F('KioskAppSettingsWebUITest', 'testUpdateApp', function() {
    130   var appItems = $('kiosk-app-list').items;
    131   assertEquals(appItems[1].data.id, 'app_2');
    132   expectEquals(appItems[1].data.name, '');
    133   expectTrue(appItems[1].icon.classList.contains('spinner'));
    134   expectFalse(appItems[1].autoLaunch);
    135 
    136   // New data changes name, autoLaunch and isLoading.
    137   var newName = 'Name for App2';
    138   var newApp2 = {
    139     id: 'app_2',
    140     name: newName,
    141     iconURL: '',
    142     autoLaunch: true,
    143     isLoading: false,
    144   };
    145   extensions.KioskAppsOverlay.updateApp(newApp2);
    146 
    147   assertEquals('app_2', appItems[1].data.id);
    148   expectEquals(newName, appItems[1].data.name, newName);
    149   expectEquals(newName, appItems[1].name.textContent);
    150   expectFalse(appItems[1].icon.classList.contains('spinner'));
    151   expectTrue(appItems[1].autoLaunch);
    152 });
    153 
    154 // Verify that showError makes error banner visible.
    155 TEST_F('KioskAppSettingsWebUITest', 'testShowError', function() {
    156   extensions.KioskAppsOverlay.showError('A bad app');
    157   expectTrue($('kiosk-apps-error-banner').classList.contains('visible'));
    158 });
    159 
    160 // Verify that checking disable bailout checkbox brings up confirmation UI and
    161 // the check only remains when the confirmation UI is acknowledged.
    162 TEST_F('KioskAppSettingsWebUITest', 'testCheckDisableBailout', function() {
    163   var checkbox = $('kiosk-disable-bailout-shortcut');
    164   var confirmOverlay = $('kiosk-disable-bailout-confirm-overlay');
    165   expectFalse(confirmOverlay.classList.contains('showing'));
    166 
    167   // Un-checking the box does not trigger confirmation.
    168   checkbox.checked = false;
    169   cr.dispatchSimpleEvent(checkbox, 'change');
    170   expectFalse(confirmOverlay.classList.contains('showing'));
    171 
    172   // Checking the box trigger confirmation.
    173   checkbox.checked = true;
    174   cr.dispatchSimpleEvent(checkbox, 'change');
    175   expectTrue(confirmOverlay.classList.contains('showing'));
    176 
    177   // Confirm it and the check remains.
    178   cr.dispatchSimpleEvent($('kiosk-disable-bailout-confirm-button'), 'click');
    179   expectTrue(checkbox.checked);
    180   expectFalse(confirmOverlay.classList.contains('showing'));
    181 
    182   // And canceling resets the check.
    183   checkbox.checked = true;
    184   cr.dispatchSimpleEvent(checkbox, 'change');
    185   expectTrue(confirmOverlay.classList.contains('showing'));
    186   cr.dispatchSimpleEvent($('kiosk-disable-bailout-cancel-button'), 'click');
    187   expectFalse(checkbox.checked);
    188   expectFalse(confirmOverlay.classList.contains('showing'));
    189 });
    190