zhaobin | 0c08ed56 | 2017-03-07 21:19:16 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <body> |
| 4 | <script src="../resources/testharness.js"></script> |
| 5 | <script src="../resources/testharnessreport.js"></script> |
Reilly Grant | 06367ab | 2017-09-02 02:00:16 | [diff] [blame] | 6 | <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
mark a. foltz | 6bbe59f | 2018-07-24 20:06:24 | [diff] [blame] | 7 | <script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script> |
zhaobin | 0c08ed56 | 2017-03-07 21:19:16 | [diff] [blame] | 8 | <script src="resources/presentation-service-mock.js"></script> |
| 9 | <button>click me</button> |
| 10 | <script> |
| 11 | |
| 12 | var button = document.querySelector('button'); |
| 13 | var receiverConnectionClosed = false; |
| 14 | var connection = null; |
| 15 | |
| 16 | async_test(t => { |
Reilly Grant | 06367ab | 2017-09-02 02:00:16 | [diff] [blame] | 17 | // 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 | }; |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 27 | // 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 Grant | 06367ab | 2017-09-02 02:00:16 | [diff] [blame] | 33 | }); |
| 34 | }, button); |
zhaobin | 0c08ed56 | 2017-03-07 21:19:16 | [diff] [blame] | 35 | |
| 36 | window.addEventListener("message", t.step_func(e => { |
| 37 | if (e.data == "receiver connection closed") { |
| 38 | receiverConnectionClosed = true; |
zhaobin | e17728ae | 2017-05-23 01:19:08 | [diff] [blame] | 39 | t.done(); |
zhaobin | 0c08ed56 | 2017-03-07 21:19:16 | [diff] [blame] | 40 | } else if (e.data == "receiver connection ready") { |
| 41 | assert_not_equals(connection, null); |
| 42 | connection.close(); |
Derek Cheng | 2c99b53 | 2018-09-19 21:36:50 | [diff] [blame] | 43 | assert_equals(connection.state, "closed"); |
zhaobin | 0c08ed56 | 2017-03-07 21:19:16 | [diff] [blame] | 44 | } |
| 45 | })); |
| 46 | }, "controller connection.close() should fire both controller's and receiver's onclose event handler"); |
| 47 | |
| 48 | </script> |
| 49 | </body> |
| 50 | </html> |