Skip to content

Commit

Permalink
handleJavascriptDialogs (#1939) (#2106)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbellet authored and paulirish committed May 1, 2017
1 parent 9706837 commit 283af87
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,23 @@ class Driver {
const promiseArr = urlPatterns.map(url => this.sendCommand('Network.addBlockedURL', {url}));
return Promise.all(promiseArr);
}

/**
* Dismiss JavaScript dialogs (alert, confirm, prompt), providing a
* generic promptText in case the dialog is a prompt.
* @return {!Promise}
*/
dismissJavaScriptDialogs() {
return this.sendCommand('Page.enable').then(_ => {
this.once('Page.javascriptDialogOpening', _ => {
// rejection intentionally unhandled
this.sendCommand('Page.handleJavaScriptDialog', {
accept: true,
promptText: 'Lighthouse prompt response',
});
});
});
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class GatherRunner {
.then(_ => driver.beginEmulation(options.flags))
.then(_ => driver.enableRuntimeEvents())
.then(_ => driver.cacheNatives())
.then(_ => driver.dismissJavaScriptDialogs())
.then(_ => resetStorage && driver.cleanAndDisableBrowserCaches())
.then(_ => resetStorage && driver.clearDataForOrigin(options.url))
.then(_ => driver.blockUrlPatterns(options.flags.blockedUrlPatterns || []))
Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/test/gather/fake-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ module.exports = {
setThrottling() {
return Promise.resolve();
},
dismissJavaScriptDialogs() {
return Promise.resolve();
},
assertNoSameOriginServiceWorkerClients() {
return Promise.resolve();
},
Expand Down
2 changes: 2 additions & 0 deletions lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ describe('GatherRunner', function() {
assertNoSameOriginServiceWorkerClients: asyncFunc,
beginEmulation: asyncFunc,
setThrottling: asyncFunc,
dismissJavaScriptDialogs: asyncFunc,
enableRuntimeEvents: asyncFunc,
cacheNatives: asyncFunc,
cleanAndDisableBrowserCaches: createCheck('calledDisableNetworkCache'),
Expand Down Expand Up @@ -283,6 +284,7 @@ describe('GatherRunner', function() {
assertNoSameOriginServiceWorkerClients: asyncFunc,
beginEmulation: asyncFunc,
setThrottling: asyncFunc,
dismissJavaScriptDialogs: asyncFunc,
enableRuntimeEvents: asyncFunc,
cacheNatives: asyncFunc,
cleanAndDisableBrowserCaches: createCheck('calledDisableNetworkCache'),
Expand Down

0 comments on commit 283af87

Please sign in to comment.