test_registration_success.js (1702B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const userAgentID = "997ee7ba-36b1-4526-ae9e-2d3f38d6efe8"; 7 8 function run_test() { 9 do_get_profile(); 10 setPrefs({ userAgentID }); 11 run_next_test(); 12 } 13 14 add_task(async function test_registration_success() { 15 let db = PushServiceWebSocket.newPushDB(); 16 registerCleanupFunction(() => { 17 return db.drop().then(_ => db.close()); 18 }); 19 let records = [ 20 { 21 channelID: "bf001fe0-2684-42f2-bc4d-a3e14b11dd5b", 22 pushEndpoint: "https://example.com/update/same-manifest/1", 23 scope: "https://example.net/a", 24 originAttributes: "", 25 version: 5, 26 quota: Infinity, 27 }, 28 ]; 29 for (let record of records) { 30 await db.put(record); 31 } 32 33 let handshakeDone; 34 let handshakePromise = new Promise(resolve => (handshakeDone = resolve)); 35 PushService.init({ 36 serverURI: "wss://push.example.org/", 37 makeWebSocket(uri) { 38 return new MockWebSocket(uri, { 39 onHello(request) { 40 equal(request.uaid, userAgentID, "Wrong device ID in handshake"); 41 this.serverSendMsg( 42 JSON.stringify({ 43 messageType: "hello", 44 status: 200, 45 uaid: userAgentID, 46 }) 47 ); 48 handshakeDone(); 49 }, 50 }); 51 }, 52 }); 53 54 await handshakePromise; 55 56 let registration = await PushService.registration({ 57 scope: "https://example.net/a", 58 originAttributes: "", 59 }); 60 equal( 61 registration.endpoint, 62 "https://example.com/update/same-manifest/1", 63 "Wrong push endpoint for scope" 64 ); 65 equal(registration.version, 5, "Wrong version for scope"); 66 });