test_domwindowutils.html (3879B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Test for DOMWindowUtils</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 8 </head> 9 <body> 10 <div id="content" style="display: none"></div> 11 <pre id="test"> 12 <script type="application/javascript"> 13 SimpleTest.waitForExplicitFinish(); 14 15 var wrappedWindow = SpecialPowers.wrap(window); 16 function test_sendMouseEventDefaults() { 17 var x = 1, y = 2, button = 1, clickCount = 2, 18 modifiers = SpecialPowers.Ci.nsIDOMWindowUtils.MODIFIER_SHIFT; 19 20 window.addEventListener("mousedown", function(evt) { 21 // Mandatory args 22 // coordinates may change slightly due to rounding 23 ok((evt.clientX <= x+2) && (evt.clientX >= x-2), "check x"); 24 ok((evt.clientY <= y+2) && (evt.clientY >= y-2), "check y"); 25 is(evt.button, button, "check button"); 26 is(evt.detail, clickCount, "check click count"); 27 is(evt.getModifierState("Shift"), true, "check modifiers"); 28 29 // Default value for optionals 30 is(evt.mozPressure, 0, "check pressure"); 31 is(evt.mozInputSource, MouseEvent.MOZ_SOURCE_MOUSE, "check input source"); 32 is(evt.isSynthesized, undefined, "check isSynthesized is undefined in content"); 33 is(SpecialPowers.wrap(evt).isSynthesized, true, "check isSynthesized is true from chrome"); 34 SimpleTest.executeSoon(next); 35 }, {once: true}); 36 37 // Only pass mandatory arguments and check default values 38 wrappedWindow.synthesizeMouseEvent("mousedown", x, y, { button, clickCount, modifiers }); 39 } 40 41 function test_sendMouseEventOptionals() { 42 var x = 1, y = 2, button = 1, clickCount = 3, 43 modifiers = SpecialPowers.Ci.nsIDOMWindowUtils.MODIFIER_SHIFT, 44 pressure = 0.5, 45 inputSource = MouseEvent.MOZ_SOURCE_KEYBOARD; 46 47 window.addEventListener("mouseup", function(evt) { 48 is(evt.mozInputSource, inputSource, "explicit input source is valid"); 49 is(SpecialPowers.wrap(evt).isSynthesized, false, "we can dispatch event that don't look synthesized"); 50 SimpleTest.executeSoon(next); 51 }, {once: true}); 52 53 // Check explicit value for optional args 54 wrappedWindow.synthesizeMouseEvent( 55 "mouseup", x, y, 56 { button, clickCount, modifiers, pressure, inputSource}, 57 { isDOMEventSynthesized: false } 58 ); 59 } 60 61 function test_sendMouseEvent4thButton() { 62 const x = 1, y = 2, button = 3, clickCount = 1, modifiers = 0; 63 64 window.addEventListener("mousedown", evt => { 65 is(evt.buttons, 2 ** button, "check button"); 66 SimpleTest.executeSoon(next); 67 }, { once: true }); 68 69 wrappedWindow.synthesizeMouseEvent("mousedown", x, y, { button, clickCount, modifiers }); 70 } 71 72 function test_sendMouseEvent5thButton() { 73 const x = 1, y = 2, button = 4, clickCount = 1, modifiers = 0; 74 75 window.addEventListener("mousedown", evt => { 76 is(evt.buttons, 2 ** button, "check button"); 77 SimpleTest.executeSoon(next); 78 }, { once: true }); 79 80 wrappedWindow.synthesizeMouseEvent("mousedown", x, y, { button, clickCount, modifiers }); 81 } 82 83 function test_getUnanimatedComputedStyle() { 84 SpecialPowers.pushPrefEnv( 85 { 86 set: [ 87 ["layout.css.properties-and-values.enabled", true], 88 ], 89 }, 90 () => { 91 window.open("file_domwindowutils_animation.html"); 92 } 93 ); 94 } 95 96 function test_setDynamicToolbarMaxHeight() { 97 window.open("file_domwindowutils_dynamic_toolbar.html"); 98 } 99 100 var tests = [ 101 test_sendMouseEventDefaults, 102 test_sendMouseEventOptionals, 103 test_sendMouseEvent4thButton, 104 test_sendMouseEvent5thButton, 105 test_getUnanimatedComputedStyle, 106 test_setDynamicToolbarMaxHeight 107 ]; 108 109 function next() { 110 if (!tests.length) { 111 SimpleTest.finish(); 112 return; 113 } 114 115 var test = tests.shift(); 116 test(); 117 } 118 119 function start() { 120 SimpleTest.waitForExplicitFinish(); 121 SimpleTest.executeSoon(next); 122 } 123 124 window.addEventListener("load", start); 125 126 </script> 127 </pre> 128 </body> 129 </html>