OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('settings_startup_urls_page', function() { |
| 6 /** |
| 7 * @constructor |
| 8 * @implements {settings.StartupUrlsPageBrowserProxy} |
| 9 * @extends {settings.TestBrowserProxy} |
| 10 */ |
| 11 function TestStartupUrlsPageBrowserProxy() { |
| 12 settings.TestBrowserProxy.call(this, [ |
| 13 'validateStartupPage', |
| 14 'addStartupPage', |
| 15 ]); |
| 16 } |
| 17 |
| 18 TestStartupUrlsPageBrowserProxy.prototype = { |
| 19 __proto__: settings.TestBrowserProxy.prototype, |
| 20 |
| 21 urlsAreValid: false, |
| 22 |
| 23 /** @override */ |
| 24 loadStartupPages: function() {}, |
| 25 |
| 26 /** @override */ |
| 27 validateStartupPage: function(url) { |
| 28 this.methodCalled('validateStartupPage'); |
| 29 var resolver = new PromiseResolver; |
| 30 resolver.promise = Promise.resolve(this.urlsAreValid); |
| 31 return resolver; |
| 32 }, |
| 33 |
| 34 /** @override */ |
| 35 addStartupPage: function(url) { |
| 36 this.methodCalled('addStartupPage'); |
| 37 }, |
| 38 }; |
| 39 |
| 40 suite('StartupUrlsPage', function() { |
| 41 /** @type {?SettingsStartupUrlsPageElement} */ |
| 42 var page = null; |
| 43 |
| 44 var browserProxy = null; |
| 45 |
| 46 setup(function() { |
| 47 browserProxy = new TestStartupUrlsPageBrowserProxy(); |
| 48 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; |
| 49 PolymerTest.clearBody(); |
| 50 page = document.createElement('settings-startup-urls-page'); |
| 51 document.body.appendChild(page); |
| 52 }); |
| 53 |
| 54 teardown(function() { page.remove(); }); |
| 55 |
| 56 test('validate', function() { |
| 57 browserProxy.whenCalled('validateStartupPage').then(function() { |
| 58 var addButton = page.$.add; |
| 59 assertTrue(!!addButton); |
| 60 assertFalse(browserProxy.urlsAreValid); |
| 61 assertTrue(addButton.disabled); |
| 62 |
| 63 browserProxy.resetResolver('validateStartupPage'); |
| 64 browserProxy.whenCalled('validateStartupPage').then(function() { |
| 65 page.async(function() { |
| 66 assertFalse(addButton.disabled); |
| 67 MockInteractions.tap(addButton); |
| 68 }); |
| 69 }); |
| 70 |
| 71 browserProxy.urlsAreValid = true; |
| 72 page.$.newUrl.value = "overriding validation anyway"; |
| 73 }); |
| 74 |
| 75 return browserProxy.whenCalled('addStartupPage'); |
| 76 }); |
| 77 }); |
| 78 }); |
OLD | NEW |