Chromium Code Reviews| 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', |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 var basicPage = document.createElement('div'); | 158 var basicPage = document.createElement('div'); |
| 159 basicPage.dataset.page = 'basic'; | 159 basicPage.dataset.page = 'basic'; |
| 160 basicPage.appendChild(devicePage); | 160 basicPage.appendChild(devicePage); |
| 161 document.body.appendChild(basicPage); | 161 document.body.appendChild(basicPage); |
| 162 | 162 |
| 163 // Allow the light DOM to be distributed to settings-animated-pages. | 163 // Allow the light DOM to be distributed to settings-animated-pages. |
| 164 setTimeout(done); | 164 setTimeout(done); |
| 165 }); | 165 }); |
| 166 | 166 |
| 167 /** @return {!Promise<!HTMLElement>} */ | 167 /** @return {!Promise<!HTMLElement>} */ |
| 168 function showAndGetDeviceSubpage(subpage) { | 168 function showAndGetDeviceSubpage(subpage, expectedRoute) { |
| 169 return new Promise(function(resolve, reject) { | 169 return new Promise(function(resolve, reject) { |
| 170 var row = assert(devicePage.$$('#main #' + subpage + 'Row')); | 170 var row = assert(devicePage.$$('#main #' + subpage + 'Row')); |
| 171 devicePage.$.pages.addEventListener('neon-animation-finish', resolve); | 171 devicePage.$.pages.addEventListener('neon-animation-finish', resolve); |
| 172 MockInteractions.tap(row); | 172 MockInteractions.tap(row); |
| 173 }).then(function() { | 173 }).then(function() { |
| 174 assertEquals('device', settings.getCurrentRoute().section); | 174 assertEquals(expectedRoute, settings.getCurrentRoute()); |
| 175 assertEquals(subpage, settings.getCurrentRoute().subpage[0]); | 175 var page = devicePage.$$('settings-' + subpage); |
| 176 var page = devicePage.$$('#' + subpage + ' settings-' + subpage); | |
| 177 return assert(page); | 176 return assert(page); |
| 178 }); | 177 }); |
| 179 }; | 178 }; |
| 180 | 179 |
| 181 /** | 180 /** |
| 182 * @param {!HTMLElement} pointersPage | 181 * @param {!HTMLElement} pointersPage |
| 183 * @param {Boolean} expected | 182 * @param {Boolean} expected |
| 184 */ | 183 */ |
| 185 function expectNaturalScrollValue(pointersPage, expected) { | 184 function expectNaturalScrollValue(pointersPage, expected) { |
| 186 var naturalScrollOff = | 185 var naturalScrollOff = |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 206 cr.webUIListenerCallback('has-touchpad-changed', false); | 205 cr.webUIListenerCallback('has-touchpad-changed', false); |
| 207 expectEquals(0, devicePage.$.pointersRow.offsetHeight); | 206 expectEquals(0, devicePage.$.pointersRow.offsetHeight); |
| 208 cr.webUIListenerCallback('has-mouse-changed', true); | 207 cr.webUIListenerCallback('has-mouse-changed', true); |
| 209 expectLT(0, devicePage.$.pointersRow.offsetHeight); | 208 expectLT(0, devicePage.$.pointersRow.offsetHeight); |
| 210 }); | 209 }); |
| 211 | 210 |
| 212 suite(assert(TestNames.Pointers), function() { | 211 suite(assert(TestNames.Pointers), function() { |
| 213 var pointersPage; | 212 var pointersPage; |
| 214 | 213 |
| 215 setup(function() { | 214 setup(function() { |
| 216 return showAndGetDeviceSubpage('pointers').then(function(page) { | 215 return showAndGetDeviceSubpage( |
| 217 pointersPage = page; | 216 'pointers', settings.Route.POINTERS).then(function(page) { |
| 218 }); | 217 pointersPage = page; |
| 218 }); | |
| 219 }); | 219 }); |
| 220 | 220 |
| 221 test('subpage responds to pointer attach/detach', function() { | 221 test('subpage responds to pointer attach/detach', function() { |
| 222 assertEquals('pointers', settings.getCurrentRoute().subpage[0]); | |
| 223 assertTrue(settings.getCurrentRoute() == settings.Route.POINTERS); | 222 assertTrue(settings.getCurrentRoute() == settings.Route.POINTERS); |
| 224 assertLT(0, pointersPage.$.mouse.offsetHeight); | 223 assertLT(0, pointersPage.$.mouse.offsetHeight); |
| 225 assertLT(0, pointersPage.$.touchpad.offsetHeight); | 224 assertLT(0, pointersPage.$.touchpad.offsetHeight); |
| 226 assertLT(0, pointersPage.$$('#mouse h2').offsetHeight); | 225 assertLT(0, pointersPage.$$('#mouse h2').offsetHeight); |
| 227 assertLT(0, pointersPage.$$('#touchpad h2').offsetHeight); | 226 assertLT(0, pointersPage.$$('#touchpad h2').offsetHeight); |
| 228 | 227 |
| 229 cr.webUIListenerCallback('has-touchpad-changed', false); | 228 cr.webUIListenerCallback('has-touchpad-changed', false); |
| 230 assertEquals('pointers', settings.getCurrentRoute().subpage[0]); | 229 assertTrue(settings.getCurrentRoute() == settings.Route.POINTERS); |
|
michaelpg
2016/08/11 03:41:13
err, why not assertEquals, here and the others bel
tommycli
2016/08/11 19:15:02
Done.
| |
| 231 assertLT(0, pointersPage.$.mouse.offsetHeight); | 230 assertLT(0, pointersPage.$.mouse.offsetHeight); |
| 232 assertEquals(0, pointersPage.$.touchpad.offsetHeight); | 231 assertEquals(0, pointersPage.$.touchpad.offsetHeight); |
| 233 assertEquals(0, pointersPage.$$('#mouse h2').offsetHeight); | 232 assertEquals(0, pointersPage.$$('#mouse h2').offsetHeight); |
| 234 assertEquals(0, pointersPage.$$('#touchpad h2').offsetHeight); | 233 assertEquals(0, pointersPage.$$('#touchpad h2').offsetHeight); |
| 235 | 234 |
| 236 // Wait for the transition back to the main page. | 235 // Wait for the transition back to the main page. |
| 237 return new Promise(function(resolve, reject) { | 236 return new Promise(function(resolve, reject) { |
| 238 devicePage.$.pages.addEventListener('neon-animation-finish', resolve); | 237 devicePage.$.pages.addEventListener('neon-animation-finish', resolve); |
| 239 | 238 |
| 240 cr.webUIListenerCallback('has-mouse-changed', false); | 239 cr.webUIListenerCallback('has-mouse-changed', false); |
| 241 }).then(function() { | 240 }).then(function() { |
| 242 assertEquals(0, settings.getCurrentRoute().subpage.length); | 241 assertTrue(settings.getCurrentRoute() == settings.Route.DEVICE); |
| 243 assertEquals(0, devicePage.$$('#main #pointersRow').offsetHeight); | 242 assertEquals(0, devicePage.$$('#main #pointersRow').offsetHeight); |
| 244 | 243 |
| 245 cr.webUIListenerCallback('has-touchpad-changed', true); | 244 cr.webUIListenerCallback('has-touchpad-changed', true); |
| 246 assertLT(0, devicePage.$$('#main #pointersRow').offsetHeight); | 245 assertLT(0, devicePage.$$('#main #pointersRow').offsetHeight); |
| 247 return showAndGetDeviceSubpage('pointers'); | 246 return showAndGetDeviceSubpage('pointers', settings.Route.POINTERS); |
| 248 }).then(function(page) { | 247 }).then(function(page) { |
| 249 assertEquals(0, pointersPage.$.mouse.offsetHeight); | 248 assertEquals(0, pointersPage.$.mouse.offsetHeight); |
| 250 assertLT(0, pointersPage.$.touchpad.offsetHeight); | 249 assertLT(0, pointersPage.$.touchpad.offsetHeight); |
| 251 assertEquals(0, pointersPage.$$('#mouse h2').offsetHeight); | 250 assertEquals(0, pointersPage.$$('#mouse h2').offsetHeight); |
| 252 assertEquals(0, pointersPage.$$('#touchpad h2').offsetHeight); | 251 assertEquals(0, pointersPage.$$('#touchpad h2').offsetHeight); |
| 253 | 252 |
| 254 cr.webUIListenerCallback('has-mouse-changed', true); | 253 cr.webUIListenerCallback('has-mouse-changed', true); |
| 255 assertEquals('pointers', settings.getCurrentRoute().subpage[0]); | 254 assertTrue(settings.getCurrentRoute() == settings.Route.POINTERS); |
| 256 assertLT(0, pointersPage.$.mouse.offsetHeight); | 255 assertLT(0, pointersPage.$.mouse.offsetHeight); |
| 257 assertLT(0, pointersPage.$.touchpad.offsetHeight); | 256 assertLT(0, pointersPage.$.touchpad.offsetHeight); |
| 258 assertLT(0, pointersPage.$$('#mouse h2').offsetHeight); | 257 assertLT(0, pointersPage.$$('#mouse h2').offsetHeight); |
| 259 assertLT(0, pointersPage.$$('#touchpad h2').offsetHeight); | 258 assertLT(0, pointersPage.$$('#touchpad h2').offsetHeight); |
| 260 }); | 259 }); |
| 261 }); | 260 }); |
| 262 | 261 |
| 263 test('mouse', function() { | 262 test('mouse', function() { |
| 264 expectLT(0, pointersPage.$.mouse.offsetHeight); | 263 expectLT(0, pointersPage.$.mouse.offsetHeight); |
| 265 | 264 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 Polymer.Base.async(function() { | 318 Polymer.Base.async(function() { |
| 320 expectNaturalScrollValue(pointersPage, true); | 319 expectNaturalScrollValue(pointersPage, true); |
| 321 done(); | 320 done(); |
| 322 }, 1); | 321 }, 1); |
| 323 }, 1); | 322 }, 1); |
| 324 }); | 323 }); |
| 325 }); | 324 }); |
| 326 | 325 |
| 327 test(assert(TestNames.Keyboard), function() { | 326 test(assert(TestNames.Keyboard), function() { |
| 328 // Open the keyboard subpage. | 327 // Open the keyboard subpage. |
| 329 return showAndGetDeviceSubpage('keyboard').then(function(keyboardPage) { | 328 return showAndGetDeviceSubpage( |
| 329 'keyboard', settings.Route.KEYBOARD).then(function(keyboardPage) { | |
| 330 // Initially, the optional keys are hidden. | 330 // Initially, the optional keys are hidden. |
| 331 expectFalse(!!keyboardPage.$$('#capsLockKey')); | 331 expectFalse(!!keyboardPage.$$('#capsLockKey')); |
| 332 expectFalse(!!keyboardPage.$$('#diamondKey')); | 332 expectFalse(!!keyboardPage.$$('#diamondKey')); |
| 333 | 333 |
| 334 // Pretend the diamond key is available. | 334 // Pretend the diamond key is available. |
| 335 var showCapsLock = false; | 335 var showCapsLock = false; |
| 336 var showDiamondKey = true; | 336 var showDiamondKey = true; |
| 337 cr.webUIListenerCallback( | 337 cr.webUIListenerCallback( |
| 338 'show-keys-changed', showCapsLock, showDiamondKey); | 338 'show-keys-changed', showCapsLock, showDiamondKey); |
| 339 Polymer.dom.flush(); | 339 Polymer.dom.flush(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 width: 1920, | 413 width: 1920, |
| 414 height: 1080, | 414 height: 1080, |
| 415 }, | 415 }, |
| 416 }; | 416 }; |
| 417 fakeSystemDisplay.addDisplayForTest(display); | 417 fakeSystemDisplay.addDisplayForTest(display); |
| 418 }; | 418 }; |
| 419 | 419 |
| 420 var displayPage; | 420 var displayPage; |
| 421 return Promise.all([ | 421 return Promise.all([ |
| 422 // Get the display sub-page. | 422 // Get the display sub-page. |
| 423 showAndGetDeviceSubpage('display').then(function(page) { | 423 showAndGetDeviceSubpage( |
| 424 'display', settings.Route.DISPLAY).then(function(page) { | |
| 424 displayPage = page; | 425 displayPage = page; |
| 425 }), | 426 }), |
| 426 // Wait for the initial call to getInfo. | 427 // Wait for the initial call to getInfo. |
| 427 fakeSystemDisplay.getInfoCalled.promise, | 428 fakeSystemDisplay.getInfoCalled.promise, |
| 428 ]).then(function() { | 429 ]).then(function() { |
| 429 // Add a display. | 430 // Add a display. |
| 430 addDisplay(1); | 431 addDisplay(1); |
| 431 fakeSystemDisplay.onDisplayChanged.callListeners(); | 432 fakeSystemDisplay.onDisplayChanged.callListeners(); |
| 432 | 433 |
| 433 return Promise.all([ | 434 return Promise.all([ |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 expectTrue(displayPage.showMirror_(displayPage.displays)); | 512 expectTrue(displayPage.showMirror_(displayPage.displays)); |
| 512 expectTrue(displayPage.isMirrored_(displayPage.displays)); | 513 expectTrue(displayPage.isMirrored_(displayPage.displays)); |
| 513 }); | 514 }); |
| 514 }); | 515 }); |
| 515 }); | 516 }); |
| 516 | 517 |
| 517 return { | 518 return { |
| 518 TestNames: TestNames | 519 TestNames: TestNames |
| 519 }; | 520 }; |
| 520 }); | 521 }); |
| OLD | NEW |