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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/push_messaging/push-subscription-options.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/push_messaging/push-subscription-options.html b/third_party/WebKit/LayoutTests/http/tests/push_messaging/push-subscription-options.html
new file mode 100644
index 0000000000000000000000000000000000000000..1425c98240e787f1137c880329efffcb72752a07
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/push_messaging/push-subscription-options.html
@@ -0,0 +1,145 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>PushSubscriptionOptions should be correctly reflected on PushSubscription objects</title>
+ <link rel="manifest" href="resources/push_manifest.json">
+ <script src="../resources/testharness.js"></script>
+ <script src="../resources/testharnessreport.js"></script>
+ <script src="../serviceworker/resources/test-helpers.js"></script>
+ </head>
+ <body>
+ <script>
+ // When running this test manually, grant permission when prompted.
+ if (window.testRunner)
+ testRunner.setPermission('push-messaging', 'granted', location.origin, location.origin);
+
+ function assert_options_equals(actual_subscription, expected_options, description) {
+
+ // PushSubscription should have:
+ // [SameObject] readonly attribute PushSubscriptionOptions options;
+ assert_true(actual_subscription instanceof PushSubscription,
+ description + ": instanceof PushSubscription");
+ assert_inherits(actual_subscription, 'options', description);
+ assert_readonly(actual_subscription, 'options', description);
+ assert_equals(actual_subscription.options, actual_subscription.options,
+ description + ": options [SameObject]");
+ var actual_options = actual_subscription.options;
+
+ // PushSubscriptionOptions should have:
+ // readonly attribute boolean userVisibleOnly;
+ // [SameObject] readonly attribute ArrayBuffer? applicationServerKey;
+ assert_true(actual_options instanceof PushSubscriptionOptions,
+ description + ": options instanceof PushSubscriptionOptions");
+ assert_inherits(actual_options, 'userVisibleOnly', description);
+ assert_inherits(actual_options, 'applicationServerKey', description);
+ assert_readonly(actual_options, 'userVisibleOnly', description);
+ assert_readonly(actual_options, 'applicationServerKey', description);
+ assert_equals(actual_options.applicationServerKey, actual_options.applicationServerKey,
+ description + ": applicationServerKey [SameObject]");
+
+ // PushSubscriptionOptions should match expected_options.
+ assert_equals(actual_options.userVisibleOnly, expected_options.userVisibleOnly,
+ description + ": userVisibleOnly");
+ if (!expected_options.applicationServerKey) {
+ assert_equals(actual_options.applicationServerKey, null,
+ description + ": applicationServerKey");
+ } else {
+ assert_true(actual_options.applicationServerKey instanceof ArrayBuffer,
+ description + ": applicationServerKey instanceof window.ArrayBuffer");
+ var actual_bytes = new Uint8Array(actual_options.applicationServerKey);
+ var expected_bytes = new Uint8Array(expected_options.applicationServerKey);
+ assert_equals(actual_bytes.byteLength, expected_bytes.byteLength,
+ description + ": applicationServerKey byteLength");
+ for (var i = 0; i < expected_bytes.byteLength; i++) {
+ assert_equals(actual_bytes[i], expected_bytes[i],
+ description + ": applicationServerKey[" + i + "]");
+ }
+
+ // The applicationServerKey is actually mutable (https://github.com/w3c/push-api/issues/198).
+ new Uint8Array(actual_options.applicationServerKey)[0] = 0x7F;
+ assert_equals(new Uint8Array(actual_subscription.options.applicationServerKey)[0], 0x7F,
+ description + ": applicationServerKey mutable");
+ }
+ }
+
+ const PUBLIC_KEY = [
+ 0x04, 0x56, 0x23, 0xC0, 0x45, 0xD7, 0x6C, 0x5D, 0x45, 0x1A, 0x29,
+ 0x19, 0xAA, 0xE5, 0x02, 0x2F, 0x43, 0x55, 0xC2, 0x5C, 0x59, 0x86,
+ 0x69, 0xA0, 0xAD, 0xD7, 0x2D, 0x54, 0x22, 0xD8, 0x43, 0xB6, 0xCD,
+ 0xE3, 0x33, 0xB4, 0xBB, 0x66, 0x2F, 0x47, 0xE5, 0xE6, 0x20, 0xFF,
+ 0x0E, 0x10, 0x7F, 0xCD, 0xA3, 0x44, 0x8C, 0x65, 0x54, 0x64, 0x7E,
+ 0x25, 0xF3, 0x67, 0xF4, 0x7C, 0x4B, 0x0C, 0xBD, 0xCF, 0xF4
+ ];
+ const VAPID_OPTIONS = {
+ userVisibleOnly: true,
+ applicationServerKey: new Uint8Array(PUBLIC_KEY)
+ };
+ const SENDER_ID_OPTIONS = {
+ userVisibleOnly: true,
+ // This is equal to the gcm_sender_id in push_manifest.json
+ applicationServerKey: new TextEncoder().encode('1234567890')
+ };
+ const MANIFEST_OPTIONS = {
+ userVisibleOnly: true
+ };
+
+ // This test verifies that PushSubscriptionOptions is correctly
+ // reflected on PushSubscription objects.
+ promise_test(test => {
+ var workerScript = 'resources/instrumentation-service-worker.js';
+ var workerScope = 'resources/scope/' + location.pathname;
+ var pushManager;
+
+ return service_worker_unregister_and_register(test, workerScript, workerScope)
+ .then(serviceWorkerRegistration => {
+ pushManager = serviceWorkerRegistration.pushManager;
+ return wait_for_state(test, serviceWorkerRegistration.installing, 'activated');
+ }).then(() => {
+
+ // 1. Test subscription with SENDER_ID_OPTIONS.
+ // -------------------------------------------.
+ return pushManager.subscribe(SENDER_ID_OPTIONS);
+ }).then(pushSubscription => {
+ assert_options_equals(pushSubscription, SENDER_ID_OPTIONS,
+ "subscribe with SENDER_ID_OPTIONS");
+ return pushManager.getSubscription();
+ }).then(pushSubscription => {
+ assert_options_equals(pushSubscription, SENDER_ID_OPTIONS,
+ "getSubscription with SENDER_ID_OPTIONS");
+ return pushSubscription.unsubscribe();
+ }).then(unsubscribed => {
+ assert_true(unsubscribed, "unsubscribed (with SENDER_ID_OPTIONS)");
+
+ // 2. Test subscription with VAPID_OPTIONS.
+ // ----------------------------------------
+ return pushManager.subscribe(VAPID_OPTIONS);
+ }).then(pushSubscription => {
+ assert_options_equals(pushSubscription, VAPID_OPTIONS,
+ "subscribe with VAPID_OPTIONS");
+ return pushManager.getSubscription();
+ }).then(pushSubscription => {
+ assert_options_equals(pushSubscription, VAPID_OPTIONS,
+ "getSubscription with VAPID_OPTIONS");
+ return pushSubscription.unsubscribe();
+ }).then(unsubscribed => {
+ assert_true(unsubscribed, "unsubscribed (with VAPID_OPTIONS)");
+
+ // 3. Test subscription with MANIFEST_OPTIONS.
+ // -------------------------------------------
+ return pushManager.subscribe(MANIFEST_OPTIONS);
+ }).then(pushSubscription => {
+ // Since MANIFEST_OPTIONS passed to subscribe has no
+ // applicationServerKey, the sender ID from the manifest
+ // should be reflected in the PushSubscriptionOptions.
+ assert_options_equals(pushSubscription, SENDER_ID_OPTIONS,
+ "subscribe with MANIFEST_OPTIONS");
+ return pushManager.getSubscription();
+ }).then(pushSubscription => {
+ assert_options_equals(pushSubscription, SENDER_ID_OPTIONS,
+ "getSubscription with MANIFEST_OPTIONS");
+ });
+
+ }, "PushSubscriptionOptions should be correctly reflected on PushSubscription objects");
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698