Bug 1035091 part 2: disable @-moz-document in author sheets. r=heycam
☠☠ backed out by 3602ae56a243 ☠ ☠
authorZack Weinberg <zackw@panix.com>
Wed, 02 Sep 2015 13:54:30 -0400
changeset 260586 1fc07bdd9aa8
parent 260585 f6e98029d1cb
child 260587 825bd60177ed
push id64528
push userzackw@panix.com
push dateWed, 02 Sep 2015 19:00:43 +0000
treeherdermozilla-inbound@1fc07bdd9aa8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1035091
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1035091 part 2: disable @-moz-document in author sheets. r=heycam
dom/locales/en-US/chrome/layout/css.properties
editor/libeditor/tests/test_bug520189.html
layout/reftests/scoped-style/reftest.list
layout/reftests/scoped-style/scoped-style-document-ref.html
layout/reftests/scoped-style/scoped-style-document.html
layout/reftests/w3c-css/submitted/conditional3/css-supports-027.xht
layout/reftests/w3c-css/submitted/conditional3/css-supports-028.xht
layout/reftests/w3c-css/submitted/conditional3/reftest.list
layout/style/crashtests/473720-1.html
layout/style/crashtests/495269-2.html
layout/style/crashtests/crashtests.list
layout/style/crashtests/long-url-list-stack-overflow.html
layout/style/nsCSSParser.cpp
layout/style/test/chrome/chrome.ini
layout/style/test/chrome/moz_document_condition_text.css
layout/style/test/chrome/moz_document_nesting.css
layout/style/test/chrome/moz_document_serialization.css
layout/style/test/chrome/test_moz_document_condition_text.html
layout/style/test/chrome/test_moz_document_crashes.html
layout/style/test/chrome/test_moz_document_matching.html
layout/style/test/chrome/test_moz_document_nesting.html
layout/style/test/chrome/test_moz_document_rules.html
layout/style/test/chrome/test_moz_document_serialization.html
layout/style/test/chrome/test_moz_document_usability.html
layout/style/test/mochitest.ini
layout/style/test/test_bug511909.html
layout/style/test/test_condition_text.html
layout/style/test/test_css_eof_handling.html
layout/style/test/test_rule_insertion.html
layout/style/test/test_rule_serialization.html
--- a/dom/locales/en-US/chrome/layout/css.properties
+++ b/dom/locales/en-US/chrome/layout/css.properties
@@ -164,8 +164,9 @@ PEValueWithVariablesParsingError=Error i
 PEValueWithVariablesFallbackInherit=Falling back to 'inherit'.
 PEValueWithVariablesFallbackInitial=Falling back to 'initial'.
 PEInvalidVariableReference=Property contained reference to invalid variable.
 PEInvalidVariableTokenFallback=Found invalid token '%1$S' at top level of variable reference fallback.
 PEExpectedVariableNameEOF=identifier for variable name
 PEExpectedVariableName=Expected identifier for variable name but found '%1$S'.
 PEExpectedVariableFallback=Expected variable reference fallback after ','.
 PEExpectedVariableCommaOrCloseParen=Expected ',' or ')' after variable name in variable reference but found '%1$S'.
+PEMozDocumentRuleNotAllowed=@-moz-document rules may only be used in user style sheets.
--- a/editor/libeditor/tests/test_bug520189.html
+++ b/editor/libeditor/tests/test_bug520189.html
@@ -1,15 +1,15 @@
 <!DOCTYPE HTML>
 <html>
 <!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=520182
+https://bugzilla.mozilla.org/show_bug.cgi?id=520189
 -->
 <head>
-  <title>Test for Bug 520182</title>
+  <title>Test for Bug 520189</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>  
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=520182">Mozilla Bug 520182</a>
 <p id="display"></p>
 <div id="content">
@@ -74,17 +74,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <div id="xxx" contenteditable="true"></div>
   <iframe id="xxxx" src="about:blank"></iframe>
   <div id="yyy" contenteditable="true"></div>
   <iframe id="yyyy" src="about:blank"></iframe>
 </div>
 <pre id="test">
 <script type="application/javascript">
 
-/** Test for Bug 520182 **/
+/** Test for Bug 520189 **/
 
 const dataPayload = "foo<iframe src=\"data:text/html,bar\"></iframe>baz";
 const jsPayload = "foo<iframe src=\"javascript:void('bar');\"></iframe>baz";
 const httpPayload = "foo<iframe src=\"http://mochi.test:8888/\"></iframe>baz";
 const scriptPayload ="foo<script>document.write(\"<iframe></iframe>\");</sc" + "ript>baz";
 const scriptExternalPayload = "foo<script src=\"data:text/javascript,document.write('<iframe></iframe>');\"></sc" + "ript>baz";
 const validStyle1Payload = "foo<style>#bar{color:red;}</style>baz";
 const validStyle2Payload = "foo<span style=\"color:red\">bar</span>baz";
@@ -416,23 +416,31 @@ var tests = [
     rootElement() { return document.getElementById("rr"); },
     checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the _bar attribute"); },
   },
   {
     id: "ss",
     isIFrame: true,
     payload: invalidStyle8Payload,
     rootElement() { return document.getElementById("ss").contentDocument.documentElement; },
-    checkResult(html) { is(html.indexOf("@-moz-document"), -1, "Should not have retained the @-moz-document rule"); },
+    // The sanitizer currently doesn't discard unrecognized rules when
+    // that would make the sheet completely empty (see bug 1177546).
+    // This is harmless, since @-moz-document is inoperative in author
+    // style sheets (see bug 1035091).
+    checkResult(html) { todo_is(html.indexOf("@-moz-document"), -1, "Should not have retained the @-moz-document rule"); },
   },
   {
     id: "tt",
     payload: invalidStyle8Payload,
     rootElement() { return document.getElementById("tt"); },
-    checkResult(html) { is(html.indexOf("@-moz-document"), -1, "Should not have retained the @-moz-document rule"); },
+    // The sanitizer currently doesn't discard unrecognized rules when
+    // that would make the sheet completely empty (see bug 1177546).
+    // This is harmless, since @-moz-document is inoperative in author
+    // style sheets (see bug 1035091).
+    checkResult(html) { todo_is(html.indexOf("@-moz-document"), -1, "Should not have retained the @-moz-document rule"); },
   },
   {
     id: "uu",
     isIFrame: true,
     payload: invalidStyle9Payload,
     rootElement() { return document.getElementById("uu").contentDocument.documentElement; },
     checkResult(html) { is(html.indexOf("@-moz-keyframes"), -1, "Should not have retained the @-moz-keyframes rule"); },
   },
