blob: c0efb32b5d21c9a018669fc1dba48a599a367c9f [file] [log] [blame]
zhaobin0c08ed562017-03-07 21:19:161<!DOCTYPE html>
2<html>
3<body>
4<script src="../resources/testharness.js"></script>
5<script src="../resources/testharnessreport.js"></script>
Reilly Grant06367ab2017-09-02 02:00:166<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
mark a. foltz6bbe59f2018-07-24 20:06:247<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
zhaobin0c08ed562017-03-07 21:19:168<script src="resources/presentation-service-mock.js"></script>
9<button>click me</button>
10<script>
11
12var button = document.querySelector('button');
13var receiverConnectionClosed = false;
14var connection = null;
15
16async_test(t => {
Reilly Grant06367ab2017-09-02 02:00:1617 // This is receiving the user gesture and runs the callback.
18 waitForClick(() => {
19 new PresentationRequest("https://example.com/").start().then(
20 theConnection => {
21 connection = theConnection;
22 connection.onclose = (closeEvent) => {
23 assert_equals(closeEvent.reason, "closed");
24 assert_equals(closeEvent.message, "");
25 assert_equals(connection.state, "closed");
26 };
btolsch8ca10fb22018-08-29 01:35:0927 // Open a receiver page and pass controller connection's
28 // controllerConnectionPtr and receiverConnectionRequest to it.
29 w = window.open("resources/presentation-receiver-close-connection.html");
30 w.controllerConnectionPtr = presentationServiceMock.getControllerConnectionPtr();
31 w.receiverConnectionRequest = presentationServiceMock.getReceiverConnectionRequest();
32 w.shouldCallClose = false;
Reilly Grant06367ab2017-09-02 02:00:1633 });
34 }, button);
zhaobin0c08ed562017-03-07 21:19:1635
36 window.addEventListener("message", t.step_func(e => {
37 if (e.data == "receiver connection closed") {
38 receiverConnectionClosed = true;
zhaobine17728ae2017-05-23 01:19:0839 t.done();
zhaobin0c08ed562017-03-07 21:19:1640 } else if (e.data == "receiver connection ready") {
41 assert_not_equals(connection, null);
42 connection.close();
Derek Cheng2c99b532018-09-19 21:36:5043 assert_equals(connection.state, "closed");
zhaobin0c08ed562017-03-07 21:19:1644 }
45 }));
46}, "controller connection.close() should fire both controller's and receiver's onclose event handler");
47
48</script>
49</body>
50</html>