@@ -168,30 +168,11 @@ fxdriver.modals.signalOpenModal = function(parent, text) {
168
168
if ( driver && driver . response_ ) {
169
169
fxdriver . modals . setFlag ( driver , text ) ;
170
170
var res = driver . response_ ;
171
- if ( driver . response_ . name == 'executeAsyncScript' && ! driver . response_ . responseSent_ ) {
171
+ if ( res . name == 'executeAsyncScript' && ! res . responseSent_ ) {
172
172
// Special case handling. If a modal is open when executeAsyncScript
173
173
// tries to respond with a result, it doesn't do anything, so that this
174
174
// codepath can be followed.
175
- fxdriver . modals . isModalPresent ( function ( present ) {
176
- var errorMessage = 'Unexpected modal dialog (text: ' + text + ')' ;
177
- if ( present ) {
178
- try {
179
- fxdriver . modals . dismissAlert ( driver ) ;
180
- } catch ( e ) {
181
- errorMessage +=
182
- ' The alert could not be closed. The browser may be in a ' +
183
- 'wildly inconsistent state, and the alert may still be ' +
184
- 'open. This is not good. If you can reliably reproduce this' +
185
- ', please report a new issue at ' +
186
- 'https://code.google.com/p/selenium/issues/entry ' +
187
- 'with reproduction steps. Exception message: ' + e ;
188
- }
189
- } else {
190
- errorMessage += ' The alert disappeared before it could be closed.' ;
191
- }
192
- res . sendError ( new WebDriverError ( bot . ErrorCode . UNEXPECTED_ALERT_OPEN ,
193
- errorMessage , { alert : { text : text } } ) ) ;
194
- } , 2000 ) ;
175
+ fxdriver . modals . closeUnhandledAlert ( res , driver , false ) ;
195
176
} else {
196
177
// We hope that modals can only be opened by actions which don't pay
197
178
// attention to the results of the command. Given this, the only ways we
@@ -252,3 +233,32 @@ fxdriver.modals.getUnexpectedAlertBehaviour = function() {
252
233
var raw = prefs . getCharPref ( 'webdriver_unexpected_alert_behaviour' ) ;
253
234
return fxdriver . modals . asAcceptableAlertValue ( raw ) ;
254
235
} ;
236
+
237
+
238
+ fxdriver . modals . closeUnhandledAlert = function ( response , driver , accept ) {
239
+ var text = driver . modalOpen ;
240
+ fxdriver . modals . isModalPresent ( function ( present ) {
241
+ var errorMessage = 'Unexpected modal dialog (text: ' + text + ')' ;
242
+ if ( present ) {
243
+ try {
244
+ if ( accept ) {
245
+ fxdriver . modals . acceptAlert ( driver ) ;
246
+ } else {
247
+ fxdriver . modals . dismissAlert ( driver ) ;
248
+ }
249
+ } catch ( e ) {
250
+ errorMessage +=
251
+ ' The alert could not be closed. The browser may be in a ' +
252
+ 'wildly inconsistent state, and the alert may still be ' +
253
+ 'open. This is not good. If you can reliably reproduce this' +
254
+ ', please report a new issue at ' +
255
+ 'https://code.google.com/p/selenium/issues/entry ' +
256
+ 'with reproduction steps. Exception message: ' + e ;
257
+ }
258
+ } else {
259
+ errorMessage += ' The alert disappeared before it could be closed.' ;
260
+ }
261
+ response . sendError ( new WebDriverError ( bot . ErrorCode . UNEXPECTED_ALERT_OPEN ,
262
+ errorMessage , { alert : { text : text } } ) ) ;
263
+ } , 2000 ) ;
264
+ } ;
0 commit comments