| 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 settings.TestBrowserProxy.call(this, [ | 12 var methodNames = [ |
| 13 'pageReady', | 13 'pageReady', |
| 14 'refreshUpdateStatus', | 14 'refreshUpdateStatus', |
| 15 'openHelpPage', | 15 'openHelpPage', |
| 16 'openFeedbackDialog', | 16 'openFeedbackDialog', |
| 17 'getCurrentChannel', | 17 ]; |
| 18 'getTargetChannel', | |
| 19 'getVersionInfo', | |
| 20 ]); | |
| 21 | 18 |
| 22 /** @type {!VersionInfo} */ | 19 if (cr.isChromeOS) { |
| 23 this.versionInfo_ = { | 20 methodNames.push( |
| 24 arcVersion: '', | 21 'getCurrentChannel', |
| 25 osFirmware: '', | 22 'getTargetChannel', |
| 26 osVersion: '', | 23 'getVersionInfo', |
| 27 }; | 24 'getRegulatoryInfo'); |
| 25 } |
| 26 |
| 27 settings.TestBrowserProxy.call(this, methodNames); |
| 28 | 28 |
| 29 /** @private {!UpdateStatus} */ | 29 /** @private {!UpdateStatus} */ |
| 30 this.updateStatus_ = UpdateStatus.UPDATED; | 30 this.updateStatus_ = UpdateStatus.UPDATED; |
| 31 | 31 |
| 32 if (cr.isChromeOS) { | 32 if (cr.isChromeOS) { |
| 33 /** @type {!VersionInfo} */ |
| 34 this.versionInfo_ = { |
| 35 arcVersion: '', |
| 36 osFirmware: '', |
| 37 osVersion: '', |
| 38 }; |
| 39 |
| 33 /** @private {!BrowserChannel} */ | 40 /** @private {!BrowserChannel} */ |
| 34 this.currentChannel_ = BrowserChannel.BETA; | 41 this.currentChannel_ = BrowserChannel.BETA; |
| 35 | 42 |
| 36 /** @private {!BrowserChannel} */ | 43 /** @private {!BrowserChannel} */ |
| 37 this.targetChannel_ = BrowserChannel.BETA; | 44 this.targetChannel_ = BrowserChannel.BETA; |
| 45 |
| 46 /** @private {?RegulatoryInfo} */ |
| 47 this.regulatoryInfo_ = null; |
| 38 } | 48 } |
| 39 }; | 49 }; |
| 40 | 50 |
| 41 TestAboutPageBrowserProxy.prototype = { | 51 TestAboutPageBrowserProxy.prototype = { |
| 42 __proto__: settings.TestBrowserProxy.prototype, | 52 __proto__: settings.TestBrowserProxy.prototype, |
| 43 | 53 |
| 44 /** @param {!VersionInfo} */ | |
| 45 setVersionInfo: function(versionInfo) { | |
| 46 this.versionInfo_ = versionInfo; | |
| 47 }, | |
| 48 | |
| 49 /** @param {!UpdateStatus} updateStatus */ | 54 /** @param {!UpdateStatus} updateStatus */ |
| 50 setUpdateStatus: function(updateStatus) { | 55 setUpdateStatus: function(updateStatus) { |
| 51 this.updateStatus_ = updateStatus; | 56 this.updateStatus_ = updateStatus; |
| 52 }, | 57 }, |
| 53 | 58 |
| 54 /** @override */ | 59 /** @override */ |
| 55 pageReady: function() { | 60 pageReady: function() { |
| 56 this.methodCalled('pageReady'); | 61 this.methodCalled('pageReady'); |
| 57 }, | 62 }, |
| 58 | 63 |
| 59 /** @override */ | 64 /** @override */ |
| 60 refreshUpdateStatus: function() { | 65 refreshUpdateStatus: function() { |
| 61 cr.webUIListenerCallback( | 66 cr.webUIListenerCallback( |
| 62 'update-status-changed', {status: this.updateStatus_}); | 67 'update-status-changed', {status: this.updateStatus_}); |
| 63 this.methodCalled('refreshUpdateStatus'); | 68 this.methodCalled('refreshUpdateStatus'); |
| 64 }, | 69 }, |
| 65 | 70 |
| 66 /** @override */ | 71 /** @override */ |
| 67 openFeedbackDialog: function() { | 72 openFeedbackDialog: function() { |
| 68 this.methodCalled('openFeedbackDialog'); | 73 this.methodCalled('openFeedbackDialog'); |
| 69 }, | 74 }, |
| 70 | 75 |
| 71 /** @override */ | 76 /** @override */ |
| 72 openHelpPage: function() { | 77 openHelpPage: function() { |
| 73 this.methodCalled('openHelpPage'); | 78 this.methodCalled('openHelpPage'); |
| 74 }, | 79 }, |
| 75 }; | 80 }; |
| 76 | 81 |
| 77 if (cr.isChromeOS) { | 82 if (cr.isChromeOS) { |
| 83 /** @param {!VersionInfo} */ |
| 84 TestAboutPageBrowserProxy.prototype.setVersionInfo = function(versionInfo) { |
| 85 this.versionInfo_ = versionInfo; |
| 86 }; |
| 87 |
| 78 /** | 88 /** |
| 79 * @param {!BrowserChannel} current | 89 * @param {!BrowserChannel} current |
| 80 * @param {!BrowserChannel} target | 90 * @param {!BrowserChannel} target |
| 81 */ | 91 */ |
| 82 TestAboutPageBrowserProxy.prototype.setChannels = function( | 92 TestAboutPageBrowserProxy.prototype.setChannels = function( |
| 83 current, target) { | 93 current, target) { |
| 84 this.currentChannel_ = current; | 94 this.currentChannel_ = current; |
| 85 this.targetChannel_ = target; | 95 this.targetChannel_ = target; |
| 86 }; | 96 }; |
| 87 | 97 |
| 98 |
| 99 /** @param {?RegulatoryInfo} regulatoryInfo */ |
| 100 TestAboutPageBrowserProxy.prototype.setRegulatoryInfo = function( |
| 101 regulatoryInfo) { |
| 102 this.regulatoryInfo_ = regulatoryInfo; |
| 103 }; |
| 104 |
| 88 /** @override */ | 105 /** @override */ |
| 89 TestAboutPageBrowserProxy.prototype.getCurrentChannel = function() { | 106 TestAboutPageBrowserProxy.prototype.getCurrentChannel = function() { |
| 90 this.methodCalled('getCurrentChannel'); | 107 this.methodCalled('getCurrentChannel'); |
| 91 return Promise.resolve(this.currentChannel_); | 108 return Promise.resolve(this.currentChannel_); |
| 92 }; | 109 }; |
| 93 | 110 |
| 94 /** @override */ | 111 /** @override */ |
| 95 TestAboutPageBrowserProxy.prototype.getTargetChannel = function() { | 112 TestAboutPageBrowserProxy.prototype.getTargetChannel = function() { |
| 96 this.methodCalled('getTargetChannel'); | 113 this.methodCalled('getTargetChannel'); |
| 97 return Promise.resolve(this.targetChannel_); | 114 return Promise.resolve(this.targetChannel_); |
| 98 }; | 115 }; |
| 99 | 116 |
| 100 /** @override */ | 117 /** @override */ |
| 101 TestAboutPageBrowserProxy.prototype.getVersionInfo = function() { | 118 TestAboutPageBrowserProxy.prototype.getVersionInfo = function() { |
| 102 this.methodCalled('getVersionInfo'); | 119 this.methodCalled('getVersionInfo'); |
| 103 return Promise.resolve(this.versionInfo_); | 120 return Promise.resolve(this.versionInfo_); |
| 104 }; | 121 }; |
| 122 |
| 123 /** @override */ |
| 124 TestAboutPageBrowserProxy.prototype.getRegulatoryInfo = function() { |
| 125 this.methodCalled('getRegulatoryInfo'); |
| 126 return Promise.resolve(this.regulatoryInfo_); |
| 127 }; |
| 105 } | 128 } |
| 106 | 129 |
| 107 | 130 |
| 108 function registerAboutPageTests() { | 131 function registerAboutPageTests() { |
| 109 /** @param {!UpdateStatus} status */ | 132 /** @param {!UpdateStatus} status */ |
| 110 function fireStatusChanged(status) { | 133 function fireStatusChanged(status) { |
| 111 cr.webUIListenerCallback('update-status-changed', {status: status}); | 134 cr.webUIListenerCallback('update-status-changed', {status: status}); |
| 112 } | 135 } |
| 113 | 136 |
| 114 suite('AboutPageTest', function() { | 137 suite('AboutPageTest', function() { |
| 115 var page = null; | 138 var page = null; |
| 116 var browserProxy = null; | 139 var browserProxy = null; |
| 117 | 140 |
| 118 setup(function() { | 141 setup(function() { |
| 119 browserProxy = new TestAboutPageBrowserProxy(); | 142 browserProxy = new TestAboutPageBrowserProxy(); |
| 120 settings.AboutPageBrowserProxyImpl.instance_ = browserProxy; | 143 settings.AboutPageBrowserProxyImpl.instance_ = browserProxy; |
| 121 return initNewPage(); | 144 return initNewPage(); |
| 122 }); | 145 }); |
| 123 | 146 |
| 124 /** @return {!Promise} */ | 147 /** @return {!Promise} */ |
| 125 function initNewPage() { | 148 function initNewPage() { |
| 126 browserProxy.resetResolver('refreshUpdateStatus'); | 149 browserProxy.reset(); |
| 127 PolymerTest.clearBody(); | 150 PolymerTest.clearBody(); |
| 128 page = document.createElement('settings-about-page'); | 151 page = document.createElement('settings-about-page'); |
| 129 document.body.appendChild(page); | 152 document.body.appendChild(page); |
| 130 return browserProxy.whenCalled('refreshUpdateStatus'); | 153 return browserProxy.whenCalled('refreshUpdateStatus'); |
| 131 } | 154 } |
| 132 | 155 |
| 133 /** | 156 /** |
| 134 * Test that the status icon updates according to incoming | 157 * Test that the status icon updates according to incoming |
| 135 * 'update-status-changed' events. | 158 * 'update-status-changed' events. |
| 136 */ | 159 */ |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 browserProxy.setUpdateStatus(UpdateStatus.NEARLY_UPDATED); | 274 browserProxy.setUpdateStatus(UpdateStatus.NEARLY_UPDATED); |
| 252 | 275 |
| 253 return initNewPage().then(function() { | 276 return initNewPage().then(function() { |
| 254 assertTrue(!!page.$.relaunch); | 277 assertTrue(!!page.$.relaunch); |
| 255 assertTrue(!!page.$.relaunchAndPowerwash); | 278 assertTrue(!!page.$.relaunchAndPowerwash); |
| 256 | 279 |
| 257 assertFalse(page.$.relaunch.hidden); | 280 assertFalse(page.$.relaunch.hidden); |
| 258 assertTrue(page.$.relaunchAndPowerwash.hidden); | 281 assertTrue(page.$.relaunchAndPowerwash.hidden); |
| 259 }); | 282 }); |
| 260 }); | 283 }); |
| 284 |
| 285 test('RegulatoryInfo', function() { |
| 286 var regulatoryInfo = null; |
| 287 |
| 288 /** |
| 289 * Checks the visibility of the "regulatory info" section. |
| 290 * @param {boolean} isShowing Whether the section is expected to be |
| 291 * visible. |
| 292 * @return {!Promise} |
| 293 */ |
| 294 function checkRegulatoryInfo(isShowing) { |
| 295 return browserProxy.whenCalled('getRegulatoryInfo').then( |
| 296 function() { |
| 297 var regulatoryInfoEl = page.$.regulatoryInfo; |
| 298 assertTrue(!!regulatoryInfoEl); |
| 299 assertEquals(isShowing, !regulatoryInfoEl.hidden); |
| 300 |
| 301 if (isShowing) { |
| 302 var img = regulatoryInfoEl.querySelector('img'); |
| 303 assertTrue(!!img); |
| 304 assertEquals(regulatoryInfo.text, img.getAttribute('alt')); |
| 305 assertEquals(regulatoryInfo.url, img.getAttribute('src')); |
| 306 } |
| 307 }); |
| 308 } |
| 309 |
| 310 return checkRegulatoryInfo(false).then(function() { |
| 311 regulatoryInfo = {text: 'foo', url: 'bar'}; |
| 312 browserProxy.setRegulatoryInfo(regulatoryInfo); |
| 313 return initNewPage(); |
| 314 }).then(function() { |
| 315 return checkRegulatoryInfo(true); |
| 316 }); |
| 317 }); |
| 261 } | 318 } |
| 262 | 319 |
| 263 if (!cr.isChromeOS) { | 320 if (!cr.isChromeOS) { |
| 264 /* | 321 /* |
| 265 * Test that the "Check for updates" button updates according to | 322 * Test that the "Check for updates" button updates according to |
| 266 * incoming 'update-status-changed' events. | 323 * incoming 'update-status-changed' events. |
| 267 */ | 324 */ |
| 268 test('ButtonsUpdate', function() { | 325 test('ButtonsUpdate', function() { |
| 269 var relaunch = page.$.relaunch; | 326 var relaunch = page.$.relaunch; |
| 270 assertTrue(!!relaunch); | 327 assertTrue(!!relaunch); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 return { | 420 return { |
| 364 registerTests: function() { | 421 registerTests: function() { |
| 365 if (cr.isChromeOS) { | 422 if (cr.isChromeOS) { |
| 366 registerDetailedBuildInfoTests(); | 423 registerDetailedBuildInfoTests(); |
| 367 } | 424 } |
| 368 registerAboutPageTests(); | 425 registerAboutPageTests(); |
| 369 }, | 426 }, |
| 370 registerOfficialBuildTests: registerOfficialBuildTests, | 427 registerOfficialBuildTests: registerOfficialBuildTests, |
| 371 }; | 428 }; |
| 372 }); | 429 }); |
| OLD | NEW |