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', |
| 11 Pointers: 'pointers', | 11 Pointers: 'pointers', |
| 12 Power: 'power', | 12 Power: 'power', |
| 13 Stylus: 'stylus', | |
| 13 }; | 14 }; |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * @constructor | 17 * @constructor |
| 17 * @implements {settings.DevicePageBrowserProxy} | 18 * @implements {settings.DevicePageBrowserProxy} |
| 18 */ | 19 */ |
| 19 function TestDevicePageBrowserProxy() { | 20 function TestDevicePageBrowserProxy() { |
| 20 this.keyboardShortcutsOverlayShown_ = 0; | 21 this.keyboardShortcutsOverlayShown_ = 0; |
| 21 this.updatePowerStatusCalled_ = 0; | 22 this.updatePowerStatusCalled_ = 0; |
| 23 this.onNoteTakingAppsUpdatedCallback_ = null; | |
| 24 this.requestNoteTakingApps_ = 0; | |
| 25 this.setPreferredNoteTakingApp_ = ''; | |
| 22 } | 26 } |
| 23 | 27 |
| 24 TestDevicePageBrowserProxy.prototype = { | 28 TestDevicePageBrowserProxy.prototype = { |
| 25 /** override */ | 29 /** override */ |
| 26 initializePointers: function() { | 30 initializePointers: function() { |
| 27 // Enable mouse and touchpad. | 31 // Enable mouse and touchpad. |
| 28 cr.webUIListenerCallback('has-mouse-changed', true); | 32 cr.webUIListenerCallback('has-mouse-changed', true); |
| 29 cr.webUIListenerCallback('has-touchpad-changed', true); | 33 cr.webUIListenerCallback('has-touchpad-changed', true); |
| 30 }, | 34 }, |
| 31 | 35 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 47 | 51 |
| 48 /** @override */ | 52 /** @override */ |
| 49 updatePowerStatus: function() { | 53 updatePowerStatus: function() { |
| 50 this.updatePowerStatusCalled_++; | 54 this.updatePowerStatusCalled_++; |
| 51 }, | 55 }, |
| 52 | 56 |
| 53 /** @override */ | 57 /** @override */ |
| 54 setPowerSource: function(powerSourceId) { | 58 setPowerSource: function(powerSourceId) { |
| 55 this.powerSourceId_ = powerSourceId; | 59 this.powerSourceId_ = powerSourceId; |
| 56 }, | 60 }, |
| 61 | |
| 62 /** @override */ | |
| 63 onNoteTakingAppsUpdated: function(callback) { | |
| 64 this.onNoteTakingAppsUpdated_ = callback; | |
| 65 }, | |
| 66 | |
| 67 /** @override */ | |
| 68 requestNoteTakingApps: function() { | |
| 69 this.requestNoteTakingApps_ += 1; | |
|
stevenjb
2017/01/25 01:40:08
nit: ++
jdufault
2017/02/03 21:32:09
Done.
| |
| 70 }, | |
| 71 | |
| 72 /** @override */ | |
| 73 setPreferredNoteTakingApp: function(appId) { | |
| 74 this.setPreferredNoteTakingApp_ = appId; | |
| 75 }, | |
| 57 }; | 76 }; |
| 58 | 77 |
| 59 function getFakePrefs() { | 78 function getFakePrefs() { |
| 60 return { | 79 return { |
| 61 settings: { | 80 settings: { |
| 62 touchpad: { | 81 touchpad: { |
| 63 enable_tap_to_click: { | 82 enable_tap_to_click: { |
| 64 key: 'settings.touchpad.enable_tap_to_click', | 83 key: 'settings.touchpad.enable_tap_to_click', |
| 65 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 84 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 66 value: true, | 85 value: true, |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 // Select the device. | 711 // Select the device. |
| 693 powerSourceSelect.value = powerSourceSelect.children[1].value; | 712 powerSourceSelect.value = powerSourceSelect.children[1].value; |
| 694 powerSourceSelect.dispatchEvent(new CustomEvent('change')); | 713 powerSourceSelect.dispatchEvent(new CustomEvent('change')); |
| 695 Polymer.dom.flush(); | 714 Polymer.dom.flush(); |
| 696 expectEquals( | 715 expectEquals( |
| 697 powerSource.id, | 716 powerSource.id, |
| 698 settings.DevicePageBrowserProxyImpl.getInstance().powerSourceId_); | 717 settings.DevicePageBrowserProxyImpl.getInstance().powerSourceId_); |
| 699 }); | 718 }); |
| 700 }); | 719 }); |
| 701 }); | 720 }); |
| 721 | |
| 722 suite(assert(TestNames.Stylus), function() { | |
| 723 var stylusPage; | |
| 724 var appSelector; | |
| 725 var browserProxy; | |
| 726 var noAppsDiv; | |
| 727 var waitingDiv; | |
| 728 var selectAppDiv; | |
| 729 | |
| 730 suiteSetup(function() { | |
| 731 // Always show stylus settings. | |
| 732 loadTimeData.overrideValues({ | |
| 733 stylusAllowed: true, | |
| 734 }); | |
| 735 }); | |
| 736 | |
| 737 setup(function() { | |
| 738 return showAndGetDeviceSubpage('stylus', settings.Route.STYLUS).then( | |
| 739 function(page) { | |
| 740 stylusPage = page; | |
| 741 browserProxy = settings.DevicePageBrowserProxyImpl.getInstance(); | |
| 742 appSelector = assert(page.$$('#menu')); | |
| 743 noAppsDiv = assert(page.$$('#no-apps')); | |
| 744 waitingDiv = assert(page.$$('#waiting')); | |
| 745 selectAppDiv = assert(page.$$('#select-app')); | |
| 746 | |
| 747 assertEquals(1, browserProxy.requestNoteTakingApps_); | |
| 748 assertEquals('', browserProxy.setPreferredNoteTakingApp_); | |
| 749 assert(browserProxy.onNoteTakingAppsUpdated_); | |
| 750 }); | |
| 751 }); | |
| 752 | |
| 753 // Helper function to allocate a note app entry. | |
| 754 function entry(name, value, preferred) { | |
| 755 return { | |
| 756 name: name, | |
| 757 value: value, | |
| 758 preferred: preferred | |
| 759 }; | |
| 760 } | |
| 761 | |
| 762 test('initial app choice selector value', function() { | |
| 763 // Selector chooses the first value in list if there is no preferred | |
| 764 // value set. | |
| 765 browserProxy.onNoteTakingAppsUpdated_( | |
| 766 [entry('n1', 'v1', false), entry('n2', 'v2', false)], false); | |
| 767 Polymer.dom.flush(); | |
| 768 assertEquals('v1', appSelector.value); | |
| 769 | |
| 770 // Selector chooses the preferred value if set. | |
| 771 browserProxy.onNoteTakingAppsUpdated_( | |
| 772 [entry('n1', 'v1', false), entry('n2', 'v2', true)], false); | |
| 773 Polymer.dom.flush(); | |
| 774 assertEquals('v2', appSelector.value); | |
| 775 }); | |
| 776 | |
| 777 test('change preferred app', function() { | |
| 778 // Load app list. | |
| 779 browserProxy.onNoteTakingAppsUpdated_( | |
| 780 [entry('n1', 'v1', false), entry('n2', 'v2', true)], false); | |
| 781 Polymer.dom.flush(); | |
| 782 assertEquals('', browserProxy.setPreferredNoteTakingApp_); | |
| 783 | |
| 784 // Update select element to new value, verify browser proxy is called. | |
| 785 appSelector.value = 'v1'; | |
| 786 stylusPage.onSelectedAppChanged_(); | |
| 787 assertEquals('v1', browserProxy.setPreferredNoteTakingApp_); | |
| 788 }); | |
| 789 | |
| 790 test('preferred app does not change without interaction', function() { | |
| 791 // Pass various types of data to page, verify the preferred note-app | |
| 792 // does not change. | |
| 793 browserProxy.onNoteTakingAppsUpdated_([], false); | |
| 794 Polymer.dom.flush(); | |
|
stevenjb
2017/01/25 01:40:08
It seems like we should be asserting after each of
jdufault
2017/02/03 21:32:09
I think the test is okay without the extra asserts
| |
| 795 browserProxy.onNoteTakingAppsUpdated_([], true); | |
| 796 Polymer.dom.flush(); | |
| 797 browserProxy.onNoteTakingAppsUpdated_([entry('n', 'v', false)], true); | |
| 798 Polymer.dom.flush(); | |
| 799 browserProxy.onNoteTakingAppsUpdated_([entry('n', 'v', false)], false); | |
| 800 Polymer.dom.flush(); | |
| 801 browserProxy.onNoteTakingAppsUpdated_( | |
| 802 [entry('n1', 'v1', false), entry('n2', 'v2', true)], false); | |
| 803 Polymer.dom.flush(); | |
| 804 | |
| 805 assertEquals('', browserProxy.setPreferredNoteTakingApp_); | |
| 806 }); | |
| 807 | |
| 808 test('app-visibility', function() { | |
| 809 // No apps available. | |
| 810 browserProxy.onNoteTakingAppsUpdated_([], false); | |
| 811 assert(!noAppsDiv.hidden); | |
| 812 assert(waitingDiv.hidden); | |
| 813 assert(selectAppDiv.hidden); | |
| 814 | |
| 815 // Waiting for apps to finish loading. | |
| 816 browserProxy.onNoteTakingAppsUpdated_([], true); | |
| 817 assert(noAppsDiv.hidden); | |
| 818 assert(!waitingDiv.hidden); | |
| 819 assert(selectAppDiv.hidden); | |
| 820 | |
| 821 browserProxy.onNoteTakingAppsUpdated_([entry('n', 'v', false)], true); | |
| 822 assert(noAppsDiv.hidden); | |
| 823 assert(!waitingDiv.hidden); | |
| 824 assert(selectAppDiv.hidden); | |
| 825 | |
| 826 // Apps loaded, show selector. | |
| 827 browserProxy.onNoteTakingAppsUpdated_([entry('n', 'v', false)], false); | |
| 828 assert(noAppsDiv.hidden); | |
| 829 assert(waitingDiv.hidden); | |
| 830 assert(!selectAppDiv.hidden); | |
| 831 }); | |
| 832 }); | |
| 702 }); | 833 }); |
| 703 | 834 |
| 704 return { | 835 return { |
| 705 TestNames: TestNames | 836 TestNames: TestNames |
| 706 }; | 837 }; |
| 707 }); | 838 }); |
| OLD | NEW |