Bug 848489 - send 'contextmenu' event if we are long pressing, r=mdas
--- a/testing/marionette/client/marionette/tests/unit/test_single_finger.py
+++ b/testing/marionette/client/marionette/tests/unit/test_single_finger.py
@@ -54,8 +54,20 @@ class testSingleFinger(MarionetteTestCas
self.assertEqual("End", self.marionette.execute_script("return document.getElementById('delayed').innerHTML;"))
def test_no_press(self):
testTouch = self.marionette.absolute_url("testAction.html")
self.marionette.navigate(testTouch)
action = Actions(self.marionette)
action.release()
self.assertRaises(NoSuchElementException, action.perform)
+
+ def test_long_press(self):
+ testTouch = self.marionette.absolute_url("testAction.html")
+ self.marionette.navigate(testTouch)
+ button = self.marionette.find_element("id", "mozLinkCopy")
+ action = Actions(self.marionette)
+ action.press(button).wait(5).perform()
+ time.sleep(10)
+ self.assertEqual("Context", self.marionette.execute_script("return document.getElementById('mozLinkCopy').innerHTML;"))
+ action.release().perform()
+ time.sleep(10)
+ self.assertEqual("End", self.marionette.execute_script("return document.getElementById('mozLinkCopy').innerHTML;"))
--- a/testing/marionette/client/marionette/www/testAction.html
+++ b/testing/marionette/client/marionette/www/testAction.html
@@ -32,16 +32,18 @@
// touchmove and touchend must be performed on the same element as touchstart
// here is press for vertical move
press.addEventListener("touchstart", function(){changePressText("mozLink")}, false);
press.addEventListener("touchmove", changeMoveText, false);
press.addEventListener("touchend", changeReleaseText, false);
// here is second for a tap
second.addEventListener("touchstart", function(){changePressText("mozLinkCopy")}, false);
second.addEventListener("touchend", function(){changeClickText("mozLinkCopy")}, false);
+ // change for contextmenu
+ second.addEventListener("contextmenu", onContextMenuChange, false);
// here is third for horizontal move
third.addEventListener("touchstart", function(){changePressText("mozLinkStart")}, false);
third.addEventListener("touchmove", changeHorizontalMove, false);
third.addEventListener("touchend", changeHorizontalRelease, false);
// here is fourth for touch up and down with time shown
fourth.addEventListener("touchstart", changeTimePress, false);
fourth.addEventListener("touchend", changeTimeRelease, false);
// here is fifth for a cancel
@@ -90,17 +92,17 @@
var timeDiff = d.getTime() - press.innerHTML;
document.getElementById("mozLinkEnd").innerHTML = timeDiff;
}
}
function changeClickText(strId) {
var second = document.getElementById(strId);
- if (second.innerHTML == "Start") {
+ if (second.innerHTML == "Start" || second.innerHTML == "Context") {
second.innerHTML = "End";
}
else {
second.innerHTML = "Error";
}
}
function changeTimePress() {
@@ -124,11 +126,16 @@
}
else {
fourth.innerHTML = "Error";
}
if (checkPosition(event, "delayed")) {
document.getElementById("delayed").innerHTML = "End";
}
}
+
+ function onContextMenuChange() {
+ var context = document.getElementById("mozLinkCopy");
+ context.innerHTML = "Context";
+ }
</script>
</body>
</html>
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -960,16 +960,24 @@ function actions(finger, touchId, comman
// after this block, the element will be scrolled into view
if (!checkVisible(el, command_id)) {
sendError("Element is not currently visible and may not be manipulated", 11, null, command_id);
return;
}
touch = createATouch(el, corx, cory, touchId);
lastTouch = touch;
emitTouchEvent('touchstart', touch);
+ // check if it's a long press
+ // standard waiting time to fire contextmenu
+ let standard = Services.prefs.getIntPref("ui.click_hold_context_menus.delay");
+ // long press only happens when wait follows press
+ if (finger[i] != undefined && finger[i][0] == 'wait' && finger[i][1] != null && finger[i][1]*1000 >= standard) {
+ finger[i][1] = finger[i][1] - standard/1000;
+ finger.splice(i, 0, ['wait', standard/1000], ['longPress']);
+ }
actions(finger,touchId, command_id, i);
break;
case 'release':
if (lastTouch == null) {
sendError("Element has not been pressed: no such element", 7, null, command_id);
return;
}
touch = lastTouch;
@@ -1022,16 +1030,24 @@ function actions(finger, touchId, comman
}
break;
case 'cancel':
touch = lastTouch;
emitTouchEvent('touchcancel', touch);
lastTouch = null;
actions(finger, touchId, command_id, i);
break;
+ case 'longPress':
+ let event = curWindow.document.createEvent('HTMLEvents');
+ event.initEvent('contextmenu',
+ true,
+ true);
+ lastTouch.target.dispatchEvent(event);
+ actions(finger, touchId, command_id, i);
+ break;
}
}
/**
* Function to start action chain on one finger
*/
function actionChain(msg) {
let command_id = msg.json.command_id;