Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>PushSubscriptionOptions should be correctly reflected on PushSubs cription objects</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="../serviceworker/resources/test-helpers.js"></script> | |
| 9 </head> | |
| 10 <body> | |
| 11 <script> | |
| 12 // When running this test manually, grant permission when prompted. | |
| 13 if (window.testRunner) | |
| 14 testRunner.setPermission('push-messaging', 'granted', location.o rigin, location.origin); | |
| 15 | |
| 16 function assert_options_equals(actual_subscription, expected_options , description) { | |
| 17 | |
| 18 // PushSubscription should have: | |
| 19 // [SameObject] readonly attribute PushSubscriptionOptions optio ns; | |
| 20 assert_true(actual_subscription instanceof window.PushSubscripti on, | |
|
Peter Beverloo
2016/07/08 18:30:12
nit: why do you prefix these types with `window`?
johnme
2016/07/13 17:51:57
Done.
| |
| 21 description + ": instanceof PushSubscription"); | |
| 22 assert_inherits(actual_subscription, 'options', description); | |
| 23 assert_readonly(actual_subscription, 'options', description); | |
| 24 assert_equals(actual_subscription.options, actual_subscription.o ptions, | |
| 25 description + ": options [SameObject]"); | |
| 26 var actual_options = actual_subscription.options; | |
| 27 | |
| 28 // PushSubscriptionOptions should have: | |
| 29 // readonly attribute boolean userVisibleOnly; | |
| 30 // [SameObject] readonly attribute ArrayBuffer? applicationServe rKey; | |
| 31 assert_true(actual_options instanceof window.PushSubscriptionOpt ions, | |
| 32 description + ": options instanceof PushSubscription Options"); | |
| 33 assert_inherits(actual_options, 'userVisibleOnly', description); | |
| 34 assert_inherits(actual_options, 'applicationServerKey', descript ion); | |
| 35 assert_readonly(actual_options, 'userVisibleOnly', description); | |
| 36 assert_readonly(actual_options, 'applicationServerKey', descript ion); | |
| 37 assert_equals(actual_options.applicationServerKey, actual_option s.applicationServerKey, | |
| 38 description + ": applicationServerKey [SameObject] "); | |
| 39 | |
| 40 // PushSubscriptionOptions should match expected_options. | |
| 41 assert_equals(actual_options.userVisibleOnly, expected_options.u serVisibleOnly, | |
| 42 description + ": userVisibleOnly"); | |
| 43 if (!expected_options.applicationServerKey) { | |
| 44 assert_equals(actual_options.applicationServerKey, null, | |
| 45 description + ": applicationServerKey"); | |
| 46 } else { | |
| 47 assert_true(actual_options.applicationServerKey instanceof w indow.ArrayBuffer, | |
| 48 description + ": applicationServerKey instanceof win dow.ArrayBuffer"); | |
|
Peter Beverloo
2016/07/08 18:30:12
nit: alignment
johnme
2016/07/13 17:51:57
Done.
| |
| 49 var actual_bytes = new Uint8Array(actual_options.application ServerKey); | |
| 50 var expected_bytes = new Uint8Array(expected_options.applica tionServerKey); | |
| 51 assert_equals(actual_bytes.byteLength, expected_bytes.byteLe ngth, | |
| 52 description + ": applicationServerKey byteLeng th"); | |
| 53 for (var i = 0; i < expected_bytes.byteLength; i++) { | |
| 54 assert_equals(actual_bytes[i], expected_bytes[i], | |
| 55 description + ": applicationServerKey[" + i + "]"); | |
| 56 } | |
| 57 | |
| 58 // The applicationServerKey is actually mutable, for good or | |
| 59 // for bad (https://github.com/w3c/push-api/issues/198). | |
|
Peter Beverloo
2016/07/08 18:30:12
no need to imply judgement calls in our code :)
johnme
2016/07/13 17:51:57
Done.
| |
| 60 new Uint8Array(actual_options.applicationServerKey)[0] = 0x7 F; | |
| 61 assert_equals(new Uint8Array(actual_subscription.options.app licationServerKey)[0], 0x7F, | |
| 62 description + ": applicationServerKey mutable" ); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 const PUBLIC_KEY = [ | |
| 67 0x04, 0x56, 0x23, 0xC0, 0x45, 0xD7, 0x6C, 0x5D, 0x45, 0x1A, 0x29 , | |
| 68 0x19, 0xAA, 0xE5, 0x02, 0x2F, 0x43, 0x55, 0xC2, 0x5C, 0x59, 0x86 , | |
| 69 0x69, 0xA0, 0xAD, 0xD7, 0x2D, 0x54, 0x22, 0xD8, 0x43, 0xB6, 0xCD , | |
| 70 0xE3, 0x33, 0xB4, 0xBB, 0x66, 0x2F, 0x47, 0xE5, 0xE6, 0x20, 0xFF , | |
| 71 0x0E, 0x10, 0x7F, 0xCD, 0xA3, 0x44, 0x8C, 0x65, 0x54, 0x64, 0x7E , | |
| 72 0x25, 0xF3, 0x67, 0xF4, 0x7C, 0x4B, 0x0C, 0xBD, 0xCF, 0xF4 | |
| 73 ]; | |
| 74 var VAPID_OPTIONS = { | |
|
Peter Beverloo
2016/07/08 18:30:12
const as you use on :66? Same on :78 and :83
johnme
2016/07/13 17:51:57
Done.
| |
| 75 userVisibleOnly: true, | |
| 76 applicationServerKey: new Uint8Array(PUBLIC_KEY) | |
| 77 }; | |
| 78 var SENDER_ID_OPTIONS = { | |
| 79 userVisibleOnly: true, | |
| 80 // This is equal to the gcm_sender_id in push_manifest.json | |
| 81 applicationServerKey: new TextEncoder().encode('1234567890') | |
| 82 }; | |
| 83 var MANIFEST_OPTIONS = { | |
| 84 userVisibleOnly: true | |
| 85 }; | |
| 86 | |
| 87 // This test verifies that PushSubscriptionOptions is correctly | |
| 88 // reflected on PushSubscription objects. | |
| 89 promise_test(test => { | |
| 90 var workerScript = 'resources/instrumentation-service-worker.js' ; | |
| 91 var workerScope = 'resources/scope/' + location.pathname; | |
| 92 var pushManager; | |
| 93 | |
| 94 return service_worker_unregister_and_register(test, workerScript , workerScope) | |
| 95 .then(serviceWorkerRegistration => { | |
| 96 pushManager = serviceWorkerRegistration.pushManager; | |
| 97 return wait_for_state(test, serviceWorkerRegistration.in stalling, 'activated'); | |
| 98 }).then(() => { | |
| 99 | |
| 100 // 1. Test subscription with SENDER_ID_OPTIONS. | |
| 101 // -------------------------------------------. | |
| 102 return pushManager.subscribe(SENDER_ID_OPTIONS); | |
| 103 }).then(pushSubscription => { | |
| 104 assert_options_equals(pushSubscription, SENDER_ID_OPTION S, | |
| 105 "subscribe with SENDER_ID_OPTIONS" ); | |
| 106 return pushManager.getSubscription(); | |
| 107 }).then(pushSubscription => { | |
| 108 assert_options_equals(pushSubscription, SENDER_ID_OPTION S, | |
| 109 "getSubscription with SENDER_ID_OP TIONS"); | |
| 110 return pushSubscription.unsubscribe(); | |
| 111 }).then(unsubscribed => { | |
| 112 assert_true(unsubscribed, "unsubscribed (with SENDER_ID_ OPTIONS)"); | |
| 113 | |
| 114 // 2. Test subscription with VAPID_OPTIONS. | |
| 115 // ---------------------------------------- | |
| 116 return pushManager.subscribe(VAPID_OPTIONS); | |
| 117 }).then(pushSubscription => { | |
| 118 assert_options_equals(pushSubscription, VAPID_OPTIONS, | |
| 119 "subscribe with VAPID_OPTIONS"); | |
| 120 return pushManager.getSubscription(); | |
| 121 }).then(pushSubscription => { | |
| 122 assert_options_equals(pushSubscription, VAPID_OPTIONS, | |
| 123 "getSubscription with VAPID_OPTION S"); | |
| 124 return pushSubscription.unsubscribe(); | |
| 125 }).then(unsubscribed => { | |
| 126 assert_true(unsubscribed, "unsubscribed (with VAPID_OPTI ONS)"); | |
| 127 | |
| 128 // 3. Test subscription with MANIFEST_OPTIONS. | |
| 129 // ------------------------------------------- | |
| 130 return pushManager.subscribe(MANIFEST_OPTIONS); | |
| 131 }).then(pushSubscription => { | |
| 132 // Since MANIFEST_OPTIONS passed to subscribe has no | |
| 133 // applicationServerKey, the sender ID from the manifest | |
| 134 // should be reflected in the PushSubscriptionOptions. | |
| 135 assert_options_equals(pushSubscription, SENDER_ID_OPTION S, | |
| 136 "subscribe with MANIFEST_OPTIONS") ; | |
| 137 return pushManager.getSubscription(); | |
| 138 }).then(pushSubscription => { | |
| 139 assert_options_equals(pushSubscription, SENDER_ID_OPTION S, | |
| 140 "getSubscription with MANIFEST_OPT IONS"); | |
| 141 }); | |
| 142 | |
| 143 }, "PushSubscriptionOptions should be correctly reflected on PushSub scription objects"); | |
| 144 </script> | |
| 145 </body> | |
| 146 </html> | |
|
Peter Beverloo
2016/07/08 18:30:12
nit: -2 indent
johnme
2016/07/13 17:51:57
Done.
| |
| OLD | NEW |