OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Subscribing should provide a Curve25519 ECDH public key.</title> |
| 5 <link rel="manifest" href="resources/push_manifest.json"> |
| 6 <script src="../resources/testharness.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> |
| 10 </head> |
| 11 <body> |
| 12 <script> |
| 13 // Serializes |buffer| to a base64-encoded string. |
| 14 function SerializeArrayBuffer(buffer) { |
| 15 return btoa(String.fromCharCode.apply(null, new Uint8Array(buffe
r))); |
| 16 } |
| 17 |
| 18 // When running this test manually, grant permission when prompted. |
| 19 // This test verifies that push subscriptions get an ECDH Curve25519 |
| 20 // key that can be used on the application server to encrypt payload
s. |
| 21 async_test(function(test) { |
| 22 var workerUrl = 'resources/empty_worker.js'; |
| 23 var workerScope = 'resources/scope/' + location.pathname; |
| 24 var swRegistration, encryptionKey; |
| 25 |
| 26 // Size of an ECDH curve25519 public key, in bytes. |
| 27 var EXPECTED_KEY_LENGTH = 32; |
| 28 |
| 29 service_worker_unregister_and_register(test, workerUrl, workerSc
ope) |
| 30 .then(function(serviceWorkerRegistration) { |
| 31 swRegistration = serviceWorkerRegistration; |
| 32 return wait_for_state(test, swRegistration.installing, '
activated'); |
| 33 }) |
| 34 .then(function() { |
| 35 if (window.testRunner) |
| 36 testRunner.setPermission('push-messaging', 'granted'
, location.origin, location.origin); |
| 37 |
| 38 return swRegistration.pushManager.subscribe(); |
| 39 }) |
| 40 .then(function(pushSubscription) { |
| 41 assert_idl_attribute(pushSubscription, 'curve25519dh'); |
| 42 assert_equals(pushSubscription.curve25519dh, pushSubscri
ption.curve25519dh); |
| 43 assert_readonly(pushSubscription, 'curve25519dh'); |
| 44 assert_equals(pushSubscription.curve25519dh.byteLength,
EXPECTED_KEY_LENGTH); |
| 45 |
| 46 encryptionKey = SerializeArrayBuffer(pushSubscription.cu
rve25519dh); |
| 47 |
| 48 return swRegistration.pushManager.getSubscription(); |
| 49 }) |
| 50 .then(function(pushSubscription) { |
| 51 assert_equals(SerializeArrayBuffer(pushSubscription.curv
e25519dh), encryptionKey); |
| 52 |
| 53 return service_worker_unregister_and_done(test, workerSc
ope); |
| 54 }) |
| 55 .catch(unreached_rejection(test)); |
| 56 |
| 57 }, 'Subscribing should provide a Curve25519 ECDH public key'); |
| 58 </script> |
| 59 </body> |
| 60 </html> |
OLD | NEW |