Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: LayoutTests/fast/events/mouse-event-buttons-attribute.html

Issue 727593003: Implement MouseEvent buttons attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: nits Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/events/mouse-event-buttons-attribute.html
diff --git a/LayoutTests/fast/events/mouse-event-buttons-attribute.html b/LayoutTests/fast/events/mouse-event-buttons-attribute.html
new file mode 100644
index 0000000000000000000000000000000000000000..d5fef635a799aa2f8ff0f0142f1f99ab67c47a7e
--- /dev/null
+++ b/LayoutTests/fast/events/mouse-event-buttons-attribute.html
@@ -0,0 +1,153 @@
+<!DOCTYPE html>
+<div id="region" style="width:100px; height:100px; position:absolute; left:0px; top:0px;"></div>
+<script src="../../resources/js-test.js"></script>
+<script>
+
+const L = 'leftButton';
+const R = 'rightButton';
+const M = 'middleButton';
+const TABLE = {
+ 'leftButton': 1,
+ 'rightButton': 2,
+ 'middleButton': 4
+};
+const ME = 'MouseEvent';
+const WE = 'WheelEvent';
+const GE = 'GestureEvent';
+
+var buttons = -2;
+var div = document.getElementById('region');
+var testSet = [
+ { type: ME, name: 'dblclick', modifiers: [L], expectedModifiers: [], action: doubleClickAction },
+ { type: ME, name: 'click', modifiers: [L, R], expectedModifiers: [R], action: clickAction },
+ { type: ME, name: 'mousedown', modifiers: [L, M, R], action: clickAction },
+ { type: ME, name: 'mouseup', modifiers: [L, M, R], expectedModifiers: [M, R], action: clickAction },
+ { type: ME, name: 'mousemove', modifiers: [], action: moveAction },
+ { type: ME, name: 'mousemove', modifiers: [L], action: moveAction },
+ { type: ME, name: 'mouseenter', modifiers: [R, M], action: moveAction },
+ { type: ME, name: 'mouseleave', modifiers: [L, R], action: moveAction },
+ { type: ME, name: 'mouseover', modifiers: [L, M], action: moveAction },
+ { type: ME, name: 'mouseout', modifiers: [L], action: moveAction },
+ { type: ME, name: 'contextmenu', modifiers: [R], action: rightClickAction, showContextMenuOnMouseUp: false },
+ { type: ME, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action: rightClickAction, showContextMenuOnMouseUp: true },
+ { type: WE, name: 'mousewheel', modifiers: [L, R], action: wheelAction },
+ { type: GE, name: 'dblclick', modifiers: [L], expectedModifiers: [], action: doubleTapAction },
+ { type: GE, name: 'click', modifiers: [L], expectedModifiers: [], action: tapAction },
+ { type: GE, name: 'mousedown', modifiers: [L], action: tapAction },
+ { type: GE, name: 'mouseup', modifiers: [L], expectedModifiers: [], action: tapAction },
+ { type: GE, name: 'mousemove', modifiers: [], action: tapAction },
+ { type: GE, name: 'mousedown', modifiers: [R], action: longPressAction },
+ { type: GE, name: 'contextmenu', modifiers: [R], action: longPressAction, showContextMenuOnMouseUp: false },
+ { type: GE, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action: longPressAction, showContextMenuOnMouseUp: true },
+ { type: GE, name: 'contextmenu', modifiers: [R], action: longTapAction, showContextMenuOnMouseUp: false },
+ { type: GE, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action: longTapAction, showContextMenuOnMouseUp: true },
+];
+
+function eventHandler(e)
+{
+ buttons = e.buttons;
+}
+
+function moveAction(modifiers)
+{
+ eventSender.mouseMoveTo(-1, -1, modifiers);
+ eventSender.mouseMoveTo(50, 50, modifiers);
+}
+
+function clickAction(modifiers)
+{
+ moveAction(modifiers);
+ eventSender.mouseDown(0, modifiers);
+ eventSender.mouseUp(0, modifiers);
+}
+
+function rightClickAction(modifiers)
+{
+ moveAction(modifiers);
+ eventSender.mouseDown(2, modifiers);
+ eventSender.mouseUp(2, modifiers);
+}
+
+function doubleClickAction(modifiers)
+{
+ clickAction(modifiers);
+ clickAction(modifiers);
+}
+
+function wheelAction(modifiers)
+{
+ moveAction(modifiers);
+ eventSender.mouseScrollBy(0, 120, false, true, modifiers);
+}
+
+function tapAction(modifiers)
+{
+ eventSender.gestureTap(50, 50);
+}
+
+function longPressAction(modifiers)
+{
+ eventSender.gestureLongPress(50, 50);
+}
+
+function longTapAction(modifiers)
+{
+ eventSender.gestureLongPress(50, 50);
+ eventSender.gestureLongTap(50, 50);
+}
+
+function doubleTapAction(modifiers)
+{
+ eventSender.gestureTap(50, 50, 2);
+}
+
+function raiseEvent(n)
+{
+ if (!window.eventSender)
+ return;
+
+ div.addEventListener(testSet[n].name, eventHandler, false);
+ testSet[n].action(testSet[n].modifiers);
+ testSet[n].buttons = buttons;
+ div.removeEventListener(testSet[n].name, eventHandler, false);
+ buttons = -1;
+}
+
+function expectedValue(testItem)
+{
+ var modifiers;
+ if (testItem.expectedModifiers != undefined)
+ modifiers = testItem.expectedModifiers;
+ else
+ modifiers = testItem.modifiers;
+
+ var value = 0;
+ for (var i = 0; i < modifiers.length; i++)
+ value |= TABLE[modifiers[i]];
+
+ return value;
+}
+
+function printTestInfo(testItem)
+{
+ var modifiers = testSet[i].expectedModifiers || testSet[i].modifiers;
+ var expectedModifiersString = ' -> shouldBe([' + modifiers +'])';
+
+ var showContextMenuOnMouseUp = "";
+ if (testSet[i].showContextMenuOnMouseUp != undefined)
+ showContextMenuOnMouseUp = " with |showContextMenuOnMouseUp=" +
+ testSet[i].showContextMenuOnMouseUp + "|";
+
+ debug(testSet[i].type + '::' + testSet[i].name + showContextMenuOnMouseUp + ' '
+ + testSet[i].action.name + '([' + testSet[i].modifiers + '])' + expectedModifiersString);
+}
+
+for (var i = 0; i < testSet.length; i++) {
+ internals.settings.setShowContextMenuOnMouseUp(testSet[i].showContextMenuOnMouseUp);
+ raiseEvent(i);
+ printTestInfo(testSet[i]);
+ shouldBeEqualToNumber('testSet[i].buttons', expectedValue(testSet[i]));
+ debug('');
+}
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698