Chromium Code Reviews| 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', |
| 11 ResetBannerReset: 'ResetBannerReset', | 11 ResetBannerReset: 'ResetBannerReset', |
| 12 ResetProfileDialogAction: 'ResetProfileDialogAction', | 12 ResetProfileDialogAction: 'ResetProfileDialogAction', |
| 13 ResetProfileDialogOpenClose: 'ResetProfileDialogOpenClose', | 13 ResetProfileDialogOpenClose: 'ResetProfileDialogOpenClose', |
| 14 }; | 14 }; |
| 15 | 15 |
| 16 /** | |
| 17 * @constructor | |
| 18 * @implements {settings.ResetBrowserProxy} | |
| 19 * @extends {settings.TestBrowserProxy} | |
| 20 */ | |
| 21 var TestResetBrowserProxy = function() { | |
| 22 settings.TestBrowserProxy.call(this, [ | |
| 23 'performResetProfileSettings', | |
| 24 'onHideResetProfileDialog', | |
| 25 'onHideResetProfileBanner', | |
| 26 'onShowResetProfileDialog', | |
| 27 'onPowerwashDialogShow', | |
| 28 'requestFactoryResetRestart', | |
| 29 ]); | |
| 30 }; | |
| 16 | 31 |
| 17 /** | 32 TestResetBrowserProxy.prototype = { |
| 18 * @param {string} name chrome.send message name. | 33 __proto__: settings.TestBrowserProxy.prototype, |
| 19 * @return {!Promise} Fires when chrome.send is called with the given message | 34 |
| 20 * name. | 35 /** @override */ |
| 21 */ | 36 performResetProfileSettings: function(sendSettings) { |
| 22 function whenChromeSendCalled(name) { | 37 this.methodCalled('performResetProfileSettings'); |
| 23 return new Promise(function(resolve, reject) { | 38 return Promise.resolve(); |
| 24 registerMessageCallback(name, null, resolve); | 39 }, |
| 25 }); | 40 |
| 26 } | 41 /** @override */ |
| 42 onHideResetProfileDialog: function() { | |
| 43 this.methodCalled('onHideResetProfileDialog'); | |
| 44 }, | |
| 45 | |
| 46 /** @override */ | |
| 47 onHideResetProfileBanner: function() { | |
| 48 this.methodCalled('onHideResetProfileBanner'); | |
| 49 }, | |
| 50 | |
| 51 /** @override */ | |
| 52 onShowResetProfileDialog: function() { | |
| 53 this.methodCalled('onShowResetProfileDialog'); | |
| 54 }, | |
| 55 | |
| 56 /** @override */ | |
| 57 onPowerwashDialogShow: function() { | |
| 58 this.methodCalled('onPowerwashDialogShow'); | |
| 59 }, | |
| 60 | |
| 61 /** @override */ | |
| 62 requestFactoryResetRestart: function() { | |
| 63 this.methodCalled('requestFactoryResetRestart'); | |
| 64 }, | |
| 65 }; | |
| 27 | 66 |
| 28 function registerBannerTests() { | 67 function registerBannerTests() { |
| 29 suite('BannerTests', function() { | 68 suite('BannerTests', function() { |
| 30 var resetBanner = null; | 69 var resetBanner = null; |
| 70 var browserProxy = null; | |
| 31 | 71 |
| 32 suiteSetup(function() { | 72 suiteSetup(function() { |
| 33 return Promise.all([ | 73 return PolymerTest.importHtml( |
| 34 PolymerTest.importHtml('chrome://md-settings/i18n_setup.html'), | 74 'chrome://md-settings/reset_page/reset_profile_banner.html'); |
| 35 PolymerTest.importHtml( | |
| 36 'chrome://md-settings/reset_page/reset_profile_banner.html') | |
| 37 ]); | |
| 38 }); | 75 }); |
| 39 | 76 |
| 40 setup(function() { | 77 setup(function() { |
| 78 browserProxy = new TestResetBrowserProxy(); | |
| 79 settings.ResetBrowserProxyImpl.instance_ = browserProxy; | |
| 41 PolymerTest.clearBody(); | 80 PolymerTest.clearBody(); |
| 42 resetBanner = document.createElement('settings-reset-profile-banner'); | 81 resetBanner = document.createElement('settings-reset-profile-banner'); |
| 43 document.body.appendChild(resetBanner); | 82 document.body.appendChild(resetBanner); |
| 44 }); | 83 }); |
| 45 | 84 |
| 85 teardown(function() { resetBanner.remove(); }); | |
| 86 | |
| 46 // Tests that the reset profile banner | 87 // Tests that the reset profile banner |
| 47 // - opens the reset profile dialog when the reset button is clicked. | 88 // - opens the reset profile dialog when the reset button is clicked. |
| 48 // - the reset profile dialog is closed after reset is done. | 89 // - the reset profile dialog is closed after reset is done. |
| 49 test(TestNames.ResetBannerReset, function() { | 90 test(TestNames.ResetBannerReset, function() { |
| 50 var dialog = resetBanner.$$('settings-reset-profile-dialog'); | 91 var dialog = resetBanner.$$('settings-reset-profile-dialog'); |
| 51 assert(!dialog); | 92 assertFalse(!!dialog); |
| 52 MockInteractions.tap(resetBanner.$['reset']); | 93 MockInteractions.tap(resetBanner.$['reset']); |
| 53 Polymer.dom.flush(); | 94 Polymer.dom.flush(); |
| 54 dialog = resetBanner.$$('settings-reset-profile-dialog'); | 95 dialog = resetBanner.$$('settings-reset-profile-dialog'); |
| 55 assertNotEquals(undefined, dialog); | 96 assertTrue(!!dialog); |
| 56 | 97 |
| 57 dialog.dispatchResetDoneEvent(); | 98 dialog.dispatchResetDoneEvent(); |
| 58 Polymer.dom.flush(); | 99 Polymer.dom.flush(); |
| 59 assertEquals('none', dialog.style.display); | 100 assertEquals('none', dialog.style.display); |
| 60 return Promise.resolve(); | 101 return Promise.resolve(); |
| 61 }); | 102 }); |
| 62 | 103 |
| 63 // 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 |
| 64 // the close button is clicked and that | 105 // the close button is clicked and that |onHideResetProfileBanner| is |
| 65 // chrome.send('onHideResetProfileBanner') is called. | 106 // called. |
| 66 test(TestNames.ResetBannerClose, function() { | 107 test(TestNames.ResetBannerClose, function() { |
| 67 var whenOnHideResetProfileBanner = whenChromeSendCalled( | |
| 68 'onHideResetProfileBanner'); | |
| 69 MockInteractions.tap(resetBanner.$['close']); | 108 MockInteractions.tap(resetBanner.$['close']); |
| 70 assert(!resetBanner.parentNode); | 109 assertFalse(!!resetBanner.parentNode); |
| 71 return whenOnHideResetProfileBanner; | 110 return browserProxy.whenCalled('onHideResetProfileBanner'); |
| 72 }); | 111 }); |
| 73 }); | 112 }); |
| 74 } | 113 } |
| 75 | 114 |
| 76 function registerDialogTests() { | 115 function registerDialogTests() { |
| 77 suite('DialogTests', function() { | 116 suite('DialogTests', function() { |
| 78 var resetPage = null; | 117 var resetPage = null; |
| 79 | 118 |
| 80 suiteSetup(function() { | |
| 81 return Promise.all([ | |
| 82 PolymerTest.importHtml('chrome://md-settings/i18n_setup.html'), | |
| 83 PolymerTest.importHtml( | |
| 84 'chrome://md-settings/reset_page/reset_page.html') | |
| 85 ]); | |
| 86 }); | |
| 87 | |
| 88 setup(function() { | 119 setup(function() { |
| 120 browserProxy = new TestResetBrowserProxy(); | |
| 121 settings.ResetBrowserProxyImpl.instance_ = browserProxy; | |
| 89 PolymerTest.clearBody(); | 122 PolymerTest.clearBody(); |
| 90 resetPage = document.createElement('settings-reset-page'); | 123 resetPage = document.createElement('settings-reset-page'); |
| 91 document.body.appendChild(resetPage); | 124 document.body.appendChild(resetPage); |
| 92 }); | 125 }); |
| 93 | 126 |
| 127 teardown(function() { resetPage.remove(); }); | |
| 94 | 128 |
| 95 /** | 129 /** |
| 96 * @param {function(SettingsResetProfileDialogElemeent)} | 130 * @param {function(SettingsResetProfileDialogElemeent)} |
| 97 * closeDialogFn A function to call for closing the dialog. | 131 * closeDialogFn A function to call for closing the dialog. |
| 98 * @return {!Promise} | 132 * @return {!Promise} |
| 99 */ | 133 */ |
| 100 function testOpenCloseResetProfileDialog(closeDialogFn) { | 134 function testOpenCloseResetProfileDialog(closeDialogFn) { |
| 101 var onShowResetProfileDialogCalled = whenChromeSendCalled( | 135 browserProxy.resetResolver('onShowResetProfileDialog'); |
| 102 'onShowResetProfileDialog'); | 136 browserProxy.resetResolver('onHideResetProfileDialog'); |
| 103 var onHideResetProfileDialogCalled = whenChromeSendCalled( | |
| 104 'onHideResetProfileDialog'); | |
| 105 | 137 |
| 106 // Open reset profile dialog. | 138 // Open reset profile dialog. |
| 107 MockInteractions.tap(resetPage.$.resetProfile); | 139 MockInteractions.tap(resetPage.$.resetProfile); |
| 108 var dialog = resetPage.$$('settings-reset-profile-dialog'); | 140 var dialog = resetPage.$$('settings-reset-profile-dialog'); |
| 141 assertTrue(!!dialog); | |
| 109 var onDialogClosed = new Promise( | 142 var onDialogClosed = new Promise( |
| 110 function(resolve, reject) { | 143 function(resolve, reject) { |
| 111 dialog.addEventListener('iron-overlay-closed', resolve); | 144 dialog.addEventListener('iron-overlay-closed', resolve); |
| 112 }); | 145 }); |
| 113 | 146 |
| 114 closeDialogFn(dialog); | 147 return browserProxy.whenCalled('onShowResetProfileDialog').then( |
| 115 | 148 function() { |
| 116 return Promise.all([ | 149 closeDialogFn(dialog); |
| 117 onShowResetProfileDialogCalled, | 150 return Promise.all([ |
| 118 onHideResetProfileDialogCalled, | 151 onDialogClosed, |
|
tommycli
2016/04/05 18:46:29
nit: Tricky but I like it. I think the indentation
dpapad
2016/04/05 19:23:12
You are right, done.
| |
| 119 onDialogClosed | 152 browserProxy.whenCalled('onHideResetProfileDialog'), |
| 120 ]); | 153 ]); |
| 154 }); | |
| 121 } | 155 } |
| 122 | 156 |
| 123 // Tests that the reset profile dialog opens and closes correctly and that | 157 // Tests that the reset profile dialog opens and closes correctly and that |
| 124 // chrome.send calls are propagated as expected. | 158 // browserProxy calls are ocurring as expected. |
|
tommycli
2016/04/05 18:46:28
typo: occurring
| |
| 125 test(TestNames.ResetProfileDialogOpenClose, function() { | 159 test(TestNames.ResetProfileDialogOpenClose, function() { |
| 126 return Promise.all([ | 160 return Promise.all([ |
| 127 // Test case where the 'cancel' button is clicked. | 161 // Test case where the 'cancel' button is clicked. |
| 128 testOpenCloseResetProfileDialog( | 162 testOpenCloseResetProfileDialog( |
| 129 function(dialog) { | 163 function(dialog) { |
| 130 MockInteractions.tap(dialog.$.cancel); | 164 MockInteractions.tap(dialog.$.cancel); |
| 131 }), | 165 }), |
| 132 // Test case where the 'close' button is clicked. | 166 // Test case where the 'close' button is clicked. |
| 133 testOpenCloseResetProfileDialog( | 167 testOpenCloseResetProfileDialog( |
| 134 function(dialog) { | 168 function(dialog) { |
| 135 MockInteractions.tap(dialog.$.dialog.getCloseButton()); | 169 MockInteractions.tap(dialog.$.dialog.getCloseButton()); |
| 136 }), | 170 }), |
| 137 // Test case where the 'Esc' key is pressed. | 171 // Test case where the 'Esc' key is pressed. |
| 138 testOpenCloseResetProfileDialog( | 172 testOpenCloseResetProfileDialog( |
| 139 function(dialog) { | 173 function(dialog) { |
| 140 MockInteractions.pressAndReleaseKeyOn( | 174 MockInteractions.pressAndReleaseKeyOn( |
| 141 dialog, 27 /* 'Esc' key code */); | 175 dialog, 27 /* 'Esc' key code */); |
| 142 }), | 176 }), |
| 143 ]); | 177 ]); |
| 144 }); | 178 }); |
| 145 | 179 |
| 146 // Tests that when resetting the profile is requested chrome.send calls | 180 // Tests that when user request to reset the profile the appropriate |
| 147 // are propagated as expected. | 181 // message is sent to the browser. |
| 148 test(TestNames.ResetProfileDialogAction, function() { | 182 test(TestNames.ResetProfileDialogAction, function() { |
| 149 // Open reset profile dialog. | 183 // Open reset profile dialog. |
| 150 MockInteractions.tap(resetPage.$.resetProfile); | 184 MockInteractions.tap(resetPage.$.resetProfile); |
| 151 var dialog = resetPage.$$('settings-reset-profile-dialog'); | 185 var dialog = resetPage.$$('settings-reset-profile-dialog'); |
| 152 var promise = whenChromeSendCalled('performResetProfileSettings'); | 186 assertTrue(!!dialog); |
| 153 MockInteractions.tap(dialog.$.reset); | 187 MockInteractions.tap(dialog.$.reset); |
| 154 return promise; | 188 return browserProxy.whenCalled('performResetProfileSettings'); |
| 155 }); | 189 }); |
| 156 | 190 |
| 157 if (cr.isChromeOS) { | 191 if (cr.isChromeOS) { |
| 158 /** | 192 /** |
| 159 * @param {function(SettingsPowerwashDialogElemeent):!Element} | 193 * @param {function(SettingsPowerwashDialogElemeent):!Element} |
| 160 * closeButtonFn A function that returns the button to be used for | 194 * closeButtonFn A function that returns the button to be used for |
| 161 * closing the dialog. | 195 * closing the dialog. |
| 162 * @return {!Promise} | 196 * @return {!Promise} |
| 163 */ | 197 */ |
| 164 function testOpenClosePowerwashDialog(closeButtonFn) { | 198 function testOpenClosePowerwashDialog(closeButtonFn) { |
| 165 var onPowerwashDialogShowCalled = whenChromeSendCalled( | |
| 166 'onPowerwashDialogShow'); | |
| 167 | |
| 168 // Open powerwash dialog. | 199 // Open powerwash dialog. |
| 169 MockInteractions.tap(resetPage.$.powerwash); | 200 MockInteractions.tap(resetPage.$.powerwash); |
| 170 var dialog = resetPage.$$('settings-powerwash-dialog'); | 201 var dialog = resetPage.$$('settings-powerwash-dialog'); |
| 202 assertTrue(!!dialog); | |
| 171 var onDialogClosed = new Promise( | 203 var onDialogClosed = new Promise( |
| 172 function(resolve, reject) { | 204 function(resolve, reject) { |
| 173 dialog.addEventListener('iron-overlay-closed', resolve); | 205 dialog.addEventListener('iron-overlay-closed', resolve); |
| 174 }); | 206 }); |
| 175 | 207 |
| 176 MockInteractions.tap(closeButtonFn(dialog)); | 208 MockInteractions.tap(closeButtonFn(dialog)); |
| 177 return Promise.all([onPowerwashDialogShowCalled, onDialogClosed]); | 209 return Promise.all([ |
| 210 onDialogClosed, | |
| 211 browserProxy.whenCalled('onPowerwashDialogShow'), | |
| 212 ]); | |
| 178 } | 213 } |
| 179 | 214 |
| 180 // Tests that the powerwash dialog opens and closes correctly, and | 215 // Tests that the powerwash dialog opens and closes correctly, and |
| 181 // that chrome.send calls are propagated as expected. | 216 // that chrome.send calls are propagated as expected. |
| 182 test(TestNames.PowerwashDialogOpenClose, function() { | 217 test(TestNames.PowerwashDialogOpenClose, function() { |
| 183 return Promise.all([ | 218 return Promise.all([ |
| 184 // Test case where the 'cancel' button is clicked. | 219 // Test case where the 'cancel' button is clicked. |
| 185 testOpenClosePowerwashDialog( | 220 testOpenClosePowerwashDialog( |
| 186 function(dialog) { return dialog.$.cancel; }), | 221 function(dialog) { return dialog.$.cancel; }), |
| 187 // Test case where the 'close' button is clicked. | 222 // Test case where the 'close' button is clicked. |
| 188 testOpenClosePowerwashDialog( | 223 testOpenClosePowerwashDialog( |
| 189 function(dialog) { return dialog.$.dialog.getCloseButton(); }), | 224 function(dialog) { return dialog.$.dialog.getCloseButton(); }), |
| 190 ]); | 225 ]); |
| 191 }); | 226 }); |
| 192 | 227 |
| 193 // Tests that when powerwash is requested chrome.send calls are | 228 // Tests that when powerwash is requested chrome.send calls are |
| 194 // propagated as expected. | 229 // propagated as expected. |
| 195 test(TestNames.PowerwashDialogAction, function() { | 230 test(TestNames.PowerwashDialogAction, function() { |
| 196 // Open powerwash dialog. | 231 // Open powerwash dialog. |
| 197 MockInteractions.tap(resetPage.$.powerwash); | 232 MockInteractions.tap(resetPage.$.powerwash); |
| 198 var dialog = resetPage.$$('settings-powerwash-dialog'); | 233 var dialog = resetPage.$$('settings-powerwash-dialog'); |
| 199 var promise = whenChromeSendCalled('requestFactoryResetRestart'); | 234 assertTrue(!!dialog); |
| 200 MockInteractions.tap(dialog.$.powerwash); | 235 MockInteractions.tap(dialog.$.powerwash); |
| 201 return promise; | 236 return browserProxy.whenCalled('requestFactoryResetRestart'); |
| 202 }); | 237 }); |
| 203 } | 238 } |
| 204 }); | 239 }); |
| 205 } | 240 } |
| 206 | 241 |
| 207 return { | 242 return { |
| 208 registerTests: function() { | 243 registerTests: function() { |
| 209 registerBannerTests(); | 244 registerBannerTests(); |
| 210 registerDialogTests(); | 245 registerDialogTests(); |
| 211 }, | 246 }, |
| 212 }; | 247 }; |
| 213 }); | 248 }); |
| OLD | NEW |