--- a/layout/reftests/scoped-style/reftest.list
+++ b/layout/reftests/scoped-style/reftest.list
@@ -43,15 +43,14 @@
 == scoped-style-dynamic-012.svg scoped-style-dynamic-012-ref.svg
 == scoped-style-dynamic-013.svg scoped-style-dynamic-013-ref.svg
 == scoped-style-dynamic-014.svg scoped-style-dynamic-014-ref.svg
 == scoped-style-dynamic-015.svg scoped-style-dynamic-015-ref.svg
 == scoped-style-import.html scoped-style-import-ref.html
 == scoped-style-media.html scoped-style-media-ref.html
 == scoped-style-namespace.html scoped-style-namespace-ref.html
 == scoped-style-charset.html scoped-style-charset-ref.html
-== scoped-style-document.html scoped-style-document-ref.html
 HTTP(..) == scoped-style-font-face.html scoped-style-font-face-ref.html
 == scoped-style-keyframes.html scoped-style-keyframes-ref.html
 == scoped-style-supports.html scoped-style-supports-ref.html
 pref(layout.css.scope-pseudo.enabled,true) == scoped-style-pseudo-001.html scoped-style-pseudo-001-ref.html
 pref(layout.css.scope-pseudo.enabled,true) == scoped-style-pseudo-002.html scoped-style-pseudo-002-ref.html
 pref(layout.css.scope-pseudo.enabled,true) == scoped-style-pseudo-003.html scoped-style-pseudo-003-ref.html
deleted file mode 100644
--- a/layout/reftests/scoped-style/scoped-style-document-ref.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE html>
-<body>
-  <p>First</p>
-  <p style="color: blue">Second</p>
-  <p>Third</p>
-</body>
deleted file mode 100644
--- a/layout/reftests/scoped-style/scoped-style-document.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!DOCTYPE html>
-<body>
-  <p>First</p>
-  <p>
-    <style scoped>
-      @-moz-document regexp("^.*scoped-style-document\\.html$") {
-        p { color: blue }
-      }
-    </style>
-    Second
-  </p>
-  <p>Third</p>
-</body>
deleted file mode 100644
--- a/layout/reftests/w3c-css/submitted/conditional3/css-supports-027.xht
+++ /dev/null
@@ -1,21 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head>
-  <title>CSS Test: A nested @supports rule with valid syntax and a passing condition must apply rules inside it</title>
-  <link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
-  <link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
-  <link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-document" />
-  <meta name="flags" content="" />
-  <meta name="assert" content="An outer @document rule with an inner @supports rule must apply the rules inside the @supports only if both the @supports and @document conditions pass."/>
-  <link rel="match" href="support/pass.xht" />
-  <style type="text/css"><![CDATA[
-    @-moz-document url-prefix("") {
-      @supports (color: green) {
-        html { background-color: green }
-      }
-    }
-  ]]></style>
- </head>
- <body>
- </body>
-</html>
deleted file mode 100644
--- a/layout/reftests/w3c-css/submitted/conditional3/css-supports-028.xht
+++ /dev/null
@@ -1,20 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head>
-  <title>CSS Test: A nested @supports rule with valid syntax and a passing condition must apply rules inside it</title>
-  <link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
-  <link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
-  <meta name="flags" content="" />
-  <meta name="assert" content="An inner @document rule with an outer @supports rule must apply the rules inside the @document only if both the @supports and @document conditions pass."/>
-  <link rel="match" href="support/pass.xht" />
-  <style type="text/css"><![CDATA[
-    @supports (color: green) {
-      @-moz-document url-prefix("") {
-        html { background-color: green }
-      }
-    }
-  ]]></style>
- </head>
- <body>
- </body>
-</html>
--- a/layout/reftests/w3c-css/submitted/conditional3/reftest.list
+++ b/layout/reftests/w3c-css/submitted/conditional3/reftest.list
@@ -19,18 +19,16 @@
 == css-supports-019.xht support/pass.xht
 == css-supports-020.xht support/pass.xht
 == css-supports-021.xht support/pass.xht
 == css-supports-022.xht support/pass.xht
 == css-supports-023.xht support/pass.xht
 == css-supports-024.xht support/pass.xht
 == css-supports-025.xht support/pass.xht
 == css-supports-026.xht support/pass.xht
-== css-supports-027.xht support/pass.xht
-== css-supports-028.xht support/pass.xht
 == css-supports-029.xht support/pass.xht
 == css-supports-030.xht support/pass.xht
 == css-supports-031.xht support/pass.xht
 == css-supports-032.xht support/pass.xht
 == css-supports-033.xht support/pass.xht
 == css-supports-034.xht support/pass.xht
 == css-supports-035.xht support/pass.xht
 == css-supports-036.xht support/pass.xht
--- a/layout/style/crashtests/473720-1.html
+++ b/layout/style/crashtests/473720-1.html
@@ -1,15 +1,14 @@
 <html><head><style>
 /* Recovery from an unparseable recognized @-rule is not the same thing
    as recovery from an unrecognized @-rule.  */
 
 @charset # { }
 @import # { }
 @namespace # { }
 @media # { }
-@-moz-document # { }
 @font-face # { }
 @page # { }
 @-non-mozilla # { }
 @nonstandard # { }
 
 </style></head></html>
deleted file mode 100644
--- a/layout/style/crashtests/495269-2.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<!DOCTYPE html>
-<html>
-  <head>
-    <link rel="stylesheet" href="data:text/css,@-moz-document domain(example.com) {}';">
-    <link rel="stylesheet" href="data:text/css,@-moz-document domain(example.com) {}';">
-    <script>
-      // Force a unique inner for the second linked sheet
-      document.styleSheets[1].cssRules[0];
-    </script>
-  </head>
-</html>
-
--- a/layout/style/crashtests/crashtests.list
+++ b/layout/style/crashtests/crashtests.list
@@ -44,19 +44,17 @@ load 472237-1.html # will fail, test for
 HTTP(..) load 472237-1.html
 load 473720-1.html
 load 473892-1.html
 load 473914-1.html
 load 478321-1.xhtml
 load 512851-1.xhtml
 load 539613-1.xhtml
 load 588627-1.html
-skip load long-url-list-stack-overflow.html # skipped due to being slow (bug 477490)
 load 495269-1.html
-load 495269-2.html
 load 498036-1.html
 load 509155-1.html
 load 509156-1.html
 load 509569-1.html
 load 524252-1.html
 load font-face-truncated-src.html 
 load 536789-1.html
 load 565248-1.html
