subscribe-with-faulty-applicationServerKey.https.window.js (2167B)
1 // META: script=/resources/testdriver.js 2 // META: script=/resources/testdriver-vendor.js 3 // META: script=/notifications/resources/helpers.js 4 5 // NOTE: 6 // We are not testing success cases here as doing so will try creating external network 7 // connection, which is not allowed by all browser test environments. 8 // (e.g. Gecko explicitly disables push service for testing environment.) 9 // Ideally we should have WPT-specific mock server in this case. See also 10 // https://github.com/w3c/push-api/issues/365. 11 12 promise_setup(async () => { 13 // The spec does not enforce validation order and implementations 14 // indeed check other things before checking applicationServerKey. 15 16 // Get the permission because Firefox checks it before key validation. 17 // (The permission test is done in permission.https.html.) 18 await trySettingPermission("granted"); 19 // Get the active service worker because Chrome checks it before key validation 20 registration = await prepareActiveServiceWorker("noop-sw.js"); 21 }); 22 23 promise_test(async (t) => { 24 await promise_rejects_dom( 25 t, 26 "InvalidAccessError", 27 registration.pushManager.subscribe({ applicationServerKey: "" }), 28 ); 29 }, "Reject empty string applicationServerKey"); 30 31 promise_test(async (t) => { 32 await promise_rejects_dom( 33 t, 34 "InvalidAccessError", 35 registration.pushManager.subscribe({ applicationServerKey: new ArrayBuffer(0) }), 36 ); 37 }, "Reject empty ArrayBuffer applicationServerKey"); 38 39 promise_test(async (t) => { 40 await promise_rejects_dom( 41 t, 42 "InvalidAccessError", 43 registration.pushManager.subscribe({ applicationServerKey: new Uint8Array(0) }), 44 ); 45 }, "Reject empty Uint8Array applicationServerKey"); 46 47 promise_test(async (t) => { 48 await promise_rejects_dom( 49 t, 50 "InvalidAccessError", 51 registration.pushManager.subscribe({ applicationServerKey: new Uint8Array([1, 2, 3]) }), 52 ); 53 }, "Reject a key that is not a valid point on P-256 curve"); 54 55 promise_test(async (t) => { 56 await promise_rejects_dom( 57 t, 58 "InvalidCharacterError", 59 registration.pushManager.subscribe({ applicationServerKey: "!@#$^&*" }), 60 ); 61 }, "Reject a string key that can't be decoded by base64url");