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

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: addressed comments Created 6 years, 1 month 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..8807c5f77a7fd331a69ae9db19355111471857fe
--- /dev/null
+++ b/LayoutTests/fast/events/mouse-event-buttons-attribute.html
@@ -0,0 +1,133 @@
+<!DOCTYPE html>
+<div id="region" style="width:100px; height:100px;"></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], action: doubleClickAction },
+ { type: ME, name: 'click', modifiers: [L, R], action: clickAction },
Rick Byers 2014/11/25 17:44:27 you're doing a click with the left mouse button, I
zino 2014/11/28 12:29:28 Done.
+ { type: ME, name: 'mousedown', modifiers: [L, M, R], action: clickAction },
+ { type: ME, name: 'mouseup', modifiers: [L, R], modifiersDown: [L, M, R], action: mouseUpAction },
+ { 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 },
+ { type: WE, name: 'mousewheel', modifiers: [L, R], action: wheelAction },
+ { type: GE, name: 'dblclick', modifiers: [L], action: doubleTapAction },
+ { type: GE, name: 'click', modifiers: [L], action: tapAction },
+ { type: GE, name: 'mousedown', modifiers: [L], action: tapAction },
+ { type: GE, name: 'mouseup', modifiers: [], modifiersDown: [L], action: tapAction },
+ { type: GE, name: 'mousemove', modifiers: [], action: tapAction },
+ { type: GE, name: 'contextmenu', modifiers: [R], action: longTapAction },
+];
+
+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 mouseUpAction(modifiers, modifiersDown)
+{
+ moveAction(modifiersDown);
+ eventSender.mouseDown(0, modifiersDown);
Rick Byers 2014/11/25 17:44:28 You should probably be testing the code you added
zino 2014/11/28 12:29:28 Done.
+ eventSender.mouseUp(1, modifiers);
+}
+
+function wheelAction(modifiers)
+{
+ moveAction(modifiers);
+ eventSender.mouseScrollBy(0, 120, false, true, modifiers);
+}
+
+function tapAction(modifiers)
+{
+ eventSender.gestureTap(50, 50);
+}
+
+function longTapAction(modifiers)
+{
+ eventSender.gestureLongPress(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].modifiersDown);
+ testSet[n].buttons = buttons;
+ div.removeEventListener(testSet[n].name, eventHandler, false);
+ buttons = -1;
+}
+
+function expectedValue(modifiers)
+{
+ var value = 0;
+ for (var i = 0; i < modifiers.length; i++)
+ value |= TABLE[modifiers[i]];
+
+ return value;
+}
+
+for (var i = 0; i < testSet.length; i++)
+ raiseEvent(i);
+
+for (var i = 0; i < testSet.length; i++) {
+ var modifiersDown = '';
+ if (testSet[i].modifiersDown != undefined)
+ modifiersDown += '[' + testSet[i].modifiersDown + '] -> ';
+ debug(testSet[i].type + '::' + testSet[i].name + ' test ' + modifiersDown + '[' + testSet[i].modifiers + ']');
+ shouldBeEqualToNumber('testSet[i].buttons', expectedValue(testSet[i].modifiers));
+ debug('');
+}
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698