summaryrefslogtreecommitdiffstats
path: root/devtools/shared/commands/resource/tests/browser_resources_invalid_api_usage.js
blob: 8a1d809f0466bdce56d54b3729a07aa4b43dd60e (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test watch/unwatchResources throw when provided with invalid types.

const TEST_URI = "data:text/html;charset=utf-8,invalid api usage test";

add_task(async function () {
  const tab = await addTab(TEST_URI);

  const { client, resourceCommand, targetCommand } = await initResourceCommand(
    tab
  );

  const onAvailable = function () {};

  await Assert.rejects(
    resourceCommand.watchResources([null], { onAvailable }),
    /ResourceCommand\.watchResources invoked with an unknown type/,
    "watchResources should throw for null type"
  );

  await Assert.rejects(
    resourceCommand.watchResources([undefined], { onAvailable }),
    /ResourceCommand\.watchResources invoked with an unknown type/,
    "watchResources should throw for undefined type"
  );

  await Assert.rejects(
    resourceCommand.watchResources(["NOT_A_RESOURCE"], { onAvailable }),
    /ResourceCommand\.watchResources invoked with an unknown type/,
    "watchResources should throw for unknown type"
  );

  await Assert.rejects(
    resourceCommand.watchResources(
      [resourceCommand.TYPES.CONSOLE_MESSAGE, "NOT_A_RESOURCE"],
      { onAvailable }
    ),
    /ResourceCommand\.watchResources invoked with an unknown type/,
    "watchResources should throw for unknown type mixed with a correct type"
  );

  await Assert.throws(
    () => resourceCommand.unwatchResources([null], { onAvailable }),
    /ResourceCommand\.unwatchResources invoked with an unknown type/,
    "unwatchResources should throw for null type"
  );

  await Assert.throws(
    () => resourceCommand.unwatchResources([undefined], { onAvailable }),
    /ResourceCommand\.unwatchResources invoked with an unknown type/,
    "unwatchResources should throw for undefined type"
  );

  await Assert.throws(
    () => resourceCommand.unwatchResources(["NOT_A_RESOURCE"], { onAvailable }),
    /ResourceCommand\.unwatchResources invoked with an unknown type/,
    "unwatchResources should throw for unknown type"
  );

  await Assert.throws(
    () =>
      resourceCommand.unwatchResources(
        [resourceCommand.TYPES.CONSOLE_MESSAGE, "NOT_A_RESOURCE"],
        { onAvailable }
      ),
    /ResourceCommand\.unwatchResources invoked with an unknown type/,
    "unwatchResources should throw for unknown type mixed with a correct type"
  );

  targetCommand.destroy();
  await client.close();
});