tor-browser

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

test_parsingMode.html (2493B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>CSSStyleSheet parsingMode test - bug 1230491</title>
      5  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
      7 <script type="application/javascript">
      8  SimpleTest.waitForExplicitFinish();
      9  function sheetText(sheet) {
     10    return [...sheet.cssRules].map(r => r.cssText).join();
     11  }
     12  function run() {
     13    const sss = Cc["@mozilla.org/content/style-sheet-service;1"]
     14      .getService(Ci.nsIStyleSheetService);
     15    const utils = window.windowUtils;
     16 
     17    const userUrl = encodeURI("data:text/css,body { color: seagreen; -moz-window-transform: none }");
     18    utils.loadSheetUsingURIString(userUrl, sss.USER_SHEET);
     19 
     20    const agentUrl = encodeURI("data:text/css,body { color: tomato; }");
     21    utils.loadSheetUsingURIString(agentUrl, sss.AGENT_SHEET);
     22 
     23    const authorUrl = "chrome://mochikit/content/tests/SimpleTest/test.css";
     24 
     25    let results = [];
     26    for (let sheet of InspectorUtils.getAllStyleSheets(document)) {
     27      if (sheet.href === agentUrl) {
     28        is(sheet.parsingMode, "agent", "agent sheet has expected mode");
     29        results[sss.AGENT_SHEET] = 1;
     30      } else if (sheet.href === userUrl) {
     31        is(sheet.parsingMode, "user", "user sheet has expected mode");
     32        is(sheet.cssRules[0].style.length, 2, "Chrome-only properties are parsed in user sheet")
     33        results[sss.USER_SHEET] = 1;
     34      } else if (sheet.href === authorUrl) {
     35        is(sheet.parsingMode, "author", "author sheet has expected mode");
     36        results[sss.AUTHOR_SHEET] = 1;
     37      } else {
     38        // Ignore sheets we don't care about.
     39        continue;
     40      }
     41 
     42      // Check that re-parsing preserves the mode.
     43      let mode = sheet.parsingMode;
     44      let text = sheetText(sheet);
     45      InspectorUtils.parseStyleSheet(sheet, "body { color: chartreuse; }");
     46      if (mode == "agent") {
     47        is(sheetText(sheet), text,
     48           "Reparsing should not have changed a UA sheet");
     49      } else {
     50        isnot(sheetText(sheet), text,
     51           "Reparsing should have changed a non-UA sheet");
     52      }
     53      is(sheet.parsingMode, mode,
     54         "check that re-parsing preserved mode " + mode);
     55    }
     56 
     57    ok(results[sss.AGENT_SHEET] && results[sss.USER_SHEET] &&
     58      results[sss.AUTHOR_SHEET],
     59      "all sheets seen");
     60 
     61    SimpleTest.finish();
     62  }
     63 </script>
     64 </head>
     65 <body onload="run()">
     66  <div> What? </div>
     67 </body>
     68 </html>