|
| 1 | +<!DOCTYPE html> |
| 2 | +<title>moveBefore() updates stylesheet cascade order</title> |
| 3 | +<link rel="help" href="https://dom.spec.whatwg.org/#dom-parentnode-movebefore"> |
| 4 | +<script src="/resources/testharness.js"></script> |
| 5 | +<script src="/resources/testharnessreport.js"></script> |
| 6 | + |
| 7 | +<div id="target" class="target">target</div> |
| 8 | + |
| 9 | +<script> |
| 10 | +function createStylesheet(url) { |
| 11 | + const link = document.createElement("link"); |
| 12 | + link.rel = "stylesheet"; |
| 13 | + link.href = url; |
| 14 | + return link; |
| 15 | +} |
| 16 | + |
| 17 | +promise_test(async t => { |
| 18 | + const purple = |
| 19 | + createStylesheet("resources/stylesheet-cascade-purple.css"); |
| 20 | + const blue = |
| 21 | + createStylesheet("resources/stylesheet-cascade-blue.css"); |
| 22 | + |
| 23 | + t.add_cleanup(() => { |
| 24 | + purple.remove(); |
| 25 | + blue.remove(); |
| 26 | + }); |
| 27 | + |
| 28 | + const purpleEvents = new EventWatcher(t, purple, ["load", "error"]); |
| 29 | + const blueEvents = new EventWatcher(t, blue, ["load", "error"]); |
| 30 | + const loaded = Promise.all([ |
| 31 | + purpleEvents.wait_for("load"), |
| 32 | + blueEvents.wait_for("load"), |
| 33 | + ]); |
| 34 | + document.head.append(purple, blue); |
| 35 | + await loaded; |
| 36 | + |
| 37 | + const target = document.getElementById("target"); |
| 38 | + assert_equals(getComputedStyle(target).color, "rgb(0, 0, 255)", |
| 39 | + "the second stylesheet initially wins"); |
| 40 | + |
| 41 | + document.head.moveBefore(blue, purple); |
| 42 | + |
| 43 | + assert_equals(getComputedStyle(target).color, "rgb(128, 0, 128)", |
| 44 | + "moving the blue stylesheet first makes purple win"); |
| 45 | + |
| 46 | + purple.remove(); |
| 47 | + assert_equals(getComputedStyle(target).color, "rgb(0, 0, 255)", |
| 48 | + "removing the purple stylesheet makes blue win again"); |
| 49 | +}, "Moving loaded link stylesheets updates their cascade order"); |
| 50 | +</script> |
0 commit comments