| OLD | NEW |
| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 var dialog = resetPage.$$('settings-reset-profile-dialog'); | 152 var dialog = resetPage.$$('settings-reset-profile-dialog'); |
| 153 assertTrue(!!dialog); | 153 assertTrue(!!dialog); |
| 154 assertTrue(dialog.$.dialog.opened); |
| 154 var onDialogClosed = new Promise( | 155 var onDialogClosed = new Promise( |
| 155 function(resolve, reject) { | 156 function(resolve, reject) { |
| 156 dialog.addEventListener('iron-overlay-closed', resolve); | 157 dialog.addEventListener('iron-overlay-closed', function() { |
| 158 assertFalse(dialog.$.dialog.opened); |
| 159 resolve(); |
| 160 }); |
| 157 }); | 161 }); |
| 158 | 162 |
| 159 return resetPageBrowserProxy.whenCalled( | 163 return new Promise(function(resolve, reject) { |
| 160 'onShowResetProfileDialog').then( | 164 resetPageBrowserProxy.whenCalled( |
| 161 function() { | 165 'onShowResetProfileDialog').then(function() { |
| 166 // Need to call requestAnimationFrame here, otherwise the dialog has |
| 167 // not been registered to the IronOverlayManager at the time we |
| 168 // attempt to close it (which prevents closing by 'esc' key from |
| 169 // working). |
| 170 window.requestAnimationFrame(function() { |
| 162 closeDialogFn(dialog); | 171 closeDialogFn(dialog); |
| 163 return Promise.all([ | 172 Promise.all([ |
| 164 onDialogClosed, | 173 onDialogClosed, |
| 165 resetPageBrowserProxy.whenCalled('onHideResetProfileDialog'), | 174 resetPageBrowserProxy.whenCalled('onHideResetProfileDialog'), |
| 166 ]); | 175 ]).then(resolve, reject); |
| 167 }); | 176 }); |
| 177 }); |
| 178 }); |
| 168 } | 179 } |
| 169 | 180 |
| 170 // Tests that the reset profile dialog opens and closes correctly and that | 181 // Tests that the reset profile dialog opens and closes correctly and that |
| 171 // resetPageBrowserProxy calls are occurring as expected. | 182 // resetPageBrowserProxy calls are occurring as expected. |
| 172 test(TestNames.ResetProfileDialogOpenClose, function() { | 183 test(TestNames.ResetProfileDialogOpenClose, function() { |
| 173 return Promise.all([ | 184 return testOpenCloseResetProfileDialog(function(dialog) { |
| 174 // Test case where the 'cancel' button is clicked. | 185 // Test case where the 'cancel' button is clicked. |
| 175 testOpenCloseResetProfileDialog( | 186 MockInteractions.tap(dialog.$.cancel); |
| 176 function(dialog) { | 187 }).then(function() { |
| 177 MockInteractions.tap(dialog.$.cancel); | 188 return testOpenCloseResetProfileDialog(function(dialog) { |
| 178 }), | 189 // Test case where the 'close' button is clicked. |
| 179 // Test case where the 'close' button is clicked. | 190 MockInteractions.tap(dialog.$.dialog.getCloseButton()); |
| 180 testOpenCloseResetProfileDialog( | 191 }); |
| 181 function(dialog) { | 192 }).then(function() { |
| 182 MockInteractions.tap(dialog.$.dialog.getCloseButton()); | 193 return testOpenCloseResetProfileDialog(function(dialog) { |
| 183 }), | 194 // Test case where the 'Esc' key is pressed. |
| 184 // Test case where the 'Esc' key is pressed. | 195 MockInteractions.pressAndReleaseKeyOn( |
| 185 testOpenCloseResetProfileDialog( | 196 dialog, 27 /* 'Esc' key code */); |
| 186 function(dialog) { | 197 }); |
| 187 MockInteractions.pressAndReleaseKeyOn( | 198 }); |
| 188 dialog, 27 /* 'Esc' key code */); | |
| 189 }), | |
| 190 ]); | |
| 191 }); | 199 }); |
| 192 | 200 |
| 193 // Tests that when user request to reset the profile the appropriate | 201 // Tests that when user request to reset the profile the appropriate |
| 194 // message is sent to the browser. | 202 // message is sent to the browser. |
| 195 test(TestNames.ResetProfileDialogAction, function() { | 203 test(TestNames.ResetProfileDialogAction, function() { |
| 196 // Open reset profile dialog. | 204 // Open reset profile dialog. |
| 197 MockInteractions.tap(resetPage.$.resetProfile); | 205 MockInteractions.tap(resetPage.$.resetProfile); |
| 198 var dialog = resetPage.$$('settings-reset-profile-dialog'); | 206 var dialog = resetPage.$$('settings-reset-profile-dialog'); |
| 199 assertTrue(!!dialog); | 207 assertTrue(!!dialog); |
| 200 | 208 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 }); | 269 }); |
| 262 } | 270 } |
| 263 | 271 |
| 264 return { | 272 return { |
| 265 registerTests: function() { | 273 registerTests: function() { |
| 266 registerBannerTests(); | 274 registerBannerTests(); |
| 267 registerDialogTests(); | 275 registerDialogTests(); |
| 268 }, | 276 }, |
| 269 }; | 277 }; |
| 270 }); | 278 }); |
| OLD | NEW |