Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/test/data/webui/settings/startup_urls_page_test.js

Issue 1882483002: MD Settings: OnStartup, implementing "Edit" functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@edit_on_startup_move_delete
Patch Set: Nit. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'editStartupPage',
14 'loadStartupPages', 15 'loadStartupPages',
15 'removeStartupPage', 16 'removeStartupPage',
16 'useCurrentPages', 17 'useCurrentPages',
17 'validateStartupPage', 18 'validateStartupPage',
18 ]); 19 ]);
19 20
20 /** @private {boolean} */ 21 /** @private {boolean} */
21 this.urlIsValid_ = true; 22 this.urlIsValid_ = true;
22 } 23 }
23 24
24 TestStartupUrlsPageBrowserProxy.prototype = { 25 TestStartupUrlsPageBrowserProxy.prototype = {
25 __proto__: settings.TestBrowserProxy.prototype, 26 __proto__: settings.TestBrowserProxy.prototype,
26 27
27 /** @param {boolean} isValid */ 28 /** @param {boolean} isValid */
28 setUrlValidity: function(isValid) { 29 setUrlValidity: function(isValid) {
29 this.urlIsValid_ = isValid; 30 this.urlIsValid_ = isValid;
30 }, 31 },
31 32
32 /** @override */ 33 /** @override */
33 addStartupPage: function(url) { 34 addStartupPage: function(url) {
34 this.methodCalled('addStartupPage', url); 35 this.methodCalled('addStartupPage', url);
35 return Promise.resolve(this.urlIsValid_); 36 return Promise.resolve(this.urlIsValid_);
36 }, 37 },
37 38
38 /** @override */ 39 /** @override */
40 editStartupPage: function(modelIndex, url) {
41 this.methodCalled('editStartupPage', [modelIndex, url]);
42 return Promise.resolve(this.urlIsValid_);
43 },
44
45 /** @override */
39 loadStartupPages: function() { 46 loadStartupPages: function() {
40 this.methodCalled('loadStartupPages'); 47 this.methodCalled('loadStartupPages');
41 }, 48 },
42 49
43 /** @override */ 50 /** @override */
44 removeStartupPage: function(modelIndex) { 51 removeStartupPage: function(modelIndex) {
45 this.methodCalled('removeStartupPage', modelIndex); 52 this.methodCalled('removeStartupPage', modelIndex);
46 }, 53 },
47 54
48 /** @override */ 55 /** @override */
(...skipping 22 matching lines...) Expand all
71 function pressSpace(element) { 78 function pressSpace(element) {
72 // The actual key code is irrelevant for these tests. 79 // The actual key code is irrelevant for these tests.
73 MockInteractions.keyEventOn(element, 'input', 32 /* space key code */); 80 MockInteractions.keyEventOn(element, 'input', 32 /* space key code */);
74 } 81 }
75 82
76 setup(function() { 83 setup(function() {
77 browserProxy = new TestStartupUrlsPageBrowserProxy(); 84 browserProxy = new TestStartupUrlsPageBrowserProxy();
78 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; 85 settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy;
79 PolymerTest.clearBody(); 86 PolymerTest.clearBody();
80 dialog = document.createElement('settings-startup-url-dialog'); 87 dialog = document.createElement('settings-startup-url-dialog');
81 document.body.appendChild(dialog);
82 }); 88 });
83 89
84 teardown(function() { dialog.remove(); }); 90 teardown(function() { dialog.remove(); });
85 91
92 test('Initialization_Add', function() {
93 document.body.appendChild(dialog);
94 assertTrue(dialog.$.dialog.opened);
95
96 // Assert that the "Add" button is disabled.
97 var actionButton = dialog.$.actionButton;
98 assertTrue(!!actionButton);
99 assertTrue(actionButton.disabled);
100
101 // Assert that the text field is empty.
102 var inputElement = dialog.$.url;
103 assertTrue(!!inputElement);
104 assertEquals('', inputElement.value);
105 });
106
107 test('Initialization_Edit', function() {
108 dialog.model = createSampleUrlEntry();
109 document.body.appendChild(dialog);
110 assertTrue(dialog.$.dialog.opened);
111
112 // Assert that the "Edit" button is enabled.
113 var actionButton = dialog.$.actionButton;
114 assertTrue(!!actionButton);
115 assertFalse(actionButton.disabled);
116 // Assert that the text field is pre-populated.
117 var inputElement = dialog.$.url;
118 assertTrue(!!inputElement);
119 assertEquals(dialog.model.url, inputElement.value);
120 });
121
86 // Test that validation occurs as the user is typing, and that the action 122 // Test that validation occurs as the user is typing, and that the action
87 // button is updated accordingly. 123 // button is updated accordingly.
88 test('Validation', function() { 124 test('Validation', function() {
89 assertTrue(dialog.$.dialog.opened); 125 document.body.appendChild(dialog);
90 var addButton = dialog.$.add;
91 assertTrue(!!addButton);
92 assertTrue(addButton.disabled);
93 126
127 var actionButton = dialog.$.actionButton;
128 assertTrue(actionButton.disabled);
94 var inputElement = dialog.$.url; 129 var inputElement = dialog.$.url;
95 assertTrue(!!inputElement);
96 130
97 var expectedUrl = "dummy-foo.com"; 131 var expectedUrl = "dummy-foo.com";
98 inputElement.value = expectedUrl; 132 inputElement.value = expectedUrl;
99 browserProxy.setUrlValidity(false); 133 browserProxy.setUrlValidity(false);
100 pressSpace(inputElement); 134 pressSpace(inputElement);
101 135
102 return browserProxy.whenCalled('validateStartupPage').then(function(url) { 136 return browserProxy.whenCalled('validateStartupPage').then(function(url) {
103 assertEquals(expectedUrl, url); 137 assertEquals(expectedUrl, url);
104 assertTrue(addButton.disabled); 138 assertTrue(actionButton.disabled);
105 139
106 browserProxy.setUrlValidity(true); 140 browserProxy.setUrlValidity(true);
107 browserProxy.resetResolver('validateStartupPage'); 141 browserProxy.resetResolver('validateStartupPage');
108 pressSpace(inputElement); 142 pressSpace(inputElement);
109 143
110 return browserProxy.whenCalled('validateStartupPage'); 144 return browserProxy.whenCalled('validateStartupPage');
111 }).then(function() { 145 }).then(function() {
112 assertFalse(addButton.disabled); 146 assertFalse(actionButton.disabled);
113 }); 147 });
114 }); 148 });
115 149
116 test('AddStartupPage', function() { 150 /**
117 assertTrue(dialog.$.dialog.opened); 151 * Tests that the appropritae browser proxy method is called when the action
118 var addButton = dialog.$.add; 152 * button is tapped.
119 addButton.disabled = false; 153 * @param {string} proxyMethodName
154 */
155 function testProxyCalled(proxyMethodName) {
156 var actionButton = dialog.$.actionButton;
157 actionButton.disabled = false;
120 158
121 // Test that the dialog remains open if the user somehow manages to submit 159 // Test that the dialog remains open if the user somehow manages to submit
122 // an invalid URL. 160 // an invalid URL.
123 browserProxy.setUrlValidity(false); 161 browserProxy.setUrlValidity(false);
124 MockInteractions.tap(addButton); 162 MockInteractions.tap(actionButton);
125 return browserProxy.whenCalled('addStartupPage').then(function() { 163 return browserProxy.whenCalled(proxyMethodName).then(function() {
126 assertTrue(dialog.$.dialog.opened); 164 assertTrue(dialog.$.dialog.opened);
127 165
128 // Test that dialog is closed if the user submits a valid URL. 166 // Test that dialog is closed if the user submits a valid URL.
129 browserProxy.setUrlValidity(true); 167 browserProxy.setUrlValidity(true);
130 browserProxy.resetResolver('addStartupPage'); 168 browserProxy.resetResolver(proxyMethodName);
131 MockInteractions.tap(addButton); 169 MockInteractions.tap(actionButton);
132 return browserProxy.whenCalled('addStartupPage'); 170 return browserProxy.whenCalled(proxyMethodName);
133 }).then(function() { 171 }).then(function() {
134 assertFalse(dialog.$.dialog.opened); 172 assertFalse(dialog.$.dialog.opened);
135 }); 173 });
174 }
175
176 test('AddStartupPage', function() {
177 document.body.appendChild(dialog);
178 return testProxyCalled('addStartupPage');
179 });
180
181 test('EditStartupPage', function() {
182 dialog.model = createSampleUrlEntry();
183 document.body.appendChild(dialog);
184 return testProxyCalled('editStartupPage');
136 }); 185 });
137 }); 186 });
138 187
139 suite('StartupUrlsPage', function() { 188 suite('StartupUrlsPage', function() {
140 /** @type {?SettingsStartupUrlsPageElement} */ 189 /** @type {?SettingsStartupUrlsPageElement} */
141 var page = null; 190 var page = null;
142 191
143 var browserProxy = null; 192 var browserProxy = null;
144 193
145 setup(function() { 194 setup(function() {
(...skipping 20 matching lines...) Expand all
166 215
167 test('AddPage_OpensDialog', function() { 216 test('AddPage_OpensDialog', function() {
168 var addPageButton = page.$.addPage; 217 var addPageButton = page.$.addPage;
169 assertTrue(!!addPageButton); 218 assertTrue(!!addPageButton);
170 assertFalse(!!page.$$('settings-startup-url-dialog')); 219 assertFalse(!!page.$$('settings-startup-url-dialog'));
171 220
172 MockInteractions.tap(addPageButton); 221 MockInteractions.tap(addPageButton);
173 Polymer.dom.flush(); 222 Polymer.dom.flush();
174 assertTrue(!!page.$$('settings-startup-url-dialog')); 223 assertTrue(!!page.$$('settings-startup-url-dialog'));
175 }); 224 });
225
226 test('EditPage_OpensDialog', function() {
227 assertFalse(!!page.$$('settings-startup-url-dialog'));
228 page.fire(settings.EDIT_STARTUP_URL_EVENT, createSampleUrlEntry());
229 Polymer.dom.flush();
230 assertTrue(!!page.$$('settings-startup-url-dialog'));
231 });
176 }); 232 });
177 233
178 /** @return {!StartupPageInfo} */ 234 /** @return {!StartupPageInfo} */
179 function createSampleUrlEntry() { 235 function createSampleUrlEntry() {
180 return { 236 return {
181 modelIndex: 2, 237 modelIndex: 2,
182 title: 'Test page', 238 title: 'Test page',
183 tooltip: 'test tooltip', 239 tooltip: 'test tooltip',
184 url: 'chrome://foo', 240 url: 'chrome://foo',
185 }; 241 };
(...skipping 25 matching lines...) Expand all
211 test('MenuOptions_Remove', function() { 267 test('MenuOptions_Remove', function() {
212 var removeButton = element.shadowRoot.querySelector('#remove') 268 var removeButton = element.shadowRoot.querySelector('#remove')
213 MockInteractions.tap(removeButton); 269 MockInteractions.tap(removeButton);
214 return browserProxy.whenCalled('removeStartupPage').then( 270 return browserProxy.whenCalled('removeStartupPage').then(
215 function(modelIndex) { 271 function(modelIndex) {
216 assertEquals(element.model.modelIndex, modelIndex); 272 assertEquals(element.model.modelIndex, modelIndex);
217 }); 273 });
218 }); 274 });
219 }); 275 });
220 }); 276 });
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698