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