This repository has been archived by the owner on May 30, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support contextmenu events using webpage.sendEvent('contextmenu')
Phantomjs issue #10688 Fixes #11429 by allowing to send a "contextmenu" event. Intentionally does not map a "click" event using "right" button into contextmenu event because this would be inconsistent with how browsers work. Related issue in Ghostdriver: https://github.com/detro/ghostdriver/issues/125
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
test(function () { | ||
var page = require('webpage').create(); | ||
|
||
page.evaluate(function() { | ||
window.addEventListener('contextmenu', function(event) { | ||
window.loggedEvent = window.loggedEvent || {}; | ||
window.loggedEvent.contextmenu = event; | ||
}, false); | ||
}); | ||
page.sendEvent('contextmenu', 42, 217); | ||
|
||
var event = page.evaluate(function() { | ||
return window.loggedEvent; | ||
}); | ||
assert_equals(event.contextmenu.clientX, 42); | ||
assert_equals(event.contextmenu.clientY, 217); | ||
|
||
// click with modifier key | ||
page.evaluate(function() { | ||
window.addEventListener('contextmenu', function(event) { | ||
window.loggedEvent = window.loggedEvent || {}; | ||
window.loggedEvent.contextmenu = event; | ||
}, false); | ||
}); | ||
page.sendEvent('contextmenu', 100, 100, 'left', page.event.modifier.shift); | ||
|
||
var event = page.evaluate(function() { | ||
return window.loggedEvent.contextmenu; | ||
}); | ||
assert_is_true(event.shiftKey); | ||
|
||
}, "context click events"); |