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..7479effabbff59a562adcc844d7ef723ba82171c |
--- /dev/null |
+++ b/LayoutTests/fast/events/mouse-event-buttons-attribute.html |
@@ -0,0 +1,137 @@ |
+<!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: [L, 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], expectedModifiers: [], action: rightClickAction }, |
+ { 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: 'contextmenu', modifiers: [R], expectedModifiers: [], action: longTapAction }, |
Rick Byers
2014/11/28 17:36:02
please add a longTapAction 'mousedown' test (since
zino
2014/12/03 15:47:15
Done.
|
+]; |
+ |
+function eventHandler(e) |
+{ |
+ buttons = e.buttons; |
+} |
+ |
+function moveAction(modifiers) |
+{ |
+ eventSender.mouseMoveTo(-1, -1, modifiers); |
+ eventSender.mouseMoveTo(50, 50, modifiers); |
+} |
+ |
+function clickAction(modifiersDown, modifiersUp) |
+{ |
+ moveAction(modifiersDown); |
+ eventSender.mouseDown(0, modifiersDown); |
+ eventSender.mouseUp(0, modifiersUp); |
+} |
+ |
+function rightClickAction(modifiers) |
+{ |
+ moveAction(modifiers); |
+ eventSender.mouseDown(2, modifiers); |
+ eventSender.mouseUp(2, modifiers); |
+} |
+ |
+function doubleClickAction(modifiers) |
+{ |
+ clickAction(modifiers); |
+ clickAction(modifiers); |
+} |
+ |
+function mouseUpAction(modifiersDown, modifiersUp) |
+{ |
+ moveAction(modifiersDown); |
+ eventSender.mouseDown(0, modifiersDown); |
+ eventSender.mouseUp(1, modifiersUp); |
Rick Byers
2014/11/28 17:36:02
This says to press the left mouse button (0) then
zino
2014/12/03 15:47:15
Done.
|
+} |
+ |
+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); |
Rick Byers
2014/11/28 17:36:02
This is a little confusing. LongPress and LongTap
zino
2014/12/03 15:47:15
Thank you for the information.
I added contextmen
Rick Byers
2014/12/03 16:58:09
Yes, ignore drag and drop here. Touch drag and dro
|
+} |
+ |
+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].expectedModifiers); |
Rick Byers
2014/11/28 17:36:02
you shouldn't have to pass your 'expected modifier
zino
2014/12/03 15:47:15
Done.
|
+ 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; |
+} |
+ |
+for (var i = 0; i < testSet.length; i++) { |
+ raiseEvent(i); |
+ var expectedModifiers = ''; |
+ if (testSet[i].expectedModifiers != undefined) |
+ expectedModifiers += ' -> [' + testSet[i].expectedModifiers + ']'; |
+ debug(testSet[i].type + '::' + testSet[i].name + ' test [' + testSet[i].modifiers + ']' + expectedModifiers); |
+ shouldBeEqualToNumber('testSet[i].buttons', expectedValue(testSet[i])); |
+ debug(''); |
+} |
+ |
+</script> |