summaryrefslogtreecommitdiffstats
path: root/devtools/shared/protocol/tests/xpcshell/test_protocol_unregister.js
blob: 060a1743b1112867141b57c480a6deb36408a4e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use strict";

const { types } = require("resource://devtools/shared/protocol.js");

function run_test() {
  types.addType("test", {
    read: v => "successful read: " + v,
    write: v => "successful write: " + v,
  });

  // Verify the type registered correctly.

  const type = types.getType("test");
  const arrayType = types.getType("array:test");
  Assert.equal(type.read("foo"), "successful read: foo");
  Assert.equal(arrayType.read(["foo"])[0], "successful read: foo");

  types.removeType("test");

  Assert.equal(type.name, "DEFUNCT:test");
  try {
    types.getType("test");
    Assert.ok(false, "getType should fail");
  } catch (ex) {
    Assert.equal(ex.toString(), "Error: Unknown type: test");
  }

  try {
    type.read("foo");
    Assert.ok(false, "type.read should have thrown an exception.");
  } catch (ex) {
    Assert.equal(ex.toString(), "Error: Using defunct type: test");
  }

  try {
    arrayType.read(["foo"]);
    Assert.ok(false, "array:test.read should have thrown an exception.");
  } catch (ex) {
    Assert.equal(ex.toString(), "Error: Using defunct type: test");
  }
}