layout/style/test/test_cascade.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <!-- vim: set shiftwidth=4 tabstop=8 autoindent expandtab: -->
michael@0 3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
michael@0 6 <html>
michael@0 7 <head>
michael@0 8 <title>Test for Author style sheet aspects of CSS cascading</title>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 <style type="text/css">
michael@0 12
michael@0 13 </style>
michael@0 14 </head>
michael@0 15 <body id="thebody">
michael@0 16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
michael@0 17 <div class="content_class" id="content" style="position:relative"></div>
michael@0 18 <pre id="test">
michael@0 19 <script class="testbody" type="text/javascript">
michael@0 20
michael@0 21 /** Test for Author style sheet aspects of CSS cascading **/
michael@0 22
michael@0 23 var style_element = document.createElement("style");
michael@0 24 var style_contents = document.createTextNode("");
michael@0 25 style_element.appendChild(style_contents);
michael@0 26 document.getElementsByTagName("head")[0].appendChild(style_element);
michael@0 27
michael@0 28 var div = document.getElementById("content");
michael@0 29 var cs = window.getComputedStyle(div, "");
michael@0 30 var zindex = 0;
michael@0 31
michael@0 32 /**
michael@0 33 * Given the selectors |sel1| and |sel2|, in that order (the "order"
michael@0 34 * aspect of the cascade), with declarations that are !important if
michael@0 35 * |imp1|/|imp2| are true, assert that the one that wins in the
michael@0 36 * cascading order is given by |winning| (which must be either 1 or 2).
michael@0 37 */
michael@0 38 function do_test(sel1, imp1, sel2, imp2, winning) {
michael@0 39 var ind1 = ++zindex;
michael@0 40 var ind2 = ++zindex;
michael@0 41 style_contents.data =
michael@0 42 sel1 + " { z-index: " + ind1 + (imp1 ? "!important" :"") + " } " +
michael@0 43 sel2 + " { z-index: " + ind2 + (imp2 ? "!important" :"") + " } ";
michael@0 44 var result = cs.zIndex;
michael@0 45 is(result, (winning == 1) ? ind1 : ind2,
michael@0 46 "cascading of " + style_contents.data);
michael@0 47 }
michael@0 48
michael@0 49 // Test order, and order combined with !important
michael@0 50 do_test("div", false, "div", false, 2);
michael@0 51 do_test("div", false, "div", true, 2);
michael@0 52 do_test("div", true, "div", false, 1);
michael@0 53 do_test("div", true, "div", true, 2);
michael@0 54
michael@0 55 // Test specificity on a single element
michael@0 56 do_test("div", false, "div.content_class", false, 2);
michael@0 57 do_test("div.content_class", false, "div", false, 1);
michael@0 58
michael@0 59 // Test specificity across elements
michael@0 60 do_test("body#thebody div", false, "body div.content_class", false, 1);
michael@0 61 do_test("body div.content_class", false, "body#thebody div", false, 2);
michael@0 62
michael@0 63 // Test specificity combined with !important
michael@0 64 do_test("div.content_class", false, "div", false, 1);
michael@0 65 do_test("div.content_class", true, "div", false, 1);
michael@0 66 do_test("div.content_class", false, "div", true, 2);
michael@0 67 do_test("div.content_class", true, "div", true, 1);
michael@0 68
michael@0 69 function do_test_greater(sel1, sel2) {
michael@0 70 do_test(sel1, false, sel2, false, 1);
michael@0 71 do_test(sel2, false, sel1, false, 2);
michael@0 72 }
michael@0 73
michael@0 74 function do_test_equal(sel1, sel2) {
michael@0 75 do_test(sel1, false, sel2, false, 2);
michael@0 76 do_test(sel2, false, sel1, false, 2);
michael@0 77 }
michael@0 78
michael@0 79 // Test specificity of contents of :not()
michael@0 80 do_test_equal("div.content_class", "div:not(.wrong_class)");
michael@0 81 do_test_greater("div.content_class.content_class", "div.content_class");
michael@0 82 do_test_greater("div.content_class", "div");
michael@0 83 do_test_greater("div:not(.wrong_class)", "div");
michael@0 84 do_test_greater("div:not(.wrong_class):not(.wrong_class)",
michael@0 85 "div:not(.wrong_class)");
michael@0 86
michael@0 87 </script>
michael@0 88 </pre>
michael@0 89 </body>
michael@0 90 </html>
michael@0 91

mercurial