| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 }); | 86 }); |
| 87 | 87 |
| 88 setup(function() { | 88 setup(function() { |
| 89 PolymerTest.clearBody(); | 89 PolymerTest.clearBody(); |
| 90 resetPage = document.createElement('settings-reset-page'); | 90 resetPage = document.createElement('settings-reset-page'); |
| 91 document.body.appendChild(resetPage); | 91 document.body.appendChild(resetPage); |
| 92 }); | 92 }); |
| 93 | 93 |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * @param {function(SettingsResetProfileDialogElemeent):!Element} | 96 * @param {function(SettingsResetProfileDialogElemeent)} |
| 97 * closeButtonFn A function that returns the button to be used for | 97 * closeDialogFn A function to call for closing the dialog. |
| 98 * closing the dialog. | |
| 99 * @return {!Promise} | 98 * @return {!Promise} |
| 100 */ | 99 */ |
| 101 function testOpenCloseResetProfileDialog(closeButtonFn) { | 100 function testOpenCloseResetProfileDialog(closeDialogFn) { |
| 102 var onShowResetProfileDialogCalled = whenChromeSendCalled( | 101 var onShowResetProfileDialogCalled = whenChromeSendCalled( |
| 103 'onShowResetProfileDialog'); | 102 'onShowResetProfileDialog'); |
| 104 var onHideResetProfileDialogCalled = whenChromeSendCalled( | 103 var onHideResetProfileDialogCalled = whenChromeSendCalled( |
| 105 'onHideResetProfileDialog'); | 104 'onHideResetProfileDialog'); |
| 106 | 105 |
| 107 // Open reset profile dialog. | 106 // Open reset profile dialog. |
| 108 MockInteractions.tap(resetPage.$.resetProfile); | 107 MockInteractions.tap(resetPage.$.resetProfile); |
| 109 var dialog = resetPage.$$('settings-reset-profile-dialog'); | 108 var dialog = resetPage.$$('settings-reset-profile-dialog'); |
| 110 var onDialogClosed = new Promise( | 109 var onDialogClosed = new Promise( |
| 111 function(resolve, reject) { | 110 function(resolve, reject) { |
| 112 dialog.addEventListener('iron-overlay-closed', resolve); | 111 dialog.addEventListener('iron-overlay-closed', resolve); |
| 113 }); | 112 }); |
| 114 | 113 |
| 115 MockInteractions.tap(closeButtonFn(dialog)); | 114 closeDialogFn(dialog); |
| 116 | 115 |
| 117 return Promise.all([ | 116 return Promise.all([ |
| 118 onShowResetProfileDialogCalled, | 117 onShowResetProfileDialogCalled, |
| 119 onHideResetProfileDialogCalled, | 118 onHideResetProfileDialogCalled, |
| 120 onDialogClosed | 119 onDialogClosed |
| 121 ]); | 120 ]); |
| 122 } | 121 } |
| 123 | 122 |
| 124 // Tests that the reset profile dialog opens and closes correctly and that | 123 // Tests that the reset profile dialog opens and closes correctly and that |
| 125 // chrome.send calls are propagated as expected. | 124 // chrome.send calls are propagated as expected. |
| 126 test(TestNames.ResetProfileDialogOpenClose, function() { | 125 test(TestNames.ResetProfileDialogOpenClose, function() { |
| 127 return Promise.all([ | 126 return Promise.all([ |
| 128 // Test case where the 'cancel' button is clicked. | 127 // Test case where the 'cancel' button is clicked. |
| 129 testOpenCloseResetProfileDialog( | 128 testOpenCloseResetProfileDialog( |
| 130 function(dialog) { return dialog.$.cancel;}), | 129 function(dialog) { |
| 130 MockInteractions.tap(dialog.$.cancel); |
| 131 }), |
| 131 // Test case where the 'close' button is clicked. | 132 // Test case where the 'close' button is clicked. |
| 132 testOpenCloseResetProfileDialog( | 133 testOpenCloseResetProfileDialog( |
| 133 function(dialog) { return dialog.$.dialog.getCloseButton(); }), | 134 function(dialog) { |
| 135 MockInteractions.tap(dialog.$.dialog.getCloseButton()); |
| 136 }), |
| 137 // Test case where the 'Esc' key is pressed. |
| 138 testOpenCloseResetProfileDialog( |
| 139 function(dialog) { |
| 140 MockInteractions.pressAndReleaseKeyOn( |
| 141 dialog, 27 /* 'Esc' key code */); |
| 142 }), |
| 134 ]); | 143 ]); |
| 135 }); | 144 }); |
| 136 | 145 |
| 137 // Tests that when resetting the profile is requested chrome.send calls | 146 // Tests that when resetting the profile is requested chrome.send calls |
| 138 // are propagated as expected. | 147 // are propagated as expected. |
| 139 test(TestNames.ResetProfileDialogAction, function() { | 148 test(TestNames.ResetProfileDialogAction, function() { |
| 140 // Open reset profile dialog. | 149 // Open reset profile dialog. |
| 141 MockInteractions.tap(resetPage.$.resetProfile); | 150 MockInteractions.tap(resetPage.$.resetProfile); |
| 142 var dialog = resetPage.$$('settings-reset-profile-dialog'); | 151 var dialog = resetPage.$$('settings-reset-profile-dialog'); |
| 143 var promise = whenChromeSendCalled('performResetProfileSettings'); | 152 var promise = whenChromeSendCalled('performResetProfileSettings'); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 var dialog = resetPage.$$('settings-powerwash-dialog'); | 198 var dialog = resetPage.$$('settings-powerwash-dialog'); |
| 190 var promise = whenChromeSendCalled('requestFactoryResetRestart'); | 199 var promise = whenChromeSendCalled('requestFactoryResetRestart'); |
| 191 MockInteractions.tap(dialog.$.powerwash); | 200 MockInteractions.tap(dialog.$.powerwash); |
| 192 return promise; | 201 return promise; |
| 193 }); | 202 }); |
| 194 } | 203 } |
| 195 }); | 204 }); |
| 196 } | 205 } |
| 197 | 206 |
| 198 return { | 207 return { |
| 199 registerBannerTests: registerBannerTests, | 208 registerTests: function() { |
| 200 registerDialogTests: registerDialogTests | 209 registerBannerTests(); |
| 210 registerDialogTests(); |
| 211 }, |
| 201 }; | 212 }; |
| 202 }); | 213 }); |
| OLD | NEW |