deleted file mode 100644
--- a/layout/style/crashtests/long-url-list-stack-overflow.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<style id="s"></style>
-<script type="text/javascript">
-
-// Duplicates the string 2^n times
-function exp(s, n)
-{
-  for (var i = 0; i < n; ++i)
-    s += s;
-  return s;
-}
-
-var stylesheet = "@-moz-document url(http://www.w3.org/)" + exp(", url-prefix(file:///)", 20) + " { }";
-document.getElementById("s").textContent = stylesheet;
-
-</script>
-</head>
-<body>
-<div></div>
-</body>
-</html>
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -2994,18 +2994,24 @@ CSSParserImpl::ParseAtRule(RuleAppendFun
     parseFunc = &CSSParserImpl::ParseNameSpaceRule;
     newSection = eCSSSection_NameSpace;
 
   } else if (mToken.mIdent.LowerCaseEqualsLiteral("media")) {
     parseFunc = &CSSParserImpl::ParseMediaRule;
     newSection = eCSSSection_General;
 
   } else if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-document")) {
-    parseFunc = &CSSParserImpl::ParseMozDocumentRule;
-    newSection = eCSSSection_General;
+    if (UserRulesEnabled()) {
+      parseFunc = &CSSParserImpl::ParseMozDocumentRule;
+      newSection = eCSSSection_General;
+    } else {
+      REPORT_UNEXPECTED_TOKEN(PEMozDocumentRuleNotAllowed);
+      OUTPUT_ERROR();
+      return SkipAtRule(aInAtRule);
+    }
 
   } else if (mToken.mIdent.LowerCaseEqualsLiteral("font-face")) {
     parseFunc = &CSSParserImpl::ParseFontFaceRule;
     newSection = eCSSSection_General;
 
   } else if (mToken.mIdent.LowerCaseEqualsLiteral("font-feature-values")) {
     parseFunc = &CSSParserImpl::ParseFontFeatureValuesRule;
     newSection = eCSSSection_General;
--- a/layout/style/test/chrome/chrome.ini
+++ b/layout/style/test/chrome/chrome.ini
@@ -3,19 +3,27 @@ skip-if = buildapp == 'b2g' || os == 'an
 support-files =
   bug418986-2.js
   bug535806-css.css
   bug535806-html.html
   bug535806-xul.xul
   hover_helper.html
   match.png
   mismatch.png
+  moz_document_condition_text.css
+  moz_document_nesting.css
+  moz_document_serialization.css
 
 [test_addSheet.html]
 [test_additional_sheets.html]
 [test_author_specified_style.html]
 [test_bug418986-2.xul]
 [test_bug1157097.html]
 [test_bug1160724.xul]
 [test_bug535806.xul]
 [test_hover.html]
 skip-if = buildapp == 'mulet'
-[test_moz_document_rules.html]
+[test_moz_document_condition_text.html]
+[test_moz_document_crashes.html]
+[test_moz_document_matching.html]
+[test_moz_document_nesting.html]
+[test_moz_document_serialization.html]
+[test_moz_document_usability.html]
copy from layout/style/test/test_condition_text.html
copy to layout/style/test/chrome/moz_document_condition_text.css
--- a/layout/style/test/test_condition_text.html
+++ b/layout/style/test/chrome/moz_document_condition_text.css
@@ -1,93 +1,10 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=814907
--->
-<head>
-  <title>Test for Bug 814907</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">
-    @-moz-document url(http://www.example.com/) {}
-    @-moz-document url('http://www.example.com/') {}
-    @-moz-document url("http://www.example.com/") {}
-    @-moz-document url-prefix('http://www.example.com/') {}
-    @-moz-document url-prefix("http://www.example.com/") {}
-    @-moz-document domain('example.com') {}
-    @-moz-document domain("example.com") {}
-    @-moz-document regexp('http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/') {}
-    @-moz-document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {}
-
-    @media all {}
-    @media only color {}
-    @media (color ) {}
-    @media color \0061ND ( monochrome ) {}
-    @media (max-width: 200px), (color) {}
-
-    @supports(color: green){}
-    @supports (color: green) {}
-    @supports ((color: green)) {}
-    @supports (color: green) and (color: blue) {}
-    @supports ( Font:  20px serif ! Important)  {}
-  </style>
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=814907">Mozilla Bug 814907</a>
-<p id="display"></p>
-<div id="content" style="display: none">
-
-</div>
-<pre id="test">
-<script type="application/javascript">
-
-/** Test for Bug 814907 **/
-
-function runTest()
-{
-  // re-parse the style sheet with the pref turned on
-  var style = document.getElementById("style");
-  style.textContent += " ";
-
-  var sheet = style.sheet;
-
-  var conditions = [
-    "url(\"http://www.example.com/\")",
-    "url(\"http://www.example.com/\")",
-    "url(\"http://www.example.com/\")",
-    "url-prefix(\"http://www.example.com/\")",
-    "url-prefix(\"http://www.example.com/\")",
-    "domain(\"example.com\")",
-    "domain(\"example.com\")",
-    "regexp(\"http://www.w3.org/TR/\\\\d{4}/[^/]*-CSS2-\\\\d{8}/\")",
-    "regexp(\"http://www.w3.org/TR/\\\\d{4}/[^/]*-CSS2-\\\\d{8}/\")",
-    "all",
-    "only color",
-    "(color)",
-    "color and (monochrome)",
-    "(max-width: 200px), (color)",
-    "(color: green)",
-    "(color: green)",
-    "((color: green))",
-    "(color: green) and (color: blue)",
-    "( Font:  20px serif ! Important)"
-  ];
-
-  is(sheet.cssRules.length, conditions.length);
-
-  for (var i = 0; i < sheet.cssRules.length; i++) {
-    var rule = sheet.cssRules[i];
-    is(rule.conditionText, conditions[i], "rule " + i + " has expected conditionText");
-    if (rule.type == CSSRule.MEDIA_RULE) {
-      is(rule.conditionText, rule.media.mediaText, "rule " + i + " conditionText matches media.mediaText");
-    }
-  }
-
-  SimpleTest.finish();
-}
-
-SimpleTest.waitForExplicitFinish();
-runTest();
-</script>
-</pre>
-</body>
-</html>
+/* Bug 814907 (@-moz-document cases) */
+@-moz-document url(http://www.example.com/) {}
+@-moz-document url('http://www.example.com/') {}
+@-moz-document url("http://www.example.com/") {}
+@-moz-document url-prefix('http://www.example.com/') {}
+@-moz-document url-prefix("http://www.example.com/") {}
+@-moz-document domain('example.com') {}
+@-moz-document domain("example.com") {}
+@-moz-document regexp('http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/') {}
+@-moz-document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {}
new file mode 100644
--- /dev/null
+++ b/layout/style/test/chrome/moz_document_nesting.css
@@ -0,0 +1,89 @@
+/* formerly test_bug511909.html */
+
+a {
+    font-weight: bold;
+}
+#pink {
+    color: pink;
+}
+
+#green {
+    color: green;
+}
+
+#blue {
+    color: blue;
+}
+
+
+pre {
+    border: 1px solid black;
+}
+
+@-moz-document regexp(".*test_moz_document_nesting.*") {
+    #d {
+        color: pink;
+    }
+}
+
+@media screen {
+    #m {
+        color: green;
+    }
+}
+
+@-moz-document regexp(".*test_moz_document_nesting.*") {
+    @media screen {
+        #dm {
+            color: blue;
+        }
+    }
+}
+
+@media screen {
+    @-moz-document regexp(".*test_moz_document_nesting.*") {
+        #md {
+            color: green;
+        }
+    }
+}
+
+/* syntax error - recover at end of @media block */
+@media print { @-moz-document regexp("not_this_url") , }
+#mx {
+    color: pink;
+}
+
+/* syntax error - recover at end of @-moz-document block */
+@-moz-document regexp("not_this_url") { @media , }
+#mxx {
+    color: blue;
+}
+
+@media screen {
+    @-moz-document regexp(".*test_moz_document_nesting.*") {
+        @media screen {
+            @-moz-document regexp(".*test_moz_document_nesting.*") {
+                @media screen {
+                    #me {
+                        color: blue;
+                    }
+                }
+            }
+        }
+    }
+}
+
+/* formerly reftests/w3c-css/submitted/conditional3/css-supports-027.xht */
+@-moz-document regexp(".*test_moz_document_nesting.*") {
+    @supports (color: green) {
+        #mf { color: green }
+    }
+}
+
+/* formerly reftests/w3c-css/submitted/conditional3/css-supports-028.xht */
+@supports (color: pink) {
+    @-moz-document regexp(".*test_moz_document_nesting.*") {
+        #mg { color: pink }
+    }
+}
rename from layout/style/test/test_rule_serialization.html
rename to layout/style/test/chrome/moz_document_serialization.css
--- a/layout/style/test/test_rule_serialization.html
+++ b/layout/style/test/chrome/moz_document_serialization.css
@@ -1,53 +1,9 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=
--->
-<head>
-  <title>Test for Bug </title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-  <style type="text/css" id="style"></style>
-</head>
-<body>
-<pre id="test">
-<script type="application/javascript">
-
-var rules = [
-  { rule: "@-moz-document url(http://www.example.com/) {}" },
-  { rule: "@-moz-document url('http://www.example.com/') {}" },
-  { rule: '@-moz-document url("http://www.example.com/") {}' },
-  { rule: "@-moz-document url-prefix('http://www.example.com/') {}" },
-  { rule: '@-moz-document url-prefix("http://www.example.com/") {}' },
-  { rule: "@-moz-document domain('example.com') {}" },
-  { rule: '@-moz-document domain("example.com") {}' },
-  { rule: "@-moz-document regexp('http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/') {}" },
-  { rule: '@-moz-document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {}' },
-];
-
-var style = document.getElementById("style");
-var style_text = document.createTextNode("");
-style.appendChild(style_text);
-
-for (var i in rules) {
-  var obj = rules[i];
-  var rule = obj.rule;
-
-  style_text.data = rule;
-  is(style.sheet.cssRules.length, 1, "should have one rule");
-  var ser1 = style.sheet.cssRules[0].cssText;
-  if ("is_canonical" in obj) {
-    is(ser1, rule, "rule '" + rule + "' should serialize to itself");
-  }
-
-  style_text.data = ser1;
-  is(style.sheet.cssRules.length, 1, "should have one rule");
-  var ser2 = style.sheet.cssRules[0].cssText;
-  is(ser2, ser1,
-     "parse+serialize for rule '" + rule + "' should be idempotent");
-}
-
-</script>
-</pre>
-</body>
-</html>
+@-moz-document url(http://www.example.com/) {}
+@-moz-document url('http://www.example.com/') {}
+@-moz-document url("http://www.example.com/") {}
+@-moz-document url-prefix('http://www.example.com/') {}
+@-moz-document url-prefix("http://www.example.com/") {}
+@-moz-document domain('example.com') {}
+@-moz-document domain("example.com") {}
+@-moz-document regexp('http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/') {}
+@-moz-document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {}
copy from layout/style/test/test_condition_text.html
copy to layout/style/test/chrome/test_moz_document_condition_text.html
--- a/layout/style/test/test_condition_text.html
+++ b/layout/style/test/chrome/test_moz_document_condition_text.html
@@ -1,93 +1,61 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=814907
--->
-<head>
-  <title>Test for Bug 814907</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">
-    @-moz-document url(http://www.example.com/) {}
-    @-moz-document url('http://www.example.com/') {}
-    @-moz-document url("http://www.example.com/") {}
-    @-moz-document url-prefix('http://www.example.com/') {}
-    @-moz-document url-prefix("http://www.example.com/") {}
-    @-moz-document domain('example.com') {}
-    @-moz-document domain("example.com") {}
-    @-moz-document regexp('http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/') {}
-    @-moz-document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {}
+<!doctype html><html><head><meta charset="utf-8">
+<title>Test for Bug 814907 (@-moz-document cases)</title>
+<!-- Split from test_condition_text.html.
+     This is a chrome test because @-moz-document can only be used
+     from user style sheets.  See bug 1035091. -->
 
-    @media all {}
-    @media only color {}
-    @media (color ) {}
-    @media color \0061ND ( monochrome ) {}
-    @media (max-width: 200px), (color) {}
-
-    @supports(color: green){}
-    @supports (color: green) {}
-    @supports ((color: green)) {}
-    @supports (color: green) and (color: blue) {}
-    @supports ( Font:  20px serif ! Important)  {}
-  </style>
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=814907">Mozilla Bug 814907</a>
-<p id="display"></p>
-<div id="content" style="display: none">
-
-</div>
+<script type="application/javascript" src="/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="/content/tests/SimpleTest/test.css"/>
+</head><body>
+  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=814907">Mozilla Bug 814907</a>
+  <p id="display"></p>
+  <div id="content" style="display: none"></div>
 <pre id="test">
 <script type="application/javascript">
+SimpleTest.waitForExplicitFinish();
 
-/** Test for Bug 814907 **/
+var windowUtils =
+    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+          .getInterface(Components.interfaces.nsIDOMWindowUtils);
 
-function runTest()
-{
-  // re-parse the style sheet with the pref turned on
-  var style = document.getElementById("style");
-  style.textContent += " ";
+var sheetURI =
+    Components.classes["@mozilla.org/network/io-service;1"]
+    .getService(Components.interfaces.nsIIOService)
+    .newURI("moz_document_condition_text.css", null, document.baseURIObject);
 
-  var sheet = style.sheet;
+var sheet =
+    Components.classes["@mozilla.org/content/style-sheet-service;1"]
+    .getService(Components.interfaces.nsIStyleSheetService)
+    .preloadSheet(sheetURI, Components.interfaces.nsIStyleSheetService.USER_SHEET);
 
+windowUtils.addSheet(sheet, windowUtils.USER_SHEET);
+
+addLoadEvent(function () {
   var conditions = [
     "url(\"http://www.example.com/\")",
     "url(\"http://www.example.com/\")",
     "url(\"http://www.example.com/\")",
     "url-prefix(\"http://www.example.com/\")",
     "url-prefix(\"http://www.example.com/\")",
     "domain(\"example.com\")",
     "domain(\"example.com\")",
     "regexp(\"http://www.w3.org/TR/\\\\d{4}/[^/]*-CSS2-\\\\d{8}/\")",
     "regexp(\"http://www.w3.org/TR/\\\\d{4}/[^/]*-CSS2-\\\\d{8}/\")",
-    "all",
-    "only color",
-    "(color)",
-    "color and (monochrome)",
-    "(max-width: 200px), (color)",
-    "(color: green)",
-    "(color: green)",
-    "((color: green))",
-    "(color: green) and (color: blue)",
-    "( Font:  20px serif ! Important)"
   ];
 
   is(sheet.cssRules.length, conditions.length);
 
   for (var i = 0; i < sheet.cssRules.length; i++) {
     var rule = sheet.cssRules[i];
     is(rule.conditionText, conditions[i], "rule " + i + " has expected conditionText");
     if (rule.type == CSSRule.MEDIA_RULE) {
       is(rule.conditionText, rule.media.mediaText, "rule " + i + " conditionText matches media.mediaText");
     }
   }
 
   SimpleTest.finish();
-}
-
-SimpleTest.waitForExplicitFinish();
-runTest();
+});
 </script>
 </pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/layout/style/test/chrome/test_moz_document_crashes.html
@@ -0,0 +1,53 @@
+<!doctype html><html><head><meta charset="UTF-8">
+<title>@-moz-document crash tests</title>
+<!-- This test was formerly known as
+     crashtests/long-url-list-stack-overflow.html and
+     crashtests/495269-2.html.
+
+     This is a chrome mochitest because @-moz-document can only be
+     used from user style sheets.  See bug 1035091. -->
+
+<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+</head><body>
+<script>
+    // Duplicates the string 2^n times
+    function exp(s, n)
+    {
+        for (var i = 0; i < n; ++i)
+            s += s;
+        return s;
+    }
+
+    var windowUtils =
+        window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+              .getInterface(Components.interfaces.nsIDOMWindowUtils);
+
+    var ios =
+        Components.classes["@mozilla.org/network/io-service;1"]
+        .getService(Components.interfaces.nsIIOService);
+
+    var sss =
+        Components.classes["@mozilla.org/content/style-sheet-service;1"]
+       .getService(Components.interfaces.nsIStyleSheetService);
+
+    var style = "@-moz-document url(http://www.w3.org/)" + exp(", url-prefix(file:///)", 20) + " { }";
+    var url1 = ios.newURI("data:text/css," + style, null, null)
+
+    // should not crash at this point
+    windowUtils.loadSheet(url1, windowUtils.USER_SHEET);
+    ok(true, "long-url-list-stack-overflow: no crash");
+
+    var url2 = ios.newURI("data:text/css,@-moz-document domain(example.com) {}';", null, null);
+
+    var sheet1 = sss.preloadSheet(url2, sss.USER_SHEET);
+    var sheet2 = sss.preloadSheet(url2, sss.USER_SHEET);
+    windowUtils.addSheet(sheet1, windowUtils.USER_SHEET);
+    windowUtils.addSheet(sheet2, windowUtils.USER_SHEET);
+
+    // Force a unique inner for the second linked sheet; should not crash
+    sheet2.cssRules[0];
+    ok(true, "495269-2: no crash");
+</script>
+</body></html>
rename from layout/style/test/chrome/test_moz_document_rules.html
rename to layout/style/test/chrome/test_moz_document_matching.html
rename from layout/style/test/test_bug511909.html
rename to layout/style/test/chrome/test_moz_document_nesting.html
--- a/layout/style/test/test_bug511909.html
+++ b/layout/style/test/chrome/test_moz_document_nesting.html
@@ -1,205 +1,120 @@
-<html><!--
-   https://bugzilla.mozilla.org/show_bug.cgi?id=511909
-   --><head>
-<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<!doctype html><html><head><meta charset="UTF-8">
 <title>@media and @-moz-document testcases</title>
-  
-<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
+<!-- This test was formerly known as test_bug511909.html.
+     This is a chrome test because @-moz-document can only be used
+     from user style sheets.  See bug 1035091. -->
 
-<style type="text/css">
-a {
-    font-weight: bold; 
-}
-  #pink {
-    color: pink;
-  }
-  
-  #green {
-    color: green;
-  }
-  
-  #blue {
-    color: blue;
-  }
-
+<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css">
 
