4 <script src=
"../../resources/js-test.js"></script>
6 <div id=
"detector"></div>
9 #detector { width:
100px; }
10 @media (resolution:
1.00dppx) { #detector { width:
10px; } }
11 @media (resolution:
1.50dppx) { #detector { width:
15px; } }
12 @media (resolution:
2.00dppx) { #detector { width:
20px; } }
13 @media (resolution:
2.25dppx) { #detector { width:
23px; } }
14 @media print and (min-resolution:
3dppx) { #detector { width:
30px; } }
18 description("CSS3 media query test: resolution query with dppx. Using style element, @media css rule.")
20 if (window
.testRunner
&& window
.internals
) {
21 window
.testRunner
.dumpAsText();
23 function resolutionFromStyle() {
24 var width
= getComputedStyle(document
.getElementById("detector")).width
;
43 function appendMediaRule(rule
) {
44 var lastStyleSheet
= document
.styleSheets
[document
.styleSheets
.length
- 1];
45 lastStyleSheet
.insertRule(rule
, lastStyleSheet
.cssRules
.length
);
48 shouldBe("matchMedia('(resolution: 0dpi)').matches", "false");
49 shouldBe("matchMedia('(min-resolution: 0dpi)').matches", "false");
50 shouldBe("matchMedia('(max-resolution: 0dpi)').matches", "false");
52 window
.internals
.setDeviceScaleFactor(1.5)
53 shouldBe("matchMedia('(resolution: 1.5dppx)').matches", "true");
54 shouldBe("resolutionFromStyle()", "1.5");
56 window
.internals
.setDeviceScaleFactor(2);
57 shouldBe("matchMedia('(resolution: 2dppx)').matches", "true");
58 shouldBe("resolutionFromStyle()", "2");
60 window
.internals
.setDeviceScaleFactor(1);
61 shouldBe("matchMedia('(resolution: 1dppx)').matches", "true");
62 shouldBe("resolutionFromStyle()", "1");
64 window
.internals
.setDeviceScaleFactor(2.25);
65 shouldBe("matchMedia('(resolution: 2.25dppx)').matches", "true");
66 shouldBe("resolutionFromStyle()", "2.25");
67 shouldBe("matchMedia('(resolution)').matches", "true");
68 shouldBe("matchMedia('(resolution: 216dpi)').matches", "true");
69 shouldBe("matchMedia('(min-resolution: 216dpi)').matches", "true");
70 shouldBe("matchMedia('(max-resolution: 216dpi)').matches", "true");
72 shouldBe("matchMedia('(resolution: 85dpcm)').matches", "true");
73 shouldBe("matchMedia('(min-resolution: 85dpcm)').matches", "true");
74 shouldBe("matchMedia('(max-resolution: 85dpcm)').matches", "true");
78 window
.internals
.settings
.setMediaTypeOverride("print");
79 shouldBe("matchMedia('(min-resolution: 300dpi)').matches", "true");
80 shouldBe("matchMedia('(min-resolution: 118dpcm)').matches", "true");
82 // Should match the one requiring 'print' media type.
83 shouldBe("resolutionFromStyle()", "3");
85 // As well as those matching 'all'.
86 appendMediaRule("@media (resolution: 3.125dppx) { #detector { width: 31px; } }");
87 shouldBe("resolutionFromStyle()", "3.125");