2 <script src=
"../../resources/js-test.js"></script>
4 window
.jsTestIsAsync
= true;
6 document
.querySelector("iframe").style
.width
= "500px";
7 shouldBe("getComputedStyle(document.querySelector('iframe').contentDocument.querySelector('.cssom')).backgroundColor", "\"rgb(0, 128, 0)\"");
8 shouldBe("getComputedStyle(document.querySelector('iframe').contentDocument.querySelector('.cssom-import')).backgroundColor", "\"rgb(0, 128, 0)\"");
12 <iframe style=
"width: 300px; height: 300px;" srcdoc='
14 .cssom-import, .cssom, .std {
18 @media (max-width:
400px) {
20 background-color: green;
24 <style id=
"media-rule"></style>
25 <style id=
"import-rule"></style>
27 Tests that dynamically inserted media rules apply. The boxes below should be green.
<br>
29 <div class=
"std">The styles for this box are handled in standard CSS.
</div>
30 <div class=
"cssom">The styles for this box are handled via CSS created dynamically.
</div>
31 <div class=
"cssom-import">The styles for this box are handled via CSS created dynamically with an import rule.
</div>
34 document
.getElementById("media-rule").sheet
.insertRule("@media (max-width: 400px) { .cssom { background: red; display: block; }}", 0);
35 document
.getElementById("import-rule").sheet
.insertRule("@import url(resources/media-query-insert-rule.css) (max-width: 400px)", 0);
37 function hasImportLoaded() {
38 return document
.getElementById("import-rule").sheet
.rules
[0].styleSheet
;
41 function runTestOnImportLoad() {
42 if (hasImportLoaded())
45 setTimeout(runTestOnImportLoad
);
48 document
.documentElement
.offsetTop
;
49 runTestOnImportLoad();