| 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('settings_about_page', function() { | 5 cr.define('settings_about_page', function() { |
| 6 /** | 6 /** |
| 7 * @constructor | 7 * @constructor |
| 8 * @implements {settings.AboutPageBrowserProxy} | 8 * @implements {settings.AboutPageBrowserProxy} |
| 9 * @extends {settings.TestBrowserProxy} | 9 * @extends {settings.TestBrowserProxy} |
| 10 */ | 10 */ |
| 11 var TestAboutPageBrowserProxy = function() { | 11 var TestAboutPageBrowserProxy = function() { |
| 12 var methodNames = [ | 12 var methodNames = [ |
| 13 'pageReady', | 13 'pageReady', |
| 14 'refreshUpdateStatus', | 14 'refreshUpdateStatus', |
| 15 'openHelpPage', | 15 'openHelpPage', |
| 16 'openFeedbackDialog', | 16 'openFeedbackDialog', |
| 17 ]; | 17 ]; |
| 18 | 18 |
| 19 if (cr.isChromeOS) { | 19 if (cr.isChromeOS) { |
| 20 methodNames.push( | 20 methodNames.push( |
| 21 'getCurrentChannel', | 21 'getChannelInfo', |
| 22 'getTargetChannel', | |
| 23 'getVersionInfo', | 22 'getVersionInfo', |
| 24 'getRegulatoryInfo', | 23 'getRegulatoryInfo', |
| 25 'setChannel'); | 24 'setChannel'); |
| 26 } | 25 } |
| 27 | 26 |
| 28 settings.TestBrowserProxy.call(this, methodNames); | 27 settings.TestBrowserProxy.call(this, methodNames); |
| 29 | 28 |
| 30 /** @private {!UpdateStatus} */ | 29 /** @private {!UpdateStatus} */ |
| 31 this.updateStatus_ = UpdateStatus.UPDATED; | 30 this.updateStatus_ = UpdateStatus.UPDATED; |
| 32 | 31 |
| 33 if (cr.isChromeOS) { | 32 if (cr.isChromeOS) { |
| 34 /** @type {!VersionInfo} */ | 33 /** @private {!VersionInfo} */ |
| 35 this.versionInfo_ = { | 34 this.versionInfo_ = { |
| 36 arcVersion: '', | 35 arcVersion: '', |
| 37 osFirmware: '', | 36 osFirmware: '', |
| 38 osVersion: '', | 37 osVersion: '', |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 /** @private {!BrowserChannel} */ | 40 /** @private {!ChannelInfo} */ |
| 42 this.currentChannel_ = BrowserChannel.BETA; | 41 this.channelInfo_ = { |
| 43 | 42 currentChannel: BrowserChannel.BETA, |
| 44 /** @private {!BrowserChannel} */ | 43 targetChannel: BrowserChannel.BETA, |
| 45 this.targetChannel_ = BrowserChannel.BETA; | 44 canChangeChannel: true, |
| 45 }; |
| 46 | 46 |
| 47 /** @private {?RegulatoryInfo} */ | 47 /** @private {?RegulatoryInfo} */ |
| 48 this.regulatoryInfo_ = null; | 48 this.regulatoryInfo_ = null; |
| 49 } | 49 } |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 TestAboutPageBrowserProxy.prototype = { | 52 TestAboutPageBrowserProxy.prototype = { |
| 53 __proto__: settings.TestBrowserProxy.prototype, | 53 __proto__: settings.TestBrowserProxy.prototype, |
| 54 | 54 |
| 55 /** @param {!UpdateStatus} updateStatus */ | 55 /** @param {!UpdateStatus} updateStatus */ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 81 this.methodCalled('openHelpPage'); | 81 this.methodCalled('openHelpPage'); |
| 82 }, | 82 }, |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 if (cr.isChromeOS) { | 85 if (cr.isChromeOS) { |
| 86 /** @param {!VersionInfo} */ | 86 /** @param {!VersionInfo} */ |
| 87 TestAboutPageBrowserProxy.prototype.setVersionInfo = function(versionInfo) { | 87 TestAboutPageBrowserProxy.prototype.setVersionInfo = function(versionInfo) { |
| 88 this.versionInfo_ = versionInfo; | 88 this.versionInfo_ = versionInfo; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 /** @param {boolean} canChangeChannel */ |
| 92 TestAboutPageBrowserProxy.prototype.setCanChangeChannel = function( |
| 93 canChangeChannel) { |
| 94 this.channelInfo_.canChangeChannel = canChangeChannel; |
| 95 }; |
| 96 |
| 91 /** | 97 /** |
| 92 * @param {!BrowserChannel} current | 98 * @param {!BrowserChannel} current |
| 93 * @param {!BrowserChannel} target | 99 * @param {!BrowserChannel} target |
| 94 */ | 100 */ |
| 95 TestAboutPageBrowserProxy.prototype.setChannels = function( | 101 TestAboutPageBrowserProxy.prototype.setChannels = function( |
| 96 current, target) { | 102 current, target) { |
| 97 this.currentChannel_ = current; | 103 this.channelInfo_.currentChannel = current; |
| 98 this.targetChannel_ = target; | 104 this.channelInfo_.targetChannel = target; |
| 99 }; | 105 }; |
| 100 | 106 |
| 101 | |
| 102 /** @param {?RegulatoryInfo} regulatoryInfo */ | 107 /** @param {?RegulatoryInfo} regulatoryInfo */ |
| 103 TestAboutPageBrowserProxy.prototype.setRegulatoryInfo = function( | 108 TestAboutPageBrowserProxy.prototype.setRegulatoryInfo = function( |
| 104 regulatoryInfo) { | 109 regulatoryInfo) { |
| 105 this.regulatoryInfo_ = regulatoryInfo; | 110 this.regulatoryInfo_ = regulatoryInfo; |
| 106 }; | 111 }; |
| 107 | 112 |
| 108 /** @override */ | 113 /** @override */ |
| 109 TestAboutPageBrowserProxy.prototype.getCurrentChannel = function() { | 114 TestAboutPageBrowserProxy.prototype.getChannelInfo = function() { |
| 110 this.methodCalled('getCurrentChannel'); | 115 this.methodCalled('getChannelInfo'); |
| 111 return Promise.resolve(this.currentChannel_); | 116 return Promise.resolve(this.channelInfo_); |
| 112 }; | 117 }; |
| 113 | 118 |
| 114 /** @override */ | 119 /** @override */ |
| 115 TestAboutPageBrowserProxy.prototype.getTargetChannel = function() { | |
| 116 this.methodCalled('getTargetChannel'); | |
| 117 return Promise.resolve(this.targetChannel_); | |
| 118 }; | |
| 119 | |
| 120 /** @override */ | |
| 121 TestAboutPageBrowserProxy.prototype.getVersionInfo = function() { | 120 TestAboutPageBrowserProxy.prototype.getVersionInfo = function() { |
| 122 this.methodCalled('getVersionInfo'); | 121 this.methodCalled('getVersionInfo'); |
| 123 return Promise.resolve(this.versionInfo_); | 122 return Promise.resolve(this.versionInfo_); |
| 124 }; | 123 }; |
| 125 | 124 |
| 126 /** @override */ | 125 /** @override */ |
| 127 TestAboutPageBrowserProxy.prototype.getRegulatoryInfo = function() { | 126 TestAboutPageBrowserProxy.prototype.getRegulatoryInfo = function() { |
| 128 this.methodCalled('getRegulatoryInfo'); | 127 this.methodCalled('getRegulatoryInfo'); |
| 129 return Promise.resolve(this.regulatoryInfo_); | 128 return Promise.resolve(this.regulatoryInfo_); |
| 130 }; | 129 }; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 }); | 178 }); |
| 180 | 179 |
| 181 /** @return {!Promise} */ | 180 /** @return {!Promise} */ |
| 182 function initNewPage() { | 181 function initNewPage() { |
| 183 aboutBrowserProxy.reset(); | 182 aboutBrowserProxy.reset(); |
| 184 lifetimeBrowserProxy.reset(); | 183 lifetimeBrowserProxy.reset(); |
| 185 PolymerTest.clearBody(); | 184 PolymerTest.clearBody(); |
| 186 page = document.createElement('settings-about-page'); | 185 page = document.createElement('settings-about-page'); |
| 187 settings.navigateTo(settings.Route.ABOUT); | 186 settings.navigateTo(settings.Route.ABOUT); |
| 188 document.body.appendChild(page); | 187 document.body.appendChild(page); |
| 189 return aboutBrowserProxy.whenCalled('refreshUpdateStatus'); | 188 if (!cr.isChromeOS) { |
| 189 return aboutBrowserProxy.whenCalled('refreshUpdateStatus'); |
| 190 } else { |
| 191 return Promise.all([ |
| 192 aboutBrowserProxy.whenCalled('getChannelInfo'), |
| 193 aboutBrowserProxy.whenCalled('refreshUpdateStatus'), |
| 194 ]); |
| 195 } |
| 190 } | 196 } |
| 191 | 197 |
| 192 /** | 198 /** |
| 193 * Test that the status icon and status message update according to | 199 * Test that the status icon and status message update according to |
| 194 * incoming 'update-status-changed' events. | 200 * incoming 'update-status-changed' events. |
| 195 */ | 201 */ |
| 196 test('IconAndMessageUpdates', function() { | 202 test('IconAndMessageUpdates', function() { |
| 197 var icon = page.$$('iron-icon'); | 203 var icon = page.$$('iron-icon'); |
| 198 assertTrue(!!icon); | 204 assertTrue(!!icon); |
| 199 var statusMessageEl = page.$.updateStatusMessage; | 205 var statusMessageEl = page.$.updateStatusMessage; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 osVersion: 'dummyOsVersion', | 584 osVersion: 'dummyOsVersion', |
| 579 }; | 585 }; |
| 580 browserProxy.setVersionInfo(versionInfo); | 586 browserProxy.setVersionInfo(versionInfo); |
| 581 | 587 |
| 582 page = document.createElement('settings-detailed-build-info'); | 588 page = document.createElement('settings-detailed-build-info'); |
| 583 document.body.appendChild(page); | 589 document.body.appendChild(page); |
| 584 | 590 |
| 585 return Promise.all([ | 591 return Promise.all([ |
| 586 browserProxy.whenCalled('pageReady'), | 592 browserProxy.whenCalled('pageReady'), |
| 587 browserProxy.whenCalled('getVersionInfo'), | 593 browserProxy.whenCalled('getVersionInfo'), |
| 588 browserProxy.whenCalled('getCurrentChannel'), | 594 browserProxy.whenCalled('getChannelInfo'), |
| 589 ]).then(function() { | 595 ]).then(function() { |
| 590 assertEquals(versionInfo.arcVersion, page.$.arcVersion.textContent); | 596 assertEquals(versionInfo.arcVersion, page.$.arcVersion.textContent); |
| 591 assertEquals(versionInfo.osVersion, page.$.osVersion.textContent); | 597 assertEquals(versionInfo.osVersion, page.$.osVersion.textContent); |
| 592 assertEquals(versionInfo.osFirmware, page.$.osFirmware.textContent); | 598 assertEquals(versionInfo.osFirmware, page.$.osFirmware.textContent); |
| 593 }); | 599 }); |
| 594 }); | 600 }); |
| 595 | 601 |
| 596 /** | 602 /** |
| 597 * Checks whether the "change channel" button state (enabled/disabled) | 603 * Checks whether the "change channel" button state (enabled/disabled) |
| 598 * correctly reflects whether the user is allowed to change channel (as | 604 * correctly reflects whether the user is allowed to change channel (as |
| 599 * dictated by the browser via loadTimeData boolean). | 605 * dictated by the browser via loadTimeData boolean). |
| 600 * @param {boolean} canChangeChannel Whether to simulate the case where | 606 * @param {boolean} canChangeChannel Whether to simulate the case where |
| 601 * changing channels is allowed. | 607 * changing channels is allowed. |
| 608 * @return {!Promise} |
| 602 */ | 609 */ |
| 603 function checkChangeChannelButton(canChangeChannel) { | 610 function checkChangeChannelButton(canChangeChannel) { |
| 604 loadTimeData.overrideValues({ | 611 browserProxy.setCanChangeChannel(canChangeChannel); |
| 605 aboutCanChangeChannel: canChangeChannel | |
| 606 }); | |
| 607 page = document.createElement('settings-detailed-build-info'); | 612 page = document.createElement('settings-detailed-build-info'); |
| 608 document.body.appendChild(page); | 613 document.body.appendChild(page); |
| 609 | 614 return browserProxy.whenCalled('getChannelInfo').then(function() { |
| 610 var changeChannelButton = page.$$('paper-button'); | 615 var changeChannelButton = page.$$('paper-button'); |
| 611 assertTrue(!!changeChannelButton); | 616 assertTrue(!!changeChannelButton); |
| 612 assertEquals(canChangeChannel, !changeChannelButton.disabled) | 617 assertEquals(canChangeChannel, !changeChannelButton.disabled); |
| 618 }); |
| 613 } | 619 } |
| 614 | 620 |
| 615 test('ChangeChannel_Enabled', function() { | 621 test('ChangeChannel_Enabled', function() { |
| 616 checkChangeChannelButton(true); | 622 return checkChangeChannelButton(true); |
| 617 }); | 623 }); |
| 618 | 624 |
| 619 test('ChangeChannel_Disabled', function() { | 625 test('ChangeChannel_Disabled', function() { |
| 620 checkChangeChannelButton(false); | 626 return checkChangeChannelButton(false); |
| 621 }); | 627 }); |
| 622 }); | 628 }); |
| 623 } | 629 } |
| 624 | 630 |
| 625 function registerChannelSwitcherDialogTests() { | 631 function registerChannelSwitcherDialogTests() { |
| 626 suite('ChannelSwitcherDialogTest', function() { | 632 suite('ChannelSwitcherDialogTest', function() { |
| 627 var dialog = null; | 633 var dialog = null; |
| 628 var radioButtons = null; | 634 var radioButtons = null; |
| 629 var browserProxy = null; | 635 var browserProxy = null; |
| 630 var currentChannel = BrowserChannel.BETA; | 636 var currentChannel = BrowserChannel.BETA; |
| 631 | 637 |
| 632 setup(function() { | 638 setup(function() { |
| 633 browserProxy = new TestAboutPageBrowserProxy(); | 639 browserProxy = new TestAboutPageBrowserProxy(); |
| 634 browserProxy.setChannels(currentChannel, currentChannel); | 640 browserProxy.setChannels(currentChannel, currentChannel); |
| 635 settings.AboutPageBrowserProxyImpl.instance_ = browserProxy; | 641 settings.AboutPageBrowserProxyImpl.instance_ = browserProxy; |
| 636 PolymerTest.clearBody(); | 642 PolymerTest.clearBody(); |
| 637 dialog = document.createElement('settings-channel-switcher-dialog'); | 643 dialog = document.createElement('settings-channel-switcher-dialog'); |
| 638 document.body.appendChild(dialog); | 644 document.body.appendChild(dialog); |
| 639 | 645 |
| 640 radioButtons = dialog.shadowRoot.querySelectorAll( | 646 radioButtons = dialog.shadowRoot.querySelectorAll( |
| 641 'paper-radio-button'); | 647 'paper-radio-button'); |
| 642 assertEquals(3, radioButtons.length); | 648 assertEquals(3, radioButtons.length); |
| 643 return browserProxy.whenCalled('getCurrentChannel'); | 649 return browserProxy.whenCalled('getChannelInfo'); |
| 644 }); | 650 }); |
| 645 | 651 |
| 646 teardown(function() { dialog.remove(); }); | 652 teardown(function() { dialog.remove(); }); |
| 647 | 653 |
| 648 test('Initialization', function() { | 654 test('Initialization', function() { |
| 649 var radioGroup = dialog.$$('paper-radio-group'); | 655 var radioGroup = dialog.$$('paper-radio-group'); |
| 650 assertTrue(!!radioGroup); | 656 assertTrue(!!radioGroup); |
| 651 assertTrue(!!dialog.$.warning); | 657 assertTrue(!!dialog.$.warning); |
| 652 assertTrue(!!dialog.$.changeChannel); | 658 assertTrue(!!dialog.$.changeChannel); |
| 653 assertTrue(!!dialog.$.changeChannelAndPowerwash); | 659 assertTrue(!!dialog.$.changeChannelAndPowerwash); |
| 654 | 660 |
| 655 // Check that upon initialization the radio button corresponding to | 661 // Check that upon initialization the radio button corresponding to |
| 656 // the current release channel is pre-selected. | 662 // the current release channel is pre-selected. |
| 657 assertEquals(currentChannel, radioGroup.selected); | 663 assertEquals(currentChannel, radioGroup.selected); |
| 658 assertTrue(dialog.$.warning.hidden); | 664 assertTrue(dialog.$.warning.hidden); |
| 659 | 665 |
| 660 // Check that action buttons are hidden when current and target | 666 // Check that action buttons are hidden when current and target |
| 661 // channel are the same. | 667 // channel are the same. |
| 662 assertTrue(dialog.$.changeChannel.hidden); | 668 assertTrue(dialog.$.changeChannel.hidden); |
| 663 assertTrue(dialog.$.changeChannelAndPowerwash.hidden); | 669 assertTrue(dialog.$.changeChannelAndPowerwash.hidden); |
| 664 }); | 670 }); |
| 665 | 671 |
| 666 // Test case where user switches to a less stable channel. | 672 // Test case where user switches to a less stable channel. |
| 667 test('ChangeChannel_LessStable', function() { | 673 test('ChangeChannel_LessStable', function() { |
| 668 assertEquals(BrowserChannel.DEV, radioButtons.item(2).name); | 674 assertEquals(BrowserChannel.DEV, radioButtons.item(2).name); |
| 669 MockInteractions.tap(radioButtons.item(2)); | 675 MockInteractions.tap(radioButtons.item(2)); |
| 670 Polymer.dom.flush(); | 676 Polymer.dom.flush(); |
| 671 | 677 |
| 672 assertFalse(dialog.$.warning.hidden); | 678 return browserProxy.whenCalled('getChannelInfo').then(function() { |
| 673 // Check that only the "Change channel" button becomes visible. | 679 assertFalse(dialog.$.warning.hidden); |
| 674 assertTrue(dialog.$.changeChannelAndPowerwash.hidden); | 680 // Check that only the "Change channel" button becomes visible. |
| 675 assertFalse(dialog.$.changeChannel.hidden); | 681 assertTrue(dialog.$.changeChannelAndPowerwash.hidden); |
| 682 assertFalse(dialog.$.changeChannel.hidden); |
| 676 | 683 |
| 677 var whenTargetChannelChangedFired = test_util.eventToPromise( | 684 var whenTargetChannelChangedFired = test_util.eventToPromise( |
| 678 'target-channel-changed', dialog); | 685 'target-channel-changed', dialog); |
| 679 | 686 |
| 680 MockInteractions.tap(dialog.$.changeChannel); | 687 MockInteractions.tap(dialog.$.changeChannel); |
| 681 return browserProxy.whenCalled('setChannel').then(function(args) { | 688 return browserProxy.whenCalled('setChannel').then(function(args) { |
| 682 assertEquals(BrowserChannel.DEV, args[0]); | 689 assertEquals(BrowserChannel.DEV, args[0]); |
| 683 assertFalse(args[1]); | 690 assertFalse(args[1]); |
| 684 return whenTargetChannelChangedFired; | 691 return whenTargetChannelChangedFired; |
| 685 }).then(function(event) { | 692 }).then(function(event) { |
| 686 assertEquals(BrowserChannel.DEV, event.detail); | 693 assertEquals(BrowserChannel.DEV, event.detail); |
| 694 }); |
| 687 }); | 695 }); |
| 688 }); | 696 }); |
| 689 | 697 |
| 690 // Test case where user switches to a more stable channel. | 698 // Test case where user switches to a more stable channel. |
| 691 test('ChangeChannel_MoreStable', function() { | 699 test('ChangeChannel_MoreStable', function() { |
| 692 assertEquals(BrowserChannel.STABLE, radioButtons.item(0).name); | 700 assertEquals(BrowserChannel.STABLE, radioButtons.item(0).name); |
| 693 MockInteractions.tap(radioButtons.item(0)); | 701 MockInteractions.tap(radioButtons.item(0)); |
| 694 Polymer.dom.flush(); | 702 Polymer.dom.flush(); |
| 695 | 703 |
| 696 assertFalse(dialog.$.warning.hidden); | 704 return browserProxy.whenCalled('getChannelInfo').then(function() { |
| 697 // Check that only the "Change channel and Powerwash" button becomes | 705 assertFalse(dialog.$.warning.hidden); |
| 698 // visible. | 706 // Check that only the "Change channel and Powerwash" button becomes |
| 699 assertFalse(dialog.$.changeChannelAndPowerwash.hidden); | 707 // visible. |
| 700 assertTrue(dialog.$.changeChannel.hidden); | 708 assertFalse(dialog.$.changeChannelAndPowerwash.hidden); |
| 709 assertTrue(dialog.$.changeChannel.hidden); |
| 701 | 710 |
| 702 var whenTargetChannelChangedFired = test_util.eventToPromise( | 711 var whenTargetChannelChangedFired = test_util.eventToPromise( |
| 703 'target-channel-changed', dialog); | 712 'target-channel-changed', dialog); |
| 704 | 713 |
| 705 MockInteractions.tap(dialog.$.changeChannelAndPowerwash); | 714 MockInteractions.tap(dialog.$.changeChannelAndPowerwash); |
| 706 return browserProxy.whenCalled('setChannel').then(function(args) { | 715 return browserProxy.whenCalled('setChannel').then(function(args) { |
| 707 assertEquals(BrowserChannel.STABLE, args[0]); | 716 assertEquals(BrowserChannel.STABLE, args[0]); |
| 708 assertTrue(args[1]); | 717 assertTrue(args[1]); |
| 709 return whenTargetChannelChangedFired; | 718 return whenTargetChannelChangedFired; |
| 710 }).then(function(event) { | 719 }).then(function(event) { |
| 711 assertEquals(BrowserChannel.STABLE, event.detail); | 720 assertEquals(BrowserChannel.STABLE, event.detail); |
| 721 }); |
| 712 }); | 722 }); |
| 713 }); | 723 }); |
| 714 }); | 724 }); |
| 715 } | 725 } |
| 716 } | 726 } |
| 717 | 727 |
| 718 return { | 728 return { |
| 719 registerTests: function() { | 729 registerTests: function() { |
| 720 if (cr.isChromeOS) { | 730 if (cr.isChromeOS) { |
| 721 registerDetailedBuildInfoTests(); | 731 registerDetailedBuildInfoTests(); |
| 722 registerChannelSwitcherDialogTests(); | 732 registerChannelSwitcherDialogTests(); |
| 723 } | 733 } |
| 724 registerAboutPageTests(); | 734 registerAboutPageTests(); |
| 725 }, | 735 }, |
| 726 registerOfficialBuildTests: registerOfficialBuildTests, | 736 registerOfficialBuildTests: registerOfficialBuildTests, |
| 727 }; | 737 }; |
| 728 }); | 738 }); |
| OLD | NEW |