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

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

Issue 2339853003: MD Settings: Fix Reset profile dialog scenario that causes a crash. (Closed)
Patch Set: Nit Created 4 years, 3 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/resources/settings/settings_resources.grd ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_reset_page', function() { 5 cr.define('settings_reset_page', function() {
6 /** @enum {string} */ 6 /** @enum {string} */
7 var TestNames = { 7 var TestNames = {
8 PowerwashDialogAction: 'PowerwashDialogAction', 8 PowerwashDialogAction: 'PowerwashDialogAction',
9 PowerwashDialogOpenClose: 'PowerwashDialogOpenClose', 9 PowerwashDialogOpenClose: 'PowerwashDialogOpenClose',
10 ResetBannerClose: 'ResetBannerClose', 10 ResetBannerClose: 'ResetBannerClose',
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // - opens the reset profile dialog when the reset button is clicked. 88 // - opens the reset profile dialog when the reset button is clicked.
89 // - the reset profile dialog is closed after reset is done. 89 // - the reset profile dialog is closed after reset is done.
90 test(TestNames.ResetBannerReset, function() { 90 test(TestNames.ResetBannerReset, function() {
91 var dialog = resetBanner.$$('settings-reset-profile-dialog'); 91 var dialog = resetBanner.$$('settings-reset-profile-dialog');
92 assertFalse(!!dialog); 92 assertFalse(!!dialog);
93 MockInteractions.tap(resetBanner.$['reset']); 93 MockInteractions.tap(resetBanner.$['reset']);
94 Polymer.dom.flush(); 94 Polymer.dom.flush();
95 dialog = resetBanner.$$('settings-reset-profile-dialog'); 95 dialog = resetBanner.$$('settings-reset-profile-dialog');
96 assertTrue(!!dialog); 96 assertTrue(!!dialog);
97 97
98 dialog.dispatchEvent(new CustomEvent('reset-done')); 98 dialog.fire('reset-done');
99 Polymer.dom.flush(); 99 Polymer.dom.flush();
100 assertEquals('none', dialog.style.display); 100 assertEquals('none', dialog.style.display);
101 return Promise.resolve(); 101 return Promise.resolve();
102 }); 102 });
103 103
104 // Tests that the reset profile banner removes itself from the DOM when 104 // Tests that the reset profile banner removes itself from the DOM when
105 // the close button is clicked and that |onHideResetProfileBanner| is 105 // the close button is clicked and that |onHideResetProfileBanner| is
106 // called. 106 // called.
107 test(TestNames.ResetBannerClose, function() { 107 test(TestNames.ResetBannerClose, function() {
108 MockInteractions.tap(resetBanner.$['close']); 108 MockInteractions.tap(resetBanner.$['close']);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 * @param {function(SettingsResetProfileDialogElemeent)} 142 * @param {function(SettingsResetProfileDialogElemeent)}
143 * closeDialogFn A function to call for closing the dialog. 143 * closeDialogFn A function to call for closing the dialog.
144 * @return {!Promise} 144 * @return {!Promise}
145 */ 145 */
146 function testOpenCloseResetProfileDialog(closeDialogFn) { 146 function testOpenCloseResetProfileDialog(closeDialogFn) {
147 resetPageBrowserProxy.resetResolver('onShowResetProfileDialog'); 147 resetPageBrowserProxy.resetResolver('onShowResetProfileDialog');
148 resetPageBrowserProxy.resetResolver('onHideResetProfileDialog'); 148 resetPageBrowserProxy.resetResolver('onHideResetProfileDialog');
149 149
150 // Open reset profile dialog. 150 // Open reset profile dialog.
151 MockInteractions.tap(resetPage.$.resetProfile); 151 MockInteractions.tap(resetPage.$.resetProfile);
152 Polymer.dom.flush();
152 var dialog = resetPage.$$('settings-reset-profile-dialog'); 153 var dialog = resetPage.$$('settings-reset-profile-dialog');
153 assertTrue(!!dialog); 154 assertTrue(!!dialog);
154 assertTrue(dialog.$.dialog.open);
155 var onDialogClosed = new Promise( 155 var onDialogClosed = new Promise(
156 function(resolve, reject) { 156 function(resolve, reject) {
157 dialog.addEventListener('close', function() { 157 dialog.addEventListener('close', function() {
158 assertFalse(dialog.$.dialog.open); 158 assertFalse(dialog.$.dialog.open);
159 resolve(); 159 resolve();
160 }); 160 });
161 }); 161 });
162 162
163 return resetPageBrowserProxy.whenCalled( 163 return resetPageBrowserProxy.whenCalled(
164 'onShowResetProfileDialog').then(function() { 164 'onShowResetProfileDialog').then(function() {
165 assertTrue(dialog.$.dialog.open);
165 closeDialogFn(dialog); 166 closeDialogFn(dialog);
166 return Promise.all([ 167 return Promise.all([
167 onDialogClosed, 168 onDialogClosed,
168 resetPageBrowserProxy.whenCalled('onHideResetProfileDialog'), 169 resetPageBrowserProxy.whenCalled('onHideResetProfileDialog'),
169 ]); 170 ]);
170 }); 171 });
171 } 172 }
172 173
173 // Tests that the reset profile dialog opens and closes correctly and that 174 // Tests that the reset profile dialog opens and closes correctly and that
174 // resetPageBrowserProxy calls are occurring as expected. 175 // resetPageBrowserProxy calls are occurring as expected.
175 test(TestNames.ResetProfileDialogOpenClose, function() { 176 test(TestNames.ResetProfileDialogOpenClose, function() {
176 return testOpenCloseResetProfileDialog(function(dialog) { 177 return testOpenCloseResetProfileDialog(function(dialog) {
177 // Test case where the 'cancel' button is clicked. 178 // Test case where the 'cancel' button is clicked.
178 MockInteractions.tap(dialog.$.cancel); 179 MockInteractions.tap(dialog.$.cancel);
179 }).then(function() { 180 }).then(function() {
180 return testOpenCloseResetProfileDialog(function(dialog) { 181 return testOpenCloseResetProfileDialog(function(dialog) {
181 // Test case where the 'close' button is clicked. 182 // Test case where the 'close' button is clicked.
182 MockInteractions.tap(dialog.$.dialog.getCloseButton()); 183 MockInteractions.tap(dialog.$.dialog.getCloseButton());
183 }); 184 });
184 }); 185 });
185 }); 186 });
186 187
187 // Tests that when user request to reset the profile the appropriate 188 // Tests that when user request to reset the profile the appropriate
188 // message is sent to the browser. 189 // message is sent to the browser.
189 test(TestNames.ResetProfileDialogAction, function() { 190 test(TestNames.ResetProfileDialogAction, function() {
190 // Open reset profile dialog. 191 // Open reset profile dialog.
191 MockInteractions.tap(resetPage.$.resetProfile); 192 MockInteractions.tap(resetPage.$.resetProfile);
193 Polymer.dom.flush();
192 var dialog = resetPage.$$('settings-reset-profile-dialog'); 194 var dialog = resetPage.$$('settings-reset-profile-dialog');
193 assertTrue(!!dialog); 195 assertTrue(!!dialog);
194 196
195 var showReportedSettingsLink = dialog.$$('.footer a'); 197 var showReportedSettingsLink = dialog.$$('.footer a');
196 assertTrue(!!showReportedSettingsLink); 198 assertTrue(!!showReportedSettingsLink);
197 MockInteractions.tap(showReportedSettingsLink); 199 MockInteractions.tap(showReportedSettingsLink);
198 200
199 return resetPageBrowserProxy.whenCalled('showReportedSettings').then( 201 return resetPageBrowserProxy.whenCalled('showReportedSettings').then(
200 function() { 202 function() {
201 assertFalse(dialog.$.reset.disabled); 203 assertFalse(dialog.$.reset.disabled);
202 assertFalse(dialog.$.resetSpinner.active); 204 assertFalse(dialog.$.resetSpinner.active);
203 MockInteractions.tap(dialog.$.reset); 205 MockInteractions.tap(dialog.$.reset);
204 assertTrue(dialog.$.reset.disabled); 206 assertTrue(dialog.$.reset.disabled);
207 assertTrue(dialog.$.cancel.disabled);
205 assertTrue(dialog.$.resetSpinner.active); 208 assertTrue(dialog.$.resetSpinner.active);
206 return resetPageBrowserProxy.whenCalled( 209 return resetPageBrowserProxy.whenCalled(
207 'performResetProfileSettings'); 210 'performResetProfileSettings');
208 }); 211 });
209 }); 212 });
210 213
211 if (cr.isChromeOS) { 214 if (cr.isChromeOS) {
212 /** 215 /**
213 * @param {function(SettingsPowerwashDialogElemeent):!Element} 216 * @param {function(SettingsPowerwashDialogElemeent):!Element}
214 * closeButtonFn A function that returns the button to be used for 217 * closeButtonFn A function that returns the button to be used for
215 * closing the dialog. 218 * closing the dialog.
216 * @return {!Promise} 219 * @return {!Promise}
217 */ 220 */
218 function testOpenClosePowerwashDialog(closeButtonFn) { 221 function testOpenClosePowerwashDialog(closeButtonFn) {
219 // Open powerwash dialog. 222 // Open powerwash dialog.
220 MockInteractions.tap(resetPage.$.powerwash); 223 MockInteractions.tap(resetPage.$.powerwash);
224 Polymer.dom.flush();
221 var dialog = resetPage.$$('settings-powerwash-dialog'); 225 var dialog = resetPage.$$('settings-powerwash-dialog');
222 assertTrue(!!dialog); 226 assertTrue(!!dialog);
223 assertTrue(dialog.$.dialog.open); 227 assertTrue(dialog.$.dialog.open);
224 var onDialogClosed = new Promise( 228 var onDialogClosed = new Promise(
225 function(resolve, reject) { 229 function(resolve, reject) {
226 dialog.addEventListener('close', function() { 230 dialog.addEventListener('close', function() {
227 assertFalse(dialog.$.dialog.open); 231 assertFalse(dialog.$.dialog.open);
228 resolve(); 232 resolve();
229 }); 233 });
230 }); 234 });
231 235
232 MockInteractions.tap(closeButtonFn(dialog)); 236 MockInteractions.tap(closeButtonFn(dialog));
233 return Promise.all([ 237 return Promise.all([
234 onDialogClosed, 238 onDialogClosed,
235 resetPageBrowserProxy.whenCalled('onPowerwashDialogShow'), 239 resetPageBrowserProxy.whenCalled('onPowerwashDialogShow'),
236 ]); 240 ]);
237 } 241 }
238 242
239 // Tests that the powerwash dialog opens and closes correctly, and 243 // Tests that the powerwash dialog opens and closes correctly, and
240 // that chrome.send calls are propagated as expected. 244 // that chrome.send calls are propagated as expected.
241 test(TestNames.PowerwashDialogOpenClose, function() { 245 test(TestNames.PowerwashDialogOpenClose, function() {
242 return Promise.all([ 246 // Test case where the 'cancel' button is clicked.
243 // Test case where the 'cancel' button is clicked. 247 return testOpenClosePowerwashDialog(function(dialog) {
244 testOpenClosePowerwashDialog( 248 return dialog.$.cancel;
245 function(dialog) { return dialog.$.cancel; }), 249 }).then(function() {
246 // Test case where the 'close' button is clicked. 250 // Test case where the 'close' button is clicked.
247 testOpenClosePowerwashDialog( 251 return testOpenClosePowerwashDialog(function(dialog) {
248 function(dialog) { return dialog.$.dialog.getCloseButton(); }), 252 return dialog.$.dialog.getCloseButton();
249 ]); 253 });
254 });
250 }); 255 });
251 256
252 // Tests that when powerwash is requested chrome.send calls are 257 // Tests that when powerwash is requested chrome.send calls are
253 // propagated as expected. 258 // propagated as expected.
254 test(TestNames.PowerwashDialogAction, function() { 259 test(TestNames.PowerwashDialogAction, function() {
255 // Open powerwash dialog. 260 // Open powerwash dialog.
256 MockInteractions.tap(resetPage.$.powerwash); 261 MockInteractions.tap(resetPage.$.powerwash);
262 Polymer.dom.flush();
257 var dialog = resetPage.$$('settings-powerwash-dialog'); 263 var dialog = resetPage.$$('settings-powerwash-dialog');
258 assertTrue(!!dialog); 264 assertTrue(!!dialog);
259 MockInteractions.tap(dialog.$.powerwash); 265 MockInteractions.tap(dialog.$.powerwash);
260 return lifetimeBrowserProxy.whenCalled('factoryReset'); 266 return lifetimeBrowserProxy.whenCalled('factoryReset');
261 }); 267 });
262 } 268 }
263 }); 269 });
264 } 270 }
265 271
266 return { 272 return {
267 registerTests: function() { 273 registerTests: function() {
268 registerBannerTests(); 274 registerBannerTests();
269 registerDialogTests(); 275 registerDialogTests();
270 }, 276 },
271 }; 277 };
272 }); 278 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/settings_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698