test_protocol_unregister.js (1106B)
1 "use strict"; 2 3 const { types } = require("resource://devtools/shared/protocol.js"); 4 5 function run_test() { 6 types.addType("test", { 7 read: v => "successful read: " + v, 8 write: v => "successful write: " + v, 9 }); 10 11 // Verify the type registered correctly. 12 13 const type = types.getType("test"); 14 const arrayType = types.getType("array:test"); 15 Assert.equal(type.read("foo"), "successful read: foo"); 16 Assert.equal(arrayType.read(["foo"])[0], "successful read: foo"); 17 18 types.removeType("test"); 19 20 Assert.equal(type.name, "DEFUNCT:test"); 21 try { 22 types.getType("test"); 23 Assert.ok(false, "getType should fail"); 24 } catch (ex) { 25 Assert.equal(ex.toString(), "Error: Unknown type: test"); 26 } 27 28 try { 29 type.read("foo"); 30 Assert.ok(false, "type.read should have thrown an exception."); 31 } catch (ex) { 32 Assert.equal(ex.toString(), "Error: Using defunct type: test"); 33 } 34 35 try { 36 arrayType.read(["foo"]); 37 Assert.ok(false, "array:test.read should have thrown an exception."); 38 } catch (ex) { 39 Assert.equal(ex.toString(), "Error: Using defunct type: test"); 40 } 41 }