test_register_case.js (1652B)
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 = "1760b1f5-c3ba-40e3-9344-adef7c18ab12"; 7 8 function run_test() { 9 do_get_profile(); 10 setPrefs(); 11 run_next_test(); 12 } 13 14 add_task(async function test_register_case() { 15 let db = PushServiceWebSocket.newPushDB(); 16 registerCleanupFunction(() => { 17 return db.drop().then(_ => db.close()); 18 }); 19 20 PushService.init({ 21 serverURI: "wss://push.example.org/", 22 db, 23 makeWebSocket(uri) { 24 return new MockWebSocket(uri, { 25 onHello() { 26 this.serverSendMsg( 27 JSON.stringify({ 28 messageType: "HELLO", 29 uaid: userAgentID, 30 status: 200, 31 }) 32 ); 33 }, 34 onRegister(request) { 35 this.serverSendMsg( 36 JSON.stringify({ 37 messageType: "ReGiStEr", 38 uaid: userAgentID, 39 channelID: request.channelID, 40 status: 200, 41 pushEndpoint: "https://example.com/update/case", 42 }) 43 ); 44 }, 45 }); 46 }, 47 }); 48 49 let newRecord = await PushService.register({ 50 scope: "https://example.net/case", 51 originAttributes: ChromeUtils.originAttributesToSuffix({ 52 inIsolatedMozBrowser: false, 53 }), 54 }); 55 equal( 56 newRecord.endpoint, 57 "https://example.com/update/case", 58 "Wrong push endpoint in registration record" 59 ); 60 61 let record = await db.getByPushEndpoint("https://example.com/update/case"); 62 equal( 63 record.scope, 64 "https://example.net/case", 65 "Wrong scope in database record" 66 ); 67 });