-pre {
-   border: 1px solid black;
-}
-</style>
-  
-<style type="text/css">
-@-moz-document regexp(".*test_bug511909.*"){
-    #d {
-      color: pink;
-    }
-}
-
-</style>
-  
-<style type="text/css">
-    
-@media screen {
-   #m {
-      color: green;
-   }
-}
+</head><body>
+<script>
+    SimpleTest.waitForExplicitFinish();
 
-</style>
-  
-<style type="text/css">
-  
-@-moz-document regexp(".*test_bug511909.*"){
-  @media screen {
-      #dm {
-         color: blue;
-      }
-   }
-}
+    var windowUtils =
+        window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+              .getInterface(Components.interfaces.nsIDOMWindowUtils);
 
-</style>
-  
-<!-- should parse -->
-<style type="text/css">
+    var sheetURI =
+        Components.classes["@mozilla.org/network/io-service;1"]
+        .getService(Components.interfaces.nsIIOService)
+        .newURI("moz_document_nesting.css", null, document.baseURIObject);
 
-@media print {
-  @-moz-document regexp("not_this_url"),}
-    #mx {
-        color: pink;
-    }
-  }
-}
+    windowUtils.loadSheet(sheetURI, windowUtils.USER_SHEET);
 
-</style>
-  
-<!-- should parse -->
-<style type="text/css">
-    
-@-moz-document regexp("not_this_url"){
-  @media print ,}
-    #mxx {
-      color: blue;
-    }
-  }
-}
+    addLoadEvent(function() {
+      var pink = getComputedStyle(document.getElementById("pink"), "");
+      var green = getComputedStyle(document.getElementById("green"), "");
+      var blue = getComputedStyle(document.getElementById("blue"), "");
 
-</style>
-  
-<style type="text/css">  
-  
-@media screen {
-  @-moz-document regexp(".*test_bug511909.*"){
-      #md {
-         color: green;
-      }
-   }
-}
+      var cs1 = getComputedStyle(document.getElementById("d"), "");
+      var cs2 = getComputedStyle(document.getElementById("m"), "");
+      var cs3 = getComputedStyle(document.getElementById("dm"), "");
+      var cs4 = getComputedStyle(document.getElementById("md"), "");
+      var cs5 = getComputedStyle(document.getElementById("mx"), "");
+      var cs6 = getComputedStyle(document.getElementById("mxx"), "");
+      var cs7 = getComputedStyle(document.getElementById("me"), "");
+      var cs8 = getComputedStyle(document.getElementById("mf"), "");
+      var cs9 = getComputedStyle(document.getElementById("mg"), "");
 
-</style>
-  
-<style type="text/css">
-    
-@media screen {
-  @-moz-document regexp(".*test_bug511909.*"){
-      @media screen { 
-        @-moz-document regexp(".*test_bug511909.*"){
-          @media screen {
-            #me {
-             color: blue; 
-            }
-          }
-        }
-     }
-   }
-}
-  
-</style>
-</head>
-<body>
-  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=511909">Mozilla Bug 511909</a>
-  <p id="display"></p>
-  <div id="content" style="display: none">
-    
-  </div>
-  
-  <script class="testbody" type="text/javascript">
+      is(cs1.color, pink.color, "@-moz-document applies");
+      is(cs2.color, green.color, "@media applies");
+      is(cs3.color, blue.color, "@media nested in @-moz-document applies");
+      is(cs4.color, green.color, "@-moz-document nested in @media applies");
+      is(cs5.color, pink.color, "broken @media nested in @-moz-document correctly handled");
+      is(cs6.color, blue.color, "broken @-moz-document nested in @media correctly handled");
+      is(cs7.color, blue.color, "@media nested in @-moz-document nested in @media applies");
+      is(cs8.color, green.color, "@supports nested in @-moz-document applies");
+      is(cs9.color, pink.color, "@-moz-document nested in @supports applies");
 
