summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_urlclassification.js
blob: 9c2296c7daae781a7921fed6a8b1c3cd6b566108 (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
"use strict";

const { Schemas } = ChromeUtils.import("resource://gre/modules/Schemas.jsm");

/**
 * If this test fails, likely nsIClassifiedChannel has added or changed a
 * CLASSIFIED_* flag.  Those changes must be in sync with
 * ChannelWrapper.webidl/cpp and the web_request.json schema file.
 */
add_task(async function test_webrequest_url_classification_enum() {
  // use normalizeManifest to get the schema loaded.
  await ExtensionTestUtils.normalizeManifest({ permissions: ["webRequest"] });

  let ns = Schemas.getNamespace("webRequest");
  let schema_enum = ns.get("UrlClassificationFlags").enumeration;
  ok(
    !!schema_enum.length,
    `UrlClassificationFlags: ${JSON.stringify(schema_enum)}`
  );

  let prefix = /^(?:CLASSIFIED_)/;
  let entries = 0;
  for (let c of Object.keys(Ci.nsIClassifiedChannel).filter(name =>
    prefix.test(name)
  )) {
    let entry = c.replace(prefix, "").toLowerCase();
    if (!entry.startsWith("socialtracking")) {
      ok(schema_enum.includes(entry), `schema ${entry} is in IDL`);
      entries++;
    }
  }
  equal(schema_enum.length, entries, "same number of entries");
});