OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../../resources/js-test.js"></script> | 2 <script src="../../resources/js-test.js"></script> |
3 | 3 |
4 <div id="sandbox"></div> | 4 <div id="sandbox"></div> |
5 | 5 |
6 <script> | 6 <script> |
7 description("Media query listeners should fire on changes to matches status.
"); | 7 description("Media query listeners should fire on changes to matches status.
"); |
8 var jsTestIsAsync = true; | 8 var jsTestIsAsync = true; |
9 | 9 |
10 var sandbox = document.getElementById("sandbox"); | 10 var sandbox = document.getElementById("sandbox"); |
11 var iframe = document.createElement("iframe"); | 11 var iframe = document.createElement("iframe"); |
12 sandbox.appendChild(iframe); | 12 sandbox.appendChild(iframe); |
13 | 13 |
14 var matchMedia = iframe.contentWindow.matchMedia; | 14 var matchMedia = iframe.contentWindow.matchMedia; |
15 var mediaList = matchMedia("(max-width: 100px)"); | 15 var mediaList = matchMedia("(max-width: 100px)"); |
16 var expectedValue = ""; | 16 var expectedValue = ""; |
17 | 17 |
18 var tests = []; | 18 var tests = []; |
19 var currentTest = 0; | 19 var currentTest = 0; |
20 function runNextTest() { | 20 function runNextTest() { |
21 tests[currentTest++](); | 21 tests[currentTest++](); |
22 } | 22 } |
23 function listener(list) { | 23 function listener(list) { |
24 window.mediaListArgument = list; | 24 window.mediaListArgument = list; |
25 shouldBe("mediaList", "mediaListArgument"); | 25 shouldBe("mediaList.matches", "mediaListArgument.matches"); |
| 26 shouldBe("mediaList.media", "mediaListArgument.media"); |
26 shouldBe("mediaList.matches", expectedValue); | 27 shouldBe("mediaList.matches", expectedValue); |
27 runNextTest(); | 28 runNextTest(); |
28 } | 29 } |
29 | 30 |
30 mediaList.addListener(listener); | 31 mediaList.addListener(listener); |
31 | 32 |
32 shouldBe("mediaList.matches", "true"); | 33 shouldBe("mediaList.matches", "true"); |
33 | 34 |
34 // Should fire. | 35 // Should fire. |
35 iframe.style.width = "200px"; | 36 iframe.style.width = "200px"; |
(...skipping 16 matching lines...) Expand all Loading... |
52 tests.push(function() { | 53 tests.push(function() { |
53 // Should not fire. | 54 // Should not fire. |
54 mediaList.removeListener(listener); | 55 mediaList.removeListener(listener); |
55 iframe.style.width = "200px"; | 56 iframe.style.width = "200px"; |
56 iframe.offsetTop; | 57 iframe.offsetTop; |
57 shouldBe("mediaList.matches", "false"); | 58 shouldBe("mediaList.matches", "false"); |
58 | 59 |
59 setTimeout(finishJSTest, 20); | 60 setTimeout(finishJSTest, 20); |
60 }); | 61 }); |
61 </script> | 62 </script> |
OLD | NEW |