layout/style/test/chrome/test_moz_document_crashes.html
author Zack Weinberg <zackw@panix.com>
Wed, 02 Sep 2015 13:54:30 -0400
changeset 260586 1fc07bdd9aa8d04a50c5f77956638bc452df45c5
permissions -rw-r--r--
Bug 1035091 part 2: disable @-moz-document in author sheets. r=heycam

<!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>