-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CapturedMouseEvents] Export web platform tests
This patch exports existing WPT tests added in [1], using the directory recently introduced in [2] and taking into account the recent renaming to "captured mouse events". It also adds a manual test that is verified to pass with [3] applied. WPT does not provide support for more complex and automated tests, so this is just a minimal verification. More advanced internal tests with wider coverage will be added in [3]. [1] https://chromium-review.googlesource.com/c/chromium/src/+/4517372 [2] #40826 [3] https://chromium-review.googlesource.com/c/chromium/src/+/4549484 Bug: 1444712 Change-Id: I8ed455c406d6cba81cb4df0651509b6d6f7bd991
- Loading branch information
1 parent
66166fa
commit fcc06b8
Showing
6 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
captured-mouse-events/capture-controller-oncapturedmousechange.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<link rel='help' href='https://screen-share.github.io/captured-mouse-events/#capture-controller-extensions'> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
test(() => { | ||
const controller = new CaptureController(); | ||
assert_equals(controller.oncapturedmousechange, null); | ||
}, "oncapturedmousechange is initially unset"); | ||
|
||
test(() => { | ||
const controller = new CaptureController(); | ||
let result = undefined; | ||
controller.oncapturedmousechange = (e) => { | ||
result = { | ||
target: e.currentTarget, | ||
surfaceX: e.surfaceX, | ||
surfaceY: e.surfaceY, | ||
}; | ||
}; | ||
const init = {surfaceX: 5, surfaceY: 7}; | ||
controller.dispatchEvent( | ||
new CapturedMouseEvent("capturedmousechange", init) | ||
); | ||
assert_equals(result.target, controller); | ||
assert_equals(result.surfaceX, init.surfaceX); | ||
assert_equals(result.surfaceY, init.surfaceY); | ||
}, "dispatching a CapturedMouseEvent on CaptureController should trigger oncapturedmousechange"); | ||
</script> |
29 changes: 29 additions & 0 deletions
29
captured-mouse-events/captured-mouse-event-constructor-inherited.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<link rel='help' href='https://screen-share.github.io/captured-mouse-events/#captured-mouse-change-event'> | ||
<link rel='help' href='https://dom.spec.whatwg.org/#event'> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
test(() => { | ||
assert_equals((new CapturedMouseEvent("custom")).type, "custom"); | ||
}, "type argument is passed to the Event's constructor"); | ||
|
||
const inherited_options = ["bubbles", "cancelable", "composed"]; | ||
test(() => { | ||
const event = new CapturedMouseEvent(""); | ||
inherited_options.forEach(name => { | ||
assert_equals(event[name], false, `event.${name} with default eventInitDict`); | ||
}); | ||
|
||
inherited_options.forEach(name => { | ||
const options = {}; | ||
options[name] = true; | ||
const event = new CapturedMouseEvent("", options); | ||
inherited_options.forEach(other_name => { | ||
assert_equals(event[other_name], other_name == name, | ||
`event.${other_name} with eventInitDict={${name}: true}`); | ||
}); | ||
}); | ||
}, "EventInit options are passed to the Event's constructor"); | ||
</script> |
68 changes: 68 additions & 0 deletions
68
captured-mouse-events/captured-mouse-event-constructor.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<link rel='help' href='https://screen-share.github.io/captured-mouse-events/#captured-mouse-change-event'> | ||
<link rel='help' href='https://screen-share.github.io/captured-mouse-events/#captured-mouse-change-event-init'> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
// See https://webidl.spec.whatwg.org/#idl-long | ||
const maxLongValue = 2147483647; | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => new CapturedMouseEvent()); | ||
}, "type argument is mandatory"); | ||
|
||
test(() => { | ||
[ | ||
{surfaceX: -5, surfaceY: -5}, /* X, Y negative */ | ||
{surfaceX: -5, surfaceY: +5}, /* X negative, Y non-negative */ | ||
{surfaceX: +5, surfaceY: -5}, /* X non-negative, Y negative */ | ||
{surfaceX: -1, surfaceY: +5}, /* X equal to -1, Y non-negative */ | ||
{/* surfaceX: -1, */ surfaceY: +5}, /* Same with implicit surfaceX */ | ||
{surfaceX: +5, surfaceY: -1}, /* X non-negative, Y equal to -1 */ | ||
{surfaceX: +5 /*, surfaceY: -1 */}, /* Same with implicit surfaceY */ | ||
{surfaceX: maxLongValue+1, surfaceY: +5}, /* 'long' overflow for X */ | ||
{surfaceX: +5, surfaceY: maxLongValue+1}, /* 'long' overflow for Y */ | ||
].forEach(init => { | ||
assert_throws_js(RangeError, () => new CapturedMouseEvent("", init), | ||
`eventInitDict=${JSON.stringify(init)}`); | ||
}); | ||
}, "Invalid surfaceX/surfaceY options cause a RangeError to be thrown"); | ||
|
||
test(() => { | ||
[ | ||
{surfaceX: +5, surfaceY: +7}, /* Two positive values */ | ||
{surfaceX: -1, surfaceY: -1}, /* Valid case with negative values */ | ||
{surfaceX: 0, surfaceY: 0}, /* Minimal non-negative values */ | ||
{surfaceX: 0, surfaceY: 5}, /* Minimal non-negative X and positive Y */ | ||
{surfaceX: 5, surfaceY: 0}, /* Positive X and minimal non-negative Y */ | ||
{surfaceX: maxLongValue, surfaceY: maxLongValue}, /* Maximal values */ | ||
].forEach(init => { | ||
let event = new CapturedMouseEvent("", init); | ||
assert_equals(event.surfaceX, init.surfaceX, | ||
`surfaceX with eventInitDict=${JSON.stringify(init)}`); | ||
assert_equals(event.surfaceY, init.surfaceY, | ||
`surfaceY with eventInitDict=${JSON.stringify(init)}`); | ||
}); | ||
}, "Valid surfaceX/surfaceY options are used as initial values"); | ||
|
||
test(() => { | ||
let event = new CapturedMouseEvent(""); | ||
assert_equals(event.surfaceX, -1, | ||
`surfaceX with implicit eventInitDict={}`); | ||
assert_equals(event.surfaceY, -1, | ||
`surfaceY with implicit eventInitDict={}`); | ||
|
||
[ | ||
{}, | ||
{surfaceX: -1}, | ||
{surfaceY: -1}, | ||
].forEach(init => { | ||
let event = new CapturedMouseEvent("", init); | ||
assert_equals(event.surfaceX, -1, | ||
`surfaceX with eventInitDict=${JSON.stringify(init)}`); | ||
assert_equals(event.surfaceY, -1, | ||
`surfaceY with eventInitDict=${JSON.stringify(init)}`); | ||
}); | ||
}, "surfaceX/surfaceY default to -1"); | ||
</script> |
80 changes: 80 additions & 0 deletions
80
captured-mouse-events/capturing-mouse-coordinates-manual.tentative.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<h1>Capturing mouse coordinates</h1> | ||
<link rel='help' href='https://screen-share.github.io/captured-mouse-events'> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
setup({explicit_timeout: true}) | ||
</script> | ||
<ol class="instructions"> | ||
<li><button id="start_capture">Click here</button> and share this window as | ||
a captured surface.</li> | ||
<li>Move the mouse near each corner of the window, in the following | ||
order: | ||
<ol> | ||
<li>top left corner</li> | ||
<li>top right corner</li> | ||
<li>bottom right corner</li> | ||
<li>bottom left corner</li> | ||
</ol> | ||
</li> | ||
<li>Move the mouse near the center of the window.</li> | ||
<li>Move the mouse outside the window.</li> | ||
<li>Move the mouse inside the window.</li> | ||
</ol> | ||
<pre id="log"></pre> | ||
<video width="1024" height="512" id="monitor" autoplay></video> | ||
<script> | ||
let mouse_event_listener = null; | ||
promise_test(async () => { | ||
await new Promise(resolve => { | ||
document.getElementById('start_capture') | ||
.addEventListener('click', resolve, {once: true}); | ||
}); | ||
const controller = new CaptureController(); | ||
controller.addEventListener('capturedmousechange', (event) => { | ||
if (mouse_event_listener) | ||
mouse_event_listener({x: event.surfaceX, y: event.surfaceY}); | ||
}); | ||
const video = document.getElementById('monitor'); | ||
video.srcObject = await navigator.mediaDevices.getDisplayMedia({controller}); | ||
await new Promise(resolve => video.onloadedmetadata = resolve); | ||
}, 'Starting Screen Capture'); | ||
|
||
const max_distance = 100; | ||
[{x: 0, y: 0, name: 'top left corner'}, | ||
{x: window.outerWidth, y: 0, name: 'top right corner'}, | ||
{x: window.outerWidth, y: window.outerHeight, name: 'bottom right corner'}, | ||
{x: 0, y: window.outerHeight, name: 'bottom left corner'}, | ||
{x: window.outerWidth / 2, y: window.outerHeight / 2, name: 'center'}, | ||
].forEach(target => { | ||
promise_test(async () => { | ||
await new Promise(resolve => { | ||
mouse_event_listener = (mouse) => { | ||
if (mouse.x >= 0 && mouse.y >= 0 && | ||
Math.hypot(target.x - mouse.x, target.y - mouse.y) < max_distance) | ||
resolve(); | ||
}; | ||
}); | ||
}, `Moving mouse to the ${target.name} of the window.`); | ||
}); | ||
|
||
promise_test(async () => { | ||
await new Promise(resolve => { | ||
mouse_event_listener = (mouse) => { | ||
if (mouse.x == -1 && mouse.y == -1) | ||
resolve(); | ||
}; | ||
}); | ||
}, `Moving mouse outside the window.`); | ||
|
||
promise_test(async () => { | ||
await new Promise(resolve => { | ||
mouse_event_listener = (mouse) => { | ||
if (mouse.x >= 0 && mouse.y >= 0) | ||
resolve(); | ||
}; | ||
}); | ||
}, `Moving mouse inside the window.`); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// META: script=/resources/WebIDLParser.js | ||
// META: script=/resources/idlharness.js | ||
|
||
'use strict'; | ||
|
||
// https://screen-share.github.io/captured-mouse-events/ | ||
|
||
idl_test( | ||
['captured-mouse-events.tentative'], | ||
['html', 'dom'] | ||
); |
File renamed without changes.