1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/styleinspector/test/unit/test_parseSingleValue.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* Any copyright is dedicated to the Public Domain. 1.7 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.8 + 1.9 +const Cu = Components.utils; 1.10 +Cu.import("resource://gre/modules/devtools/Loader.jsm"); 1.11 +const {parseSingleValue} = devtools.require("devtools/styleinspector/css-parsing-utils"); 1.12 + 1.13 +const TEST_DATA = [ 1.14 + {input: null, throws: true}, 1.15 + {input: undefined, throws: true}, 1.16 + {input: "", expected: {value: "", priority: ""}}, 1.17 + {input: " \t \t \n\n ", expected: {value: "", priority: ""}}, 1.18 + {input: "blue", expected: {value: "blue", priority: ""}}, 1.19 + {input: "blue !important", expected: {value: "blue", priority: "important"}}, 1.20 + {input: "blue!important", expected: {value: "blue", priority: "important"}}, 1.21 + {input: "blue ! important", expected: {value: "blue", priority: "important"}}, 1.22 + {input: "blue ! important", expected: {value: "blue", priority: "important"}}, 1.23 + {input: "blue !", expected: {value: "blue", priority: ""}}, 1.24 + {input: "blue !mportant", expected: {value: "blue !mportant", priority: ""}}, 1.25 + {input: " blue !important ", expected: {value: "blue", priority: "important"}}, 1.26 + { 1.27 + input: "url(\"http://url.com/whyWouldYouDoThat!important.png\") !important", 1.28 + expected: { 1.29 + value: "url(\"http://url.com/whyWouldYouDoThat!important.png\")", 1.30 + priority: "important" 1.31 + } 1.32 + }, 1.33 + { 1.34 + input: "url(\"http://url.com/whyWouldYouDoThat!important.png\")", 1.35 + expected: { 1.36 + value: "url(\"http://url.com/whyWouldYouDoThat!important.png\")", 1.37 + priority: "" 1.38 + } 1.39 + }, 1.40 + { 1.41 + input: "\"content!important\" !important", 1.42 + expected: { 1.43 + value: "\"content!important\"", 1.44 + priority: "important" 1.45 + } 1.46 + }, 1.47 + { 1.48 + input: "\"content!important\"", 1.49 + expected: { 1.50 + value: "\"content!important\"", 1.51 + priority: "" 1.52 + } 1.53 + } 1.54 +]; 1.55 + 1.56 +function run_test() { 1.57 + for (let test of TEST_DATA) { 1.58 + do_print("Test input value " + test.input); 1.59 + try { 1.60 + let output = parseSingleValue(test.input); 1.61 + assertOutput(output, test.expected); 1.62 + } catch (e) { 1.63 + do_print("parseSingleValue threw an exception with the given input value"); 1.64 + if (test.throws) { 1.65 + do_print("Exception expected"); 1.66 + do_check_true(true); 1.67 + } else { 1.68 + do_print("Exception unexpected\n" + e); 1.69 + do_check_true(false); 1.70 + } 1.71 + } 1.72 + } 1.73 +} 1.74 + 1.75 +function assertOutput(actual, expected) { 1.76 + do_print("Check that the output has the expected value and priority"); 1.77 + do_check_eq(expected.value, actual.value); 1.78 + do_check_eq(expected.priority, actual.priority); 1.79 +}