blob: 6d2766857c6502f57e1a4f2b45a544b74384894c [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/WebKit/public/platform/modules/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button>
<script>
var button = document.querySelector('button');
var controllerConnectionClosed = false;
async_test(t => {
// This is receiving the user gesture and runs the callback.
waitForClick(() => {
new PresentationRequest("https://example.com/").start().then(
connection => {
connection.onclose = (closeEvent) => {
assert_equals(closeEvent.reason, "closed");
assert_equals(closeEvent.message, "");
assert_equals(connection.state, "closed");
controllerConnectionClosed = true;
};
connection.onconnect = () => {
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
w = window.open("resources/presentation-receiver-close-connection.html");
w.controllerConnectionPtr = presentationServiceMock.getControllerConnectionPtr();
w.receiverConnectionRequest = presentationServiceMock.getReceiverConnectionRequest();
w.shouldCallClose = true;
};
});
}, button);
window.addEventListener("message", t.step_func(e => {
if (e.data == "receiver connection closed") {
assert_true(controllerConnectionClosed);
t.done();
}
}));
}, "receiver connection.close() should fire both controller's and receiver's onclose event handler");
</script>
</body>
</html>