summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html')
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html89
1 files changed, 89 insertions, 0 deletions
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html
new file mode 100644
index 0000000000..48ecb610c6
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Monitoring the list of available presentation displays.</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#monitoring-the-list-of-available-presentation-displays">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+
+<p id="notice">Please wait for a moment...</p>
+<p>The test passes if a "PASS" result appears.<br></p>
+
+<script>
+ // prevent the default timeout
+ setup({explicit_timeout: true});
+
+ const notice = document.getElementById('notice');
+
+ promise_test(t => {
+ // clean up the instruction notice when the test ends
+ t.add_cleanup(() => {
+ notice.parentNode.removeChild(notice);
+ });
+
+ // initialize a presentation request
+ const request = new PresentationRequest(presentationUrls);
+
+ let availability, previousState, timeout;
+
+ const wait = () => {
+ notice.textContent = 'Please wait for a moment... (It might take long time)';
+
+ // set timeout to observe the presentation availability
+ timeout = t.step_timeout(function() {
+ t.force_timeout();
+ t.done();
+ }, 90000);
+ };
+
+ const setup = () => {
+ // save the current value of the presentation availability
+ previousState = availability.value;
+
+ // show an instruction notice
+ notice.textContent = 'Please make your presentation displays '
+ + (previousState ? 'unavailable' : 'available')
+ + ' and click this button: ';
+ const button = document.createElement('button');
+ button.textContent = 'Start Monitoring';
+ button.onclick = wait;
+ notice.appendChild(button);
+ };
+
+ // check the event and its attributes
+ const checkEvent = evt => {
+ clearTimeout(timeout);
+ timeout = undefined;
+
+ assert_true(evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event, 'A simple event is fired.');
+ assert_equals(evt.type, 'change', 'The event name is "change".');
+ assert_equals(evt.target, availability, 'event.target is the presentation availability.');
+ assert_not_equals(previousState, availability.value, 'Value of the presentation availability is changed.');
+ setup();
+ };
+
+ const watchEvent = (obj, watcher, type) => {
+ const watchHandler = new Promise(resolve => {
+ obj['on' + type] = evt => { resolve(evt); };
+ });
+ return Promise.all([ watchHandler, watcher.wait_for(type) ]).then(results => {
+ assert_equals(results[0], results[1], 'Both on' + type + ' and addEventListener pass the same event object.');
+ return results[0];
+ });
+ };
+
+ // check the change of PresentationAvailability.value twice; "true to false" and "false to true"
+ return request.getAvailability().then(a => {
+ availability = a;
+ setup();
+
+ // wait until a "change" event is fired twice
+ var eventWatcher = new EventWatcher(t, availability, 'change');
+ return watchEvent(availability, eventWatcher, 'change')
+ .then(checkEvent)
+ .then(() => { return eventWatcher.wait_for('change'); })
+ .then(checkEvent);
+ });
+ });
+</script> \ No newline at end of file