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('settings_startup_urls_page', function() { | 5 cr.define('settings_startup_urls_page', function() { |
| 6 /** | 6 /** |
| 7 * @constructor | 7 * @constructor |
| 8 * @implements {settings.StartupUrlsPageBrowserProxy} | 8 * @implements {settings.StartupUrlsPageBrowserProxy} |
| 9 * @extends {settings.TestBrowserProxy} | 9 * @extends {settings.TestBrowserProxy} |
| 10 */ | 10 */ |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 /** @type {?SettingsStartupUrlsPageElement} */ | 189 /** @type {?SettingsStartupUrlsPageElement} */ |
| 190 var page = null; | 190 var page = null; |
| 191 | 191 |
| 192 var browserProxy = null; | 192 var browserProxy = null; |
| 193 | 193 |
| 194 setup(function() { | 194 setup(function() { |
| 195 browserProxy = new TestStartupUrlsPageBrowserProxy(); | 195 browserProxy = new TestStartupUrlsPageBrowserProxy(); |
| 196 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; | 196 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; |
| 197 PolymerTest.clearBody(); | 197 PolymerTest.clearBody(); |
| 198 page = document.createElement('settings-startup-urls-page'); | 198 page = document.createElement('settings-startup-urls-page'); |
| 199 page.prefs = { | |
| 200 session: { | |
| 201 restore_on_startup: { | |
| 202 type: chrome.settingsPrivate.PrefType.NUMBER, | |
| 203 value: 5, | |
| 204 }, | |
| 205 }, | |
| 206 }; | |
| 199 document.body.appendChild(page); | 207 document.body.appendChild(page); |
| 208 Polymer.dom.flush(); | |
| 200 }); | 209 }); |
| 201 | 210 |
| 202 teardown(function() { page.remove(); }); | 211 teardown(function() { page.remove(); }); |
| 203 | 212 |
| 204 // Test that the page is requesting information from the browser. | 213 // Test that the page is requesting information from the browser. |
| 205 test('Initialization', function() { | 214 test('Initialization', function() { |
| 206 return browserProxy.whenCalled('loadStartupPages'); | 215 return browserProxy.whenCalled('loadStartupPages'); |
| 207 }); | 216 }); |
| 208 | 217 |
| 209 test('UseCurrentPages', function() { | 218 test('UseCurrentPages', function() { |
| 210 var useCurrentPagesButton = page.$.useCurrentPages; | 219 var useCurrentPagesButton = page.$$('#useCurrentPages'); |
| 211 assertTrue(!!useCurrentPagesButton); | 220 assertTrue(!!useCurrentPagesButton); |
| 212 MockInteractions.tap(useCurrentPagesButton); | 221 MockInteractions.tap(useCurrentPagesButton); |
| 213 return browserProxy.whenCalled('useCurrentPages'); | 222 return browserProxy.whenCalled('useCurrentPages'); |
| 214 }); | 223 }); |
| 215 | 224 |
| 216 test('AddPage_OpensDialog', function() { | 225 test('AddPage_OpensDialog', function() { |
| 217 var addPageButton = page.$.addPage; | 226 var addPageButton = page.$$('#addPage'); |
| 218 assertTrue(!!addPageButton); | 227 assertTrue(!!addPageButton); |
| 219 assertFalse(!!page.$$('settings-startup-url-dialog')); | 228 assertFalse(!!page.$$('settings-startup-url-dialog')); |
| 220 | 229 |
| 221 MockInteractions.tap(addPageButton); | 230 MockInteractions.tap(addPageButton); |
| 222 Polymer.dom.flush(); | 231 Polymer.dom.flush(); |
| 223 assertTrue(!!page.$$('settings-startup-url-dialog')); | 232 assertTrue(!!page.$$('settings-startup-url-dialog')); |
| 224 }); | 233 }); |
| 225 | 234 |
| 226 test('EditPage_OpensDialog', function() { | 235 test('EditPage_OpensDialog', function() { |
| 227 assertFalse(!!page.$$('settings-startup-url-dialog')); | 236 assertFalse(!!page.$$('settings-startup-url-dialog')); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 248 cr.webUIListenerCallback('update-startup-pages', [entry1, entry2]); | 257 cr.webUIListenerCallback('update-startup-pages', [entry1, entry2]); |
| 249 page.fire(settings.EDIT_STARTUP_URL_EVENT, entry2); | 258 page.fire(settings.EDIT_STARTUP_URL_EVENT, entry2); |
| 250 Polymer.dom.flush(); | 259 Polymer.dom.flush(); |
| 251 | 260 |
| 252 assertTrue(!!page.$$('settings-startup-url-dialog')); | 261 assertTrue(!!page.$$('settings-startup-url-dialog')); |
| 253 cr.webUIListenerCallback('update-startup-pages', [entry1]); | 262 cr.webUIListenerCallback('update-startup-pages', [entry1]); |
| 254 Polymer.dom.flush(); | 263 Polymer.dom.flush(); |
| 255 | 264 |
| 256 assertFalse(!!page.$$('settings-startup-url-dialog')); | 265 assertFalse(!!page.$$('settings-startup-url-dialog')); |
| 257 }); | 266 }); |
| 267 | |
| 268 test('StarupPages_WhenExtensionControlled', function() { | |
| 269 assertFalse(!!page.get('prefs.session.startup_urls.controlledBy')); | |
| 270 assertFalse(!!page.$$('extension-controlled-indicator')); | |
| 271 assertTrue(!!page.$$('#addPage')); | |
| 272 assertTrue(!!page.$$('#useCurrentPages')); | |
| 273 | |
| 274 page.set('prefs.session.startup_urls', { | |
| 275 controlledBy: chrome.settingsPrivate.ControlledBy.EXTENSION, | |
| 276 controlledByName: 'Totally Real Extension', | |
| 277 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED, | |
| 278 extensionId: 'mefmhpjnkplhdhmfmblilkgpkbjebmij', | |
| 279 type: chrome.settingsPrivate.PrefType.NUMBER, | |
| 280 value: 5, | |
| 281 }); | |
| 282 Polymer.dom.flush(); | |
| 283 | |
| 284 assertTrue(!!page.$$('extension-controlled-indicator')); | |
| 285 assertFalse(!!page.$$('#addPage')); | |
| 286 assertFalse(!!page.$$('#useCurrentPages')); | |
| 287 }); | |
| 258 }); | 288 }); |
| 259 | 289 |
| 260 /** @return {!StartupPageInfo} */ | 290 /** @return {!StartupPageInfo} */ |
| 261 function createSampleUrlEntry() { | 291 function createSampleUrlEntry() { |
| 262 return { | 292 return { |
| 263 modelIndex: 2, | 293 modelIndex: 2, |
| 264 title: 'Test page', | 294 title: 'Test page', |
| 265 tooltip: 'test tooltip', | 295 tooltip: 'test tooltip', |
| 266 url: 'chrome://foo', | 296 url: 'chrome://foo', |
| 267 }; | 297 }; |
| 268 } | 298 } |
| 269 | 299 |
| 270 suite('StartupUrlEntry', function() { | 300 suite('StartupUrlEntry', function() { |
| 271 /** @type {?SettingsStartupUrlEntryElement} */ | 301 /** @type {?SettingsStartupUrlEntryElement} */ |
| 272 var element = null; | 302 var element = null; |
| 273 | 303 |
| 274 var browserProxy = null; | 304 var browserProxy = null; |
| 275 | 305 |
| 276 setup(function() { | 306 setup(function() { |
| 277 browserProxy = new TestStartupUrlsPageBrowserProxy(); | 307 browserProxy = new TestStartupUrlsPageBrowserProxy(); |
| 278 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; | 308 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; |
| 279 PolymerTest.clearBody(); | 309 PolymerTest.clearBody(); |
| 280 element = document.createElement('settings-startup-url-entry'); | 310 element = document.createElement('settings-startup-url-entry'); |
| 281 element.model = createSampleUrlEntry(); | 311 element.model = createSampleUrlEntry(); |
| 282 document.body.appendChild(element); | 312 document.body.appendChild(element); |
| 283 | |
| 284 // Bring up the popup menu for the following tests to use. | |
| 285 assertFalse(!!element.$$('dialog[is=cr-action-menu]')); | |
| 286 MockInteractions.tap(element.$.dots); | |
| 287 Polymer.dom.flush(); | 313 Polymer.dom.flush(); |
| 288 assertTrue(!!element.$$('dialog[is=cr-action-menu]')); | |
| 289 }); | 314 }); |
| 290 | 315 |
| 291 teardown(function() { element.remove(); }); | 316 teardown(function() { element.remove(); }); |
| 292 | 317 |
| 293 test('MenuOptions_Remove', function() { | 318 test('MenuOptions_Remove', function() { |
| 319 element.editable = true; | |
|
dpapad
2016/11/19 01:32:39
Nit (optional): Perhaps do this in setup() so that
Dan Beam
2016/11/19 01:55:28
eh, that results in more touching of the prod code
Dan Beam
2016/11/19 01:55:49
(if I don't add restamp to the dom-if in the prod
| |
| 320 Polymer.dom.flush(); | |
| 321 | |
| 322 // Bring up the popup menu. | |
| 323 assertFalse(!!element.$$('dialog[is=cr-action-menu]')); | |
| 324 MockInteractions.tap(element.$$('#dots')); | |
| 325 Polymer.dom.flush(); | |
| 326 assertTrue(!!element.$$('dialog[is=cr-action-menu]')); | |
| 327 | |
| 294 var removeButton = element.shadowRoot.querySelector('#remove') | 328 var removeButton = element.shadowRoot.querySelector('#remove') |
| 295 MockInteractions.tap(removeButton); | 329 MockInteractions.tap(removeButton); |
| 296 return browserProxy.whenCalled('removeStartupPage').then( | 330 return browserProxy.whenCalled('removeStartupPage').then( |
| 297 function(modelIndex) { | 331 function(modelIndex) { |
| 298 assertEquals(element.model.modelIndex, modelIndex); | 332 assertEquals(element.model.modelIndex, modelIndex); |
| 299 }); | 333 }); |
| 300 }); | 334 }); |
| 335 | |
| 336 test('Editable', function() { | |
| 337 assertFalse(!!element.editable); | |
| 338 assertFalse(!!element.$$('#dots')); | |
| 339 | |
| 340 element.editable = true; | |
| 341 Polymer.dom.flush(); | |
| 342 assertTrue(!!element.$$('#dots')); | |
| 343 }); | |
| 301 }); | 344 }); |
| 302 }); | 345 }); |
| OLD | NEW |