-    SimpleTest.waitForExplicitFinish();
-    
-    addLoadEvent(function() {
-    var pink = getComputedStyle(document.getElementById("pink"), "");
-    var green = getComputedStyle(document.getElementById("green"), "");
-    var blue = getComputedStyle(document.getElementById("blue"), "");
-                 
-    var cs1 = getComputedStyle(document.getElementById("d"), "");
-    var cs2 = getComputedStyle(document.getElementById("m"), "");
-    var cs3 = getComputedStyle(document.getElementById("dm"), "");
-    var cs4 = getComputedStyle(document.getElementById("md"), "");
-    var cs5 = getComputedStyle(document.getElementById("mx"), "");                 
-    var cs6 = getComputedStyle(document.getElementById("mxx"), "");                  
-    var cs7 = getComputedStyle(document.getElementById("me"), "");  
-                 
-    is(cs1.color, pink.color, "@-moz-document applies");
-    is(cs2.color, green.color, "@media applies");
-    is(cs3.color, blue.color, "@media nested in @-moz-document applies");
-    is(cs4.color, green.color, "@-moz-document nested in @media applies");
-    is(cs5.color, pink.color, "broken @media nested in @-moz-document correctly handled");      
-    is(cs6.color, blue.color, "broken @-moz-document nested in @media correctly handled");   
-    is(cs7.color, blue.color, "@media nested in @-moz-document nested in @media applies");
-    SimpleTest.finish();
+      SimpleTest.finish();
     });
