Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/layout/style/test/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 4 kB image not shown  

Quelle  test_addSheet.html   Sprache: HTML

 

 products/Sources/formale Sprachen/C/Firefox/layout/style/test/test_addSheet.html


<!DOCTYPE HTML>
<html>
<head>
  <title>Test for addSheet</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1024707">Mozilla Bug 1024707</a>

<iframe id="iframe1" src="additional_sheets_helper.html"></iframe>
<iframe id="iframe2" src="additional_sheets_helper.html"></iframe>

<pre id="test">
<script type="application/javascript">

let gIOService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
  .getService(SpecialPowers.Ci.nsIIOService);

let gSSService = SpecialPowers.Cc["@mozilla.org/content/style-sheet-service;1"]
  .getService(SpecialPowers.Ci.nsIStyleSheetService);

function test(win, sheet) {
  let cs = win.getComputedStyle(win.document.body);
  is(cs.getPropertyValue("color"), "rgb(0, 0, 0)", "should have default color");
  var windowUtils = SpecialPowers.getDOMWindowUtils(win);
  windowUtils.addSheet(sheet, SpecialPowers.Ci.nsIDOMWindowUtils.USER_SHEET);
  is(cs.getPropertyValue("color"), "rgb(255, 0, 0)", "should have changed color to red");
}

function onDocumentElementInserted(url, callback) {
  const obs = SpecialPowers.Services.obs;
  function observer(doc) {
    if (doc.URL === url) {
      obs.removeObserver(observer, "document-element-inserted");
      callback(doc);
    }
  };
  obs.addObserver(observer, "document-element-inserted");
}

// Resolves when the document (and iframe1 + iframe2) have loaded.
const loadedPromise = new Promise(resolve => {
  window.addEventListener("load", () => resolve(), { once: true });
});
add_setup(async () => loadedPromise);

add_task(async function test_addSheet_in_existing_frame() {
  var uri = gIOService.newURI("data:text/css,body{color:red;}");
  let sheet = gSSService.preloadSheet(uri, SpecialPowers.Ci.nsIStyleSheetService.USER_SHEET);

  test(document.getElementById("iframe1").contentWindow, sheet);
  test(document.getElementById("iframe2").contentWindow, sheet);
});

// Regression test for https://bugzilla.mozilla.org/show_bug.cgi?id=1961064
add_task(async function test_addSheet_order_in_new_frame() {
  const USER_SHEET = SpecialPowers.Ci.nsIStyleSheetService.USER_SHEET;
  var uri1 = gIOService.newURI("data:text/css,body{--css-var:1;}");
  var uri2 = gIOService.newURI("data:text/css,body{--css-var:2;}");
  var uri3 = gIOService.newURI("data:text/css,body{--css-var:3;}");
  var uri4 = gIOService.newURI("data:text/css,body{--css-var:4;}");
  let sheet1 = gSSService.preloadSheet(uri1, USER_SHEET);
  let sheet2 = gSSService.preloadSheet(uri2, USER_SHEET);
  let sheet3 = gSSService.preloadSheet(uri3, USER_SHEET);
  let sheet4 = gSSService.preloadSheet(uri4, USER_SHEET);

  let f = document.createElement("iframe");
  f.src = "additional_sheets_helper.html?frame";
  let elementInsertedPromise = new Promise(resolve => {
    onDocumentElementInserted(f.src, doc => {
      info("Testing addSheet at document-element-inserted");
      // At this point, mStyleSetFilled == false, so the initialization
      // of the styles is delayed until Document::FillStyleSet is called:
      // https://bugzilla.mozilla.org/show_bug.cgi?id=1961064#c5
      let windowUtils = SpecialPowers.getDOMWindowUtils(doc.defaultView);
      windowUtils.addSheet(sheet1, USER_SHEET);
      windowUtils.addSheet(sheet2, USER_SHEET);
      resolve();
    });
  });
  await new Promise(resolve => {
    f.onload = resolve;
    document.body.append(f);
  });
  await elementInsertedPromise;
  let cs = f.contentWindow.getComputedStyle(f.contentDocument.body);
  is(cs.getPropertyValue("--css-var"), "2", "Last addSheet (2) applies last");

  info("Testing addSheet in an existing document");
  // At this point, mStyleSetFilled == true, so the style sheets are applied
  // immediately.
  let windowUtils = SpecialPowers.getDOMWindowUtils(f.contentWindow);
  windowUtils.addSheet(sheet3, USER_SHEET);
  windowUtils.addSheet(sheet4, USER_SHEET);
  is(cs.getPropertyValue("--css-var"), "4", "Last addSheet (4) applies last");

  f.remove();
});

</script>
</body>
</html>

Messung V0.5 in Prozent
C=97 H=96 G=96

¤ Dauer der Verarbeitung: 0.40 Sekunden  (vorverarbeitet am  2026-09-29) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.