54 netscape.security.PrivilegeManager.enablePrivilege(
"UniversalXPConnect");
55 test_utils =
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
56 getInterface(Components.interfaces.nsIDOMWindowUtils);
85 "evt.type (" + evt.type +
") does not match expected value");
86 is(evt.target,
test_utils.elementFromPoint(20, 20,
false,
false),
87 "evt.target (" + evt.target +
") does not match expected value");
89 "evt.clientX (" + evt.clientX +
") does not match expected value");
91 "evt.clientY (" + evt.clientY +
") does not match expected value");
93 "evt.screenX (" + evt.screenX +
") does not match expected value");
95 "evt.screenY (" + evt.screenY +
") does not match expected value");
98 "evt.direction (" + evt.direction +
") does not match expected value");
100 "evt.delta (" + evt.delta +
") does not match expected value");
103 "evt.shiftKey did not match expected value");
105 "evt.ctrlKey did not match expected value");
107 "evt.altKey did not match expected value");
109 "evt.metaKey did not match expected value");
125 test_utils.sendSimpleGestureEvent(type, 20, 20, direction, delta, modifiers);
128 is(expectedEventCount,
test_eventCount,
"Event (" + type +
") was never received by event listener");
136 e(
"MozSwipeGesture", SimpleGestureEvent.DIRECTION_LEFT, 0.0, 0);
137 e(
"MozSwipeGesture", SimpleGestureEvent.DIRECTION_RIGHT, 0.0, 0);
138 e(
"MozSwipeGesture", SimpleGestureEvent.DIRECTION_UP, 0.0, 0);
139 e(
"MozSwipeGesture", SimpleGestureEvent.DIRECTION_DOWN, 0.0, 0);
141 SimpleGestureEvent.DIRECTION_UP | SimpleGestureEvent.DIRECTION_LEFT, 0.0, 0);
143 SimpleGestureEvent.DIRECTION_DOWN | SimpleGestureEvent.DIRECTION_RIGHT, 0.0, 0);
145 SimpleGestureEvent.DIRECTION_UP | SimpleGestureEvent.DIRECTION_RIGHT, 0.0, 0);
147 SimpleGestureEvent.DIRECTION_DOWN | SimpleGestureEvent.DIRECTION_LEFT, 0.0, 0);
150 e(
"MozMagnifyGestureStart", 0, 50.0, 0);
151 e(
"MozMagnifyGestureUpdate", 0, -25.0, 0);
152 e(
"MozMagnifyGestureUpdate", 0, 5.0, 0);
153 e(
"MozMagnifyGesture", 0, 30.0, 0);
156 e(
"MozRotateGestureStart", SimpleGestureEvent.ROTATION_CLOCKWISE, 33.0, 0);
157 e(
"MozRotateGestureUpdate", SimpleGestureEvent.ROTATION_COUNTERCLOCKWISE, -13.0, 0);
158 e(
"MozRotateGestureUpdate", SimpleGestureEvent.ROTATION_CLOCKWISE, 13.0, 0);
159 e(
"MozRotateGesture", SimpleGestureEvent.ROTATION_CLOCKWISE, 33.0, 0);
162 e(
"MozTapGesture", 0, 0.0, 0);
163 e(
"MozPressTapGesture", 0, 0.0, 0);
166 let modifier = Components.interfaces.nsIDOMNSEvent.SHIFT_MASK;
167 e(
"MozSwipeGesture", SimpleGestureEvent.DIRECTION_RIGHT, 0, modifier);
170 modifier = Components.interfaces.nsIDOMNSEvent.META_MASK;
171 e(
"MozSwipeGesture", SimpleGestureEvent.DIRECTION_RIGHT, 0, modifier);
174 modifier = Components.interfaces.nsIDOMNSEvent.ALT_MASK;
175 e(
"MozSwipeGesture", SimpleGestureEvent.DIRECTION_RIGHT, 0, modifier);
178 modifier = Components.interfaces.nsIDOMNSEvent.CONTROL_MASK;
179 e(
"MozSwipeGesture", SimpleGestureEvent.DIRECTION_RIGHT, 0, modifier);
185 evt.stopPropagation();
194 event = document.createEvent(
"SimpleGestureEvent");
200 ok(successful,
"Unable to create SimpleGestureEvent");
203 event.initSimpleGestureEvent(type,
true,
true,
window, 1,
205 ctrlKey, altKey, shiftKey, metaKey,
213 ok(successful,
"event.initSimpleGestureEvent should not fail");
216 is(
event.type, type,
"Mismatch on evt.type");
217 is(
event.direction, direction,
"Mismatch on evt.direction");
218 is(
event.delta, delta,
"Mismatch on evt.delta");
219 is(
event.altKey, altKey,
"Mismatch on evt.altKey");
221 is(
event.shiftKey, shiftKey,
"Mismatch on evt.shiftKey");
222 is(
event.metaKey, metaKey,
"Mismatch on evt.metaKey");
224 is(
event.detail, 1,
"Mismatch on evt.detail");
225 is(
event.clientX, 10,
"Mismatch on evt.clientX");
226 is(
event.clientY, 10,
"Mismatch on evt.clientY");
227 is(
event.screenX, 10,
"Mismatch on evt.screenX");
228 is(
event.screenY, 10,
"Mismatch on evt.screenY");
229 is(
event.button, 1,
"Mismatch on evt.button");
230 is(
event.relatedTarget,
window,
"Mismatch on evt.relatedTarget");
235 document.dispatchEvent(
event);
237 is(expectedEventCount,
test_eventCount,
"Dispatched event was never received by listener");
243 test_helper2(
"MozMagnifyGesture", SimpleGestureEvent.DIRECTION_RIGHT, 20.0,
244 true,
false,
true,
false);
245 test_helper2(
"MozMagnifyGesture", SimpleGestureEvent.DIRECTION_LEFT, -20.0,
246 false,
true,
false,
true);
251 let up = SimpleGestureEvent.DIRECTION_UP;
252 let down = SimpleGestureEvent.DIRECTION_DOWN;
253 let
left = SimpleGestureEvent.DIRECTION_LEFT;
254 let
right = SimpleGestureEvent.DIRECTION_RIGHT;
256 let clockwise = SimpleGestureEvent.ROTATION_CLOCKWISE;
257 let cclockwise = SimpleGestureEvent.ROTATION_COUNTERCLOCKWISE;
259 ok(up ^ down,
"DIRECTION_UP and DIRECTION_DOWN are not bitwise disjoint");
260 ok(up ^ left,
"DIRECTION_UP and DIRECTION_LEFT are not bitwise disjoint");
261 ok(up ^ right,
"DIRECTION_UP and DIRECTION_RIGHT are not bitwise disjoint");
262 ok(down ^ left,
"DIRECTION_DOWN and DIRECTION_LEFT are not bitwise disjoint");
263 ok(down ^ right,
"DIRECTION_DOWN and DIRECTION_RIGHT are not bitwise disjoint");
264 ok(left ^ right,
"DIRECTION_LEFT and DIRECTION_RIGHT are not bitwise disjoint");
265 ok(clockwise ^ cclockwise,
"ROTATION_CLOCKWISE and ROTATION_COUNTERCLOCKWISE are not bitwise disjoint");
273 let cumulativeDelta = 0;
274 let isIncreasing = initialDelta > 0;
279 cmd[
dir].callCount = expect[
dir] = 0;
281 let
check =
function(aDir, aMsg) ok(cmd[aDir].callCount == expect[aDir], aMsg);
282 let checkBoth =
function(aNum, aInc, aDec) {
283 let prefix =
"Step " + aNum +
": ";
284 check(
"inc", prefix + aInc);
285 check(
"dec", prefix + aDec);
289 test_utils.sendSimpleGestureEvent(eventPrefix +
"Start", 0, 0, 0, initialDelta, 0);
290 cumulativeDelta += initialDelta;
293 checkBoth(1,
"Increasing command was not triggered",
"Decreasing command was triggered");
296 checkBoth(1,
"Increasing command was triggered",
"Decreasing command was not triggered");
301 for (let
i = 0;
i < 5;
i++) {
302 let delta = Math.random() * (isIncreasing ? 100 : -100);
303 test_utils.sendSimpleGestureEvent(eventPrefix +
"Update", 0, 0, 0, delta, 0);
304 cumulativeDelta += delta;
305 checkBoth(2,
"Increasing command was triggered",
"Decreasing command was triggered");
309 test_utils.sendSimpleGestureEvent(eventPrefix +
"Update", 0, 0, 0,
311 cumulativeDelta += - initialDelta;
314 checkBoth(3,
"Increasing command was triggered",
"Decreasing command was not triggered");
317 checkBoth(3,
"Increasing command was not triggered",
"Decreasing command was triggered");
322 for (let
i = 0;
i < 5;
i++) {
323 let delta = Math.random() * (isIncreasing ? -100 : 100);
324 test_utils.sendSimpleGestureEvent(eventPrefix +
"Update", 0, 0, 0, delta, 0);
325 cumulativeDelta += delta;
326 checkBoth(4,
"Increasing command was triggered",
"Decreasing command was triggered");
330 test_utils.sendSimpleGestureEvent(eventPrefix +
"Update", 0, 0, 0,
332 cumulativeDelta += initialDelta;
335 checkBoth(5,
"Increasing command was not triggered",
"Decreasing command was triggered");
338 checkBoth(5,
"Increasing command was triggered",
"Decreasing command was not triggered");
342 test_utils.sendSimpleGestureEvent(eventPrefix, 0, 0, 0, cumulativeDelta, 0);
343 checkBoth(6,
"Increasing command was triggered",
"Decreasing command was triggered");
348 let cmd =
test_commandset.appendChild(document.createElement(
"command"));
349 cmd.setAttribute(
"id",
id);
350 cmd.setAttribute(
"oncommand",
"this.callCount++;");
352 cmd.origPrefName = prefName;
361 gPrefService.setCharPref(cmd.origPrefName, cmd.origPrefValue);
371 let oldLatchedValue =
gPrefService.getBoolPref(branch +
"latched");
385 gPrefService.setBoolPref(branch +
"latched", oldLatchedValue);
396 let oldLatchedValue =
gPrefService.getBoolPref(branch +
"latched");
400 let oldThresholdValue =
gPrefService.getIntPref(branch +
"threshold");
408 cmdInc.callCount = cmdDec.callCount = 0;
409 test_utils.sendSimpleGestureEvent(eventPrefix +
"Start", 0, 0, 0, 49.5, 0);
410 ok(cmdInc.callCount == 0,
"Increasing command was triggered");
411 ok(cmdDec.callCount == 0,
"Decreasing command was triggered");
414 cmdInc.callCount = cmdDec.callCount = 0;
415 test_utils.sendSimpleGestureEvent(eventPrefix +
"Update", 0, 0, 0, 1, 0);
416 ok(cmdInc.callCount == 1,
"Increasing command was not triggered");
417 ok(cmdDec.callCount == 0,
"Decreasing command was triggered");
421 cmdInc.callCount = cmdDec.callCount = 0;
422 test_utils.sendSimpleGestureEvent(eventPrefix +
"Update", 0, 0, 0, -49.5, 0);
423 ok(cmdInc.callCount == 0,
"Increasing command was triggered");
424 ok(cmdDec.callCount == 0,
"Decreasing command was triggered");
427 cmdInc.callCount = cmdDec.callCount = 0;
428 test_utils.sendSimpleGestureEvent(eventPrefix +
"Update", 0, 0, 0, -1.5, 0);
429 ok(cmdInc.callCount == 0,
"Increasing command was triggered");
430 ok(cmdDec.callCount == 1,
"Decreasing command was not triggered");
433 cmdInc.callCount = cmdDec.callCount = 0;
434 test_utils.sendSimpleGestureEvent(eventPrefix, 0, 0, 0, -0.5, 0);
435 ok(cmdInc.callCount == 0,
"Increasing command was triggered");
436 ok(cmdDec.callCount == 0,
"Decreasing command was triggered");
439 gPrefService.setBoolPref(branch +
"latched", oldLatchedValue);
440 gPrefService.setIntPref(branch +
"threshold", oldThresholdValue);
448 let up = SimpleGestureEvent.DIRECTION_UP;
449 let down = SimpleGestureEvent.DIRECTION_DOWN;
450 let
left = SimpleGestureEvent.DIRECTION_LEFT;
451 let
right = SimpleGestureEvent.DIRECTION_RIGHT;
461 function resetCounts() {
463 cmdDown.callCount = 0;
464 cmdLeft.callCount = 0;
465 cmdRight.callCount = 0;
470 test_utils.sendSimpleGestureEvent(
"MozSwipeGesture", 0, 0, up, 0, 0);
471 ok(cmdUp.callCount == 1,
"Step 1: Up command was not triggered");
472 ok(cmdDown.callCount == 0,
"Step 1: Down command was triggered");
473 ok(cmdLeft.callCount == 0,
"Step 1: Left command was triggered");
474 ok(cmdRight.callCount == 0,
"Step 1: Right command was triggered");
478 test_utils.sendSimpleGestureEvent(
"MozSwipeGesture", 0, 0, down, 0, 0);
479 ok(cmdUp.callCount == 0,
"Step 2: Up command was triggered");
480 ok(cmdDown.callCount == 1,
"Step 2: Down command was not triggered");
481 ok(cmdLeft.callCount == 0,
"Step 2: Left command was triggered");
482 ok(cmdRight.callCount == 0,
"Step 2: Right command was triggered");
486 test_utils.sendSimpleGestureEvent(
"MozSwipeGesture", 0, 0, left, 0, 0);
487 ok(cmdUp.callCount == 0,
"Step 3: Up command was triggered");
488 ok(cmdDown.callCount == 0,
"Step 3: Down command was triggered");
489 ok(cmdLeft.callCount == 1,
"Step 3: Left command was not triggered");
490 ok(cmdRight.callCount == 0,
"Step 3: Right command was triggered");
494 test_utils.sendSimpleGestureEvent(
"MozSwipeGesture", 0, 0, right, 0, 0);
495 ok(cmdUp.callCount == 0,
"Step 4: Up command was triggered");
496 ok(cmdDown.callCount == 0,
"Step 4: Down command was triggered");
497 ok(cmdLeft.callCount == 0,
"Step 4: Left command was triggered");
498 ok(cmdRight.callCount == 1,
"Step 4: Right command was not triggered");
502 for (let
i = 0;
i < combos.length;
i++) {
504 test_utils.sendSimpleGestureEvent(
"MozSwipeGesture", 0, 0, combos[
i], 0, 0);
505 ok(cmdUp.callCount == 0,
"Step 5-"+i+
": Up command was triggered");
506 ok(cmdDown.callCount == 0,
"Step 5-"+i+
": Down command was triggered");
507 ok(cmdLeft.callCount == 0,
"Step 5-"+i+
": Left command was triggered");
508 ok(cmdRight.callCount == 0,
"Step 5-"+i+
": Right command was triggered");
function test_EnsureConstantsAreDisjoint()
function test_removeCommand(cmd)
function test_gestureListener(evt)
let test_expectedDirection
function test_swipeGestures()
function test_thresholdGesture(gesture, inc, dec, eventPrefix)
function test_helper2(type, direction, delta, altKey, ctrlKey, shiftKey, metaKey)
function test_eventDispatchListener(evt)
function test_TestEventListeners()
function test_TestEventCreation()
return e ctrlKey(chr<' '||!chars||chars.indexOf(chr)>-1)
let test_expectedModifiers
function test_latchedGesture(gesture, inc, dec, eventPrefix)
function test_helper1(type, direction, delta, modifiers)
_getSelectedPageStyle s i
function test_addCommand(prefName, id)
function test_emitLatchedEvents(eventPrefix, initialDelta, cmd)