test_notification_version_string.js (2005B)
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 = "ba31ac13-88d4-4984-8e6b-8731315a7cf8"; 7 8 function run_test() { 9 do_get_profile(); 10 setPrefs({ 11 userAgentID, 12 }); 13 run_next_test(); 14 } 15 16 add_task(async function test_notification_version_string() { 17 let db = PushServiceWebSocket.newPushDB(); 18 registerCleanupFunction(() => { 19 return db.drop().then(_ => db.close()); 20 }); 21 await db.put({ 22 channelID: "6ff97d56-d0c0-43bc-8f5b-61b855e1d93b", 23 pushEndpoint: "https://example.org/updates/1", 24 scope: "https://example.com/page/1", 25 originAttributes: "", 26 version: 2, 27 quota: Infinity, 28 systemRecord: true, 29 }); 30 31 let notifyPromise = promiseObserverNotification( 32 PushServiceComponent.pushTopic 33 ); 34 35 let ackDone; 36 let ackPromise = new Promise(resolve => (ackDone = resolve)); 37 PushService.init({ 38 serverURI: "wss://push.example.org/", 39 db, 40 makeWebSocket(uri) { 41 return new MockWebSocket(uri, { 42 onHello() { 43 this.serverSendMsg( 44 JSON.stringify({ 45 messageType: "hello", 46 status: 200, 47 uaid: userAgentID, 48 }) 49 ); 50 this.serverSendMsg( 51 JSON.stringify({ 52 messageType: "notification", 53 updates: [ 54 { 55 channelID: "6ff97d56-d0c0-43bc-8f5b-61b855e1d93b", 56 version: "4", 57 }, 58 ], 59 }) 60 ); 61 }, 62 onACK: ackDone, 63 }); 64 }, 65 }); 66 67 let { subject: message } = await notifyPromise; 68 equal( 69 message.QueryInterface(Ci.nsIPushMessage).data, 70 null, 71 "Unexpected data for Simple Push message" 72 ); 73 74 await ackPromise; 75 76 let storeRecord = await db.getByKeyID("6ff97d56-d0c0-43bc-8f5b-61b855e1d93b"); 77 strictEqual(storeRecord.version, 4, "Wrong record version"); 78 equal(storeRecord.quota, Infinity, "Wrong quota"); 79 });