browser/devtools/styleinspector/test/unit/test_parseSingleValue.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* Any copyright is dedicated to the Public Domain.
     4    http://creativecommons.org/publicdomain/zero/1.0/ */
     6 const Cu = Components.utils;
     7 Cu.import("resource://gre/modules/devtools/Loader.jsm");
     8 const {parseSingleValue} = devtools.require("devtools/styleinspector/css-parsing-utils");
    10 const TEST_DATA = [
    11   {input: null, throws: true},
    12   {input: undefined, throws: true},
    13   {input: "", expected: {value: "", priority: ""}},
    14   {input: "  \t \t \n\n  ", expected: {value: "", priority: ""}},
    15   {input: "blue", expected: {value: "blue", priority: ""}},
    16   {input: "blue !important", expected: {value: "blue", priority: "important"}},
    17   {input: "blue!important", expected: {value: "blue", priority: "important"}},
    18   {input: "blue ! important", expected: {value: "blue", priority: "important"}},
    19   {input: "blue !  important", expected: {value: "blue", priority: "important"}},
    20   {input: "blue !", expected: {value: "blue", priority: ""}},
    21   {input: "blue !mportant", expected: {value: "blue !mportant", priority: ""}},
    22   {input: "  blue   !important ", expected: {value: "blue", priority: "important"}},
    23   {
    24     input: "url(\"http://url.com/whyWouldYouDoThat!important.png\") !important",
    25     expected: {
    26       value: "url(\"http://url.com/whyWouldYouDoThat!important.png\")",
    27       priority: "important"
    28     }
    29   },
    30   {
    31     input: "url(\"http://url.com/whyWouldYouDoThat!important.png\")",
    32     expected: {
    33       value: "url(\"http://url.com/whyWouldYouDoThat!important.png\")",
    34       priority: ""
    35     }
    36   },
    37   {
    38     input: "\"content!important\" !important",
    39     expected: {
    40       value: "\"content!important\"",
    41       priority: "important"
    42     }
    43   },
    44   {
    45     input: "\"content!important\"",
    46     expected: {
    47       value: "\"content!important\"",
    48       priority: ""
    49     }
    50   }
    51 ];
    53 function run_test() {
    54   for (let test of TEST_DATA) {
    55     do_print("Test input value " + test.input);
    56     try {
    57       let output = parseSingleValue(test.input);
    58       assertOutput(output, test.expected);
    59     } catch (e) {
    60       do_print("parseSingleValue threw an exception with the given input value");
    61       if (test.throws) {
    62         do_print("Exception expected");
    63         do_check_true(true);
    64       } else {
    65         do_print("Exception unexpected\n" + e);
    66         do_check_true(false);
    67       }
    68     }
    69   }
    70 }
    72 function assertOutput(actual, expected) {
    73   do_print("Check that the output has the expected value and priority");
    74   do_check_eq(expected.value, actual.value);
    75   do_check_eq(expected.priority, actual.priority);
    76 }

mercurial