fix right click spec and implementation

This commit is contained in:
Michal Cichra 2013-02-27 22:25:01 +01:00
parent 47ac51e4dc
commit cb02ea7752
2 changed files with 9 additions and 5 deletions

View File

@ -991,12 +991,9 @@ describe Capybara::Webkit::Driver do
<ul id="events"></ul>
<script type="text/javascript">
var events = document.getElementById("events");
// https://developer.mozilla.org/en-US/docs/DOM/MouseEvent
var RIGHT_BUTTON = 2;
var recordEvent = function (event) {
var element = document.createElement("li");
var type = event.button == RIGHT_BUTTON ? 'contextmenu' : event.type;
element.innerHTML = type;
element.innerHTML = event.type;
events.appendChild(element);
};
@ -1032,7 +1029,7 @@ describe Capybara::Webkit::Driver do
it "triggers right click" do
watch.right_click
fired_events.should == %w(contextmenu)
fired_events.should == %w(mousedown contextmenu mouseup)
end
end

View File

@ -3,6 +3,7 @@
#include "InvocationResult.h"
#include <QApplication>
#include <QEvent>
#include <QContextMenuEvent>
JavascriptInvocation::JavascriptInvocation(const QString &functionName, const QStringList &arguments, WebPage *page, QObject *parent) : QObject(parent) {
m_functionName = functionName;
@ -48,6 +49,12 @@ void JavascriptInvocation::rightClick(int x, int y) {
hover(mousePos);
JavascriptInvocation::mouseEvent(QEvent::MouseButtonPress, mousePos, Qt::RightButton);
// swallowContextMenuEvent tries to fire contextmenu event in html page
QContextMenuEvent *event = new QContextMenuEvent(QContextMenuEvent::Mouse, mousePos);
m_page->swallowContextMenuEvent(event);
JavascriptInvocation::mouseEvent(QEvent::MouseButtonRelease, mousePos, Qt::RightButton);
}
void JavascriptInvocation::doubleClick(int x, int y) {