-  </script>
-<div>
+</script>
+
 <pre>default style
 </pre>
 <a id="pink">This line should be pink</a><br>
-  
 <a id="green">This line should be green</a><br>
-  
 <a id="blue">This line should be blue</a><br>
-  
+
 <pre>@-moz-document {...}
 </pre>
 <a id="d">This line should be pink</a><br>
+
 <pre>@media screen {...}
 </pre>
 <a id="m">This line should be green</a><br>
+
 <pre>@-moz-document {
    @media screen {...}
 }
 </pre>
 <a id="dm">This line should be blue</a><br>
+
 <pre>@media print {
   @-moz-document regexp("not_this_url"),}
     #mx {
         color: pink;
     }
   }
 }
 </pre>
 <a id="mx">This line should be pink</a><br></div>
+
 <pre>@-moz-document regexp("not_this_url"){
   @media print ,}
     #mxx {
       color: blue;
     }
   }
 }
 </pre>
 <a id="mxx">This line should be blue</a><br>
+
 <pre>@media screen {
-  @-moz-documen {...}
+  @-moz-document {...}
 }
 </pre>
 <a id="md">This line should be green</a><br>
+
 <pre>@media screen {
   @-moz-document {
     @media screen {...}
   }
 }
 </pre>
 <a id="me">This line should be blue</a><br>
 
+<pre>@-moz-document {
+  @supports { ... }
+}
+</pre>
+<a id="mf">This line should be green</a><br>
+
+<pre>@supports {
+  @-moz-document { ... }
+}
+</pre>
+<a id="mg">This line should be pink</a><br>
 
 </body></html>
copy from layout/style/test/test_rule_serialization.html
copy to layout/style/test/chrome/test_moz_document_serialization.html
--- a/layout/style/test/test_rule_serialization.html
+++ b/layout/style/test/chrome/test_moz_document_serialization.html
@@ -1,53 +1,50 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=
--->
-<head>
-  <title>Test for Bug </title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-  <style type="text/css" id="style"></style>
-</head>
-<body>
-<pre id="test">
+<!doctype html><html><head><meta charset="utf-8">
+<title>Test for reserialization of @-moz-document rules</title>
+<!-- This is a chrome test because @-moz-document can only be used
+     from user style sheets.  See bug 1035091. -->
+
+<script type="application/javascript" src="/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="/content/tests/SimpleTest/test.css"/>
+
+</head><body>
 <script type="application/javascript">
