summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/presentation-api/controlling-ua
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/presentation-api/controlling-ua
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/presentation-api/controlling-ua')
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html89
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnectionCloseEvent.https.html24
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onclose-manual.https.html145
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onconnect-manual.https.html72
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onmessage-manual.https.html144
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onterminate-manual.https.html157
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_send-manual.https.html125
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_error.https.html36
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_mixedcontent.https.html18
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_mixedcontent_multiple.https.html21
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_onconnectionavailable-manual.https.html85
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_error.https.html26
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_success.https.html26
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_success.https.html31
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/common.js25
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest.https.html24
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest_success-manual.https.html63
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/getAvailability.https.html54
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/getAvailability_sandboxing_success.https.html25
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/idlharness.https.html51
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/reconnectToMultiplePresentations_success-manual.https.html138
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_notfound_error-manual.https.html61
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_sandboxing_success.https.html25
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_success-manual.https.html185
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/startMultiplePresentations_success-manual.https.html99
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotallowed-manual.https.html45
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotfound-manual.https.html45
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_error.https.html20
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_sandboxing_success-manual.https.html31
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_success-manual.https.html95
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_unsettledpromise-manual.https.html44
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/support/iframe.html181
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/support/presentation.html98
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/support/stash.js83
-rw-r--r--testing/web-platform/tests/presentation-api/controlling-ua/support/stash.py10
35 files changed, 2401 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
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnectionCloseEvent.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnectionCloseEvent.https.html
new file mode 100644
index 0000000000..34c935a603
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnectionCloseEvent.https.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Constructing a PresentationConnectionCloseEvent</title>
+<link rel="author" title="mark a. foltz" href="https://github.com/mfoltzgoogle">
+<link rel="help" href="http://w3c.github.io/presentation-api/#controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+ test(() => {
+ let eventWithMessage, eventWithoutMessage;
+ for (let reason of ["error", "closed", "wentaway"]) {
+ eventWithMessage = new PresentationConnectionCloseEvent("close", {reason: reason, message: "A message" });
+ assert_equals(eventWithMessage.type, "close");
+ assert_equals(eventWithMessage.reason, reason);
+ assert_equals(eventWithMessage.message, "A message");
+
+ eventWithoutMessage = new PresentationConnectionCloseEvent("close", {reason: reason});
+ assert_equals(eventWithoutMessage.type, "close");
+ assert_equals(eventWithoutMessage.reason, reason);
+ assert_equals(eventWithoutMessage.message, "");
+ }
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onclose-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onclose-manual.https.html
new file mode 100644
index 0000000000..f63806f82b
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onclose-manual.https.html
@@ -0,0 +1,145 @@
+<!DOCTYPE html>
+
+<meta charset="utf-8">
+<title>Closing a PresentationConnection</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="author" title="He Yue" href="mailto:yue.he@intel.com">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="https://w3c.github.io/presentation-api/#closing-a-presentationconnection">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<script src="support/stash.js"></script>
+<h2>Description</h2>
+<p>
+ This test validates that after connection close,<br/>
+ the connection state is set closed,<br/>
+ the onclose EventHandler is triggered.
+</p>
+<br/>
+<p>Click the button below to start the test.</p>
+<button id="presentBtn" >Start Presentation Test</button>
+
+<script>
+ setup({explicit_timeout: true});
+
+ const presentBtn = document.getElementById('presentBtn');
+
+ promise_test(t => {
+ const clickWatcher = new EventWatcher(t, presentBtn, 'click');
+ const request = new PresentationRequest(presentationUrls);
+ const stash = new Stash(stashIds.toController, stashIds.toReceiver);
+ let connection, eventWatcher;
+
+ t.add_cleanup(() => {
+ if (connection) {
+ connection.onconnect = () => { connection.terminate(); };
+ if (connection.state === 'closed')
+ request.reconnect(connection.id);
+ else
+ connection.terminate();
+ }
+ stash.stop();
+ });
+
+ const checkCloseEvent = evt => {
+ assert_true(evt instanceof PresentationConnectionCloseEvent, 'An event using PresentationConnectionCloseEvent is fired.');
+ assert_true(evt.isTrusted, 'The event is a trusted event.');
+ assert_false(evt.bubbles, 'The event does not bubbles.');
+ assert_false(evt.cancelable, 'The event is not cancelable.');
+ assert_equals(evt.type, 'close', 'The event name is "close".');
+ assert_equals(evt.target, connection, 'event.target is the presentation connection.');
+ assert_equals(connection.state, 'closed', 'State of the presentation connection is "closed".');
+ assert_equals(evt.reason, 'closed', 'The reason for closing the presentation connection is "closed".');
+ };
+
+ 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];
+ });
+ };
+
+ const waitForEvent = (obj, watcher, type) => {
+ const watchHandler = new Promise(resolve => {
+ obj['on' + type] = evt => { resolve(evt); };
+ });
+ return Promise.race([ watchHandler, watcher.wait_for(type) ]);
+ };
+
+ return Promise.all([
+ clickWatcher.wait_for('click'),
+ stash.init()
+ ]).then(() => {
+ presentBtn.disabled = true;
+ return request.start();
+ }).then(c => {
+ // Enable timeout again, cause no user action is needed from here.
+ t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 10000);
+
+ connection = c;
+ eventWatcher = new EventWatcher(t, connection, ['connect', 'close', 'terminate']);
+
+ // Step 1: close the presentation connection in "connecting" state
+ connection.close();
+ return Promise.race([
+ new Promise((_, reject) => {
+ t.step_timeout(() => { reject('The presentation connection in "connecting" state was not closed successfully.'); }, 3000);
+ }),
+ watchEvent(connection, eventWatcher, 'close')
+ ]);
+ }).then(evt => {
+ checkCloseEvent(evt);
+
+ // Step 2: close the presentation connection in "connected" state
+ return request.reconnect(connection.id);
+ }).then(() => {
+ return eventWatcher.wait_for('connect');
+ }).then(() => {
+ connection.close();
+ return watchEvent(connection, eventWatcher, 'close');
+ }).then(evt => {
+ checkCloseEvent(evt);
+
+ // Step 3: check a connection closed by the receiving user agent
+ return request.reconnect(connection.id);
+ }).then(() => {
+ return eventWatcher.wait_for('connect');
+ }).then(() => {
+ return Promise.all([ stash.send('close'), watchEvent(connection, eventWatcher, 'close') ]);
+ }).then(results => {
+ checkCloseEvent(results[1]);
+
+ // Step 4: close the presentation connection in "closed" state (nothing should happen)
+ const closeWatcher = new EventWatcher(t, connection, 'close');
+ connection.close();
+ return Promise.race([
+ new Promise(resolve => { t.step_timeout(resolve, 1000); }),
+ waitForEvent(connection, closeWatcher, 'close').then(() => {
+ assert_unreached('Invoking PresentationConnection.close() in the "closed" state causes nothing.'); })
+ ]);
+ }).then(() => {
+ // Step 5: close the presentation connection in "terminated" state (nothing should happen)
+ return request.reconnect(connection.id);
+ }).then(() => {
+ return eventWatcher.wait_for('connect');
+ }).then(() => {
+ connection.terminate();
+ return eventWatcher.wait_for('terminate');
+ }).then(() => {
+ const closeWatcher = new EventWatcher(t, connection, 'close');
+ connection.close();
+ return Promise.race([
+ new Promise(resolve => { t.step_timeout(resolve, 1000); }),
+ waitForEvent(connection, closeWatcher, 'close').then(() => {
+ assert_unreached('Invoking PresentationConnection.close() in the "terminated" state causes nothing.'); })
+ ]);
+ });
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onconnect-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onconnect-manual.https.html
new file mode 100644
index 0000000000..0f4a4ac369
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onconnect-manual.https.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+
+<meta charset="utf-8">
+<title>Establishing a presentation connection</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="author" title="He Yue" href="mailto:yue.he@intel.com">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="https://w3c.github.io/presentation-api/#establishing-a-presentation-connection">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<h2>Description</h2>
+<p>
+ This test validates that after connection starts,<br/>
+ the onconnect EventHandler is triggered and connection state is connected.
+</p>
+<br/>
+<p>Click the button below to start the test.</p>
+<button id="presentBtn">Start Presentation Test</button>
+
+<script>
+ setup({explicit_timeout: true});
+
+ const presentBtn = document.getElementById('presentBtn');
+
+ promise_test(t => {
+ const clickWatcher = new EventWatcher(t, presentBtn, 'click');
+ const request = new PresentationRequest(presentationUrls);
+ let connection;
+
+ t.add_cleanup(() => {
+ if (connection) {
+ connection.onconnect = () => { connection.terminate(); };
+ if (connection.state === 'closed')
+ request.reconnect(connection.id);
+ else
+ connection.terminate();
+ }
+ });
+
+ 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];
+ });
+ };
+
+ return clickWatcher.wait_for('click').then(() => {
+ presentBtn.disabled = true;
+
+ return request.start();
+ }).then(c => {
+ // Enable timeout again, cause no user action is needed from here.
+ t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 5000);
+
+ connection = c;
+ const eventWatcher = new EventWatcher(t, connection, 'connect');
+ return watchEvent(connection, eventWatcher, 'connect');
+ }).then(evt => {
+ assert_true(evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event, 'A simple event is fired.');
+ assert_equals(evt.type, 'connect', 'The event name is "connect".');
+ assert_equals(evt.target, connection, 'event.target is the presentation connection.');
+ assert_equals(connection.state, 'connected', 'The presentation connection state is set to "connected".');
+ });
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onmessage-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onmessage-manual.https.html
new file mode 100644
index 0000000000..59d7e8c0e0
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onmessage-manual.https.html
@@ -0,0 +1,144 @@
+<!DOCTYPE html>
+
+<meta charset="utf-8">
+<title>Receiving a message through PresentationConnection</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="http://w3c.github.io/presentation-api/#receiving-a-message-through-presentationconnection">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<script src="support/stash.js"></script>
+
+<p id="notice">
+ Click the button below and select the available presentation display, to start the manual test. The test passes if a "PASS" result appears.<br>
+ <button id="presentBtn">Start Presentation Test</button>
+</p>
+
+<script>
+ setup({explicit_timeout: true});
+
+ const presentBtn = document.getElementById('presentBtn');
+
+ const message1 = '1st';
+ const message2 = '2nd';
+ const message3 = new Uint8Array([51, 114, 100]); // "3rd"
+ const message4 = new Uint8Array([52, 116, 104]); // "4th"
+ const message5 = new Uint8Array([108, 97, 115, 116]); // "last"
+
+ const toUint8Array = buf => {
+ return buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;
+ }
+
+ // compare two ArrayBuffer or Uint8Array
+ const compare = (a, b) => {
+ const p = toUint8Array(a);
+ const q = toUint8Array(b);
+ return !!p && !!q && p.every((item, index) => { return item === q[index]; });
+ };
+
+ promise_test(t => {
+ const clickWatcher = new EventWatcher(t, presentBtn, 'click');
+ const request = new PresentationRequest(presentationUrls);
+ const stash = new Stash(stashIds.toController, stashIds.toReceiver);
+ let connection, watcher, eventWatcher;
+
+ const checkEvent = event => {
+ assert_true(event.isTrusted, 'a trusted event is fired');
+ assert_true(event instanceof MessageEvent, 'The event uses the MessageEvent interface');
+ assert_false(event.bubbles, 'the event does not bubble');
+ assert_false(event.cancelable, 'the event is not cancelable');
+ };
+
+ 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];
+ });
+ };
+
+ t.add_cleanup(() => {
+ if (connection) {
+ connection.onconnect = () => { connection.terminate(); };
+ if (connection.state === 'closed')
+ request.reconnect(connection.id);
+ else
+ connection.terminate();
+ }
+ const notice = document.getElementById('notice');
+ notice.parentNode.removeChild(notice);
+ stash.stop();
+ });
+
+ return Promise.all([
+ clickWatcher.wait_for('click'),
+ stash.init()
+ ]).then(() => {
+ presentBtn.disabled = true;
+ return request.start();
+ }).then(c => {
+ connection = c;
+ assert_equals(connection.state, 'connecting', 'the initial state of the presentation connection is "connecting"');
+ assert_equals(connection.binaryType, 'arraybuffer', 'the default value of binaryType is "arraybuffer"');
+
+ // enable timeout again, cause no user action is needed from here.
+ t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 5000);
+
+ watcher = new EventWatcher(t, connection, 'connect');
+ return watcher.wait_for('connect');
+ }).then(() => {
+ return stash.init();
+ }).then(() => {
+ eventWatcher = new EventWatcher(t, connection, 'message');
+ // Tell receiving page to start sending messages, and wait for first message
+ return Promise.all([
+ stash.send('onmessage'),
+ watchEvent(connection, eventWatcher, 'message')
+ ]).then(results => results[1]);
+ }).then(event => {
+ checkEvent(event);
+ assert_equals(event.data, message1, 'receive a string correctly');
+ return watchEvent(connection, eventWatcher, 'message');
+ }).then(event => {
+ checkEvent(event);
+ assert_equals(event.data, message2, 'receive a string correctly');
+ return watchEvent(connection, eventWatcher, 'message');
+ }).then(event => {
+ checkEvent(event);
+ assert_true(event.data instanceof ArrayBuffer, 'receive binary data as ArrayBuffer');
+ assert_true(compare(event.data, message3), 'receive an ArrayBuffer correctly (originally a Blob at a receiving user agent)');
+ return watchEvent(connection, eventWatcher, 'message');
+ }).then(event => {
+ checkEvent(event);
+ assert_true(event.data instanceof ArrayBuffer, 'receive binary data as ArrayBuffer');
+ assert_true(compare(event.data, message4), 'receive an ArrayBuffer correctly (originally an ArrayBuffer at a receiving user agent)');
+ return watchEvent(connection, eventWatcher, 'message');
+ }).then(event => {
+ checkEvent(event);
+ assert_true(event.data instanceof ArrayBuffer, 'receive binary data as ArrayBuffer');
+ assert_true(compare(event.data, message5), 'receive an ArrayBuffer correctly (originally an ArrayBufferView at a receiving user agent)');
+
+ connection.binaryType = 'blob';
+ return Promise.all([
+ stash.send('blob'),
+ watchEvent(connection, eventWatcher, 'message')
+ ]).then(results => results[1]);
+ }).then(event => {
+ assert_true(event.data instanceof Blob, 'receive binary data as Blob');
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = resolve;
+ reader.onerror = reject;
+ reader.readAsArrayBuffer(event.data);
+ });
+ }).then(event => {
+ assert_true(compare(event.target.result, message5), 'receive a Blob correctly');
+ connection.terminate();
+ });
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onterminate-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onterminate-manual.https.html
new file mode 100644
index 0000000000..7fdc2dbdcd
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onterminate-manual.https.html
@@ -0,0 +1,157 @@
+<!DOCTYPE html>
+
+<meta charset="utf-8">
+<title>Terminating a presentation in a controlling browsing context</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="author" title="Chunyan Wang" href="mailto:chunyanx.wang@intel.com">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="https://w3c.github.io/presentation-api/#terminating-a-presentation-in-a-controlling-browsing-context">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<style>iframe { display: none; }</style>
+<p>
+ Click the button below and select the available presentation display, to start the manual test. The test passes if a "PASS" result appears.<br>
+ This test asks you to click the button twice, unless the test fails.<br>
+</p>
+<button id="presentBtn">Start Presentation Test</button>
+<iframe id="childFrame" src="support/iframe.html"></iframe>
+
+<script>
+ setup({explicit_timeout: true});
+ const presentBtn = document.getElementById('presentBtn');
+ const childFrame = document.getElementById('childFrame');
+
+ promise_test(t => {
+ const clickWatcher = new EventWatcher(t, presentBtn, 'click');
+ const messageWatcher = new EventWatcher(t, window, 'message');
+ const request = new PresentationRequest(presentationUrls);
+ let connection, eventWatcher, timeout;
+
+ t.add_cleanup(() => {
+ if (connection) {
+ connection.onconnect = () => { connection.terminate(); };
+ if (connection.state === 'closed')
+ request.reconnect(connection.id);
+ else
+ connection.terminate();
+ }
+ });
+
+ const startTimeout = () => {
+ timeout = t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 10000);
+ };
+
+ const checkTerminateEvent = evt => {
+ assert_true(evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event, 'A simple event is fired.');
+ assert_equals(evt.type, 'terminate', 'The event name is "terminate".');
+ assert_equals(evt.target, connection, 'event.target is the presentation connection.');
+ assert_equals(connection.state, 'terminated', 'State of the presentation connection is "terminated".');
+ };
+
+ 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];
+ });
+ };
+
+ const waitForEvent = (obj, watcher, type) => {
+ const watchHandler = new Promise(resolve => {
+ obj['on' + type] = evt => { resolve(evt); };
+ });
+ return Promise.race([ watchHandler, watcher.wait_for(type) ]);
+ };
+
+ return Promise.all([
+ clickWatcher.wait_for('click'),
+ messageWatcher.wait_for('message')
+ ]).then(() => {
+ presentBtn.disabled = true;
+
+ return request.start();
+ }).then(c => {
+ startTimeout();
+
+ connection = c;
+ eventWatcher = new EventWatcher(t, connection, 'terminate');
+
+ // Step 1: terminate the presentation when the presentation connection is in "connecting" state
+ connection.terminate();
+ return Promise.race([
+ new Promise((_, reject) => {
+ t.step_timeout(() => { reject('The presentation is not terminated successfully when the presentation connection in "connecting" state.'); }, 3000);
+ }),
+ watchEvent(connection, eventWatcher, 'terminate')
+ ]);
+ }).then(evt => {
+ checkTerminateEvent(evt);
+
+ // Step 2: terminate the presentation when the presentation connection is in "closed" state (nothing should happen)
+ presentBtn.textContent = 'Continue Presentation Test';
+ presentBtn.disabled = false;
+ clearTimeout(timeout);
+ return clickWatcher.wait_for('click');
+ }).then(() => {
+ return request.start();
+ }).then(c => {
+ startTimeout();
+ connection = c;
+ eventWatcher = new EventWatcher(t, connection, ['connect', 'close', 'terminate']);
+ return eventWatcher.wait_for('connect');
+ }).then(() => {
+ connection.close();
+ return eventWatcher.wait_for('close');
+ }).then(() => {
+ const terminateWatcher = new EventWatcher(t, connection, 'terminate');
+ connection.terminate();
+ return Promise.race([
+ new Promise(resolve => { t.step_timeout(resolve, 1000); }),
+ waitForEvent(connection, terminateWatcher, 'terminate').then(() => {
+ assert_unreached('Invoking PresentationConnection.terminate() in the "closed" state causes nothing.'); })
+ ]);
+ }).then(() => {
+ // Step 3: terminate the presentation when the presentation connection is in "connected" state;
+ // this step also checks an event fired at another presentation connection in a nested browsing context
+ return request.reconnect(connection.id);
+ }).then(() => {
+ return eventWatcher.wait_for('connect');
+ }).then(() => {
+ childFrame.contentWindow.postMessage('terminate?id=' + connection.id, '*');
+ return messageWatcher.wait_for('message')
+ }).then(() => {
+ connection.terminate();
+ return Promise.race([
+ new Promise((_, reject) => {
+ t.step_timeout(() => { reject('The presentation is not terminated successfully when the presentation connection in "connected" state.'); }, 3000);
+ }),
+ Promise.all([
+ watchEvent(connection, eventWatcher, 'terminate'),
+ messageWatcher.wait_for('message')
+ ])
+ ]);
+ }).then(results => {
+ checkTerminateEvent(results[0]);
+ const evt = results[1].data;
+ assert_true(evt.isSimpleEvent, 'A simple event is fired in a nested browsing context.');
+ assert_equals(evt.type, 'terminate', 'The event name is "terminate".');
+ assert_true(evt.checkConnection, 'event.target is the presentation connection.');
+ assert_equals(evt.state, 'terminated', 'State of the presentation connection is "terminated".');
+
+ // Step 4: terminate the presentation when the presentation connection is in "terminated" state (nothing should happen)
+ const terminateWatcher = new EventWatcher(t, connection, 'terminate');
+ connection.terminate();
+ return Promise.race([
+ new Promise(resolve => { t.step_timeout(resolve, 1000); }),
+ waitForEvent(connection, terminateWatcher, 'terminate').then(() => {
+ assert_unreached('Invoking PresentationConnection.terminate() in the "terminated" state causes nothing.'); })
+ ]);
+ });
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_send-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_send-manual.https.html
new file mode 100644
index 0000000000..fcc91212e0
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_send-manual.https.html
@@ -0,0 +1,125 @@
+<!DOCTYPE html>
+
+<meta charset="utf-8">
+<title>Sending a message through PresentationConnection</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="http://w3c.github.io/presentation-api/#sending-a-message-through-presentationconnection">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<script src="support/stash.js"></script>
+
+<p id="notice">
+ Click the button below and select the available presentation display, to start the manual test. The test passes if a "PASS" result appears.<br>
+ <button id="presentBtn">Start Presentation Test</button>
+</p>
+
+<script>
+ setup({explicit_timeout: true});
+
+ const presentBtn = document.getElementById('presentBtn');
+
+ const message1 = '1st';
+ const message2 = '2nd';
+ const message3 = new Uint8Array([51, 114, 100]); // "3rd"
+ const message4 = new Uint8Array([52, 116, 104]); // "4th"
+ const message5 = new Uint8Array([108, 97, 115, 116]); // "last"
+
+ const toUint8Array = buf => {
+ return buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;
+ }
+
+ // convert ArrayBuffer or Uint8Array into string
+ const toText = buf => {
+ const arr = toUint8Array(buf);
+ return !buf ? null : arr.reduce((result, item) => {
+ return result + String.fromCharCode(item);
+ }, '');
+ }
+
+ promise_test(t => {
+ const clickWatcher = new EventWatcher(t, presentBtn, 'click');
+ const stash = new Stash(stashIds.toController, stashIds.toReceiver);
+ const request = new PresentationRequest(presentationUrls);
+ let connection, watcher;
+
+ t.add_cleanup(() => {
+ if (connection) {
+ connection.onconnect = () => { connection.terminate(); };
+ if (connection.state === 'closed')
+ request.reconnect(connection.id);
+ else
+ connection.terminate();
+ }
+ const notice = document.getElementById('notice');
+ notice.parentNode.removeChild(notice);
+ stash.stop();
+ });
+
+ return clickWatcher.wait_for('click').then(() => {
+ presentBtn.disabled = true;
+
+ return request.start();
+ }).then(c => {
+ connection = c;
+
+ // send data in "connecting" state (throws an exception)
+ assert_equals(connection.state, 'connecting', 'the initial state of the presentation connection is "connecting"');
+ assert_throws_dom('InvalidStateError', () => {
+ connection.send('');
+ }, 'an InvalidStateError is thrown if the state is "connecting"');
+
+ // enable timeout again, cause no user action is needed from here.
+ t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 10000);
+
+ watcher = new EventWatcher(t, connection, ['connect', 'close', 'terminate']);
+ return watcher.wait_for('connect');
+ }).then(() => {
+ return stash.init();
+ }).then(() => {
+ return Promise.all([ stash.send('send'), stash.receive() ]);
+ }).then(results => {
+ // send messages
+ connection.send(message1); // string
+ connection.send(message2); // string
+ connection.send(new Blob([message3])); // Blob
+ connection.send(message4.buffer); // ArrayBuffer
+ connection.send(message5); // ArrayBufferView
+ return stash.receive();
+ }).then(stash => {
+ // verify messages
+ const results = JSON.parse(stash);
+ assert_true(!!results[0] && results[0].type === 'text' && results[0].data === message1, 'send a string correctly');
+ assert_true(!!results[1] && results[1].type === 'text' && results[1].data === message2, 'send a string correctly');
+ assert_true(!!results[2] && results[2].type === 'binary' && results[2].data === toText(message3), 'send a Blob correctly');
+ assert_true(!!results[3] && results[3].type === 'binary' && results[3].data === toText(message4), 'send a ArrayBuffer correctly');
+ assert_true(!!results[4] && results[4].type === 'binary' && results[4].data === toText(message5), 'send a ArrayBufferView correctly');
+
+ // send data in "closed" state (throws an exception)
+ connection.close();
+ return watcher.wait_for('close');
+ }).then(() => {
+ assert_equals(connection.state, 'closed', 'the state is set to "closed" when the presentation connection is closed');
+ assert_throws_dom('InvalidStateError', () => {
+ connection.send('');
+ }, 'an InvalidStateError is thrown if the state is "closed"');
+
+ // reconnect and terminate the connection
+ return request.reconnect(connection.id);
+ }).then(() => {
+ return watcher.wait_for('connect');
+ }).then(() => {
+ // send data in "terminated" state (throws an exception)
+ connection.terminate();
+ return watcher.wait_for('terminate');
+ }).then(() => {
+ assert_equals(connection.state, 'terminated', 'the state is set to "terminated" when the presentation connection is terminated');
+ assert_throws_dom('InvalidStateError', () => {
+ connection.send('');
+ }, 'an InvalidStateError is thrown if the state is "terminated"');
+ });
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_error.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_error.https.html
new file mode 100644
index 0000000000..68e0fbcd22
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_error.https.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Constructing a PresentationRequest (Error)</title>
+<link rel="author" title="Franck William Taffo" href="http://www.fokus.fraunhofer.de">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#constructing-a-presentationrequest">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+ test(() => {
+ assert_throws_js(TypeError, () => {
+ new PresentationRequest();
+ }, 'Call PresentationRequest() constructor without presentation URL. TypeError Exception expected.');
+
+ assert_throws_dom('NotSupportedError', () => {
+ new PresentationRequest([]);
+ }, 'Call PresentationRequest constructor with an empty sequence. NotSupportedError Exception expected.');
+
+ assert_throws_dom('SyntaxError', () => {
+ new PresentationRequest('https://@');
+ }, 'Call PresentationRequest constructor with an invalid URL. SyntaxError Exception expected.');
+
+ assert_throws_dom('NotSupportedError', () => {
+ new PresentationRequest('unsupported://example.com');
+ }, 'Call PresentationRequest constructor with an unsupported URL. NotSupportedError expected.');
+
+ assert_throws_dom('SyntaxError', function() {
+ new PresentationRequest(['presentation.html', 'https://@']);
+ }, 'Call PresentationRequest constructor with a sequence of URLs, one of them invalid. SyntaxError Exception expected.');
+
+ assert_throws_dom('NotSupportedError', function() {
+ new PresentationRequest(['unsupported://example.com', 'invalid://example.com']);
+ }, 'Call PresentationRequest constructor only with a sequence of unsupported URLs. NotSupportedError Exception expected.');
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_mixedcontent.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_mixedcontent.https.html
new file mode 100644
index 0000000000..3b19b9c9bd
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_mixedcontent.https.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Creating a PresentationRequest with an a priori unauthenticated URL in an HTTPS context throws a SecurityError exception.</title>
+<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
+<link rel="help" href="http://w3c.github.io/presentation-api/#constructing-a-presentationrequest">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+ function createPresentation() {
+ var request = new PresentationRequest('http://example.org/presentation.html');
+ };
+
+ test(function () {
+ assert_throws_dom('SecurityError', createPresentation);
+ });
+</script>
+
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_mixedcontent_multiple.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_mixedcontent_multiple.https.html
new file mode 100644
index 0000000000..e9571224d6
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_mixedcontent_multiple.https.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Creating a PresentationRequest with a set of URLs containing an a priori unauthenticated URL in an HTTPS context throws a SecurityError exception.</title>
+<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
+<link rel="help" href="http://w3c.github.io/presentation-api/#constructing-a-presentationrequest">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+ function createPresentation() {
+ var request = new PresentationRequest([
+ 'presentation.html',
+ 'http://example.org/presentation.html'
+ ]);
+ };
+
+ test(function () {
+ assert_throws_dom('SecurityError', createPresentation);
+ });
+</script>
+
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_onconnectionavailable-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_onconnectionavailable-manual.https.html
new file mode 100644
index 0000000000..d06daae11c
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_onconnectionavailable-manual.https.html
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Firing a connectionavailable event at a controlling user agent</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="https://w3c.github.io/presentation-api/#starting-a-presentation">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<p>Click the button below and select the available presentation display, to start the manual test.</p>
+<button id="presentBtn">Start Presentation Test</button>
+
+
+<script>
+ // disable the timeout function for the tests
+ setup({explicit_timeout: true});
+
+ // ----------
+ // DOM Object
+ // ----------
+ const presentBtn = document.getElementById('presentBtn');
+
+ // --------------------------------------------------------------------------
+ // Start New PresentationRequest.onconnectionavailable Test (success) - begin
+ // --------------------------------------------------------------------------
+ promise_test(t => {
+ const clickWatcher = new EventWatcher(t, presentBtn, 'click');
+ const request = new PresentationRequest(presentationUrls);
+ let connection;
+
+ t.add_cleanup(() => {
+ if (connection) {
+ connection.onconnect = () => { connection.terminate(); };
+ if (connection.state === 'closed')
+ request.reconnect(connection.id);
+ else
+ connection.terminate();
+ }
+ });
+
+ 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];
+ });
+ };
+
+ return clickWatcher.wait_for('click').then(() => {
+ presentBtn.disabled = true;
+
+ // Note: During starting a presentation, the connectionavailable event is fired (step 9)
+ // after the promise P is resolved (step 8).
+ return request.start();
+ }).then(c => {
+ connection = c;
+ assert_equals(connection.state, 'connecting', 'The initial state of the presentation connection is "connecting".');
+ assert_true(!!connection.id, 'The connection ID is set.');
+ assert_equals(typeof connection.id, 'string', 'The connection ID is a string.');
+ assert_true(connection instanceof PresentationConnection, 'The connection is an instance of PresentationConnection.');
+
+ const eventWatcher = new EventWatcher(t, request, 'connectionavailable');
+ const timeout = new Promise((_, reject) => {
+ // This test fails if request.onconnectionavailable is not invoked although the presentation is started successfully
+ // or the presentation fails to be started.
+ t.step_timeout(() => { reject('The connectionavailable event was not fired (timeout).'); }, 5000);}
+ );
+ return Promise.race([ watchEvent(request, eventWatcher, 'connectionavailable'), timeout ]);
+ }).then(evt => {
+ assert_true(evt instanceof PresentationConnectionAvailableEvent, 'An event using PresentationConnectionAvailableEvent is fired.');
+ assert_true(evt.isTrusted, 'The event is a trusted event.');
+ assert_false(evt.bubbles, 'The event does not bubbles.');
+ assert_false(evt.cancelable, 'The event is not cancelable.');
+ assert_equals(evt.type, 'connectionavailable', 'The event name is "connectionavailable".');
+ assert_equals(evt.target, request, 'event.target is the presentation request.');
+ assert_true(evt.connection instanceof PresentationConnection, 'event.connection is a presentation connection.');
+ assert_equals(evt.connection, connection, 'event.connection is set to the presentation which the promise is resolved with.');
+ });
+ });
+ // ------------------------------------------------------------------------
+ // Start New PresentationRequest.onconnectionavailable Test (success) - end
+ // ------------------------------------------------------------------------
+</script>
+
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_error.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_error.https.html
new file mode 100644
index 0000000000..ad5e32a45a
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_error.https.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Sandboxing: Creating a PresentationRequest from a nested context fails when allow-presentation is not set</title>
+<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
+<link rel="help" href="http://w3c.github.io/presentation-api/#constructing-a-presentationrequest">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ async_test(function (t) {
+ var startWhenReady = t.step_func(function (ev) {
+ var childFrame = document.getElementById('childFrame');
+ if (ev.data === 'ready') {
+ window.removeEventListener('message', startWhenReady);
+ window.addEventListener('message', checkFinalMessage);
+ childFrame.contentWindow.postMessage('create', '*');
+ }
+ });
+
+ var checkFinalMessage = t.step_func_done(function (ev) {
+ assert_equals(ev.data, 'SecurityError', 'Presentation sandboxing did not work as expected.');
+ });
+
+ window.addEventListener('message', startWhenReady);
+ });
+</script>
+<iframe id="childFrame" sandbox="allow-scripts" style="display:none" src="support/iframe.html"></iframe>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_success.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_success.https.html
new file mode 100644
index 0000000000..7ede80d595
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_success.https.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Sandboxing: Creating a PresentationRequest from a nested context succeeds when allow-presentation is set</title>
+<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
+<link rel="help" href="http://w3c.github.io/presentation-api/#constructing-a-presentationrequest">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ async_test(function (t) {
+ var startWhenReady = t.step_func(function (ev) {
+ var childFrame = document.getElementById('childFrame');
+ if (ev.data === 'ready') {
+ window.removeEventListener('message', startWhenReady);
+ window.addEventListener('message', checkFinalMessage);
+ childFrame.contentWindow.postMessage('create', '*');
+ }
+ });
+
+ var checkFinalMessage = t.step_func_done(function (ev) {
+ assert_equals(ev.data, 'success', 'Presentation sandboxing did not work as expected.');
+ });
+
+ window.addEventListener('message', startWhenReady);
+ });
+</script>
+<iframe id="childFrame" sandbox="allow-scripts allow-presentation" style="display:none" src="support/iframe.html"></iframe>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_success.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_success.https.html
new file mode 100644
index 0000000000..890e0ed624
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_success.https.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Constructing a PresentationRequest</title>
+<link rel="author" title="Franck William Taffo" href="http://www.fokus.fraunhofer.de">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="http://w3c.github.io/presentation-api/#constructing-a-presentationrequest">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+ test(() => {
+ let request = new PresentationRequest('presentation.html');
+ assert_true(request instanceof PresentationRequest, 'An instance of PresentationRequest with a relative presentation URL is constructed successfully.');
+
+ request = new PresentationRequest('https://example.org/');
+ assert_true(request instanceof PresentationRequest, 'An instance of PresentationRequest with an absolute presentation URL is constructed successfully.');
+
+ request = new PresentationRequest([
+ 'presentation.html',
+ 'https://example.org/presentation/'
+ ]);
+ assert_true(request instanceof PresentationRequest, 'An instance of PresentationRequest with an array of presentation URLs is constructed successfully.');
+
+ request = new PresentationRequest([
+ 'unsupported://example.com',
+ 'presentation.html',
+ 'https://example.org/presentation/'
+ ]);
+ assert_true(request instanceof PresentationRequest, 'An unsupported URL in an array of presentation URLs is ignored successfully.');
+ });
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/common.js b/testing/web-platform/tests/presentation-api/controlling-ua/common.js
new file mode 100644
index 0000000000..4a73acd1de
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/common.js
@@ -0,0 +1,25 @@
+(function (window) {
+ // Cast ID of the main custom receiver application linked with the test suite
+ // That application ID, maintained by W3C team, points at:
+ // https://[W3C test server]/presentation-api/controlling-ua/support/presentation.html
+ //
+ // NB: this mechanism should be improved later on as tests should not depend
+ // on something that directly or indirectly maps to a resource on the W3C test
+ // server.
+ var castAppId = '915D2A2C';
+ var castUrl = 'cast:' + castAppId;
+
+ window.presentationUrls = [
+ 'support/presentation.html',
+ castUrl
+ ];
+
+ // Both a controlling side and a receiving one must share the same Stash ID to
+ // transmit data from one to the other. On the other hand, due to polling mechanism
+ // which cleans up a stash, stashes in both controller-to-receiver direction
+ // and one for receiver-to-controller are necessary.
+ window.stashIds = {
+ toController: '9bf08fea-a71a-42f9-b3c4-fa19499e4d12',
+ toReceiver: 'f1fdfd10-b606-4748-a644-0a8e9df3bdd6'
+ }
+})(window);
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest.https.html
new file mode 100644
index 0000000000..713cea7f9a
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest.https.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Setting a default presentation request</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+ test(() => {
+ assert_equals(navigator.presentation.defaultRequest, null, 'The initial value of the default presentation request is null.');
+
+ const request = new PresentationRequest('https://example.org/');
+ navigator.presentation.defaultRequest = request;
+ assert_equals(navigator.presentation.defaultRequest, request, 'The default presentation request is set to an instance of PresentationRequest.');
+
+ assert_throws_js(TypeError, () => {
+ navigator.presentation.defaultRequest = {};
+ }, 'The default presentation request cannot be set to any value but an instance of PresentationRequest or null.');
+
+ navigator.presentation.defaultRequest = null;
+ assert_equals(navigator.presentation.defaultRequest, null, 'The default presentation request is set to null.');
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest_success-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest_success-manual.https.html
new file mode 100644
index 0000000000..840b72b849
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest_success-manual.https.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>[Optional] Starting a presentation from the browser using a default presentation request.</title>
+<link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentation-defaultrequest">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+
+<p>
+ Click the button or the menu item for presentation on your browser (for example, "Cast"), <br>
+ to start the manual test, and select a presentation display when prompted to do so.<br>
+ The test passes if a "PASS" result appears.
+</p>
+<p id="notice">
+ If your browser does not support <code>defaultRequest</code>, please click this button: <button id="notsupported">Not Supported</button>
+</p>
+
+<script>
+ // disable the timeout function for the tests
+ // and call 'done()' when the tests cases are finished.
+ setup({explicit_timeout: true});
+
+ // -----------
+ // DOM Element
+ // -----------
+ var button = document.getElementById('notsupported'),
+ notice = document.getElementById('notice');
+
+ // ------------------------------
+ // Start New Presentation with
+ // 'default request' Test - BEGIN
+ // ------------------------------
+ async_test(function(t) {
+ // clean up the presentation and the instruction notice when the test ends
+ var connection;
+ t.add_cleanup(function() {
+ notice.parentNode.removeChild(notice);
+ if(connection)
+ connection.terminate();
+ });
+ // set an event handler to make the test fail when the button is clicked
+ button.onclick = t.step_func_done(function() {
+ assert_unreached('This browser does not support defaultRequest.');
+ });
+ // set up a default presentation request
+ var request = new PresentationRequest(presentationUrls);
+ navigator.presentation.defaultRequest = request;
+ request.onconnectionavailable = t.step_func_done(function (evt) {
+ connection = evt.connection;
+ // check the presentation connection and its attributes
+ assert_equals(connection.state, 'connecting', 'The initial state of the presentation connection is "connecting".');
+ assert_true(!!connection.id, 'The connection ID is set.');
+ assert_equals(typeof connection.id, 'string', 'The connection ID is a string.');
+ assert_true(connection instanceof PresentationConnection, 'The connection is an instance of PresentationConnection.');
+ });
+ });
+ // ----------------------------
+ // Start New Presentation with
+ // 'default request' Test - END
+ // ----------------------------
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/getAvailability.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/getAvailability.https.html
new file mode 100644
index 0000000000..71b19e6a4e
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/getAvailability.https.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Getting the presentation displays availability information.</title>
+<meta name="timeout" content="long">
+<link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-presentation-display-availability">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+
+<p>The test passes if a "PASS" result appears.</p>
+
+<script>
+
+ // ---------------------------------------
+ // Presentation Availability Tests - begin
+ // ---------------------------------------
+
+ const catchNotSupported = err => {
+ assert_equals(err.name, 'NotSupportedError', 'getAvailability() rejects a Promise with a NotSupportedError exception, if the browser can find presentation displays only when starting a connection.')
+ };
+
+ promise_test(t => {
+ let availability;
+
+ const request = new PresentationRequest(presentationUrls);
+ assert_true(request instanceof PresentationRequest, 'The request is an instance of PresentationRequest.');
+
+ const promise = request.getAvailability();
+ assert_true(promise instanceof Promise, 'PresentationRequest.getAvailability() returns a Promise.');
+ const samePromise = request.getAvailability();
+ assert_true(samePromise instanceof Promise, 'PresentationRequest.getAvailabilty() returns a Promise.');
+ assert_equals(promise, samePromise, 'If the PresentationRequest object has an unsettled Promise, getAvailability returns that Promise.');
+
+ return promise.then(a => {
+ availability = a;
+ assert_true(availability instanceof PresentationAvailability, 'The promise is resolved with an instance of PresentationAvailability.');
+ assert_equals(typeof availability.value, 'boolean', 'The availability has an boolean value.');
+
+ const request2 = new PresentationRequest('https://example.com');
+ return request2.getAvailability();
+ }).then(a => {
+ assert_not_equals(availability, a, 'A presentation availability object is newly created if the presentation request has a newly added presentation URLs.');
+
+ const newPromise = request.getAvailability();
+ assert_not_equals(promise, newPromise, 'If the Promise from a previous call to getAvailability has already been settled, getAvailability returns a new Promise.');
+
+ return newPromise.then(newAvailability => {
+ assert_equals(availability, newAvailability, 'Promises from a PresentationRequest\'s getAvailability are resolved with the same PresentationAvailability object.');
+ }, catchNotSupported);
+ }, catchNotSupported);
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/getAvailability_sandboxing_success.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/getAvailability_sandboxing_success.https.html
new file mode 100644
index 0000000000..daa0a0ff14
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/getAvailability_sandboxing_success.https.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Sandboxing: Retrieving display availability from a nested context succeeds when allow-presentation is set</title>
+<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-getavailability">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ async_test(function (t) {
+ function startWhenReady(ev) {
+ var childFrame = document.getElementById('childFrame');
+ if (ev.data === 'ready') {
+ window.removeEventListener('message', startWhenReady);
+ childFrame.contentWindow.postMessage('getAvailability', '*');
+ window.addEventListener('message', t.step_func(function (ev) {
+ assert_equals(ev.data, 'success',
+ 'Presentation sandboxing did not work as expected.');
+ t.done();
+ }));
+ }
+ }
+ window.addEventListener('message', startWhenReady);
+ });
+</script>
+<iframe id="childFrame" sandbox="allow-scripts allow-presentation" style="display:none" src="support/iframe.html"></iframe>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/idlharness.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/idlharness.https.html
new file mode 100644
index 0000000000..1cb8830f89
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/idlharness.https.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Presentation API IDL tests for Controlling User Agent</title>
+<meta name="timeout" content="long">
+<link rel="author" title="Louay Bassbouss" href="http://www.fokus.fraunhofer.de">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/WebIDLParser.js"></script>
+<script src="/resources/idlharness.js"></script>
+
+<script>
+ "use strict";
+
+ promise_test(async () => {
+ const srcs = ['presentation-api', 'dom', 'html'];
+ const [idl, dom, html] = await Promise.all(
+ srcs.map(i => fetch(`/interfaces/${i}.idl`).then(r => r.text())));
+
+ const idl_array = new IdlArray();
+ idl_array.add_idls(idl, {
+ except: [
+ 'PresentationReceiver',
+ 'PresentationConnectionList'
+ ]
+ });
+ idl_array.add_dependency_idls(dom);
+ idl_array.add_dependency_idls(html);
+
+ try {
+ window.presentation_request = new PresentationRequest("/presentation-api/receiving-ua/idlharness.html");
+ window.presentation_request_urls = new PresentationRequest([
+ "/presentation-api/receiving-ua/idlharness.html",
+ "https://www.example.com/presentation.html"
+ ]);
+ navigator.presentation.defaultRequest = window.presentation_request;
+ } catch (e) {
+ // Will be surfaced in idlharness.js's test_object below.
+ }
+
+ idl_array.add_objects({
+ Presentation: ['navigator.presentation'],
+ PresentationRequest: [
+ 'navigator.presentation.defaultRequest',
+ 'presentation_request',
+ 'presentation_request_urls'
+ ],
+ });
+ idl_array.test();
+ }, "Test IDL implementation of Presentation API");
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToMultiplePresentations_success-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToMultiplePresentations_success-manual.https.html
new file mode 100644
index 0000000000..ab1bd8089d
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToMultiplePresentations_success-manual.https.html
@@ -0,0 +1,138 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Reconnecting presentations on two distinct displays</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-reconnect">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<style>
+#second-step {
+ display: none;
+}
+</style>
+
+<p id="first-step">Click the button below and select the available presentation display, to start the manual test.</p>
+<p id="second-step">Click the button below and select the other available presentation display, to continue the manual test.</p>
+<p>This test asks you to click the button twice, unless the test fails.<br>
+<em>This test requires two or more available displays.<em></p>
+<button id="presentBtn">Start Presentation Test</button>
+
+
+<script>
+ promise_test(async t => {
+ const presentBtn = document.getElementById("presentBtn");
+
+ const request1 = new PresentationRequest(presentationUrls);
+ const request2 = new PresentationRequest(presentationUrls);
+ const clickWatcher = new EventWatcher(t, presentBtn, 'click');
+ let connection1, connection2, eventWatcher1, eventWatcher2, timer;
+
+ t.add_cleanup(() => {
+ [
+ { connection: connection1, request: request1 },
+ { connection: connection2, request: request2 }
+ ].forEach(p => {
+ if (p.connection) {
+ p.connection.onconnect = () => { p.connection.terminate(); };
+ if (p.connection.state == 'closed')
+ p.request.reconnect(p.connection.id);
+ else
+ p.connection.terminate();
+ }
+ });
+ });
+
+ const disableTimeout = () => {
+ setup({explicit_timeout: true});
+ if (timer) {
+ clearTimeout(timer);
+ timer = null;
+ }
+ };
+
+ const enableTimeout = () => {
+ timer = t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 5000);
+ }
+
+ disableTimeout();
+
+ await clickWatcher.wait_for('click');
+ presentBtn.disabled = true;
+ connection1 = await request1.start();
+
+ presentBtn.disabled = false;
+ document.getElementById('first-step').style.display = 'none';
+ document.getElementById('second-step').style.display = 'block';
+ presentBtn.innerText = 'Continue Presentation Test';
+ eventWatcher1 = new EventWatcher(t, connection1, ['connect', 'close', 'terminate']);
+
+ await Promise.all([
+ eventWatcher1.wait_for('connect'),
+ (async () => {
+ await clickWatcher.wait_for('click');
+ presentBtn.disabled = true;
+
+ connection2 = await request2.start();
+ enableTimeout();
+ eventWatcher2 = new EventWatcher(t, connection2, ['connect', 'close', 'terminate']);
+ await eventWatcher2.wait_for('connect');
+ })()
+ ]);
+
+ connection1.close();
+ assert_equals(connection2.state, 'connected',
+ 'Closing one presentation connection does not affect the state of the other.');
+
+ await eventWatcher1.wait_for('close');
+ assert_equals(connection1.state, 'closed', 'The presentation connection is successfully closed.');
+
+ connection2.close();
+ await eventWatcher2.wait_for('close');
+ assert_equals(connection2.state, 'closed', 'The presentation connection is successfully closed.');
+
+ const c11 = await request1.reconnect(connection1.id);
+ assert_equals(c11, connection1, 'The promise is resolved with the existing presentation connection.');
+
+ const c22 = await request2.reconnect(connection2.id);
+ assert_equals(c22, connection2, 'The promise is resolved with the existing presentation connection.');
+
+ await Promise.all([
+ eventWatcher1.wait_for('connect'),
+ eventWatcher2.wait_for('connect')
+ ]);
+
+ assert_equals(connection1.state, 'connected', 'The presentation connection is successfully reconnected.');
+ assert_equals(connection2.state, 'connected', 'The presentation connection is successfully reconnected.');
+
+ // Reconnecting a presentation via a different presentation request with the same presentation
+ // URLs will succeed
+ connection2.close();
+ await eventWatcher2.wait_for('close');
+ const c12 = await request1.reconnect(connection2.id);
+ assert_equals(c12, connection2, 'The promise is resolved with the existing presentation connection.');
+
+ connection1.close();
+ await eventWatcher1.wait_for('close');
+ const c21 = await request2.reconnect(connection1.id);
+ assert_equals(c21, connection1, 'The promise is resolved with the existing presentation connection.');
+
+ await Promise.all([
+ eventWatcher1.wait_for('connect'),
+ eventWatcher2.wait_for('connect')
+ ]);
+
+ assert_equals(connection1.state, 'connected', 'The presentation connection is successfully reconnected.');
+ assert_equals(connection2.state, 'connected', 'The presentation connection is successfully reconnected.');
+ connection1.terminate();
+ connection2.terminate();
+
+ await Promise.all([
+ eventWatcher1.wait_for('terminate'),
+ eventWatcher2.wait_for('terminate')
+ ]);
+ });
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_notfound_error-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_notfound_error-manual.https.html
new file mode 100644
index 0000000000..f92ab80f73
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_notfound_error-manual.https.html
@@ -0,0 +1,61 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Calling "reconnect" with a wrong presentation ID fails with a NotFoundError exception</title>
+<link rel="author" title="Franck William Taffo" href="http://www.fokus.fraunhofer.de">
+<link rel="author" title="Louay Bassbouss" href="http://www.fokus.fraunhofer.de">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-reconnect">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+
+<p>Click the button below to start the manual test. Select a presentation device after the selection dialog is prompted.
+ The test assumes that at least one presentation device is available. The test passes if a "PASS" result appears.</p>
+<button id="startBtn">Start Test</button>
+
+<script>
+ promise_test(async t => {
+ const startBtn = document.getElementById('startBtn');
+ const wrongPresentationId = "wrongPresentationId";
+ const request1 = new PresentationRequest(presentationUrls);
+ const request2 = new PresentationRequest('https://www.w3.org');
+ let connection1, eventWatcher1;
+
+ t.add_cleanup(() => {
+ if (connection1) {
+ connection1.onconnect = () => { connection1.terminate(); }
+ if (connection1.state === 'closed')
+ request1.reconnect(connection1.id);
+ else
+ connection1.terminate();
+ }
+ });
+
+ await promise_rejects_dom(t, 'NotFoundError', request1.reconnect(wrongPresentationId),
+ 'Reconnecting with an unknown presentation ID fails with a NotFoundError exception.');
+
+ setup({explicit_timeout: true});
+ const clickWatcher = new EventWatcher(t, startBtn, 'click');
+ await clickWatcher.wait_for('click');
+ connection1 = await request1.start();
+
+ t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 5000);
+
+ startBtn.disabled = true;
+ eventWatcher1 = new EventWatcher(t, connection1, ['connect', 'close', 'terminate']);
+ await eventWatcher1.wait_for('connect');
+ connection1.close();
+ await eventWatcher1.wait_for('close');
+
+ await promise_rejects_dom(t, 'NotFoundError', request2.reconnect(connection1.id),
+ 'Reconnecting with a presentation ID on a presentation request with a different URL fails with a NotFoundError exception.');
+
+ await request1.reconnect(connection1.id);
+ await eventWatcher1.wait_for('connect');
+ connection1.terminate();
+ await eventWatcher1.wait_for('terminate');
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_sandboxing_success.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_sandboxing_success.https.html
new file mode 100644
index 0000000000..96505aca05
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_sandboxing_success.https.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Sandboxing: Reconnecting a presentation from a nested context succeeds when allow-presentation is set</title>
+<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-reconnect">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ async_test(function (t) {
+ function startWhenReady(ev) {
+ var childFrame = document.getElementById('childFrame');
+ if (ev.data === 'ready') {
+ window.removeEventListener('message', startWhenReady);
+ childFrame.contentWindow.postMessage('reconnect', '*');
+ window.addEventListener('message', t.step_func(function (ev) {
+ assert_equals(ev.data, 'NotFoundError',
+ 'Presentation sandboxing did not work as expected.');
+ t.done();
+ }));
+ }
+ }
+ window.addEventListener('message', startWhenReady);
+ });
+</script>
+<iframe id="childFrame" sandbox="allow-scripts allow-presentation" style="display:none" src="support/iframe.html"></iframe>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_success-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_success-manual.https.html
new file mode 100644
index 0000000000..a2619042f8
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_success-manual.https.html
@@ -0,0 +1,185 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Reconnect to presentation success manual test</title>
+<link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de">
+<link rel="author" title="Louay Bassbouss" href="http://www.fokus.fraunhofer.de">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-reconnect">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<style>iframe { display: none; }</style>
+
+<p>Click the button below to start the manual test. Select a presentation device after the selection dialog is prompted.
+ The test assumes that at least one presentation device is available. The test passes if a "PASS" result appears.</p>
+<button id="startBtn">Start Test</button>
+<iframe id="childFrame" src="support/iframe.html"></iframe>
+
+<script>
+ let receiverStack;
+ add_completion_callback(() => {
+ // overwrite a stack written in the test result
+ if (receiverStack) {
+ document.querySelector('#log pre').textContent = receiverStack;
+ }
+ });
+
+ // disable timeout for manual tests
+ setup({explicit_timeout: true});
+ const startBtn = document.getElementById('startBtn');
+ const childFrame = document.getElementById('childFrame');
+
+ promise_test(t => {
+ const startWatcher = new EventWatcher(t, startBtn, 'click');
+ const messageWatcher = new EventWatcher(t, window, 'message');
+ const request = new PresentationRequest(presentationUrls);
+ let connection, eventWatcher;
+
+ t.add_cleanup(() => {
+ if (connection) {
+ connection.onconnect = () => { connection.terminate(); }
+ if (connection.state === 'closed')
+ request.reconnect(connection.id);
+ else
+ connection.terminate();
+ }
+ });
+
+ const waitForMessage = () => {
+ return messageWatcher.wait_for('message').then(evt => {
+ return evt.data.type === 'presentation-api' ? evt : waitForMessage();
+ });
+ };
+
+ // handle a test result received from a nested browsing context
+ const parseValue = value => {
+ let r;
+
+ // String
+ if (r = value.match(/^(\(string\)\s+)?"(.*)"$/))
+ return r[2];
+ // Object
+ else if (r = value.match(/^(\(object\)\s+)?object\s+"\[object\s+(.*)\]"$/))
+ return window[r[2]].prototype;
+ // undefined
+ else if (value === "undefined")
+ return undefined;
+ // Number, boolean, null
+ else {
+ if (r = value.match(/^(\(\S+\)\s+)?(\S+)$/)) {
+ try {
+ return JSON.parse(r[2]);
+ } catch(e) {
+ return value;
+ }
+ }
+ else
+ return value;
+ }
+ };
+
+ const parseResult = t.step_func(evt => {
+ const result = evt.data;
+ if (result.test.status === 0)
+ return evt;
+
+ receiverStack = result.test.stack;
+ const message = result.test.message;
+ let r = message.match(/^(assert_.*):\s+(.*)$/);
+ if (r) {
+ const assertion = r[1];
+ const body = r[2];
+ let args;
+ if (assertion === 'assert_equals') {
+ if (r = body.match(/^((.*)\s+)?expected\s+((\(\S*\)\s+)?(\S+|(\S+\s+)?\".*\"))\s+but\s+got\s+((\(\S*\)\s+)?(\S+|(\S+\s+)?\".*\"))$/))
+ args = [parseValue(r[7]), parseValue(r[3]), r[2]];
+ }
+ else if (assertion === 'assert_true') {
+ if (r = body.match(/^((.*)\s+)?expected\s+(true|false)\s+got\s+(\S+|(\S+\s+)?\".*\")$/)) {
+ args = [parseValue(r[4]), r[2]];
+ }
+ }
+ else if (assertion === 'assert_unreached') {
+ if (r = body.match(/^((.*)\s+)?Reached\s+unreachable\s+code$/))
+ args = [r[2]];
+ }
+ if (args) {
+ window[assertion](args[0], args[1], args[2]);
+ return;
+ }
+ }
+ // default
+ assert_unreached('Test result received from a receiving user agent: ' + message + ': ');
+ });
+
+ return Promise.all([
+ startWatcher.wait_for('click'),
+ messageWatcher.wait_for('message')
+ ]).then(() => {
+ startBtn.disabled = true;
+ let presentationId = null;
+ return request.start();
+ }).then(c => {
+ connection = c;
+ presentationId = connection.id;
+
+ // No more user input needed, re-enable test timeout
+ t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 5000);
+
+ eventWatcher = new EventWatcher(t, connection, ['connect', 'close', 'terminate']);
+
+ return Promise.all([
+ // Wait for "connect" event
+ eventWatcher.wait_for('connect'),
+ // Try to reconnect when the connection state is "connecting"
+ request.reconnect(presentationId).then(c => {
+ assert_equals(c, connection, 'The promise is resolved with the existing presentation connection.');
+ assert_equals(c.state, "connecting", "The connection state remains 'connecting'.");
+ assert_equals(c.id, presentationId, "The presentation ID is not changed.");
+ })
+ ]);
+ }).then(() => {
+ // Try to reconnect when the connection state is "connected"
+ return request.reconnect(presentationId);
+ }).then(c => {
+ assert_equals(c, connection, 'The promise is resolved with the existing presentation connection.');
+ assert_equals(c.state, "connected", "The connection state remains 'connected'.");
+ assert_equals(c.id, presentationId, "The presentation ID is not changed.");
+
+ // Close connection and wait for "close" event
+ connection.close();
+ return eventWatcher.wait_for('close');
+ }).then(() => {
+ // Connection now closed, let's reconnect to it
+ return request.reconnect(presentationId);
+ }).then(c => {
+ // Check the presentation connection in "connecting" state
+ assert_equals(c, connection, 'The promise is resolved with the existing presentation connection.');
+ connection = c;
+ assert_equals(connection.state, "connecting", "The connection state is set to 'connecting'.");
+ assert_equals(connection.id, presentationId, "Ids of old and new connections must be equal.");
+
+ return eventWatcher.wait_for('connect');
+ }).then(evt => {
+ // Check the established presentation connection and its associated "connect" event
+ assert_true(evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event, 'A simple event is fired.');
+ assert_equals(evt.type, 'connect', 'The event name is "connect".');
+ assert_equals(evt.target, connection, 'event.target is the presentation connection.');
+ assert_equals(connection.state, 'connected', 'The presentation connection state is set to "connected".');
+
+ // Request an iframe to reconnect the presentation with the current presentation ID
+ childFrame.contentWindow.postMessage('reconnect?id=' + presentationId, '*');
+ return waitForMessage().then(parseResult);
+ }).then(() => {
+ // Wait until state of each presentation connection is set to "terminated"
+ connection.terminate();
+ return Promise.all([ eventWatcher.wait_for('terminate'), waitForMessage().then(parseResult) ]);
+ }).then(() => {
+ // Try to reconnect to the presentation, while all presentation connection have already been terminated
+ return promise_rejects_dom(t, 'NotFoundError', request.reconnect(presentationId),
+ 'Reconnecting to a terminated presentation rejects a promise with a "NotFoundError" exception.');
+ });
+ });
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/startMultiplePresentations_success-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/startMultiplePresentations_success-manual.https.html
new file mode 100644
index 0000000000..0268bd87e8
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/startMultiplePresentations_success-manual.https.html
@@ -0,0 +1,99 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Starting presentations on two distinct displays</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+<style>
+#second-step {
+ display: none;
+}
+</style>
+
+<p id="first-step">Click the button below and select the available presentation display, to start the manual test.</p>
+<p id="second-step">Click the button below and select the other available presentation display, to continue the manual test.</p>
+<p>This test asks you to click the button twice, unless the test fails.<br>
+<em>This test requires two or more available displays.<em></p>
+<button id="presentBtn">Start Presentation Test</button>
+
+
+<script>
+ promise_test(async t => {
+ const presentBtn = document.getElementById("presentBtn");
+
+ const request = new PresentationRequest(presentationUrls);
+ const clickWatcher = new EventWatcher(t, presentBtn, 'click');
+ let connection1, connection2, eventWatcher1, eventWatcher2, timer;
+
+ t.add_cleanup(() => {
+ [connection1, connection2].forEach(connection => {
+ if (connection) {
+ connection.onconnect = () => { connection.terminate(); };
+ if (connection.state == 'closed')
+ request.reconnect(connection.id);
+ else
+ connection.terminate();
+ }
+ });
+ });
+
+ const disableTimeout = () => {
+ setup({explicit_timeout: true});
+ if (timer) {
+ clearTimeout(timer);
+ timer = null;
+ }
+ };
+
+ const enableTimeout = () => {
+ timer = t.step_timeout(() => {
+ t.force_timeout();
+ t.done();
+ }, 5000);
+ }
+
+ disableTimeout();
+
+ await clickWatcher.wait_for('click');
+ presentBtn.disabled = true;
+ connection1 = await request.start();
+
+ presentBtn.disabled = false;
+ document.getElementById('first-step').style.display = 'none';
+ document.getElementById('second-step').style.display = 'block';
+ presentBtn.innerText = 'Continue Presentation Test';
+ eventWatcher1 = new EventWatcher(t, connection1, ['connect', 'close', 'terminate']);
+
+ await Promise.all([
+ eventWatcher1.wait_for('connect'),
+ (async () => {
+ await clickWatcher.wait_for('click');
+ presentBtn.disabled = true;
+
+ connection2 = await request.start();
+ enableTimeout();
+ eventWatcher2 = new EventWatcher(t, connection2, ['connect', 'terminate']);
+ await eventWatcher2.wait_for('connect');
+ })()
+ ]);
+
+ assert_not_equals(connection1.id, connection2.id,
+ 'Presentation connections on distinct presentations must have different presentation IDs.');
+
+ assert_equals(connection1.state, 'connected', 'The presentation connection is successfully reconnected.');
+ connection1.terminate();
+ assert_equals(connection2.state, 'connected',
+ 'Terminating one presentation connection does not affect the state of the other.');
+ connection2.terminate();
+
+ await Promise.all([
+ eventWatcher1.wait_for('terminate'),
+ eventWatcher2.wait_for('terminate')
+ ]);
+
+ assert_equals(connection1.state, 'terminated', 'One presentation connection is successfully terminated.');
+ assert_equals(connection2.state, 'terminated', 'Both presentation connections are successfully terminated.');
+ });
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotallowed-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotallowed-manual.https.html
new file mode 100644
index 0000000000..877c17a35d
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotallowed-manual.https.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Calling "start" when the user denied permission to use the display returns a Promise rejected with a NotAllowedError exception.</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+
+<p>Before starting this test, confirm that there are one or more available presentation display on your local network.</p>
+<p>Click the button below to start the manual test. If prompted to select a device, please dismiss the dialog box. The test passes if a "PASS" result appears.
+</p>
+<button id="presentBtn">Start Presentation Test</button>
+
+<script>
+ // disable the timeout function for the tests
+ setup({explicit_timeout: true});
+
+ // ----------
+ // DOM Object
+ // ----------
+ var presentBtn = document.getElementById("presentBtn");
+
+ // -------------------------------------------
+ // Start New Presentation Test (error) - begin
+ // -------------------------------------------
+ presentBtn.onclick = function () {
+ presentBtn.disabled = true;
+ promise_test(function (t) {
+ var request = new PresentationRequest(presentationUrls);
+
+ // terminate the presentation connection when the presentation is started by accident
+ var connection;
+ t.add_cleanup(function() {
+ if(connection)
+ connection.terminate();
+ });
+
+ return promise_rejects_dom(t, 'NotAllowedError', request.start().then(function(c) { connection = c; }));
+ });
+ };
+ // -----------------------------------------
+ // Start New Presentation Test (error) - end
+ // -----------------------------------------
+</script>
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotfound-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotfound-manual.https.html
new file mode 100644
index 0000000000..edfea3a4fd
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotfound-manual.https.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Calling "start" when there is no available presentation display returns a Promise rejected with a NotFoundError exception.</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+
+<p>Before starting this test, confirm that there is no available presentation display on your local network.</p>
+<p>Click the button below to start the manual test. If prompted to select a device, please dismiss the dialog box. The test passes if a "PASS" result appears.
+</p>
+<button id="presentBtn">Start Presentation Test</button>
+
+<script>
+ // disable the timeout function for the tests
+ setup({explicit_timeout: true});
+
+ // ----------
+ // DOM Object
+ // ----------
+ var presentBtn = document.getElementById("presentBtn");
+
+ // -------------------------------------------
+ // Start New Presentation Test (error) - begin
+ // -------------------------------------------
+ presentBtn.onclick = function () {
+ presentBtn.disabled = true;
+ promise_test(function (t) {
+ var request = new PresentationRequest(presentationUrls);
+
+ // terminate the presentation connection when the presentation is started by accident
+ var connection;
+ t.add_cleanup(function() {
+ if(connection)
+ connection.terminate();
+ });
+
+ return promise_rejects_dom(t, 'NotFoundError', request.start().then(function(c) { connection = c; }));
+ });
+ };
+ // -----------------------------------------
+ // Start New Presentation Test (error) - end
+ // -----------------------------------------
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_error.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_error.https.html
new file mode 100644
index 0000000000..3171c6c104
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_error.https.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Presentation API, start new presentation tests for Controlling User Agent (error)</title>
+<link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ // -----------------------------------
+ // Start New Presentation Test - begin
+ // -----------------------------------
+ promise_test(function (t) {
+ var request = new PresentationRequest('presentation.html');
+ return promise_rejects_dom(t, 'InvalidAccessError', request.start());
+ }, "The presentation could not start, because a user gesture is required.");
+ // ----------------------------------
+ // Launch New Presentation Test - end
+ // ----------------------------------
+</script>
+
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_sandboxing_success-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_sandboxing_success-manual.https.html
new file mode 100644
index 0000000000..68e037a5c0
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_sandboxing_success-manual.https.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Sandboxing: starting a presentation from a nested context succeeds when allow-presentation is set</title>
+<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-start">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<iframe id="childFrame" sandbox="allow-scripts allow-presentation" style="display:none" src="support/iframe.html"></iframe>
+<p>Click the button below to start the manual test. If prompted to select a device, please dismiss the dialog box. The test passes if a "PASS" result appears.</p>
+<button id="presentBtn" onclick="startPresentationTest()">Start Presentation Test</button>
+
+<script>
+ setup({explicit_timeout: true});
+
+ var presentBtn = document.getElementById('presentBtn');
+ var childFrame = document.getElementById('childFrame');
+
+ function startPresentationTest() {
+ presentBtn.disabled = true;
+ async_test(function (t) {
+ childFrame.contentWindow.postMessage('start', '*');
+ window.addEventListener('message', t.step_func(function (ev) {
+ assert_equals(ev.data, 'success',
+ 'Presentation could not be started from nested frame.');
+ t.done();
+ }));
+ });
+ }
+</script>
+
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_success-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_success-manual.https.html
new file mode 100644
index 0000000000..c9378c0e68
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_success-manual.https.html
@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Checking the chain of events when starting a new presentation</title>
+<link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+
+<p>Click the button below and select the available presentation display, to start the manual test.</p>
+<button id="presentBtn">Start Presentation Test</button>
+
+
+<script>
+ // description of event order
+ var description = [
+ "Phase #1: Promise is resolved",
+ "Phase #2: 'connectionavailable' event fired",
+ "Phase #3: 'connect' event fired"
+ ];
+ var step = 0;
+
+ // presentation connection
+ var connection;
+
+ // disable the timeout function for the tests
+ setup({explicit_timeout: true});
+
+ // ----------
+ // DOM Object
+ // ----------
+ var presentBtn = document.getElementById("presentBtn");
+
+ // ---------------------------------------------
+ // Start New Presentation Test (success) - begin
+ // ---------------------------------------------
+ presentBtn.onclick = function () {
+ presentBtn.disabled = true;
+ promise_test(function (t) {
+ var phase = -1, actual = -1;
+
+ // increment the count in the actual event order
+ var count = function(evt) { actual++; return evt; };
+ // increment the count in the expected event order and compare it with the actual event order
+ var checkPhase = function(evt) { phase++; assert_equals(description[actual], description[phase], 'Event order is incorrect.'); return evt; };
+
+ var request = new PresentationRequest(presentationUrls);
+ var eventWatcher = new EventWatcher(t, request, 'connectionavailable');
+ var waitConnectionavailable = eventWatcher.wait_for('connectionavailable').then(count).then(function(evt) { connection = connection || evt.connection; return evt; });
+ var waitConnect;
+
+ t.add_cleanup(function() {
+ if(connection)
+ connection.terminate();
+ });
+
+ return request.start().then(count)
+ .then(checkPhase).then(function (c) {
+ // Phase #1: Promise is resolved
+ connection = c;
+
+ // No more user input needed, re-enable timeout
+ t.step_timeout(function() {
+ t.force_timeout();
+ t.done();
+ }, 5000);
+
+ // Check the initial state of the presentation connection
+ assert_equals(connection.state, 'connecting', 'Check the initial state of the presentation connection.');
+ assert_true(!!connection.id, 'The connection ID is set.');
+ assert_equals(typeof connection.id, 'string', 'The connection ID is a string.');
+ assert_true(connection instanceof PresentationConnection, 'The connection is an instance of PresentationConnection.');
+
+ var eventWatcher = new EventWatcher(t, connection, 'connect');
+ waitConnect = eventWatcher.wait_for('connect').then(count);
+
+ return waitConnectionavailable;
+ })
+ .then(checkPhase).then(function (evt) {
+ // Phase #2: "connectionavailable" event fired
+ assert_equals(connection, evt.connection, 'Both Promise from PresentationRequest() and a "connectionavailable" event handler receive the same presentation connection.');
+
+ return waitConnect;
+ })
+ .then(checkPhase).then(function () {
+ // Phase #3: "connect" event fired
+ assert_equals(connection.state, 'connected', 'The state of the presentation connection is "connected" when a "connect" event fires.');
+ });
+ });
+ }
+ // -------------------------------------------
+ // Start New Presentation Test (success) - end
+ // -------------------------------------------
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_unsettledpromise-manual.https.html b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_unsettledpromise-manual.https.html
new file mode 100644
index 0000000000..fb747eb0a4
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_unsettledpromise-manual.https.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Calling "start" when there is already an unsettled Promise returns a Promise rejected with an OperationError exception.</title>
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="common.js"></script>
+
+<p>Click the button below to start the manual test. If prompted to select a device, please dismiss the dialog box. The test passes if a "PASS" result appears.</p>
+<button id="presentBtn">Start Presentation Test</button>
+
+<script>
+ // disable the timeout function for the tests
+ setup({explicit_timeout: true});
+
+ // ----------
+ // DOM Object
+ // ----------
+ var presentBtn = document.getElementById("presentBtn");
+
+ // -----------------------------------------------
+ // Terminate a presentation if started by accident
+ // -----------------------------------------------
+ function terminate(connection) {
+ connection.terminate();
+ }
+
+ // -------------------------------------------
+ // Start New Presentation Test (error) - begin
+ // -------------------------------------------
+ presentBtn.onclick = function () {
+ presentBtn.disabled = true;
+ promise_test(function (t) {
+ var request1 = new PresentationRequest(presentationUrls),
+ request2 = new PresentationRequest(presentationUrls);
+ request1.start().then(terminate, function(){});
+ return promise_rejects_dom(t, 'OperationError', request2.start().then(terminate));
+ });
+ };
+ // -----------------------------------------
+ // Start New Presentation Test (error) - end
+ // -----------------------------------------
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/support/iframe.html b/testing/web-platform/tests/presentation-api/controlling-ua/support/iframe.html
new file mode 100644
index 0000000000..e2171deaa8
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/support/iframe.html
@@ -0,0 +1,181 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Presentation API - controlling ua - sandboxing</title>
+<link rel="author" title="Francois Daoust" href="https://www.w3.org/People/#fd">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-start">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../common.js"></script>
+<script>
+ add_completion_callback((tests, status) => {
+ // remove unserializable attributes, then send the result to the parent window
+ // note: a single test result is supposed to appear here.
+ parent.window.postMessage(JSON.parse(JSON.stringify({
+ type: 'presentation-api', test: tests[0], status: status
+ })), '*');
+ });
+
+ // disable timeout for manual tests
+ setup({explicit_timeout: true});
+
+ window.onmessage = function (ev) {
+ try {
+ // Presentation URLs are relative to the "controlling-ua" folder,
+ // update relative URLs for this folder
+ var urls = presentationUrls.map(function (url) {
+ if (/:\/\//.test(url)) {
+ return url;
+ }
+ else {
+ return '../' + url;
+ }
+ });
+ var request = null;
+ if (ev.data === 'create') {
+ try {
+ request = new PresentationRequest(urls);
+ parent.window.postMessage('success', '*');
+ }
+ catch (err) {
+ parent.window.postMessage(err.name, '*');
+ }
+ }
+ else if (ev.data === 'start') {
+ request = new PresentationRequest(urls);
+ request.start()
+ .then(function () {
+ parent.window.postMessage('success', '*');
+ })
+ .catch(function (err) {
+ if ((err.name === 'NotFoundError') ||
+ (err.name === 'NotAllowedError')) {
+ // These errors either mean that the user dismissed the dialog
+ // box or that the UA could not find any available or suitable
+ // screen. This is equivalent of succeeding for the purpose of
+ // iframe tests.
+ parent.window.postMessage('success', '*');
+ }
+ else {
+ parent.window.postMessage(err.name, '*');
+ }
+ });
+ }
+ else if (ev.data === 'reconnect') {
+ request = new PresentationRequest(urls);
+ request.reconnect('someid')
+ .then(function () {
+ parent.window.postMessage('success', '*');
+ })
+ .catch(function (err) {
+ parent.window.postMessage(err.name, '*');
+ });
+ }
+ else if (ev.data.match(/^reconnect\?id=(.*)$/)) {
+ promise_test(function (t) {
+ var presentationId = RegExp.$1;
+ var phase = -1, actual = -1, connection, waitConnection;
+ var description = [
+ "Phase #1: Promise is resolved",
+ "Phase #2: 'connectionavailable' event fired",
+ "Phase #3: 'connect' event fired"
+ ].map(d => { return '(Reconnecting in a nested browsing context) ' + d; });
+
+ var count = function(evt) { actual++; return evt; };
+ var checkPhase = function(evt) {
+ phase++;
+ assert_equals(description[actual], description[phase], 'Event order is incorrect.');
+ return evt;
+ };
+
+ request = new PresentationRequest(urls);
+
+ var eventWatcher = new EventWatcher(t, request, 'connectionavailable');
+ var waitConnectionavailable = eventWatcher.wait_for('connectionavailable').then(count).then(function (evt) {
+ connection = connection || evt.connection; return evt;
+ });
+
+ return request.reconnect(presentationId).then(count).then(checkPhase).then(function (c) {
+ // Reconnecting Phase #1: Promise is resolved
+ connection = c;
+ assert_equals(connection.state, 'connecting', 'Check the initial state of the presentation connection.');
+ assert_equals(connection.id, presentationId, "The same presentation ID is set to the newly created presentation connection.");
+ assert_true(connection instanceof PresentationConnection, 'The connection is an instance of PresentationConnection.');
+
+ var eventWatcher = new EventWatcher(t, connection, 'connect');
+ waitConnect = eventWatcher.wait_for('connect').then(count);
+
+ // Reconnecting Phase #2: "connectionavailable" event is fired
+ return waitConnectionavailable;
+ }).then(checkPhase).then(function (evt) {
+ assert_true(evt instanceof PresentationConnectionAvailableEvent, 'An event using PresentationConnectionAvailableEvent is fired.');
+ assert_true(evt.isTrusted, 'The event is a trusted event.');
+ assert_false(evt.bubbles, 'The event does not bubbles.');
+ assert_false(evt.cancelable, 'The event is not cancelable.');
+ assert_equals(evt.type, 'connectionavailable', 'The event name is "connectionavailable".');
+ assert_equals(evt.target, request, 'event.target is the presentation request.');
+ assert_true(evt.connection instanceof PresentationConnection, 'event.connection is a presentation connection.');
+ assert_equals(evt.connection, connection, 'event.connection is set to the presentation which the promise is resolved with.');
+
+ // Reconnecting Phase #3: "connect" event is fired
+ return waitConnect;
+ }).then(checkPhase).then(function (evt) {
+ assert_true(evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event, 'A simple event is fired.');
+ assert_equals(evt.type, 'connect', 'The event name is "connect".');
+ assert_equals(evt.target, connection, 'event.target is the presentation connection.');
+ assert_equals(connection.state, 'connected', 'The presentation connection state is set to "connected".');
+ parent.window.postMessage({ type: 'presentation-api', test: { status: 0 } }, '*');
+ var terminateWatcher = new EventWatcher(t, connection, 'terminate');
+
+ // "terminate" event is fired
+ return terminateWatcher.wait_for('terminate');
+ }).then(function (evt) {
+ assert_true(evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event, 'A simple event is fired.');
+ assert_equals(evt.type, 'terminate', 'The event name is "terminate".');
+ assert_equals(evt.target, connection, 'event.target is the presentation connection.');
+ assert_equals(connection.state, 'terminated', 'The presentation connection state is set to "terminated".');
+ });
+ });
+ }
+ else if (ev.data.match(/^terminate\?id=(.*)$/)) {
+ var presentationId = RegExp.$1;
+ request = new PresentationRequest(urls);
+ request.reconnect(presentationId)
+ .then(function (c) {
+ parent.window.postMessage('reconnected', '*');
+ c.onterminate = function(evt) {
+ parent.window.postMessage({
+ isSimpleEvent: evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event,
+ type: evt.type,
+ checkConnection: evt.target === c,
+ state: c.state
+ }, '*');
+ };
+ })
+ .catch(function (err) {
+ parent.window.postMessage(err.name, '*');
+ });
+ }
+ else if (ev.data === 'getAvailability') {
+ request = new PresentationRequest(urls);
+ request.getAvailability()
+ .then(function () {
+ parent.window.postMessage('success', '*');
+ })
+ .catch(function (err) {
+ if (err.name === 'NotSupportedError') {
+ parent.window.postMessage('success', '*');
+ }
+ else {
+ parent.window.postMessage(err.name, '*');
+ }
+ });
+ }
+ }
+ catch (err) {
+ parent.window.postMessage('Could not create PresentationRequest', '*');
+ }
+ }
+ parent.window.postMessage('ready', '*');
+</script>
+
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/support/presentation.html b/testing/web-platform/tests/presentation-api/controlling-ua/support/presentation.html
new file mode 100644
index 0000000000..8ad838062f
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/support/presentation.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+
+<meta charset="utf-8">
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="author" title="He Yue" href="mailto:yue.he@intel.com">
+<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
+<link rel="help" href="http://w3c.github.io/presentation-api/#interface-presentationconnectionlist">
+<script src="../common.js"></script>
+<script src="stash.js"></script>
+<script>
+ const message1 = '1st';
+ const message2 = '2nd';
+ const message3 = new Uint8Array([51, 114, 100]); // "3rd"
+ const message4 = new Uint8Array([52, 116, 104]); // "4th"
+ const message5 = new Uint8Array([108, 97, 115, 116]); // "last"
+
+ const toUint8Array = buf => {
+ return buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;
+ }
+
+ // convert ArrayBuffer or Uint8Array into string
+ const toText = buf => {
+ const arr = toUint8Array(buf);
+ return !buf ? null : arr.reduce((result, item) => {
+ return result + String.fromCharCode(item);
+ }, '');
+ }
+
+ // compare two ArrayBuffer or Uint8Array
+ const compare = (a, b) => {
+ const p = toUint8Array(a);
+ const q = toUint8Array(b);
+ return !!p && !!q && p.every((item, index) => { return item === q[index]; });
+ };
+
+ const stash = new Stash(stashIds.toReceiver, stashIds.toController);
+
+ let connection, count = 0;
+
+ const addConnection = c => {
+ let result = [], testCase;
+ connection = c;
+ count++;
+
+ connection.onmessage = event => {
+ // PresentationConnection_send-manual.https.html
+ if (testCase === 'send') {
+ if (typeof event.data === 'string') {
+ result.push({ type: 'text', data: event.data });
+ }
+ // default value of connection.binaryType is "arraybuffer"
+ else if(event.data instanceof ArrayBuffer) {
+ result.push({ type: 'binary', data: toText(event.data) });
+ if (compare(event.data, message5)) {
+ stash.send(JSON.stringify(result));
+ }
+ }
+ else {
+ result.push({ type: 'error' });
+ }
+ }
+ };
+
+ stash.receive().then(data => {
+ testCase = data;
+
+ // PresentationConnection_send-manual.https.html
+ if (testCase === 'send') {
+ stash.send('ok');
+ }
+ // PresentationConnection_onmessage-manual.https.html
+ else if (testCase === 'onmessage') {
+ connection.send(message1); // string
+ connection.send(message2); // string
+ connection.send(new Blob([message3])); // Blob
+ connection.send(message4.buffer); // ArrayBuffer
+ connection.send(message5); // ArrayBufferView
+ stash.receive().then(data => {
+ connection.send(message5);
+ });
+ }
+ // PresentationConnection_onclose-manual.https.html
+ else if (testCase === 'close') {
+ connection.close();
+ }
+ });
+ };
+
+ navigator.presentation.receiver.connectionList
+ .then(list => {
+ list.onconnectionavailable = evt => {
+ addConnection(evt.connection);
+ };
+ list.connections.map(connection => {
+ addConnection(connection);
+ });
+ });
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/support/stash.js b/testing/web-platform/tests/presentation-api/controlling-ua/support/stash.js
new file mode 100644
index 0000000000..616907d4f2
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/support/stash.js
@@ -0,0 +1,83 @@
+var Stash = function(inbound, outbound) {
+ this.stashPath = '/presentation-api/controlling-ua/support/stash.py?id=';
+ this.inbound = inbound;
+ this.outbound = outbound;
+}
+
+// initialize a stash on wptserve
+Stash.prototype.init = function() {
+ return Promise.all([
+ fetch(this.stashPath + this.inbound).then(response => {
+ return response.text();
+ }),
+ fetch(this.stashPath + this.outbound).then(response => {
+ return response.text();
+ })
+ ]);
+}
+
+// upload a test result to a stash on wptserve
+Stash.prototype.send = function(result) {
+ return fetch(this.stashPath + this.outbound, {
+ method: 'POST',
+ body: JSON.stringify({ type: 'data', data: result })
+ }).then(response => {
+ return response.text();
+ }).then(text => {
+ return text === 'ok' ? null : Promise.reject();
+ })
+};
+
+// wait until a test result is uploaded to a stash on wptserve
+Stash.prototype.receive = function() {
+ return new Promise((resolve, reject) => {
+ let intervalId;
+ const interval = 500; // msec
+ const polling = () => {
+ return fetch(this.stashPath + this.inbound).then(response => {
+ return response.text();
+ }).then(text => {
+ if (text) {
+ try {
+ const json = JSON.parse(text);
+ if (json.type === 'data')
+ resolve(json.data);
+ else
+ reject();
+ } catch(e) {
+ resolve(text);
+ }
+ clearInterval(intervalId);
+ }
+ });
+ };
+ intervalId = setInterval(polling, interval);
+ });
+};
+
+// reset a stash on wptserve
+Stash.prototype.stop = function() {
+ return Promise.all([
+ fetch(this.stashPath + this.inbound).then(response => {
+ return response.text();
+ }),
+ fetch(this.stashPath + this.outbound).then(response => {
+ return response.text();
+ })
+ ]).then(() => {
+ return Promise.all([
+ fetch(this.stashPath + this.inbound, {
+ method: 'POST',
+ body: JSON.stringify({ type: 'stop' })
+ }).then(response => {
+ return response.text();
+ }),
+ fetch(this.stashPath + this.outbound, {
+ method: 'POST',
+ body: JSON.stringify({ type: 'stop' })
+ }).then(response => {
+ return response.text();
+ })
+ ]);
+ });
+}
diff --git a/testing/web-platform/tests/presentation-api/controlling-ua/support/stash.py b/testing/web-platform/tests/presentation-api/controlling-ua/support/stash.py
new file mode 100644
index 0000000000..83653d365a
--- /dev/null
+++ b/testing/web-platform/tests/presentation-api/controlling-ua/support/stash.py
@@ -0,0 +1,10 @@
+def main(request, response):
+ key = request.GET.first(b"id")
+
+ if request.method == u"POST":
+ request.server.stash.put(key, request.body)
+ return b"ok"
+ else:
+ value = request.server.stash.take(key)
+ assert request.server.stash.take(key) is None
+ return value \ No newline at end of file