| 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         'getCurrentChannel', | 
| 22         'getTargetChannel', | 22         'getTargetChannel', | 
| 23         'getVersionInfo', | 23         'getVersionInfo', | 
| 24         'getRegulatoryInfo'); | 24         'getRegulatoryInfo', | 
|  | 25         'setChannel'); | 
| 25     } | 26     } | 
| 26 | 27 | 
| 27     settings.TestBrowserProxy.call(this, methodNames); | 28     settings.TestBrowserProxy.call(this, methodNames); | 
| 28 | 29 | 
| 29     /** @private {!UpdateStatus} */ | 30     /** @private {!UpdateStatus} */ | 
| 30     this.updateStatus_ = UpdateStatus.UPDATED; | 31     this.updateStatus_ = UpdateStatus.UPDATED; | 
| 31 | 32 | 
| 32     if (cr.isChromeOS) { | 33     if (cr.isChromeOS) { | 
| 33       /** @type {!VersionInfo} */ | 34       /** @type {!VersionInfo} */ | 
| 34       this.versionInfo_ = { | 35       this.versionInfo_ = { | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 118     TestAboutPageBrowserProxy.prototype.getVersionInfo = function() { | 119     TestAboutPageBrowserProxy.prototype.getVersionInfo = function() { | 
| 119       this.methodCalled('getVersionInfo'); | 120       this.methodCalled('getVersionInfo'); | 
| 120       return Promise.resolve(this.versionInfo_); | 121       return Promise.resolve(this.versionInfo_); | 
| 121     }; | 122     }; | 
| 122 | 123 | 
| 123     /** @override */ | 124     /** @override */ | 
| 124     TestAboutPageBrowserProxy.prototype.getRegulatoryInfo = function() { | 125     TestAboutPageBrowserProxy.prototype.getRegulatoryInfo = function() { | 
| 125       this.methodCalled('getRegulatoryInfo'); | 126       this.methodCalled('getRegulatoryInfo'); | 
| 126       return Promise.resolve(this.regulatoryInfo_); | 127       return Promise.resolve(this.regulatoryInfo_); | 
| 127     }; | 128     }; | 
|  | 129 | 
|  | 130     /** @override */ | 
|  | 131     TestAboutPageBrowserProxy.prototype.setChannel = function( | 
|  | 132         channel, isPowerwashAllowed) { | 
|  | 133       this.methodCalled('setChannel', [channel, isPowerwashAllowed]); | 
|  | 134     }; | 
| 128   } | 135   } | 
| 129 | 136 | 
| 130 | 137 | 
| 131   function registerAboutPageTests() { | 138   function registerAboutPageTests() { | 
| 132     /** @param {!UpdateStatus} status */ | 139     /** @param {!UpdateStatus} status */ | 
| 133     function fireStatusChanged(status) { | 140     function fireStatusChanged(status) { | 
| 134       cr.webUIListenerCallback('update-status-changed', {status: status}); | 141       cr.webUIListenerCallback('update-status-changed', {status: status}); | 
| 135     } | 142     } | 
| 136 | 143 | 
| 137     suite('AboutPageTest', function() { | 144     suite('AboutPageTest', function() { | 
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 408             browserProxy.whenCalled('getVersionInfo'), | 415             browserProxy.whenCalled('getVersionInfo'), | 
| 409             browserProxy.whenCalled('getCurrentChannel'), | 416             browserProxy.whenCalled('getCurrentChannel'), | 
| 410           ]).then(function() { | 417           ]).then(function() { | 
| 411             assertEquals(versionInfo.arcVersion, page.$.arcVersion.textContent); | 418             assertEquals(versionInfo.arcVersion, page.$.arcVersion.textContent); | 
| 412             assertEquals(versionInfo.osVersion, page.$.osVersion.textContent); | 419             assertEquals(versionInfo.osVersion, page.$.osVersion.textContent); | 
| 413             assertEquals(versionInfo.osFirmware, page.$.osFirmware.textContent); | 420             assertEquals(versionInfo.osFirmware, page.$.osFirmware.textContent); | 
| 414           }); | 421           }); | 
| 415         }); | 422         }); | 
| 416       }); | 423       }); | 
| 417     } | 424     } | 
|  | 425 | 
|  | 426     function registerChannelSwitcherDialogTests() { | 
|  | 427       /** | 
|  | 428        * Converts an event occurrence to a promise. | 
|  | 429        * @param {string} eventType | 
|  | 430        * @param {!HTMLElement} target | 
|  | 431        * @return {!Promise} A promise firing once the event occurs. | 
|  | 432        * TODO(dpapad); Share this code with certificate_manager_page_test.js | 
|  | 433        * identical helper method. | 
|  | 434        */ | 
|  | 435       function eventToPromise(eventType, target) { | 
|  | 436         return new Promise(function(resolve, reject) { | 
|  | 437           target.addEventListener(eventType, resolve); | 
|  | 438         }); | 
|  | 439       } | 
|  | 440 | 
|  | 441       suite('ChannelSwitcherDialogTest', function() { | 
|  | 442         var dialog = null; | 
|  | 443         var radioButtons = null; | 
|  | 444         var browserProxy = null; | 
|  | 445         var currentChannel = BrowserChannel.BETA; | 
|  | 446 | 
|  | 447         setup(function() { | 
|  | 448           browserProxy = new TestAboutPageBrowserProxy(); | 
|  | 449           browserProxy.setChannels(currentChannel, currentChannel); | 
|  | 450           settings.AboutPageBrowserProxyImpl.instance_ = browserProxy; | 
|  | 451           PolymerTest.clearBody(); | 
|  | 452           dialog = document.createElement('settings-channel-switcher-dialog'); | 
|  | 453           document.body.appendChild(dialog); | 
|  | 454 | 
|  | 455           radioButtons = dialog.shadowRoot.querySelectorAll( | 
|  | 456               'paper-radio-button'); | 
|  | 457           assertEquals(3, radioButtons.length); | 
|  | 458           return browserProxy.whenCalled('getCurrentChannel'); | 
|  | 459         }); | 
|  | 460 | 
|  | 461         teardown(function() { dialog.remove(); }); | 
|  | 462 | 
|  | 463         test('Initialization', function() { | 
|  | 464           var radioGroup = dialog.$$('paper-radio-group'); | 
|  | 465           assertTrue(!!radioGroup); | 
|  | 466           assertTrue(!!dialog.$.warning); | 
|  | 467           assertTrue(!!dialog.$.changeChannel); | 
|  | 468           assertTrue(!!dialog.$.changeChannelAndPowerwash); | 
|  | 469 | 
|  | 470           // Check that upon initialization the radio button corresponding to | 
|  | 471           // the current release channel is pre-selected. | 
|  | 472           assertEquals(currentChannel, radioGroup.selected); | 
|  | 473           assertTrue(dialog.$.warning.hidden); | 
|  | 474 | 
|  | 475           // Check that action buttons are hidden when current and target | 
|  | 476           // channel are the same. | 
|  | 477           assertTrue(dialog.$.changeChannel.hidden); | 
|  | 478           assertTrue(dialog.$.changeChannelAndPowerwash.hidden); | 
|  | 479         }); | 
|  | 480 | 
|  | 481         // Test case where user switches to a less stable channel. | 
|  | 482         test('ChangeChannel_LessStable', function() { | 
|  | 483           assertEquals(BrowserChannel.DEV, radioButtons.item(2).name); | 
|  | 484           MockInteractions.tap(radioButtons.item(2)); | 
|  | 485           Polymer.dom.flush(); | 
|  | 486 | 
|  | 487           assertFalse(dialog.$.warning.hidden); | 
|  | 488           // Check that only the "Change channel" button becomes visible. | 
|  | 489           assertTrue(dialog.$.changeChannelAndPowerwash.hidden); | 
|  | 490           assertFalse(dialog.$.changeChannel.hidden); | 
|  | 491 | 
|  | 492           var whenTargetChannelChangedFired = eventToPromise( | 
|  | 493               'target-channel-changed', dialog); | 
|  | 494 | 
|  | 495           MockInteractions.tap(dialog.$.changeChannel); | 
|  | 496           return browserProxy.whenCalled('setChannel').then(function(args) { | 
|  | 497             assertEquals(BrowserChannel.DEV, args[0]); | 
|  | 498             assertFalse(args[1]); | 
|  | 499             return whenTargetChannelChangedFired; | 
|  | 500           }).then(function(event) { | 
|  | 501             assertEquals(BrowserChannel.DEV, event.detail); | 
|  | 502           }); | 
|  | 503         }); | 
|  | 504 | 
|  | 505         // Test case where user switches to a more stable channel. | 
|  | 506         test('ChangeChannel_MoreStable', function() { | 
|  | 507           assertEquals(BrowserChannel.STABLE, radioButtons.item(0).name); | 
|  | 508           MockInteractions.tap(radioButtons.item(0)); | 
|  | 509           Polymer.dom.flush(); | 
|  | 510 | 
|  | 511           assertFalse(dialog.$.warning.hidden); | 
|  | 512           // Check that only the "Change channel and Powerwash" button becomes | 
|  | 513           // visible. | 
|  | 514           assertFalse(dialog.$.changeChannelAndPowerwash.hidden); | 
|  | 515           assertTrue(dialog.$.changeChannel.hidden); | 
|  | 516 | 
|  | 517           var whenTargetChannelChangedFired = eventToPromise( | 
|  | 518               'target-channel-changed', dialog); | 
|  | 519 | 
|  | 520           MockInteractions.tap(dialog.$.changeChannelAndPowerwash); | 
|  | 521           return browserProxy.whenCalled('setChannel').then(function(args) { | 
|  | 522             assertEquals(BrowserChannel.STABLE, args[0]); | 
|  | 523             assertTrue(args[1]); | 
|  | 524             return whenTargetChannelChangedFired; | 
|  | 525           }).then(function(event) { | 
|  | 526             assertEquals(BrowserChannel.STABLE, event.detail); | 
|  | 527           }); | 
|  | 528         }); | 
|  | 529       }); | 
|  | 530     } | 
| 418   } | 531   } | 
| 419 | 532 | 
| 420   return { | 533   return { | 
| 421     registerTests: function() { | 534     registerTests: function() { | 
| 422       if (cr.isChromeOS) { | 535       if (cr.isChromeOS) { | 
| 423         registerDetailedBuildInfoTests(); | 536         registerDetailedBuildInfoTests(); | 
|  | 537         registerChannelSwitcherDialogTests(); | 
| 424       } | 538       } | 
| 425       registerAboutPageTests(); | 539       registerAboutPageTests(); | 
| 426     }, | 540     }, | 
| 427     registerOfficialBuildTests: registerOfficialBuildTests, | 541     registerOfficialBuildTests: registerOfficialBuildTests, | 
| 428   }; | 542   }; | 
| 429 }); | 543 }); | 
| OLD | NEW | 
|---|