-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[presentation-api] add several tests for a receiving browsing context #5562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Monitoring incoming presentation connections</title> | ||
<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs"> | ||
<link rel="help" href="https://w3c.github.io/presentation-api/#monitoring-incoming-presentation-connections"> | ||
<link rel="stylesheet" href="/resources/testharness.css"> | ||
<script src="common.js"></script> | ||
<script src="support/stash.js"></script> | ||
<style> | ||
iframe { display: none; } | ||
</style> | ||
|
||
<p>Click the button below and select the available presentation display, to start the manual test.</p> | ||
<button id="presentBtn" disabled>Start Presentation Test</button> | ||
<iframe id="childFrame" sandbox="allow-scripts allow-presentation" src="support/iframe.html"></iframe> | ||
|
||
<script> | ||
let connection; | ||
const presentBtn = document.getElementById('presentBtn'); | ||
const child = document.getElementById('childFrame'); | ||
|
||
child.onload = () => { presentBtn.disabled = false; }; | ||
|
||
presentBtn.onclick = () => { | ||
presentBtn.disabled = true; | ||
const stash = new Stash(stashIds.toController, stashIds.toReceiver); | ||
const request = new PresentationRequest('support/PresentationConnectionList_onconnectionavailable_receiving-ua.html'); | ||
|
||
return request.start().then(c => { | ||
connection = c; | ||
return stash.init(); | ||
}).then(() => { | ||
return stash.receive(); | ||
}).then(data => { | ||
const result = JSON.parse(data); | ||
if (result.type === 'ok') { | ||
connection.close(); | ||
return stash.receive(); | ||
} | ||
else | ||
return data; | ||
}).then(data => { | ||
const result = JSON.parse(data); | ||
if (result.type === 'ok') { | ||
request.reconnect(connection.id); | ||
return stash.receive(); | ||
} | ||
else | ||
return data; | ||
}).then(data => { | ||
const result = JSON.parse(data); | ||
if (result.type === 'ok') { | ||
child.contentWindow.postMessage({ type: 'connect', id: connection.id, url: connection.url }, '*'); | ||
return stash.receive(); | ||
} | ||
else | ||
return data; | ||
}).then(result => { | ||
const json = JSON.parse(result); | ||
|
||
// notify receiver's results of a parent window (e.g. test runner) | ||
if (window.opener && 'completion_callback' in window.opener) { | ||
window.opener.completion_callback(json.tests, json.status); | ||
} | ||
// display receiver's results as HTML | ||
const log = document.createElement('div'); | ||
log.id = 'log'; | ||
log.innerHTML = json.log; | ||
document.body.appendChild(log); | ||
|
||
connection.onconnect = () => { connection.terminate(); }; | ||
if (connection.state === 'closed') | ||
request.reconnect(connection.id); | ||
else | ||
connection.terminate(); | ||
}); | ||
}; | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Closing a PresentationConnection</title> | ||
<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs"> | ||
<link rel="help" href="https://w3c.github.io/presentation-api/#closing-a-presentationconnection"> | ||
<link rel="stylesheet" href="/resources/testharness.css"> | ||
<script src="common.js"></script> | ||
<script src="support/stash.js"></script> | ||
<style> | ||
iframe { display: none; } | ||
</style> | ||
|
||
<p>Click the button below and select the available presentation display, to start the manual test.</p> | ||
<button id="presentBtn" disabled>Start Presentation Test</button> | ||
<iframe id="childFrame" sandbox="allow-scripts allow-presentation" src="support/iframe.html"></iframe> | ||
|
||
<script> | ||
let connection; | ||
const presentBtn = document.getElementById('presentBtn'); | ||
const child = document.getElementById('childFrame'); | ||
|
||
child.onload = () => { presentBtn.disabled = false; }; | ||
|
||
presentBtn.onclick = () => { | ||
presentBtn.disabled = true; | ||
const stash = new Stash(stashIds.toController, stashIds.toReceiver); | ||
const request = new PresentationRequest('support/PresentationConnection_onclose_receiving-ua.html'); | ||
|
||
return request.start().then(c => { | ||
connection = c; | ||
return stash.init(); | ||
}).then(() => { | ||
return stash.receive(); | ||
}).then(data => { | ||
const result = JSON.parse(data); | ||
if (result.type === 'ok') { | ||
return request.reconnect(connection.id).then(() => data); | ||
} | ||
else | ||
return data; | ||
}).then(data => { | ||
const result = JSON.parse(data); | ||
if (result.type === 'ok') { | ||
connection.onclose = null; | ||
connection.close(); | ||
return stash.receive(); | ||
} | ||
else | ||
return data; | ||
}).then(data => { | ||
const result = JSON.parse(data); | ||
if (result.type === 'ok') { | ||
child.contentWindow.postMessage({ type: 'connect', id: connection.id, url: connection.url }, '*'); | ||
return stash.receive(); | ||
} | ||
else | ||
return data; | ||
}).then(data => { | ||
const result = JSON.parse(data); | ||
if (result.type === 'ok') { | ||
child.parentNode.removeChild(child); | ||
return stash.receive(); | ||
} | ||
else | ||
return data; | ||
}).then(result => { | ||
const json = JSON.parse(result); | ||
// notify receiver's results of a parent window (e.g. test runner) | ||
if (window.opener && 'completion_callback' in window.opener) { | ||
window.opener.completion_callback(json.tests, json.status); | ||
} | ||
// display receiver's results as HTML | ||
const log = document.createElement('div'); | ||
log.id = 'log'; | ||
log.innerHTML = json.log; | ||
document.body.appendChild(log); | ||
|
||
connection.onconnect = () => { connection.terminate(); }; | ||
if (connection.state === 'closed') | ||
request.reconnect(connection.id); | ||
else | ||
connection.terminate(); | ||
}); | ||
}; | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Terminating a presentation in a receiving browsing context</title> | ||
<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-receiving-browsing-context"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="common.js"></script> | ||
<script src="support/stash.js"></script> | ||
<style> | ||
iframe { display: none; } | ||
</style> | ||
|
||
<p>Click the button below and select the available presentation display, to start the manual test.</p> | ||
<button id="presentBtn" disabled>Start Presentation Test</button> | ||
<iframe id="childFrame" sandbox="allow-scripts allow-presentation" src="support/iframe.html"></iframe> | ||
|
||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
let connection; | ||
|
||
const presentBtn = document.getElementById('presentBtn'); | ||
const child = document.getElementById('childFrame'); | ||
|
||
child.onload = () => { presentBtn.disabled = false; }; | ||
|
||
presentBtn.onclick = () => { | ||
presentBtn.disabled = true; | ||
const stash = new Stash(stashIds.toController, stashIds.toReceiver); | ||
const request = new PresentationRequest('support/PresentationConnection_terminate_receiving-ua.html'); | ||
|
||
promise_test(t => { | ||
t.add_cleanup(() => { | ||
connection.onconnect = () => { connection.terminate(); }; | ||
if (connection.state === 'closed') | ||
request.reconnect(connection.id); | ||
else | ||
connection.terminate(); | ||
stash.stop(); | ||
}); | ||
|
||
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 eventWatcher.wait_for('connect'); | ||
}).then(() => { | ||
return stash.init(); | ||
}).then(() => { | ||
child.contentWindow.postMessage({ type: 'connect', id: connection.id, url: connection.url }, '*'); | ||
const eventWatcher1 = new EventWatcher(t, connection, 'terminate'); | ||
const eventWatcher2 = new EventWatcher(t, window, 'message'); | ||
return Promise.all([ eventWatcher1.wait_for('terminate'), eventWatcher2.wait_for('message') ]); | ||
}).then(() => { | ||
return Promise.race([ | ||
stash.receive().then(() => { | ||
assert_unreached('The presentation is not terminated successfully.'); | ||
}), | ||
new Promise(resolve => { t.step_timeout(resolve, 2000); }) | ||
]); | ||
}); | ||
}); | ||
}; | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
|
||
<meta charset="utf-8"> | ||
<title>Monitoring incoming presentation connections</title> | ||
<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs"> | ||
<link rel="help" href="https://w3c.github.io/presentation-api/#monitoring-incoming-presentation-connections"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="../common.js"></script> | ||
<script src="stash.js"></script> | ||
|
||
<script> | ||
const stash = new Stash(stashIds.toReceiver, stashIds.toController); | ||
|
||
add_completion_callback((tests, status) => { | ||
const log = document.getElementById('log'); | ||
stash.send(JSON.stringify({ type: 'result', tests: tests, status: status, log: log.innerHTML })); | ||
}); | ||
|
||
promise_test(t => { | ||
const receiver = navigator.presentation.receiver; | ||
return receiver.connectionList.then(list => { | ||
let connections = list.connections; | ||
let number = connections.length; | ||
|
||
const checkConnectionList = (connection, action) => { | ||
assert_equals(connections.length, number, 'PresentationConnectionList.connections is a frozen array.'); | ||
|
||
// Note: When a presentation is terminated, a receiving user agent unloads a document | ||
// without firing a "terminate" event. | ||
return receiver.connectionList.then(list => { | ||
connections = list.connections; | ||
if (action === 'close') { | ||
assert_true(connections.length === number && connections.includes(connection), | ||
'A closed presentation connection remains in the set of presentation controllers.'); | ||
} else if (action === 'connect') { | ||
assert_true(connections.length === number + 1 && connections.includes(connection), | ||
'A new presentation connection is added to the set of presentation controllers.'); | ||
number = connections.length; | ||
} | ||
}); | ||
}; | ||
|
||
const checkEvent = evt => { | ||
assert_true(evt instanceof PresentationConnectionAvailableEvent, 'An event using PresentationConnectionAvailableEvent is fired.'); | ||
assert_true(evt.isTrusted, 'The event is a trusted event.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just pinging @mfoltzgoogle in case that is not a known bug: Chrome does not seem to set the "isTrusted" property of the "connectionavailable" event in the receiving browsing context (it is reported as undefined). The test would pass otherwise (same buggy behavior for the "close" 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, list, 'event.target is the presentation connection list.'); | ||
assert_true(evt.connection instanceof PresentationConnection, 'event.connection is a presentation connection.'); | ||
|
||
return checkConnectionList(evt.connection, 'connect'); | ||
}; | ||
|
||
let eventNotFired = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what that variable was meant for, but test only sets it, so it can be dropped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but I forgot to remove it. Thanks! I'll drop it in the next update. |
||
|
||
// Step 1: check the first connection in "connected" state | ||
let connection = list.connections[0]; | ||
assert_equals(number, 1, 'A presentation connection list is populated with a first presentation connection.'); | ||
assert_true(list instanceof PresentationConnectionList, 'navigator.presentation.receiver.connectionList is resolved with a presentation connection list.'); | ||
assert_true(list.connections instanceof Array, 'A presentation connection list is an array.'); | ||
assert_true(connection instanceof PresentationConnection, 'A presentation connection is added to a presentation connection list.'); | ||
|
||
// Step 2: check the connection in "closed" state | ||
stash.send(JSON.stringify({ type: 'ok' })); | ||
let eventWatcher = new EventWatcher(t, connection, 'close'); | ||
return eventWatcher.wait_for('close').then(() => { | ||
return checkConnectionList(connection, 'close'); | ||
}) | ||
// Step 3: check the first connection when reconnected | ||
.then(() => { | ||
stash.send(JSON.stringify({ type: 'ok' })); | ||
eventWatcher = new EventWatcher(t, list, 'connectionavailable'); | ||
return eventWatcher.wait_for('connectionavailable') | ||
}).then(checkEvent) | ||
// Step 4: check the second connection (with <iframe>) in "connected" state | ||
.then(() => { | ||
eventNotFired = true; | ||
stash.send(JSON.stringify({ type: 'ok' })); | ||
return eventWatcher.wait_for('connectionavailable'); | ||
}).then(checkEvent); | ||
}); | ||
}); | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that a conforming implementation may not issue a "terminate" event when the receiving context is the one that calls "terminate", because it is a SHOULD in the Presentation API:
[[
When a receiving user agent is to send a termination confirmation for a presentation P, and that confirmation was received by a controlling user agent, the controlling user agent SHOULD run the following steps
]]
Ideally, that check would be done in a separate test marked as "[Optional]". Or we turn that SHOULD into a MUST in the spec, as I don't understand why it's only a SHOULD for now. I created an issue:
w3c/presentation-api#422
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this SHOULD has been changed to MUST, I leave this code as it is.