| OLD | NEW |
| 1 // Runs various navigator.connect tests, verifying that connections are accepted | 1 // Runs various navigator.connect tests, verifying that connections are accepted |
| 2 // and rejected in the right circumstances. | 2 // and rejected in the right circumstances. |
| 3 // |connect_method| is a function taking a test object as well as the regular | 3 // |connect_method| is a function taking a test object as well as the regular |
| 4 // navigator.connect parameters. This makes it possible to run the same tests | 4 // navigator.connect parameters. This makes it possible to run the same tests |
| 5 // while wrapping all navigator.connect calls in a helper making the actual | 5 // while wrapping all navigator.connect calls in a helper making the actual |
| 6 // connection from a cross origin iframe, or a web worker. | 6 // connection from a cross origin iframe, or a web worker. |
| 7 function run_connect_tests(connect_method) { | 7 function run_connect_tests(connect_method) { |
| 8 promise_test(function(t) { | 8 promise_test(function(t) { |
| 9 return assert_promise_rejects( | 9 return assert_promise_rejects( |
| 10 connect_method(t, 'https://example.test/service/does/not/exists'), | 10 connect_method(t, 'https://example.test/service/does/not/exists'), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 var scope = sw_scope + '/accepting'; | 46 var scope = sw_scope + '/accepting'; |
| 47 var sw_url = 'resources/accepting-worker.js'; | 47 var sw_url = 'resources/accepting-worker.js'; |
| 48 return service_worker_unregister_and_register(t, sw_url, scope) | 48 return service_worker_unregister_and_register(t, sw_url, scope) |
| 49 .then(function(registration) { | 49 .then(function(registration) { |
| 50 return wait_for_state(t, registration.installing, 'activated'); | 50 return wait_for_state(t, registration.installing, 'activated'); |
| 51 }) | 51 }) |
| 52 .then(function() { | 52 .then(function() { |
| 53 return connect_method(t, scope + '/service'); | 53 return connect_method(t, scope + '/service'); |
| 54 }) | 54 }) |
| 55 .then(function(port) { | 55 .then(function(port) { |
| 56 assert_class_string(port, 'MessagePort'); | 56 var targetURL = new URL(port.targetURL); |
| 57 assert_equals(targetURL.pathname, base_path() + scope + '/service'); |
| 57 return service_worker_unregister(t, scope); | 58 return service_worker_unregister(t, scope); |
| 58 }); | 59 }); |
| 59 }, 'Connection succeeds if service worker accepts connection event.'); | 60 }, 'Connection succeeds if service worker accepts connection event.'); |
| 60 | 61 |
| 61 promise_test(function(t) { | 62 promise_test(function(t) { |
| 62 var scope = sw_scope + '/async-rejecting'; | 63 var scope = sw_scope + '/async-rejecting'; |
| 63 var sw_url = 'resources/async-connect-worker.js'; | 64 var sw_url = 'resources/async-connect-worker.js'; |
| 64 return assert_promise_rejects( | 65 return assert_promise_rejects( |
| 65 service_worker_unregister_and_register(t, sw_url, scope) | 66 service_worker_unregister_and_register(t, sw_url, scope) |
| 66 .then(function(registration) { | 67 .then(function(registration) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 var scope = sw_scope + '/async-accepting'; | 78 var scope = sw_scope + '/async-accepting'; |
| 78 var sw_url = 'resources/async-connect-worker.js'; | 79 var sw_url = 'resources/async-connect-worker.js'; |
| 79 return service_worker_unregister_and_register(t, sw_url, scope) | 80 return service_worker_unregister_and_register(t, sw_url, scope) |
| 80 .then(function(registration) { | 81 .then(function(registration) { |
| 81 return wait_for_state(t, registration.installing, 'activated'); | 82 return wait_for_state(t, registration.installing, 'activated'); |
| 82 }) | 83 }) |
| 83 .then(function() { | 84 .then(function() { |
| 84 return connect_method(t, scope + '/service?accept'); | 85 return connect_method(t, scope + '/service?accept'); |
| 85 }) | 86 }) |
| 86 .then(function(port) { | 87 .then(function(port) { |
| 87 assert_class_string(port, 'MessagePort'); | 88 var targetURL = new URL(port.targetURL); |
| 89 assert_equals(targetURL.pathname, base_path() + scope + '/service'); |
| 88 return service_worker_unregister(t, scope); | 90 return service_worker_unregister(t, scope); |
| 89 }); | 91 }); |
| 90 }, 'Connection succeeds if service worker accepts connection event async.'); | 92 }, 'Connection succeeds if service worker accepts connection event async.'); |
| 93 |
| 94 promise_test(function(t) { |
| 95 var scope = sw_scope + '/accepting'; |
| 96 var sw_url = 'resources/accepting-worker.js'; |
| 97 return service_worker_unregister_and_register(t, sw_url, scope) |
| 98 .then(function(registration) { |
| 99 return wait_for_state(t, registration.installing, 'activated'); |
| 100 }) |
| 101 .then(function() { |
| 102 return connect_method(t, scope + '/service', {name: 'somename', data
: 'somedata'}); |
| 103 }) |
| 104 .then(function(port) { |
| 105 var targetURL = new URL(port.targetURL); |
| 106 assert_equals(targetURL.pathname, base_path() + scope + '/service'); |
| 107 assert_equals(port.name, 'somename'); |
| 108 assert_equals(port.data, 'somedata'); |
| 109 return service_worker_unregister(t, scope); |
| 110 }); |
| 111 }, 'Returned port has correct name and data fields'); |
| 91 } | 112 } |
| OLD | NEW |