| OLD | NEW | 
|     1 // Copyright 2016 The Chromium Authors. All rights reserved. |     1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
|     2 // Use of this source code is governed by a BSD-style license that can be |     2 // Use of this source code is governed by a BSD-style license that can be | 
|     3 // found in the LICENSE file. |     3 // found in the LICENSE file. | 
|     4  |     4  | 
|     5 cr.define('device_page_tests', function() { |     5 cr.define('device_page_tests', function() { | 
|     6   /** @enum {string} */ |     6   /** @enum {string} */ | 
|     7   var TestNames = { |     7   var TestNames = { | 
|     8     DevicePage: 'device page', |     8     DevicePage: 'device page', | 
|     9     Display: 'display', |     9     Display: 'display', | 
|    10     Keyboard: 'keyboard', |    10     Keyboard: 'keyboard', | 
|    11     Pointers: 'pointers', |    11     Pointers: 'pointers', | 
|    12     Power: 'power', |    12     Power: 'power', | 
|    13     Stylus: 'stylus', |    13     Stylus: 'stylus', | 
|    14   }; |    14   }; | 
|    15  |    15  | 
|    16   /** |    16   /** | 
|    17    * @constructor |    17    * @constructor | 
|    18    * @implements {settings.DevicePageBrowserProxy} |    18    * @implements {settings.DevicePageBrowserProxy} | 
|    19    */ |    19    */ | 
|    20   function TestDevicePageBrowserProxy() { |    20   function TestDevicePageBrowserProxy() { | 
|    21     this.keyboardShortcutsOverlayShown_ = 0; |    21     this.keyboardShortcutsOverlayShown_ = 0; | 
|    22     this.updatePowerStatusCalled_ = 0; |    22     this.updatePowerStatusCalled_ = 0; | 
 |    23     this.requestPowerManagementSettingsCalled_ = 0; | 
|    23     this.onNoteTakingAppsUpdated_ = null; |    24     this.onNoteTakingAppsUpdated_ = null; | 
|    24     this.requestNoteTakingApps_ = 0; |    25     this.requestNoteTakingApps_ = 0; | 
|    25     this.setPreferredNoteTakingApp_ = ''; |    26     this.setPreferredNoteTakingApp_ = ''; | 
|    26   } |    27   } | 
|    27  |    28  | 
|    28   TestDevicePageBrowserProxy.prototype = { |    29   TestDevicePageBrowserProxy.prototype = { | 
|    29     /** override */ |    30     /** override */ | 
|    30     initializePointers: function() { |    31     initializePointers: function() { | 
|    31       // Enable mouse and touchpad. |    32       // Enable mouse and touchpad. | 
|    32       cr.webUIListenerCallback('has-mouse-changed', true); |    33       cr.webUIListenerCallback('has-mouse-changed', true); | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|    59     updatePowerStatus: function() { |    60     updatePowerStatus: function() { | 
|    60       this.updatePowerStatusCalled_++; |    61       this.updatePowerStatusCalled_++; | 
|    61     }, |    62     }, | 
|    62  |    63  | 
|    63     /** @override */ |    64     /** @override */ | 
|    64     setPowerSource: function(powerSourceId) { |    65     setPowerSource: function(powerSourceId) { | 
|    65       this.powerSourceId_ = powerSourceId; |    66       this.powerSourceId_ = powerSourceId; | 
|    66     }, |    67     }, | 
|    67  |    68  | 
|    68     /** @override */ |    69     /** @override */ | 
 |    70     requestPowerManagementSettings: function() { | 
 |    71       this.requestPowerManagementSettingsCalled_++; | 
 |    72     }, | 
 |    73  | 
 |    74     /** @override */ | 
 |    75     setIdleBehavior: function(behavior) { | 
 |    76       this.idleBehavior_ = behavior; | 
 |    77     }, | 
 |    78  | 
 |    79     /** @override */ | 
 |    80     setLidClosedBehavior: function(behavior) { | 
 |    81       this.lidClosedBehavior_ = behavior; | 
 |    82     }, | 
 |    83  | 
 |    84     /** @override */ | 
|    69     setNoteTakingAppsUpdatedCallback: function(callback) { |    85     setNoteTakingAppsUpdatedCallback: function(callback) { | 
|    70       this.onNoteTakingAppsUpdated_ = callback; |    86       this.onNoteTakingAppsUpdated_ = callback; | 
|    71     }, |    87     }, | 
|    72  |    88  | 
|    73     /** @override */ |    89     /** @override */ | 
|    74     requestNoteTakingApps: function() { |    90     requestNoteTakingApps: function() { | 
|    75       this.requestNoteTakingApps_++; |    91       this.requestNoteTakingApps_++; | 
|    76     }, |    92     }, | 
|    77  |    93  | 
|    78     /** @override */ |    94     /** @override */ | 
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   235             'neon-animation-finish', resolve); |   251             'neon-animation-finish', resolve); | 
|   236         MockInteractions.tap(row); |   252         MockInteractions.tap(row); | 
|   237       }).then(function() { |   253       }).then(function() { | 
|   238         assertEquals(expectedRoute, settings.getCurrentRoute()); |   254         assertEquals(expectedRoute, settings.getCurrentRoute()); | 
|   239         var page = devicePage.$$('settings-' + subpage); |   255         var page = devicePage.$$('settings-' + subpage); | 
|   240         return assert(page); |   256         return assert(page); | 
|   241       }); |   257       }); | 
|   242     }; |   258     }; | 
|   243  |   259  | 
|   244     /** |   260     /** | 
 |   261      * @param {settings.IdleBehavior} idleBehavior | 
 |   262      * @param {boolean} idleControlled | 
 |   263      * @param {settings.LidClosedBehavior} lidClosedBehavior | 
 |   264      * @param {boolean} lidClosedControlled | 
 |   265      * @param {boolean} hasLid | 
 |   266      */ | 
 |   267     function sendPowerManagementSettings(idleBehavior, idleControlled, | 
 |   268                                          lidClosedBehavior, lidClosedControlled, | 
 |   269                                          hasLid) { | 
 |   270       cr.webUIListenerCallback( | 
 |   271           'power-management-settings-changed', | 
 |   272           { | 
 |   273             idleBehavior: idleBehavior, | 
 |   274             idleControlled: idleControlled, | 
 |   275             lidClosedBehavior: lidClosedBehavior, | 
 |   276             lidClosedControlled: lidClosedControlled, | 
 |   277             hasLid: hasLid, | 
 |   278           }); | 
 |   279       Polymer.dom.flush(); | 
 |   280     }; | 
 |   281  | 
 |   282     /** | 
 |   283      * @param {!HTMLElement} select | 
 |   284      * @param {!value} string | 
 |   285      */ | 
 |   286     function selectValue(select, value) { | 
 |   287       select.value = value; | 
 |   288       select.dispatchEvent(new CustomEvent('change')); | 
 |   289       Polymer.dom.flush(); | 
 |   290     } | 
 |   291  | 
 |   292     /** | 
|   245      * @param {!HTMLElement} pointersPage |   293      * @param {!HTMLElement} pointersPage | 
|   246      * @param {boolean} expected |   294      * @param {boolean} expected | 
|   247      */ |   295      */ | 
|   248     function expectNaturalScrollValue(pointersPage, expected) { |   296     function expectNaturalScrollValue(pointersPage, expected) { | 
|   249       var naturalScrollOff = |   297       var naturalScrollOff = | 
|   250           pointersPage.$$('paper-radio-button[name="false"]'); |   298           pointersPage.$$('paper-radio-button[name="false"]'); | 
|   251       var naturalScrollOn = |   299       var naturalScrollOn = | 
|   252           pointersPage.$$('paper-radio-button[name="true"]'); |   300           pointersPage.$$('paper-radio-button[name="true"]'); | 
|   253       assertTrue(!!naturalScrollOff); |   301       assertTrue(!!naturalScrollOff); | 
|   254       assertTrue(!!naturalScrollOn); |   302       assertTrue(!!naturalScrollOn); | 
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   586        */ |   634        */ | 
|   587       function setPowerSources(sources, powerSourceId, isLowPowerCharger) { |   635       function setPowerSources(sources, powerSourceId, isLowPowerCharger) { | 
|   588         var sourcesCopy = sources.map(function(source) { |   636         var sourcesCopy = sources.map(function(source) { | 
|   589           return Object.assign({}, source); |   637           return Object.assign({}, source); | 
|   590         }); |   638         }); | 
|   591         cr.webUIListenerCallback('power-sources-changed', |   639         cr.webUIListenerCallback('power-sources-changed', | 
|   592             sourcesCopy, powerSourceId, isLowPowerCharger); |   640             sourcesCopy, powerSourceId, isLowPowerCharger); | 
|   593       } |   641       } | 
|   594  |   642  | 
|   595       suite('no power settings', function() { |   643       suite('no power settings', function() { | 
 |   644         suiteSetup(function() { | 
 |   645           // Never show power settings. | 
 |   646           loadTimeData.overrideValues({ | 
 |   647             enablePowerSettings: false, | 
 |   648           }); | 
 |   649         }); | 
 |   650  | 
|   596         test('power row hidden', function() { |   651         test('power row hidden', function() { | 
|   597           assertEquals(null, devicePage.$$('#powerRow')); |   652           assertEquals(null, devicePage.$$('#powerRow')); | 
|   598           assertEquals(0, |   653           assertEquals(0, | 
|   599               settings.DevicePageBrowserProxyImpl.getInstance() |   654               settings.DevicePageBrowserProxyImpl.getInstance() | 
|   600               .updatePowerStatusCalled_); |   655               .updatePowerStatusCalled_); | 
|   601         }); |   656         }); | 
|   602       }); |   657       }); | 
|   603  |   658  | 
|   604       suite('power settings', function() { |   659       suite('power settings', function() { | 
|   605         var powerPage; |   660         var powerPage; | 
|   606         var powerSourceRow; |   661         var powerSourceRow; | 
|   607         var powerSourceWrapper; |   662         var powerSourceWrapper; | 
|   608         var powerSourceSelect; |   663         var powerSourceSelect; | 
 |   664         var idleSelect; | 
 |   665         var lidClosedSelect; | 
|   609  |   666  | 
|   610         suiteSetup(function() { |   667         suiteSetup(function() { | 
|   611           // Always show power settings. |   668           // Always show power settings. | 
|   612           loadTimeData.overrideValues({ |   669           loadTimeData.overrideValues({ | 
|   613             enablePowerSettings: true, |   670             enablePowerSettings: true, | 
|   614           }); |   671           }); | 
|   615         }); |   672         }); | 
|   616  |   673  | 
|   617         setup(function() { |   674         setup(function() { | 
|   618           return showAndGetDeviceSubpage('power', settings.Route.POWER) |   675           return showAndGetDeviceSubpage('power', settings.Route.POWER) | 
|   619               .then(function(page) { |   676               .then(function(page) { | 
|   620                 powerPage = page; |   677                 powerPage = page; | 
|   621                 powerSourceRow = assert(powerPage.$$('#powerSourceRow')); |   678                 powerSourceRow = assert(powerPage.$$('#powerSourceRow')); | 
|   622                 powerSourceWrapper = |   679                 powerSourceWrapper = | 
|   623                     assert(powerSourceRow.querySelector('.md-select-wrapper')); |   680                     assert(powerSourceRow.querySelector('.md-select-wrapper')); | 
|   624                 powerSourceSelect = assert(powerPage.$$('#powerSource')); |   681                 powerSourceSelect = assert(powerPage.$$('#powerSource')); | 
|   625                 assertEquals( |   682                 assertEquals( | 
|   626                     1, |   683                     1, | 
|   627                     settings.DevicePageBrowserProxyImpl.getInstance() |   684                     settings.DevicePageBrowserProxyImpl.getInstance() | 
|   628                         .updatePowerStatusCalled_); |   685                         .updatePowerStatusCalled_); | 
 |   686  | 
 |   687                 idleSelect = assert(powerPage.$$('#idleSelect')); | 
 |   688                 lidClosedSelect = assert(powerPage.$$('#lidClosedSelect')); | 
 |   689  | 
 |   690                 assertEquals( | 
 |   691                     1, | 
 |   692                     settings.DevicePageBrowserProxyImpl.getInstance() | 
 |   693                     .requestPowerManagementSettingsCalled_); | 
 |   694                 sendPowerManagementSettings( | 
 |   695                     settings.IdleBehavior.DISPLAY_OFF_SLEEP, | 
 |   696                     false /* idleControlled */, | 
 |   697                     settings.LidClosedBehavior.SUSPEND, | 
 |   698                     false /* lidClosedControlled */, true /* hasLid */); | 
|   629               }); |   699               }); | 
|   630         }); |   700         }); | 
|   631  |   701  | 
|   632         test('power sources', function() { |   702         test('power sources', function() { | 
|   633           var batteryStatus = { |   703           var batteryStatus = { | 
|   634             charging: false, |   704             charging: false, | 
|   635             calculating: false, |   705             calculating: false, | 
|   636             percent: 50, |   706             percent: 50, | 
|   637             statusText: '5 hours left', |   707             statusText: '5 hours left', | 
|   638           }; |   708           }; | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   686           // Attach a dual-role USB device. |   756           // Attach a dual-role USB device. | 
|   687           var powerSource = { |   757           var powerSource = { | 
|   688             id: '3', |   758             id: '3', | 
|   689             type: settings.PowerDeviceType.DUAL_ROLE_USB, |   759             type: settings.PowerDeviceType.DUAL_ROLE_USB, | 
|   690             description: 'USB-C device', |   760             description: 'USB-C device', | 
|   691           }; |   761           }; | 
|   692           setPowerSources([powerSource], '', false); |   762           setPowerSources([powerSource], '', false); | 
|   693           Polymer.dom.flush(); |   763           Polymer.dom.flush(); | 
|   694  |   764  | 
|   695           // Select the device. |   765           // Select the device. | 
|   696           powerSourceSelect.value = powerSourceSelect.children[1].value; |   766           selectValue(powerSourceSelect, powerSourceSelect.children[1].value); | 
|   697           powerSourceSelect.dispatchEvent(new CustomEvent('change')); |  | 
|   698           Polymer.dom.flush(); |  | 
|   699           expectEquals( |   767           expectEquals( | 
|   700               powerSource.id, |   768               powerSource.id, | 
|   701               settings.DevicePageBrowserProxyImpl.getInstance().powerSourceId_); |   769               settings.DevicePageBrowserProxyImpl.getInstance().powerSourceId_); | 
|   702         }); |   770         }); | 
 |   771  | 
 |   772         test('set idle behavior', function() { | 
 |   773           selectValue(idleSelect, settings.IdleBehavior.DISPLAY_ON); | 
 |   774           expectEquals( | 
 |   775               settings.IdleBehavior.DISPLAY_ON, | 
 |   776               settings.DevicePageBrowserProxyImpl.getInstance().idleBehavior_); | 
 |   777  | 
 |   778           selectValue(idleSelect, settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE); | 
 |   779           expectEquals( | 
 |   780               settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE, | 
 |   781               settings.DevicePageBrowserProxyImpl.getInstance().idleBehavior_); | 
 |   782         }); | 
 |   783  | 
 |   784         test('set lid behavior', function() { | 
 |   785           selectValue(lidClosedSelect, settings.LidClosedBehavior.DO_NOTHING); | 
 |   786           expectEquals( | 
 |   787               settings.LidClosedBehavior.DO_NOTHING, | 
 |   788               settings.DevicePageBrowserProxyImpl.getInstance() | 
 |   789                   .lidClosedBehavior_); | 
 |   790  | 
 |   791           selectValue(lidClosedSelect, settings.LidClosedBehavior.SUSPEND); | 
 |   792           expectEquals( | 
 |   793               settings.LidClosedBehavior.SUSPEND, | 
 |   794               settings.DevicePageBrowserProxyImpl.getInstance() | 
 |   795                   .lidClosedBehavior_); | 
 |   796         }); | 
 |   797  | 
 |   798         test('display idle and lid behavior', function() { | 
 |   799           return new Promise(function(resolve) { | 
 |   800             sendPowerManagementSettings( | 
 |   801                 settings.IdleBehavior.DISPLAY_ON, false /* idleControlled */, | 
 |   802                 settings.LidClosedBehavior.DO_NOTHING, | 
 |   803                 false /* lidClosedControlled */, true /* hasLid */); | 
 |   804             powerPage.async(resolve); | 
 |   805           }).then(function() { | 
 |   806             expectEquals( | 
 |   807                 settings.IdleBehavior.DISPLAY_ON.toString(), idleSelect.value); | 
 |   808             expectFalse(idleSelect.disabled); | 
 |   809             expectEquals(null, powerPage.$$('#idleControlledIndicator')); | 
 |   810             expectEquals( | 
 |   811                 settings.LidClosedBehavior.DO_NOTHING.toString(), | 
 |   812                 lidClosedSelect.value); | 
 |   813             expectFalse(lidClosedSelect.disabled); | 
 |   814             expectEquals(null, powerPage.$$('#lidClosedControlledIndicator')); | 
 |   815           }).then(function() { | 
 |   816             sendPowerManagementSettings( | 
 |   817                 settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE, | 
 |   818                 false /* idleControlled */, settings.LidClosedBehavior.SUSPEND, | 
 |   819                 false /* lidClosedControlled */, true /* hasLid */); | 
 |   820             return new Promise(function(resolve) { powerPage.async(resolve); }); | 
 |   821           }).then(function() { | 
 |   822             expectEquals( | 
 |   823                 settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE.toString(), | 
 |   824                 idleSelect.value); | 
 |   825             expectFalse(idleSelect.disabled); | 
 |   826             expectEquals(null, powerPage.$$('#idleControlledIndicator')); | 
 |   827             expectEquals( | 
 |   828                 settings.LidClosedBehavior.SUSPEND.toString(), | 
 |   829                 lidClosedSelect.value); | 
 |   830             expectFalse(lidClosedSelect.disabled); | 
 |   831             expectEquals(null, powerPage.$$('#lidClosedControlledIndicator')); | 
 |   832           }); | 
 |   833         }); | 
 |   834  | 
 |   835         test('display controlled idle and lid behavior', function() { | 
 |   836           // When settings are controlled, the selects should be disabled and | 
 |   837           // the indicators should be shown. | 
 |   838           return new Promise(function(resolve) { | 
 |   839             sendPowerManagementSettings( | 
 |   840                 settings.IdleBehavior.OTHER, true /* idleControlled */, | 
 |   841                 settings.LidClosedBehavior.SUSPEND, | 
 |   842                 true /* lidClosedControlled */, true /* hasLid */); | 
 |   843             powerPage.async(resolve); | 
 |   844           }).then(function() { | 
 |   845             expectEquals( | 
 |   846                 settings.IdleBehavior.OTHER.toString(), idleSelect.value); | 
 |   847             expectTrue(idleSelect.disabled); | 
 |   848             expectNotEquals(null, powerPage.$$('#idleControlledIndicator')); | 
 |   849             expectEquals( | 
 |   850                 settings.LidClosedBehavior.SUSPEND.toString(), | 
 |   851                 lidClosedSelect.value); | 
 |   852             expectTrue(lidClosedSelect.disabled); | 
 |   853             expectNotEquals( | 
 |   854                 null, powerPage.$$('#lidClosedControlledIndicator')); | 
 |   855           }); | 
 |   856         }); | 
 |   857  | 
 |   858         test('hide lid behavior when lid not present', function() { | 
 |   859           return new Promise(function(resolve) { | 
 |   860             expectFalse(powerPage.$$('#lidClosedRow').hidden); | 
 |   861             sendPowerManagementSettings( | 
 |   862                 settings.IdleBehavior.DISPLAY_OFF_SLEEP, | 
 |   863                 false /* idleControlled */, settings.LidClosedBehavior.SUSPEND, | 
 |   864                 false /* lidClosedControlled */, false /* hasLid */); | 
 |   865             powerPage.async(resolve); | 
 |   866           }).then(function() { | 
 |   867             expectTrue(powerPage.$$('#lidClosedRow').hidden); | 
 |   868           }); | 
 |   869         }); | 
|   703       }); |   870       }); | 
|   704     }); |   871     }); | 
|   705  |   872  | 
|   706     suite(assert(TestNames.Stylus), function() { |   873     suite(assert(TestNames.Stylus), function() { | 
|   707       var stylusPage; |   874       var stylusPage; | 
|   708       var appSelector; |   875       var appSelector; | 
|   709       var browserProxy; |   876       var browserProxy; | 
|   710       var noAppsDiv; |   877       var noAppsDiv; | 
|   711       var waitingDiv; |   878       var waitingDiv; | 
|   712       var selectAppDiv; |   879       var selectAppDiv; | 
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   977                   .value); |  1144                   .value); | 
|   978         }); |  1145         }); | 
|   979       }); |  1146       }); | 
|   980     }); |  1147     }); | 
|   981   }); |  1148   }); | 
|   982  |  1149  | 
|   983   return { |  1150   return { | 
|   984     TestNames: TestNames |  1151     TestNames: TestNames | 
|   985   }; |  1152   }; | 
|   986 }); |  1153 }); | 
| OLD | NEW |