OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>subscribe() succeeds when permission is granted and resolves with a valid
subscription</title> | 4 <title>subscribe() succeeds when permission is granted and resolves with a valid
subscription</title> |
5 <link rel="manifest" href="resources/push_manifest.json"> | 5 <link rel="manifest" href="resources/push_manifest.json"> |
6 <script src="../resources/testharness.js"></script> | 6 <script src="../resources/testharness.js"></script> |
7 <script src="../resources/testharnessreport.js"></script> | 7 <script src="../resources/testharnessreport.js"></script> |
8 <script src="../resources/testharness-helpers.js"></script> | |
9 <script src="../serviceworker/resources/test-helpers.js"></script> | 8 <script src="../serviceworker/resources/test-helpers.js"></script> |
10 </head> | 9 </head> |
11 <body> | 10 <body> |
12 <script> | 11 <script> |
13 async_test(function(test) { | 12 async_test(function(test) { |
14 var workerUrl = 'resources/empty_worker.js'; | 13 var workerUrl = 'resources/empty_worker.js'; |
15 var workerScope = 'resources/scope/' + location.pathname; | 14 var workerScope = 'resources/scope/' + location.pathname; |
16 var swRegistration; | 15 var swRegistration; |
17 service_worker_unregister_and_register(test, workerUrl, workerScope) | 16 service_worker_unregister_and_register(test, workerUrl, workerScope) |
18 .then(function(serviceWorkerRegistration) { | 17 .then(function(serviceWorkerRegistration) { |
19 swRegistration = serviceWorkerRegistration; | 18 swRegistration = serviceWorkerRegistration; |
20 return wait_for_state(test, swRegistration.installing, 'activated'); | 19 return wait_for_state(test, swRegistration.installing, 'activated'); |
21 }) | 20 }) |
22 .then(function() { | 21 .then(function() { |
23 // If running manually, grant permission when prompted. | 22 // If running manually, grant permission when prompted. |
24 if (window.testRunner) | 23 if (window.testRunner) |
25 testRunner.setPermission('push-messaging', 'granted', location.o
rigin, location.origin); | 24 testRunner.setPermission('push-messaging', 'granted', location.o
rigin, location.origin); |
26 return swRegistration.pushManager.subscribe(); | 25 return swRegistration.pushManager.subscribe(); |
27 }) | 26 }) |
28 .then(function(pushSubscription) { | 27 .then(function(pushSubscription) { |
29 assert_will_be_idl_attribute(pushSubscription, 'endpoint'); | 28 assert_idl_attribute(pushSubscription, 'endpoint'); |
30 assert_equals(typeof pushSubscription.endpoint, 'string'); | 29 assert_equals(typeof pushSubscription.endpoint, 'string'); |
31 | 30 |
32 try { | 31 try { |
33 var endpointUrl = new URL(pushSubscription.endpoint); | 32 var endpointUrl = new URL(pushSubscription.endpoint); |
34 } catch(e) { | 33 } catch(e) { |
35 assert_unreached('Constructing a URL from the endpoint should no
t throw.'); | 34 assert_unreached('Constructing a URL from the endpoint should no
t throw.'); |
36 } | 35 } |
37 | 36 |
38 return service_worker_unregister_and_done(test, workerScope); | 37 return service_worker_unregister_and_done(test, workerScope); |
39 }) | 38 }) |
40 .catch(unreached_rejection(test)); | 39 .catch(unreached_rejection(test)); |
41 }, 'subscribe() succeeds when permission is granted and resolves with a valid su
bscription'); | 40 }, 'subscribe() succeeds when permission is granted and resolves with a valid su
bscription'); |
42 </script> | 41 </script> |
43 </body> | 42 </body> |
44 </html> | 43 </html> |
OLD | NEW |