Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/push_messaging/push-subscription-options.html

Issue 2133673002: Push API: Implement and ship PushSubscription.options (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add MODULES_EXPORT Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 PushSubscription,
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 PushSubscriptionOptions,
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 A rrayBuffer,
48 description + ": applicationServerKey instanceof window.ArrayBuffer");
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 (https://git hub.com/w3c/push-api/issues/198).
59 new Uint8Array(actual_options.applicationServerKey)[0] = 0x7 F;
60 assert_equals(new Uint8Array(actual_subscription.options.app licationServerKey)[0], 0x7F,
61 description + ": applicationServerKey mutable" );
62 }
63 }
64
65 const PUBLIC_KEY = [
66 0x04, 0x56, 0x23, 0xC0, 0x45, 0xD7, 0x6C, 0x5D, 0x45, 0x1A, 0x29 ,
67 0x19, 0xAA, 0xE5, 0x02, 0x2F, 0x43, 0x55, 0xC2, 0x5C, 0x59, 0x86 ,
68 0x69, 0xA0, 0xAD, 0xD7, 0x2D, 0x54, 0x22, 0xD8, 0x43, 0xB6, 0xCD ,
69 0xE3, 0x33, 0xB4, 0xBB, 0x66, 0x2F, 0x47, 0xE5, 0xE6, 0x20, 0xFF ,
70 0x0E, 0x10, 0x7F, 0xCD, 0xA3, 0x44, 0x8C, 0x65, 0x54, 0x64, 0x7E ,
71 0x25, 0xF3, 0x67, 0xF4, 0x7C, 0x4B, 0x0C, 0xBD, 0xCF, 0xF4
72 ];
73 const VAPID_OPTIONS = {
74 userVisibleOnly: true,
75 applicationServerKey: new Uint8Array(PUBLIC_KEY)
76 };
77 const SENDER_ID_OPTIONS = {
78 userVisibleOnly: true,
79 // This is equal to the gcm_sender_id in push_manifest.json
80 applicationServerKey: new TextEncoder().encode('1234567890')
81 };
82 const MANIFEST_OPTIONS = {
83 userVisibleOnly: true
84 };
85
86 // This test verifies that PushSubscriptionOptions is correctly
87 // reflected on PushSubscription objects.
88 promise_test(test => {
89 var workerScript = 'resources/instrumentation-service-worker.js' ;
90 var workerScope = 'resources/scope/' + location.pathname;
91 var pushManager;
92
93 return service_worker_unregister_and_register(test, workerScript , workerScope)
94 .then(serviceWorkerRegistration => {
95 pushManager = serviceWorkerRegistration.pushManager;
96 return wait_for_state(test, serviceWorkerRegistration.in stalling, 'activated');
97 }).then(() => {
98
99 // 1. Test subscription with SENDER_ID_OPTIONS.
100 // -------------------------------------------.
101 return pushManager.subscribe(SENDER_ID_OPTIONS);
102 }).then(pushSubscription => {
103 assert_options_equals(pushSubscription, SENDER_ID_OPTION S,
104 "subscribe with SENDER_ID_OPTIONS" );
105 return pushManager.getSubscription();
106 }).then(pushSubscription => {
107 assert_options_equals(pushSubscription, SENDER_ID_OPTION S,
108 "getSubscription with SENDER_ID_OP TIONS");
109 return pushSubscription.unsubscribe();
110 }).then(unsubscribed => {
111 assert_true(unsubscribed, "unsubscribed (with SENDER_ID_ OPTIONS)");
112
113 // 2. Test subscription with VAPID_OPTIONS.
114 // ----------------------------------------
115 return pushManager.subscribe(VAPID_OPTIONS);
116 }).then(pushSubscription => {
117 assert_options_equals(pushSubscription, VAPID_OPTIONS,
118 "subscribe with VAPID_OPTIONS");
119 return pushManager.getSubscription();
120 }).then(pushSubscription => {
121 assert_options_equals(pushSubscription, VAPID_OPTIONS,
122 "getSubscription with VAPID_OPTION S");
123 return pushSubscription.unsubscribe();
124 }).then(unsubscribed => {
125 assert_true(unsubscribed, "unsubscribed (with VAPID_OPTI ONS)");
126
127 // 3. Test subscription with MANIFEST_OPTIONS.
128 // -------------------------------------------
129 return pushManager.subscribe(MANIFEST_OPTIONS);
130 }).then(pushSubscription => {
131 // Since MANIFEST_OPTIONS passed to subscribe has no
132 // applicationServerKey, the sender ID from the manifest
133 // should be reflected in the PushSubscriptionOptions.
134 assert_options_equals(pushSubscription, SENDER_ID_OPTION S,
135 "subscribe with MANIFEST_OPTIONS") ;
136 return pushManager.getSubscription();
137 }).then(pushSubscription => {
138 assert_options_equals(pushSubscription, SENDER_ID_OPTION S,
139 "getSubscription with MANIFEST_OPT IONS");
140 });
141
142 }, "PushSubscriptionOptions should be correctly reflected on PushSub scription objects");
143 </script>
144 </body>
145 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698