+    SimpleTest.waitForExplicitFinish();
+
+    var windowUtils =
+        window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+              .getInterface(Components.interfaces.nsIDOMWindowUtils);
+
+    var sheetURI =
+        Components.classes["@mozilla.org/network/io-service;1"]
+        .getService(Components.interfaces.nsIIOService)
+        .newURI("moz_document_serialization.css", null, document.baseURIObject);
 
-var rules = [
-  { rule: "@-moz-document url(http://www.example.com/) {}" },
-  { rule: "@-moz-document url('http://www.example.com/') {}" },
-  { rule: '@-moz-document url("http://www.example.com/") {}' },
-  { rule: "@-moz-document url-prefix('http://www.example.com/') {}" },
-  { rule: '@-moz-document url-prefix("http://www.example.com/") {}' },
-  { rule: "@-moz-document domain('example.com') {}" },
-  { rule: '@-moz-document domain("example.com") {}' },
-  { rule: "@-moz-document regexp('http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/') {}" },
-  { rule: '@-moz-document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {}' },
-];
+    var sheet =
+        Components.classes["@mozilla.org/content/style-sheet-service;1"]
+        .getService(Components.interfaces.nsIStyleSheetService)
+        .preloadSheet(sheetURI, Components.interfaces.nsIStyleSheetService.USER_SHEET);
 
-var style = document.getElementById("style");
-var style_text = document.createTextNode("");
-style.appendChild(style_text);
+    windowUtils.addSheet(sheet, windowUtils.USER_SHEET);
 
-for (var i in rules) {
-  var obj = rules[i];
-  var rule = obj.rule;
+    var rules = [
+        '@-moz-document url("http://www.example.com/") {\n}',
+        '@-moz-document url("http://www.example.com/") {\n}',
+        '@-moz-document url("http://www.example.com/") {\n}',
+        '@-moz-document url-prefix("http://www.example.com/") {\n}',
+        '@-moz-document url-prefix("http://www.example.com/") {\n}',
+        '@-moz-document domain("example.com") {\n}',
+        '@-moz-document domain("example.com") {\n}',
+        '@-moz-document regexp("http://www.w3.org/TR/\\\\d{4}/[^/]*-CSS2-\\\\d{8}/") {\n}',
+        '@-moz-document regexp("http://www.w3.org/TR/\\\\d{4}/[^/]*-CSS2-\\\\d{8}/") {\n}',
+    ];
 
-  style_text.data = rule;
-  is(style.sheet.cssRules.length, 1, "should have one rule");
-  var ser1 = style.sheet.cssRules[0].cssText;
-  if ("is_canonical" in obj) {
-    is(ser1, rule, "rule '" + rule + "' should serialize to itself");
-  }
-
-  style_text.data = ser1;
-  is(style.sheet.cssRules.length, 1, "should have one rule");
-  var ser2 = style.sheet.cssRules[0].cssText;
-  is(ser2, ser1,
-     "parse+serialize for rule '" + rule + "' should be idempotent");
-}
-
+    addLoadEvent(function () {
+        is(sheet.cssRules.length, rules.length, "number of rules");
+        for (var i = 0; i < rules.length; i++) {
+            is(sheet.cssRules[i].cssText, rules[i], "serialization for rule " + i);
+        }
+        SimpleTest.finish();
+    });
 </script>
-</pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/layout/style/test/chrome/test_moz_document_usability.html
@@ -0,0 +1,56 @@
+<!doctype html><html><head><meta charset="UTF-8">
+<title>@-moz-document usability test (Bug 1035091)</title>
+<!-- Per https://bugzilla.mozilla.org/show_bug.cgi?id=1035091
+     @-moz-document rules can only be used in user and UA style sheets
+     until further notice. -->
+
+<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+<style>
+  #green  { color: green }
+  #author { color: green }
+  #user   { color: red }
+  #agent  { color: red }
+</style>
+</head><body>
+
+<p id="green">All text should be green.</p>
+<p id="author">All text should be green.</p>
+<p id="user">All text should be green.</p>
+<p id="agent">All text should be green.</p>
+
+<script>
+    SimpleTest.waitForExplicitFinish();
+    var wu =
+        window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+              .getInterface(Components.interfaces.nsIDOMWindowUtils);
+
+    var ios =
+        Components.classes["@mozilla.org/network/io-service;1"]
+        .getService(Components.interfaces.nsIIOService);
+
+    function makeSheet(whom, color) {
+        return ios.newURI(
+          "data:text/css,@-moz-document regexp('.*test_moz_document.*') {" +
+          "%23" + whom + " { color: " + color + "!important } }",
+          null, null);
+    }
+    wu.loadSheet(makeSheet("author", "red"),   wu.AUTHOR_SHEET);
+    wu.loadSheet(makeSheet("user",   "green"), wu.USER_SHEET);
+    wu.loadSheet(makeSheet("agent",  "green"), wu.AGENT_SHEET);
+
+    addLoadEvent(function () {
+        var green  = getComputedStyle(document.getElementById("green"),  "").color;
+        var author = getComputedStyle(document.getElementById("author"), "").color;
+        var user   = getComputedStyle(document.getElementById("user"),   "").color;
+        var agent  = getComputedStyle(document.getElementById("agent"),  "").color;
+
+        is(author, green, "@-moz-document should not be honored in author sheets");
+        is(user,   green, "@-moz-document should be honored in user sheets");
+        is(agent,  green, "@-moz-document should be honored in agent sheets");
+
+        SimpleTest.finish();
+    });
+</script>
+</body></html>
--- a/layout/style/test/mochitest.ini
+++ b/layout/style/test/mochitest.ini
@@ -88,17 +88,16 @@ skip-if = android_version == '18' # bug 
 [test_bug418986-2.html]
 [test_bug437915.html]
 [test_bug450191.html]
 [test_bug453896_deck.html]
 support-files = bug453896_iframe.html
 [test_bug470769.html]
 [test_bug499655.html]
 [test_bug499655.xhtml]
-[test_bug511909.html]
 [test_bug517224.html]
 support-files = bug517224.sjs
 [test_bug524175.html]
 [test_bug525952.html]
 [test_bug534804.html]
 [test_bug573255.html]
 [test_bug580685.html]
 [test_bug621351.html]
