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', | |
14 'loadStartupPages', | |
15 'useCurrentPages', | |
13 'validateStartupPage', | 16 'validateStartupPage', |
Dan Beam
2016/04/08 23:24:42
nit: you may want to alphabetize the @interface as
dpapad
2016/04/09 00:02:19
Done.
| |
14 'addStartupPage', | |
15 ]); | 17 ]); |
18 | |
19 /** @private {boolean} */ | |
20 this.urlIsValid_ = true; | |
16 } | 21 } |
17 | 22 |
18 TestStartupUrlsPageBrowserProxy.prototype = { | 23 TestStartupUrlsPageBrowserProxy.prototype = { |
19 __proto__: settings.TestBrowserProxy.prototype, | 24 __proto__: settings.TestBrowserProxy.prototype, |
20 | 25 |
21 urlsAreValid: false, | 26 /** @param {boolean} isValid */ |
22 | 27 setUrlValidity: function(isValid) { |
Dan Beam
2016/04/08 23:24:42
this isn't really functionally different than what
dpapad
2016/04/09 00:02:18
Agreed, functionally is (almost) the same. Almost,
| |
23 /** @override */ | 28 this.urlIsValid_ = isValid; |
24 loadStartupPages: function() {}, | 29 }, |
25 | 30 |
26 /** @override */ | 31 /** @override */ |
27 validateStartupPage: function(url) { | 32 validateStartupPage: function(url) { |
28 this.methodCalled('validateStartupPage'); | 33 this.methodCalled('validateStartupPage', url); |
29 var resolver = new PromiseResolver; | 34 return Promise.resolve(this.urlIsValid_); |
30 resolver.promise = Promise.resolve(this.urlsAreValid); | 35 }, |
31 return resolver; | 36 |
37 /** @override */ | |
38 loadStartupPages: function() { | |
39 this.methodCalled('loadStartupPages'); | |
40 }, | |
41 | |
42 /** @override */ | |
43 useCurrentPages: function() { | |
44 this.methodCalled('useCurrentPages'); | |
32 }, | 45 }, |
33 | 46 |
34 /** @override */ | 47 /** @override */ |
35 addStartupPage: function(url) { | 48 addStartupPage: function(url) { |
36 this.methodCalled('addStartupPage'); | 49 this.methodCalled('addStartupPage', url); |
50 return Promise.resolve(this.urlIsValid_); | |
37 }, | 51 }, |
38 }; | 52 }; |
39 | 53 |
54 suite('StartupUrlDialog', function() { | |
55 /** @type {?SettingsStartupUrlDialogElement} */ | |
56 var dialog = null; | |
57 | |
58 var browserProxy = null; | |
59 | |
60 /** | |
61 * Triggers an 'input' event on the given text input field, which triggers | |
62 * validation to occur. | |
63 * @param {!PaperInputElement} element | |
64 */ | |
65 function triggerInputEvent(element) { | |
Dan Beam
2016/04/08 23:24:42
nit: pressSpace
dpapad
2016/04/09 00:02:18
If you are referring to https://code.google.com/p/
Dan Beam
2016/04/09 00:03:40
hah! no, I just meant "can we rename triggerInputE
dpapad
2016/04/09 00:19:57
Done.
| |
66 // The actual key code is irrelevant for these tests. | |
67 MockInteractions.keyEventOn(element, 'input', 32 /* space key code */); | |
68 } | |
69 | |
70 setup(function() { | |
71 browserProxy = new TestStartupUrlsPageBrowserProxy(); | |
72 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; | |
73 PolymerTest.clearBody(); | |
74 dialog = document.createElement('settings-startup-url-dialog'); | |
75 document.body.appendChild(dialog); | |
76 }); | |
77 | |
78 teardown(function() { dialog.remove(); }); | |
79 | |
80 // Test that validation occurs as the user is typing, and that the action | |
81 // button is updated accordingly. | |
82 test('Validation', function() { | |
83 assertTrue(dialog.$.dialog.opened); | |
84 var addButton = dialog.$.add; | |
85 assertTrue(!!addButton); | |
86 assertTrue(addButton.disabled); | |
87 | |
88 var inputElement = dialog.$.url; | |
89 assertTrue(!!inputElement); | |
90 | |
91 var expectedUrl = "dummy-foo.com"; | |
92 inputElement.value = expectedUrl; | |
93 browserProxy.setUrlValidity(false); | |
94 triggerInputEvent(inputElement); | |
95 | |
96 return browserProxy.whenCalled('validateStartupPage').then(function(url) { | |
97 assertEquals(expectedUrl, url); | |
98 assertTrue(addButton.disabled); | |
99 | |
100 browserProxy.setUrlValidity(true); | |
101 browserProxy.resetResolver('validateStartupPage'); | |
102 triggerInputEvent(inputElement); | |
103 | |
104 return browserProxy.whenCalled('validateStartupPage'); | |
105 }).then(function() { | |
106 assertFalse(addButton.disabled); | |
107 }); | |
108 }); | |
109 | |
110 test('AddStartupPage', function() { | |
111 assertTrue(dialog.$.dialog.opened); | |
112 var addButton = dialog.$.add; | |
113 | |
114 // Test that the dialog remains open if the user somehow manages to submit | |
115 // an invalid URL. | |
116 browserProxy.setUrlValidity(false); | |
117 MockInteractions.tap(addButton); | |
118 return browserProxy.whenCalled('addStartupPage').then(function() { | |
119 assertTrue(dialog.$.dialog.opened); | |
120 | |
121 // Test that dialog is closed if the user submits a valid URL. | |
122 browserProxy.setUrlValidity(true); | |
123 browserProxy.resetResolver('addStartupPage'); | |
124 MockInteractions.tap(addButton); | |
125 return browserProxy.whenCalled('addStartupPage'); | |
126 }).then(function() { | |
127 assertFalse(dialog.$.dialog.opened); | |
128 }); | |
129 }); | |
130 | |
40 suite('StartupUrlsPage', function() { | 131 suite('StartupUrlsPage', function() { |
41 /** @type {?SettingsStartupUrlsPageElement} */ | 132 /** @type {?SettingsStartupUrlsPageElement} */ |
42 var page = null; | 133 var page = null; |
43 | 134 |
44 var browserProxy = null; | 135 var browserProxy = null; |
45 | 136 |
46 setup(function() { | 137 setup(function() { |
47 browserProxy = new TestStartupUrlsPageBrowserProxy(); | 138 browserProxy = new TestStartupUrlsPageBrowserProxy(); |
48 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; | 139 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; |
49 PolymerTest.clearBody(); | 140 PolymerTest.clearBody(); |
50 page = document.createElement('settings-startup-urls-page'); | 141 page = document.createElement('settings-startup-urls-page'); |
51 document.body.appendChild(page); | 142 document.body.appendChild(page); |
52 }); | 143 }); |
53 | 144 |
54 teardown(function() { page.remove(); }); | 145 teardown(function() { page.remove(); }); |
55 | 146 |
56 test('validate', function() { | 147 // Test that the page is requesting information from the browser. |
57 browserProxy.whenCalled('validateStartupPage').then(function() { | 148 test('Initialization', function() { |
58 var addButton = page.$.add; | 149 return browserProxy.whenCalled('loadStartupPages'); |
59 assertTrue(!!addButton); | 150 }); |
60 assertFalse(browserProxy.urlsAreValid); | |
61 assertTrue(addButton.disabled); | |
62 | 151 |
63 browserProxy.resetResolver('validateStartupPage'); | 152 test('UseCurrentPages', function() { |
64 browserProxy.whenCalled('validateStartupPage').then(function() { | 153 var useCurrentPagesButton = page.$.useCurrentPages; |
65 page.async(function() { | 154 assertTrue(!!useCurrentPagesButton); |
66 assertFalse(addButton.disabled); | 155 MockInteractions.tap(useCurrentPagesButton); |
67 MockInteractions.tap(addButton); | 156 return browserProxy.whenCalled('useCurrentPages'); |
68 }); | 157 }); |
69 }); | |
70 | 158 |
71 browserProxy.urlsAreValid = true; | 159 test('AddPage_OpensDialog', function() { |
72 page.$.newUrl.value = "overriding validation anyway"; | 160 var addPageButton = page.$.addPage; |
73 }); | 161 assertTrue(!!addPageButton); |
162 assertFalse(!!page.$$('settings-startup-url-dialog')); | |
74 | 163 |
75 return browserProxy.whenCalled('addStartupPage'); | 164 MockInteractions.tap(addPageButton); |
165 Polymer.dom.flush(); | |
166 assertTrue(!!page.$$('settings-startup-url-dialog')); | |
76 }); | 167 }); |
77 }); | 168 }); |
78 }); | 169 }); |
OLD | NEW |