captured-mouse-event-constructor.html (3186B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <link rel='help' href='https://screen-share.github.io/captured-mouse-events/#captured-mouse-change-event'> 4 <link rel='help' href='https://screen-share.github.io/captured-mouse-events/#captured-mouse-change-event-init'> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script> 8 // See https://webidl.spec.whatwg.org/#idl-long 9 const maxLongValue = 2147483647; 10 11 test(() => { 12 assert_throws_js(TypeError, () => new CapturedMouseEvent()); 13 }, "type argument is mandatory"); 14 15 test(() => { 16 [ 17 {surfaceX: -5, surfaceY: -5}, /* X, Y negative */ 18 {surfaceX: -5, surfaceY: +5}, /* X negative, Y non-negative */ 19 {surfaceX: +5, surfaceY: -5}, /* X non-negative, Y negative */ 20 {surfaceX: -1, surfaceY: +5}, /* X equal to -1, Y non-negative */ 21 {/* surfaceX: -1, */ surfaceY: +5}, /* Same with implicit surfaceX */ 22 {surfaceX: +5, surfaceY: -1}, /* X non-negative, Y equal to -1 */ 23 {surfaceX: +5 /*, surfaceY: -1 */}, /* Same with implicit surfaceY */ 24 {surfaceX: maxLongValue+1, surfaceY: +5}, /* 'long' overflow for X */ 25 {surfaceX: +5, surfaceY: maxLongValue+1}, /* 'long' overflow for Y */ 26 ].forEach(init => { 27 assert_throws_js(RangeError, () => new CapturedMouseEvent("", init), 28 `eventInitDict=${JSON.stringify(init)}`); 29 }); 30 }, "Invalid surfaceX/surfaceY options cause a RangeError to be thrown"); 31 32 test(() => { 33 [ 34 {surfaceX: +5, surfaceY: +7}, /* Two positive values */ 35 {surfaceX: -1, surfaceY: -1}, /* Valid case with negative values */ 36 {surfaceX: 0, surfaceY: 0}, /* Minimal non-negative values */ 37 {surfaceX: 0, surfaceY: 5}, /* Minimal non-negative X and positive Y */ 38 {surfaceX: 5, surfaceY: 0}, /* Positive X and minimal non-negative Y */ 39 {surfaceX: maxLongValue, surfaceY: maxLongValue}, /* Maximal values */ 40 ].forEach(init => { 41 let event = new CapturedMouseEvent("", init); 42 assert_equals(event.surfaceX, init.surfaceX, 43 `surfaceX with eventInitDict=${JSON.stringify(init)}`); 44 assert_equals(event.surfaceY, init.surfaceY, 45 `surfaceY with eventInitDict=${JSON.stringify(init)}`); 46 }); 47 }, "Valid surfaceX/surfaceY options are used as initial values"); 48 49 test(() => { 50 let event = new CapturedMouseEvent(""); 51 assert_equals(event.surfaceX, -1, 52 `surfaceX with implicit eventInitDict={}`); 53 assert_equals(event.surfaceY, -1, 54 `surfaceY with implicit eventInitDict={}`); 55 56 [ 57 {}, 58 {surfaceX: -1}, 59 {surfaceY: -1}, 60 ].forEach(init => { 61 let event = new CapturedMouseEvent("", init); 62 assert_equals(event.surfaceX, -1, 63 `surfaceX with eventInitDict=${JSON.stringify(init)}`); 64 assert_equals(event.surfaceY, -1, 65 `surfaceY with eventInitDict=${JSON.stringify(init)}`); 66 }); 67 }, "surfaceX/surfaceY default to -1"); 68 </script>