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 */ |
11 function TestStartupUrlsPageBrowserProxy() { | 11 function TestStartupUrlsPageBrowserProxy() { |
12 settings.TestBrowserProxy.call(this, [ | 12 settings.TestBrowserProxy.call(this, [ |
13 'addStartupPage', | 13 'addStartupPage', |
14 'loadStartupPages', | 14 'loadStartupPages', |
| 15 'removeStartupPage', |
15 'useCurrentPages', | 16 'useCurrentPages', |
16 'validateStartupPage', | 17 'validateStartupPage', |
17 ]); | 18 ]); |
18 | 19 |
19 /** @private {boolean} */ | 20 /** @private {boolean} */ |
20 this.urlIsValid_ = true; | 21 this.urlIsValid_ = true; |
21 } | 22 } |
22 | 23 |
23 TestStartupUrlsPageBrowserProxy.prototype = { | 24 TestStartupUrlsPageBrowserProxy.prototype = { |
24 __proto__: settings.TestBrowserProxy.prototype, | 25 __proto__: settings.TestBrowserProxy.prototype, |
25 | 26 |
26 /** @param {boolean} isValid */ | 27 /** @param {boolean} isValid */ |
27 setUrlValidity: function(isValid) { | 28 setUrlValidity: function(isValid) { |
28 this.urlIsValid_ = isValid; | 29 this.urlIsValid_ = isValid; |
29 }, | 30 }, |
30 | 31 |
31 /** @override */ | 32 /** @override */ |
32 addStartupPage: function(url) { | 33 addStartupPage: function(url) { |
33 this.methodCalled('addStartupPage', url); | 34 this.methodCalled('addStartupPage', url); |
34 return Promise.resolve(this.urlIsValid_); | 35 return Promise.resolve(this.urlIsValid_); |
35 }, | 36 }, |
36 | 37 |
37 /** @override */ | 38 /** @override */ |
38 loadStartupPages: function() { | 39 loadStartupPages: function() { |
39 this.methodCalled('loadStartupPages'); | 40 this.methodCalled('loadStartupPages'); |
40 }, | 41 }, |
41 | 42 |
42 /** @override */ | 43 /** @override */ |
| 44 removeStartupPage: function(modelIndex) { |
| 45 this.methodCalled('removeStartupPage', modelIndex); |
| 46 }, |
| 47 |
| 48 /** @override */ |
43 useCurrentPages: function() { | 49 useCurrentPages: function() { |
44 this.methodCalled('useCurrentPages'); | 50 this.methodCalled('useCurrentPages'); |
45 }, | 51 }, |
46 | 52 |
47 /** @override */ | 53 /** @override */ |
48 validateStartupPage: function(url) { | 54 validateStartupPage: function(url) { |
49 this.methodCalled('validateStartupPage', url); | 55 this.methodCalled('validateStartupPage', url); |
50 return Promise.resolve(this.urlIsValid_); | 56 return Promise.resolve(this.urlIsValid_); |
51 }, | 57 }, |
52 }; | 58 }; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 test('AddPage_OpensDialog', function() { | 167 test('AddPage_OpensDialog', function() { |
162 var addPageButton = page.$.addPage; | 168 var addPageButton = page.$.addPage; |
163 assertTrue(!!addPageButton); | 169 assertTrue(!!addPageButton); |
164 assertFalse(!!page.$$('settings-startup-url-dialog')); | 170 assertFalse(!!page.$$('settings-startup-url-dialog')); |
165 | 171 |
166 MockInteractions.tap(addPageButton); | 172 MockInteractions.tap(addPageButton); |
167 Polymer.dom.flush(); | 173 Polymer.dom.flush(); |
168 assertTrue(!!page.$$('settings-startup-url-dialog')); | 174 assertTrue(!!page.$$('settings-startup-url-dialog')); |
169 }); | 175 }); |
170 }); | 176 }); |
| 177 |
| 178 /** @return {!StartupPageInfo} */ |
| 179 function createSampleUrlEntry() { |
| 180 return { |
| 181 modelIndex: 2, |
| 182 title: 'Test page', |
| 183 tooltip: 'test tooltip', |
| 184 url: 'chrome://foo', |
| 185 }; |
| 186 } |
| 187 |
| 188 suite('StartupUrlEntry', function() { |
| 189 /** @type {?SettingsStartupUrlEntryElement} */ |
| 190 var element = null; |
| 191 |
| 192 var browserProxy = null; |
| 193 |
| 194 setup(function() { |
| 195 browserProxy = new TestStartupUrlsPageBrowserProxy(); |
| 196 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; |
| 197 PolymerTest.clearBody(); |
| 198 element = document.createElement('settings-startup-url-entry'); |
| 199 element.model = createSampleUrlEntry(); |
| 200 document.body.appendChild(element); |
| 201 |
| 202 // Bring up the popup menu for the following tests to use. |
| 203 assertFalse(!!element.$$('iron-dropdown')); |
| 204 MockInteractions.tap(element.$.dots); |
| 205 Polymer.dom.flush(); |
| 206 assertTrue(!!element.$$('iron-dropdown')); |
| 207 }); |
| 208 |
| 209 teardown(function() { element.remove(); }); |
| 210 |
| 211 test('MenuOptions_Remove', function() { |
| 212 var removeButton = element.shadowRoot.querySelector('#remove') |
| 213 MockInteractions.tap(removeButton); |
| 214 return browserProxy.whenCalled('removeStartupPage').then( |
| 215 function(modelIndex) { |
| 216 assertEquals(element.model.modelIndex, modelIndex); |
| 217 }); |
| 218 }); |
| 219 }); |
171 }); | 220 }); |
OLD | NEW |