| 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 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('iron-overlay-closed', function() { | 157 dialog.addEventListener('close', function() { |
| 158 assertFalse(dialog.$.dialog.opened); | 158 assertFalse(dialog.$.dialog.open); |
| 159 resolve(); | 159 resolve(); |
| 160 }); | 160 }); |
| 161 }); | 161 }); |
| 162 | 162 |
| 163 return new Promise(function(resolve, reject) { | 163 return resetPageBrowserProxy.whenCalled( |
| 164 resetPageBrowserProxy.whenCalled( | |
| 165 'onShowResetProfileDialog').then(function() { | 164 'onShowResetProfileDialog').then(function() { |
| 166 // Need to call requestAnimationFrame here, otherwise the dialog has | 165 closeDialogFn(dialog); |
| 167 // not been registered to the IronOverlayManager at the time we | 166 return Promise.all([ |
| 168 // attempt to close it (which prevents closing by 'esc' key from | 167 onDialogClosed, |
| 169 // working). | 168 resetPageBrowserProxy.whenCalled('onHideResetProfileDialog'), |
| 170 window.requestAnimationFrame(function() { | 169 ]); |
| 171 closeDialogFn(dialog); | |
| 172 Promise.all([ | |
| 173 onDialogClosed, | |
| 174 resetPageBrowserProxy.whenCalled('onHideResetProfileDialog'), | |
| 175 ]).then(resolve, reject); | |
| 176 }); | |
| 177 }); | |
| 178 }); | 170 }); |
| 179 } | 171 } |
| 180 | 172 |
| 181 // Tests that the reset profile dialog opens and closes correctly and that | 173 // Tests that the reset profile dialog opens and closes correctly and that |
| 182 // resetPageBrowserProxy calls are occurring as expected. | 174 // resetPageBrowserProxy calls are occurring as expected. |
| 183 test(TestNames.ResetProfileDialogOpenClose, function() { | 175 test(TestNames.ResetProfileDialogOpenClose, function() { |
| 184 return testOpenCloseResetProfileDialog(function(dialog) { | 176 return testOpenCloseResetProfileDialog(function(dialog) { |
| 185 // Test case where the 'cancel' button is clicked. | 177 // Test case where the 'cancel' button is clicked. |
| 186 MockInteractions.tap(dialog.$.cancel); | 178 MockInteractions.tap(dialog.$.cancel); |
| 187 }).then(function() { | 179 }).then(function() { |
| 188 return testOpenCloseResetProfileDialog(function(dialog) { | 180 return testOpenCloseResetProfileDialog(function(dialog) { |
| 189 // Test case where the 'close' button is clicked. | 181 // Test case where the 'close' button is clicked. |
| 190 MockInteractions.tap(dialog.$.dialog.getCloseButton()); | 182 MockInteractions.tap(dialog.$.dialog.getCloseButton()); |
| 191 }); | 183 }); |
| 192 }).then(function() { | |
| 193 return testOpenCloseResetProfileDialog(function(dialog) { | |
| 194 // Test case where the 'Esc' key is pressed. | |
| 195 MockInteractions.pressAndReleaseKeyOn( | |
| 196 dialog, 27 /* 'Esc' key code */); | |
| 197 }); | |
| 198 }); | 184 }); |
| 199 }); | 185 }); |
| 200 | 186 |
| 201 // Tests that when user request to reset the profile the appropriate | 187 // Tests that when user request to reset the profile the appropriate |
| 202 // message is sent to the browser. | 188 // message is sent to the browser. |
| 203 test(TestNames.ResetProfileDialogAction, function() { | 189 test(TestNames.ResetProfileDialogAction, function() { |
| 204 // Open reset profile dialog. | 190 // Open reset profile dialog. |
| 205 MockInteractions.tap(resetPage.$.resetProfile); | 191 MockInteractions.tap(resetPage.$.resetProfile); |
| 206 var dialog = resetPage.$$('settings-reset-profile-dialog'); | 192 var dialog = resetPage.$$('settings-reset-profile-dialog'); |
| 207 assertTrue(!!dialog); | 193 assertTrue(!!dialog); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 227 * @param {function(SettingsPowerwashDialogElemeent):!Element} | 213 * @param {function(SettingsPowerwashDialogElemeent):!Element} |
| 228 * closeButtonFn A function that returns the button to be used for | 214 * closeButtonFn A function that returns the button to be used for |
| 229 * closing the dialog. | 215 * closing the dialog. |
| 230 * @return {!Promise} | 216 * @return {!Promise} |
| 231 */ | 217 */ |
| 232 function testOpenClosePowerwashDialog(closeButtonFn) { | 218 function testOpenClosePowerwashDialog(closeButtonFn) { |
| 233 // Open powerwash dialog. | 219 // Open powerwash dialog. |
| 234 MockInteractions.tap(resetPage.$.powerwash); | 220 MockInteractions.tap(resetPage.$.powerwash); |
| 235 var dialog = resetPage.$$('settings-powerwash-dialog'); | 221 var dialog = resetPage.$$('settings-powerwash-dialog'); |
| 236 assertTrue(!!dialog); | 222 assertTrue(!!dialog); |
| 223 assertTrue(dialog.$.dialog.open); |
| 237 var onDialogClosed = new Promise( | 224 var onDialogClosed = new Promise( |
| 238 function(resolve, reject) { | 225 function(resolve, reject) { |
| 239 dialog.addEventListener('iron-overlay-closed', resolve); | 226 dialog.addEventListener('close', function() { |
| 227 assertFalse(dialog.$.dialog.open); |
| 228 resolve(); |
| 240 }); | 229 }); |
| 230 }); |
| 241 | 231 |
| 242 MockInteractions.tap(closeButtonFn(dialog)); | 232 MockInteractions.tap(closeButtonFn(dialog)); |
| 243 return Promise.all([ | 233 return Promise.all([ |
| 244 onDialogClosed, | 234 onDialogClosed, |
| 245 resetPageBrowserProxy.whenCalled('onPowerwashDialogShow'), | 235 resetPageBrowserProxy.whenCalled('onPowerwashDialogShow'), |
| 246 ]); | 236 ]); |
| 247 } | 237 } |
| 248 | 238 |
| 249 // Tests that the powerwash dialog opens and closes correctly, and | 239 // Tests that the powerwash dialog opens and closes correctly, and |
| 250 // that chrome.send calls are propagated as expected. | 240 // that chrome.send calls are propagated as expected. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 273 }); | 263 }); |
| 274 } | 264 } |
| 275 | 265 |
| 276 return { | 266 return { |
| 277 registerTests: function() { | 267 registerTests: function() { |
| 278 registerBannerTests(); | 268 registerBannerTests(); |
| 279 registerDialogTests(); | 269 registerDialogTests(); |
| 280 }, | 270 }, |
| 281 }; | 271 }; |
| 282 }); | 272 }); |
| OLD | NEW |