tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_styles-computed.html (5033B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug </title>
      9 
     10  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     11  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
     12  <script type="application/javascript" src="inspector-helpers.js"></script>
     13  <script type="application/javascript">
     14 "use strict";
     15 
     16 window.onload = function() {
     17  SimpleTest.waitForExplicitFinish();
     18  runNextTest();
     19 };
     20 
     21 let gWalker = null;
     22 let gStyles = null;
     23 
     24 addTest(async function setup() {
     25  const url = document.getElementById("inspectorContent").href;
     26  const { target } = await attachURL(url);
     27  const inspector = await target.getFront("inspector");
     28  gWalker = inspector.walker;
     29  gStyles = await inspector.getPageStyle();
     30  runNextTest();
     31 });
     32 
     33 addTest(function testComputed() {
     34  promiseDone(
     35    gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
     36      return gStyles.getComputed(node, {});
     37    }).then(computed => {
     38      // Test a smattering of properties that include some system-defined
     39      // props, some props that were defined in this node's stylesheet,
     40      // and some default props.
     41      is(computed["white-space-collapse"].value, "collapse", "Default value should appear");
     42      is(computed.display.value, "block", "System stylesheet item should appear");
     43      is(computed.cursor.value, "crosshair", "Included stylesheet rule should appear");
     44      is(computed.color.value, "rgb(255, 0, 0)",
     45         "Inherited style attribute should appear");
     46      is(computed["font-size"].value, "15px", "Inherited inline rule should appear");
     47 
     48      // We didn't request markMatched, so these shouldn't be set
     49      ok(!computed.cursor.matched, "Didn't ask for matched, shouldn't get it");
     50      ok(!computed.color.matched, "Didn't ask for matched, shouldn't get it");
     51      ok(!computed["font-size"].matched, "Didn't ask for matched, shouldn't get it");
     52    }).then(runNextTest)
     53  );
     54 });
     55 
     56 addTest(function testComputedUserMatched() {
     57  promiseDone(
     58    gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
     59      return gStyles.getComputed(node, { filter: "user", markMatched: true });
     60    }).then(computed => {
     61      ok(!computed["white-space-collapse"].matched, "Default style shouldn't match");
     62      ok(!computed.display.matched, "Only user styles should match");
     63      ok(computed.cursor.matched, "Asked for matched, should get it");
     64      ok(computed.color.matched, "Asked for matched, should get it");
     65      ok(computed["font-size"].matched, "Asked for matched, should get it");
     66    }).then(runNextTest)
     67  );
     68 });
     69 
     70 addTest(function testComputedSystemMatched() {
     71  promiseDone(
     72    gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
     73      return gStyles.getComputed(node, { filter: "ua", markMatched: true });
     74    }).then(computed => {
     75      ok(!computed["white-space-collapse"].matched, "Default style shouldn't match");
     76      ok(computed.display.matched, "System stylesheets should match");
     77      ok(computed.cursor.matched, "Asked for matched, should get it");
     78      ok(computed.color.matched, "Asked for matched, should get it");
     79      ok(computed["font-size"].matched, "Asked for matched, should get it");
     80    }).then(runNextTest)
     81  );
     82 });
     83 
     84 addTest(function testComputedUserOnlyMatched() {
     85  promiseDone(
     86    gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
     87      return gStyles.getComputed(node, { filter: "user", onlyMatched: true });
     88    }).then(computed => {
     89      ok(!("white-space-collapse" in computed), "Default style shouldn't exist");
     90      ok(!("display" in computed), "System stylesheets shouldn't exist");
     91      ok(("cursor" in computed), "User items should exist.");
     92      ok(("color" in computed), "User items should exist.");
     93      ok(("font-size" in computed), "User items should exist.");
     94    }).then(runNextTest)
     95  );
     96 });
     97 
     98 addTest(function testComputedSystemOnlyMatched() {
     99  promiseDone(
    100    gWalker.querySelector(gWalker.rootNode, "#computed-test-node").then(node => {
    101      return gStyles.getComputed(node, { filter: "ua", onlyMatched: true });
    102    }).then(computed => {
    103      ok(!("white-space-collapse" in computed), "Default style shouldn't exist");
    104      ok(("display" in computed), "System stylesheets should exist");
    105      ok(("cursor" in computed), "User items should exist.");
    106      ok(("color" in computed), "User items should exist.");
    107      ok(("font-size" in computed), "User items should exist.");
    108    }).then(runNextTest)
    109  );
    110 });
    111 
    112 addTest(function cleanup() {
    113  gStyles = null;
    114  gWalker = null;
    115  runNextTest();
    116 });
    117 
    118  </script>
    119 </head>
    120 <body>
    121 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
    122 <a id="inspectorContent" target="_blank" href="inspector-styles-data.html">Test Document</a>
    123 <p id="display"></p>
    124 <div id="content" style="display: none">
    125 
    126 </div>
    127 <pre id="test">
    128 </pre>
    129 </body>
    130 </html>