Bug 1391169 Part 2: Add a test of cssText with combinations of namespaces, universal selectors, and combinators. draft
authorBrad Werth <bwerth@mozilla.com>
Tue, 22 Aug 2017 16:21:46 -0700
changeset 657578 f76d49e00ea3a82d037302fe79aef748b19f6433
parent 657500 34933f6390d52779ea498a6a5fd5f34d54734780
child 729463 48dafe1d3382b62cfd4ed9f7fadc679662bac74e
push id77561
push userbwerth@mozilla.com
push dateFri, 01 Sep 2017 16:50:09 +0000
bugs1391169
milestone57.0a1
Bug 1391169 Part 2: Add a test of cssText with combinations of namespaces, universal selectors, and combinators. MozReview-Commit-ID: GZZEGR0zyp6
dom/base/test/mochitest.ini
dom/base/test/test_style_cssText.html
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -769,16 +769,17 @@ support-files =
   file_js_cache_syntax_error.js
 [test_setInterval_from_start.html]
 [test_setInterval_uncatchable_exception.html]
 skip-if = debug == false
 [test_settimeout_extra_arguments.html]
 [test_settimeout_inner.html]
 [test_setTimeoutWith0.html]
 [test_setting_opener.html]
+[test_style_cssText.html]
 [test_text_wholeText.html]
 [test_textnode_normalize_in_selection.html]
 [test_textnode_split_in_selection.html]
 [test_timeout_clamp.html]
 skip-if = debug == true && toolkit == 'android' # Timing dependent, skip slow debug android builds
 [test_timer_flood.html]
 [test_title.html]
 support-files = file_title.xul
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_style_cssText.html
@@ -0,0 +1,85 @@
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Test for Bug 1391169</title>
+<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+<style id="style"></style>
+</head>
+<body>
+<pre id="log">
+Log is:
+</pre>
+<script>
+let styleElement = document.getElementById("style");
+let logElement = document.getElementById("log");
+console.log("logElement is " + logElement);
+
+function log(text)
+{
+  logElement.innerHTML += text + "\n";
+}
+
+function textContentToCssText(text)
+{
+  // Pass input in via textContent.
+  styleElement.textContent = text;
+
+  // Read output from concatenated cssText of all rules.
+  let s = "";
+  let rules = document.styleSheets[1].cssRules;
+  for (let i = 0; i < rules.length; ++i) {
+    s += rules.item(i).cssText;
+  }
+  return s;
+}
+
+function noWhitespace(text)
+{
+  return text.replace(/\s/g, "");
+}
+
+function testData(input)
+{
+  let text;
+  let pass1Goal;
+  if (typeof(input) == "string") {
+    // Only text data, assume characters should be the same.
+    text = input;
+    pass1Goal = input;
+  } else {
+    [text, pass1Goal] = input;
+  }
+
+  let pass1Text = textContentToCssText(text);
+  is(noWhitespace(pass1Text), noWhitespace(pass1Goal), "textContent --> cssText correct characters emitted with input \"" + text + "\"");
+
+  let pass2Text = textContentToCssText(pass1Text);
+  is(pass2Text, pass1Text, "textContent --> cssText roundtrip with input \"" + text + "\"");
+
+  log(text + " --> " + pass1Text + " --> " + pass2Text);
+}
+
+let data = [
+  "*{}",
+  "* *{}",
+  "* > *{}",
+  "*>*{}",
+  "* * *{}",
+  "* > * > *{}",
+  "* + *{}",
+  "* ~ *{}",
+  ["*|*{}", "*{}"],
+  ["*|* > *{}", "* > *{}"],
+  "#tag{}",
+  "tag{}",
+  "@namespace tag url(\"fakeURL\"); tag|*{}",
+  "@namespace tag url(\"fakeURL\"); tag|* + *{}",
+];
+
+for (let i = 0; i < data.length; i++) {
+  testData(data[i]);
+}
+</script>
+</body>
+</html>