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} idleManaged | |
263 * @param {settings.LidClosedBehavior} lidClosedBehavior | |
264 * @param {boolean} lidClosedManaged | |
265 * @param {boolean} hasLid | |
266 */ | |
267 function sendPowerManagementSettings(idleBehavior, idleManaged, | |
268 lidClosedBehavior, lidClosedManaged, | |
269 hasLid) { | |
270 cr.webUIListenerCallback( | |
271 'power-management-settings-changed', | |
272 { | |
273 idleBehavior: idleBehavior, | |
274 idleManaged: idleManaged, | |
275 lidClosedBehavior: lidClosedBehavior, | |
276 lidClosedManaged: lidClosedManaged, | |
277 hasLid: hasLid, | |
278 }); | |
michaelpg
2017/06/16 01:35:01
after changing the handler to this.async (prior co
| |
279 }; | |
280 | |
281 /** | |
245 * @param {!HTMLElement} pointersPage | 282 * @param {!HTMLElement} pointersPage |
246 * @param {boolean} expected | 283 * @param {boolean} expected |
247 */ | 284 */ |
248 function expectNaturalScrollValue(pointersPage, expected) { | 285 function expectNaturalScrollValue(pointersPage, expected) { |
249 var naturalScrollOff = | 286 var naturalScrollOff = |
250 pointersPage.$$('paper-radio-button[name="false"]'); | 287 pointersPage.$$('paper-radio-button[name="false"]'); |
251 var naturalScrollOn = | 288 var naturalScrollOn = |
252 pointersPage.$$('paper-radio-button[name="true"]'); | 289 pointersPage.$$('paper-radio-button[name="true"]'); |
253 assertTrue(!!naturalScrollOff); | 290 assertTrue(!!naturalScrollOff); |
254 assertTrue(!!naturalScrollOn); | 291 assertTrue(!!naturalScrollOn); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 */ | 623 */ |
587 function setPowerSources(sources, powerSourceId, isLowPowerCharger) { | 624 function setPowerSources(sources, powerSourceId, isLowPowerCharger) { |
588 var sourcesCopy = sources.map(function(source) { | 625 var sourcesCopy = sources.map(function(source) { |
589 return Object.assign({}, source); | 626 return Object.assign({}, source); |
590 }); | 627 }); |
591 cr.webUIListenerCallback('power-sources-changed', | 628 cr.webUIListenerCallback('power-sources-changed', |
592 sourcesCopy, powerSourceId, isLowPowerCharger); | 629 sourcesCopy, powerSourceId, isLowPowerCharger); |
593 } | 630 } |
594 | 631 |
595 suite('no power settings', function() { | 632 suite('no power settings', function() { |
633 suiteSetup(function() { | |
634 // Never show power settings. | |
635 loadTimeData.overrideValues({ | |
636 enablePowerSettings: false, | |
637 }); | |
638 }); | |
639 | |
596 test('power row hidden', function() { | 640 test('power row hidden', function() { |
597 assertEquals(null, devicePage.$$('#powerRow')); | 641 assertEquals(null, devicePage.$$('#powerRow')); |
598 assertEquals(0, | 642 assertEquals(0, |
599 settings.DevicePageBrowserProxyImpl.getInstance() | 643 settings.DevicePageBrowserProxyImpl.getInstance() |
600 .updatePowerStatusCalled_); | 644 .updatePowerStatusCalled_); |
601 }); | 645 }); |
602 }); | 646 }); |
603 | 647 |
604 suite('power settings', function() { | 648 suite('power settings', function() { |
605 var powerPage; | 649 var powerPage; |
606 var powerSourceRow; | 650 var powerSourceRow; |
607 var powerSourceWrapper; | 651 var powerSourceWrapper; |
608 var powerSourceSelect; | 652 var powerSourceSelect; |
653 var idleSelect; | |
654 var lidClosedSelect; | |
609 | 655 |
610 suiteSetup(function() { | 656 suiteSetup(function() { |
611 // Always show power settings. | 657 // Always show power settings. |
612 loadTimeData.overrideValues({ | 658 loadTimeData.overrideValues({ |
613 enablePowerSettings: true, | 659 enablePowerSettings: true, |
614 }); | 660 }); |
615 }); | 661 }); |
616 | 662 |
617 setup(function() { | 663 setup(function() { |
618 return showAndGetDeviceSubpage('power', settings.Route.POWER) | 664 return showAndGetDeviceSubpage('power', settings.Route.POWER) |
619 .then(function(page) { | 665 .then(function(page) { |
620 powerPage = page; | 666 powerPage = page; |
621 powerSourceRow = assert(powerPage.$$('#powerSourceRow')); | 667 powerSourceRow = assert(powerPage.$$('#powerSourceRow')); |
622 powerSourceWrapper = | 668 powerSourceWrapper = |
623 assert(powerSourceRow.querySelector('.md-select-wrapper')); | 669 assert(powerSourceRow.querySelector('.md-select-wrapper')); |
624 powerSourceSelect = assert(powerPage.$$('#powerSource')); | 670 powerSourceSelect = assert(powerPage.$$('#powerSource')); |
625 assertEquals( | 671 assertEquals( |
626 1, | 672 1, |
627 settings.DevicePageBrowserProxyImpl.getInstance() | 673 settings.DevicePageBrowserProxyImpl.getInstance() |
628 .updatePowerStatusCalled_); | 674 .updatePowerStatusCalled_); |
675 | |
676 idleSelect = assert(powerPage.$$('#idleSelect')); | |
677 lidClosedSelect = assert(powerPage.$$('#lidClosedSelect')); | |
678 | |
679 assertEquals( | |
680 1, | |
681 settings.DevicePageBrowserProxyImpl.getInstance() | |
682 .requestPowerManagementSettingsCalled_); | |
michaelpg
2017/06/16 01:35:00
nit: make this not private (no underscore), or add
Daniel Erat
2017/06/16 02:34:25
Acknowledged.
| |
683 sendPowerManagementSettings( | |
684 settings.IdleBehavior.DISPLAY_OFF_SLEEP, false, | |
michaelpg
2017/06/16 01:35:00
nit: add comments for parameter names for these bo
Daniel Erat
2017/06/16 02:34:25
Done.
| |
685 settings.LidClosedBehavior.SUSPEND, false, true); | |
629 }); | 686 }); |
630 }); | 687 }); |
631 | 688 |
632 test('power sources', function() { | 689 test('power sources', function() { |
633 var batteryStatus = { | 690 var batteryStatus = { |
634 charging: false, | 691 charging: false, |
635 calculating: false, | 692 calculating: false, |
636 percent: 50, | 693 percent: 50, |
637 statusText: '5 hours left', | 694 statusText: '5 hours left', |
638 }; | 695 }; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 Polymer.dom.flush(); | 750 Polymer.dom.flush(); |
694 | 751 |
695 // Select the device. | 752 // Select the device. |
696 powerSourceSelect.value = powerSourceSelect.children[1].value; | 753 powerSourceSelect.value = powerSourceSelect.children[1].value; |
697 powerSourceSelect.dispatchEvent(new CustomEvent('change')); | 754 powerSourceSelect.dispatchEvent(new CustomEvent('change')); |
698 Polymer.dom.flush(); | 755 Polymer.dom.flush(); |
699 expectEquals( | 756 expectEquals( |
700 powerSource.id, | 757 powerSource.id, |
701 settings.DevicePageBrowserProxyImpl.getInstance().powerSourceId_); | 758 settings.DevicePageBrowserProxyImpl.getInstance().powerSourceId_); |
702 }); | 759 }); |
760 | |
761 test('set idle behavior', function() { | |
762 idleSelect.value = settings.IdleBehavior.DISPLAY_ON; | |
763 idleSelect.dispatchEvent(new CustomEvent('change')); | |
michaelpg
2017/06/16 01:35:00
maybe make a helper function selectValue(selectId,
Daniel Erat
2017/06/16 02:34:25
Done.
| |
764 Polymer.dom.flush(); | |
765 expectEquals( | |
766 settings.IdleBehavior.DISPLAY_ON, | |
767 settings.DevicePageBrowserProxyImpl.getInstance().idleBehavior_); | |
768 | |
769 idleSelect.value = settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE; | |
770 idleSelect.dispatchEvent(new CustomEvent('change')); | |
771 Polymer.dom.flush(); | |
772 expectEquals( | |
773 settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE, | |
774 settings.DevicePageBrowserProxyImpl.getInstance().idleBehavior_); | |
775 }); | |
776 | |
777 test('set lid behavior', function() { | |
778 lidClosedSelect.value = settings.LidClosedBehavior.DO_NOTHING; | |
779 lidClosedSelect.dispatchEvent(new CustomEvent('change')); | |
780 Polymer.dom.flush(); | |
781 expectEquals( | |
782 settings.LidClosedBehavior.DO_NOTHING, | |
783 settings.DevicePageBrowserProxyImpl.getInstance() | |
784 .lidClosedBehavior_); | |
785 | |
786 lidClosedSelect.value = settings.LidClosedBehavior.SUSPEND; | |
787 lidClosedSelect.dispatchEvent(new CustomEvent('change')); | |
788 Polymer.dom.flush(); | |
789 expectEquals( | |
790 settings.LidClosedBehavior.SUSPEND, | |
791 settings.DevicePageBrowserProxyImpl.getInstance() | |
792 .lidClosedBehavior_); | |
793 }); | |
794 | |
795 test('display idle and lid behavior', function() { | |
796 sendPowerManagementSettings( | |
797 settings.IdleBehavior.DISPLAY_ON, false, | |
798 settings.LidClosedBehavior.DO_NOTHING, false, true); | |
799 expectEquals( | |
800 settings.IdleBehavior.DISPLAY_ON.toString(), idleSelect.value); | |
801 expectFalse(idleSelect.disabled); | |
802 expectEquals(null, powerPage.$$('#idleManagedIndicator')); | |
803 expectEquals( | |
804 settings.LidClosedBehavior.DO_NOTHING.toString(), | |
805 lidClosedSelect.value); | |
806 expectFalse(lidClosedSelect.disabled); | |
807 expectEquals(null, powerPage.$$('#lidClosedManagedIndicator')); | |
808 | |
809 sendPowerManagementSettings( | |
810 settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE, false, | |
811 settings.LidClosedBehavior.SUSPEND, false, true); | |
812 expectEquals( | |
813 settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE.toString(), | |
814 idleSelect.value); | |
815 expectFalse(idleSelect.disabled); | |
816 expectEquals(null, powerPage.$$('#idleManagedIndicator')); | |
817 expectEquals( | |
818 settings.LidClosedBehavior.SUSPEND.toString(), | |
819 lidClosedSelect.value); | |
820 expectFalse(lidClosedSelect.disabled); | |
821 expectEquals(null, powerPage.$$('#lidClosedManagedIndicator')); | |
822 | |
823 // When settings are managed, the selects should be disabled and the | |
824 // indicators should be shown. | |
825 sendPowerManagementSettings( | |
826 settings.IdleBehavior.OTHER, true, | |
827 settings.LidClosedBehavior.SUSPEND, true, true); | |
828 expectEquals( | |
829 settings.IdleBehavior.OTHER.toString(), idleSelect.value); | |
830 expectTrue(idleSelect.disabled); | |
831 expectTrue(powerPage.$$('#idleManagedIndicator') != null); | |
michaelpg
2017/06/16 01:35:00
expectNotEquals (or often we just expectTrue(!!foo
Daniel Erat
2017/06/16 02:34:25
Done.
| |
832 expectEquals( | |
833 settings.LidClosedBehavior.SUSPEND.toString(), | |
834 lidClosedSelect.value); | |
835 expectTrue(lidClosedSelect.disabled); | |
836 expectTrue(powerPage.$$('#lidClosedManagedIndicator') != null); | |
837 }); | |
703 }); | 838 }); |
704 }); | 839 }); |
705 | 840 |
706 suite(assert(TestNames.Stylus), function() { | 841 suite(assert(TestNames.Stylus), function() { |
707 var stylusPage; | 842 var stylusPage; |
708 var appSelector; | 843 var appSelector; |
709 var browserProxy; | 844 var browserProxy; |
710 var noAppsDiv; | 845 var noAppsDiv; |
711 var waitingDiv; | 846 var waitingDiv; |
712 var selectAppDiv; | 847 var selectAppDiv; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
977 .value); | 1112 .value); |
978 }); | 1113 }); |
979 }); | 1114 }); |
980 }); | 1115 }); |
981 }); | 1116 }); |
982 | 1117 |
983 return { | 1118 return { |
984 TestNames: TestNames | 1119 TestNames: TestNames |
985 }; | 1120 }; |
986 }); | 1121 }); |
OLD | NEW |