@@ -215,17 +214,16 @@ skip-if = (toolkit == 'gonk' && debug) #
 skip-if = (toolkit == 'gonk' && debug) || e10s #debug-only failure
 [test_pseudoelement_parsing.html]
 [test_redundant_font_download.html]
 support-files = redundant_font_download.sjs
 [test_rem_unit.html]
 [test_root_node_display.html]
 [test_rule_insertion.html]
 skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) # b2g-debug(monospace and serif text have sufficiently different widths) b2g-desktop(monospace and serif text have sufficiently different widths)
-[test_rule_serialization.html]
 [test_rules_out_of_sheets.html]
 [test_selectors.html]
 skip-if = (toolkit == 'gonk' && debug) || toolkit == 'android' #bug 775227 #debug-only failure; timed out
 [test_selectors_on_anonymous_content.html]
 [test_setPropertyWithNull.html]
 [test_shorthand_property_getters.html]
 [test_specified_value_serialization.html]
 [test_style_attribute_quirks.html]
--- a/layout/style/test/test_condition_text.html
+++ b/layout/style/test/test_condition_text.html
@@ -3,26 +3,16 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=814907
 -->
 <head>
   <title>Test for Bug 814907</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">
-    @-moz-document url(http://www.example.com/) {}
-    @-moz-document url('http://www.example.com/') {}
-    @-moz-document url("http://www.example.com/") {}
-    @-moz-document url-prefix('http://www.example.com/') {}
-    @-moz-document url-prefix("http://www.example.com/") {}
-    @-moz-document domain('example.com') {}
-    @-moz-document domain("example.com") {}
-    @-moz-document regexp('http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/') {}
-    @-moz-document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {}
-
     @media all {}
     @media only color {}
     @media (color ) {}
     @media color \0061ND ( monochrome ) {}
     @media (max-width: 200px), (color) {}
 
     @supports(color: green){}
     @supports (color: green) {}
@@ -37,57 +27,39 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 814907 **/
 
-function runTest()
-{
-  // re-parse the style sheet with the pref turned on
-  var style = document.getElementById("style");
-  style.textContent += " ";
+var style = document.getElementById("style");
+style.textContent += " ";
 
-  var sheet = style.sheet;
+var sheet = style.sheet;
 
-  var conditions = [
-    "url(\"http://www.example.com/\")",
-    "url(\"http://www.example.com/\")",
-    "url(\"http://www.example.com/\")",
-    "url-prefix(\"http://www.example.com/\")",
-    "url-prefix(\"http://www.example.com/\")",
-    "domain(\"example.com\")",
-    "domain(\"example.com\")",
-    "regexp(\"http://www.w3.org/TR/\\\\d{4}/[^/]*-CSS2-\\\\d{8}/\")",
-    "regexp(\"http://www.w3.org/TR/\\\\d{4}/[^/]*-CSS2-\\\\d{8}/\")",
-    "all",
-    "only color",
-    "(color)",
-    "color and (monochrome)",
-    "(max-width: 200px), (color)",
-    "(color: green)",
-    "(color: green)",
-    "((color: green))",
-    "(color: green) and (color: blue)",
-    "( Font:  20px serif ! Important)"
-  ];
+var conditions = [
+  "all",
+  "only color",
+  "(color)",
+  "color and (monochrome)",
+  "(max-width: 200px), (color)",
+  "(color: green)",
+  "(color: green)",
+  "((color: green))",
+  "(color: green) and (color: blue)",
+  "( Font:  20px serif ! Important)"
+];
 
-  is(sheet.cssRules.length, conditions.length);
+is(sheet.cssRules.length, conditions.length);
 
-  for (var i = 0; i < sheet.cssRules.length; i++) {
-    var rule = sheet.cssRules[i];
-    is(rule.conditionText, conditions[i], "rule " + i + " has expected conditionText");
-    if (rule.type == CSSRule.MEDIA_RULE) {
-      is(rule.conditionText, rule.media.mediaText, "rule " + i + " conditionText matches media.mediaText");
-    }
+for (var i = 0; i < sheet.cssRules.length; i++) {
+  var rule = sheet.cssRules[i];
+  is(rule.conditionText, conditions[i], "rule " + i + " has expected conditionText");
+  if (rule.type == CSSRule.MEDIA_RULE) {
+    is(rule.conditionText, rule.media.mediaText, "rule " + i + " conditionText matches media.mediaText");
   }
-
-  SimpleTest.finish();
 }
-
-SimpleTest.waitForExplicitFinish();
-runTest();
 </script>
 </pre>
 </body>
 </html>
--- a/layout/style/test/test_css_eof_handling.html
+++ b/layout/style/test/test_css_eof_handling.html
@@ -178,26 +178,16 @@ const tests = [
       ref: "@namespace 'http://foo.example.com/';",
       tst: "@namespace 'http://foo.example.com/'"
   },
   {
       name: "@namespace 2e",
       ref: "@namespace 'http://foo.example.com/';",
       tst: "@namespace 'http://foo.example.com/"
   },
-  {
-      name: "@-moz-document 1",
-      ref: "@-moz-document domain('example.com') {}",
-      tst: "@-moz-document domain('example.com') {"
-  },
-  {
-      name: "@-moz-document 2",
-      ref: "@-moz-document domain('example.com') { p {} }",
-      tst: "@-moz-document domain('example.com') { p {"
-  }
 ];
 
 const basestyle = ("table {\n"+
 		   "    border-collapse: collapse;\n"+
 		   "}\n"+
 		   "td {\n"+
 		   "    width: 1.5em;\n"+
 		   "    height: 1.5em;\n"+
--- a/layout/style/test/test_rule_insertion.html
+++ b/layout/style/test/test_rule_insertion.html
@@ -64,17 +64,16 @@ var controlCJKDecimal = document.getElem
 var testCounterStyle = document.getElementById("test-counter-style");
 
 var decimalWidth = controlDecimal.getBoundingClientRect().width;
 var cjkDecimalWidth = controlCJKDecimal.getBoundingClientRect().width;
 
 // [at-rule type, passing condition, failing condition]
 var outerRuleInfo = [
   ["@media", "all", "not all"],
-  ["@-moz-document", "url-prefix('')", "url-prefix('zzz')"],
   ["@supports", "(color: green)", "(unknown: unknown)"]
 ];
 
 // [rule, function to test whether the rule was successfully inserted and applied]
 var innerRuleInfo = [
   ["#test { text-decoration: underline; }",
    function(aApplied, aParent, aException) {
      return !aException &&