tor-browser

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

test_parseSingleValue.js (2813B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const {
      7  parseSingleValue,
      8 } = require("resource://devtools/shared/css/parsing-utils.js");
      9 const {
     10  isCssPropertyKnown,
     11 } = require("resource://devtools/server/actors/css-properties.js");
     12 
     13 const TEST_DATA = [
     14  { input: null, throws: true },
     15  { input: undefined, throws: true },
     16  { input: "", expected: { value: "", priority: "" } },
     17  { input: "  \t \t \n\n  ", expected: { value: "", priority: "" } },
     18  { input: "blue", expected: { value: "blue", priority: "" } },
     19  {
     20    input: "blue !important",
     21    expected: { value: "blue", priority: "important" },
     22  },
     23  {
     24    input: "blue!important",
     25    expected: { value: "blue", priority: "important" },
     26  },
     27  {
     28    input: "blue ! important",
     29    expected: { value: "blue", priority: "important" },
     30  },
     31  {
     32    input: "blue !  important",
     33    expected: { value: "blue", priority: "important" },
     34  },
     35  { input: "blue !", expected: { value: "blue !", priority: "" } },
     36  {
     37    input: "blue !mportant",
     38    expected: { value: "blue !mportant", priority: "" },
     39  },
     40  {
     41    input: "  blue   !important ",
     42    expected: { value: "blue", priority: "important" },
     43  },
     44  {
     45    input: 'url("http://url.com/whyWouldYouDoThat!important.png") !important',
     46    expected: {
     47      value: 'url("http://url.com/whyWouldYouDoThat!important.png")',
     48      priority: "important",
     49    },
     50  },
     51  {
     52    input: 'url("http://url.com/whyWouldYouDoThat!important.png")',
     53    expected: {
     54      value: 'url("http://url.com/whyWouldYouDoThat!important.png")',
     55      priority: "",
     56    },
     57  },
     58  {
     59    input: '"content!important" !important',
     60    expected: {
     61      value: '"content!important"',
     62      priority: "important",
     63    },
     64  },
     65  {
     66    input: '"content!important"',
     67    expected: {
     68      value: '"content!important"',
     69      priority: "",
     70    },
     71  },
     72  {
     73    input: '"all the \\"\'\\\\ special characters"',
     74    expected: {
     75      value: '"all the \\"\'\\\\ special characters"',
     76      priority: "",
     77    },
     78  },
     79 ];
     80 
     81 function run_test() {
     82  for (const test of TEST_DATA) {
     83    info("Test input value " + test.input);
     84    try {
     85      const output = parseSingleValue(isCssPropertyKnown, test.input);
     86      assertOutput(output, test.expected);
     87    } catch (e) {
     88      info(
     89        "parseSingleValue threw an exception with the given input " + "value"
     90      );
     91      if (test.throws) {
     92        info("Exception expected");
     93        Assert.ok(true);
     94      } else {
     95        info("Exception unexpected\n" + e);
     96        Assert.ok(false);
     97      }
     98    }
     99  }
    100 }
    101 
    102 function assertOutput(actual, expected) {
    103  info("Check that the output has the expected value and priority");
    104  Assert.equal(expected.value, actual.value);
    105  Assert.equal(expected.priority, actual.priority);
    106 }