tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_resources_invalid_api_usage.js (2479B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test watch/unwatchResources throw when provided with invalid types.
      7 
      8 const TEST_URI = "data:text/html;charset=utf-8,invalid api usage test";
      9 
     10 add_task(async function () {
     11  const tab = await addTab(TEST_URI);
     12 
     13  const { client, resourceCommand, targetCommand } =
     14    await initResourceCommand(tab);
     15 
     16  const onAvailable = function () {};
     17 
     18  await Assert.rejects(
     19    resourceCommand.watchResources([null], { onAvailable }),
     20    /ResourceCommand\.watchResources invoked with an unknown type/,
     21    "watchResources should throw for null type"
     22  );
     23 
     24  await Assert.rejects(
     25    resourceCommand.watchResources([undefined], { onAvailable }),
     26    /ResourceCommand\.watchResources invoked with an unknown type/,
     27    "watchResources should throw for undefined type"
     28  );
     29 
     30  await Assert.rejects(
     31    resourceCommand.watchResources(["NOT_A_RESOURCE"], { onAvailable }),
     32    /ResourceCommand\.watchResources invoked with an unknown type/,
     33    "watchResources should throw for unknown type"
     34  );
     35 
     36  await Assert.rejects(
     37    resourceCommand.watchResources(
     38      [resourceCommand.TYPES.CONSOLE_MESSAGE, "NOT_A_RESOURCE"],
     39      { onAvailable }
     40    ),
     41    /ResourceCommand\.watchResources invoked with an unknown type/,
     42    "watchResources should throw for unknown type mixed with a correct type"
     43  );
     44 
     45  await Assert.throws(
     46    () => resourceCommand.unwatchResources([null], { onAvailable }),
     47    /ResourceCommand\.unwatchResources invoked with an unknown type/,
     48    "unwatchResources should throw for null type"
     49  );
     50 
     51  await Assert.throws(
     52    () => resourceCommand.unwatchResources([undefined], { onAvailable }),
     53    /ResourceCommand\.unwatchResources invoked with an unknown type/,
     54    "unwatchResources should throw for undefined type"
     55  );
     56 
     57  await Assert.throws(
     58    () => resourceCommand.unwatchResources(["NOT_A_RESOURCE"], { onAvailable }),
     59    /ResourceCommand\.unwatchResources invoked with an unknown type/,
     60    "unwatchResources should throw for unknown type"
     61  );
     62 
     63  await Assert.throws(
     64    () =>
     65      resourceCommand.unwatchResources(
     66        [resourceCommand.TYPES.CONSOLE_MESSAGE, "NOT_A_RESOURCE"],
     67        { onAvailable }
     68      ),
     69    /ResourceCommand\.unwatchResources invoked with an unknown type/,
     70    "unwatchResources should throw for unknown type mixed with a correct type"
     71  );
     72 
     73  targetCommand.destroy();
     74  await client.close();
     75 });