test_protocol_invalid_response.js (1300B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const protocol = require("resource://devtools/shared/protocol.js"); 7 const { RetVal } = protocol; 8 9 // Test invalid response specs throw when generating the Actor specification. 10 11 // Test top level array response 12 add_task(async function () { 13 Assert.throws(() => { 14 protocol.generateActorSpec({ 15 typeName: "invalidArrayResponse", 16 methods: { 17 invalidMethod: { 18 response: RetVal("array:string"), 19 }, 20 }, 21 }); 22 }, /Arrays should be wrapped in objects/); 23 24 protocol.generateActorSpec({ 25 typeName: "validArrayResponse", 26 methods: { 27 validMethod: { 28 response: { 29 someArray: RetVal("array:string"), 30 }, 31 }, 32 }, 33 }); 34 ok(true, "Arrays wrapped in object are valid response packets"); 35 }); 36 37 // Test response with several placeholders 38 add_task(async function () { 39 Assert.throws(() => { 40 protocol.generateActorSpec({ 41 typeName: "tooManyPlaceholdersResponse", 42 methods: { 43 invalidMethod: { 44 response: { 45 prop1: RetVal("json"), 46 prop2: RetVal("json"), 47 }, 48 }, 49 }, 50 }); 51 }, /More than one RetVal specified in response/); 52 });