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 |
| 9 if (window.testRunner) |
| 10 testRunner.dumpAsText(); |
9 | 11 |
10 var sandbox = document.getElementById("sandbox"); | 12 var sandbox = document.getElementById("sandbox"); |
11 var iframe = document.createElement("iframe"); | 13 var iframe = document.createElement("iframe"); |
12 sandbox.appendChild(iframe); | 14 sandbox.appendChild(iframe); |
13 | 15 |
14 var matchMedia = iframe.contentWindow.matchMedia; | 16 var matchMedia = iframe.contentWindow.matchMedia; |
15 var mediaList = matchMedia("(max-width: 100px)"); | 17 var mediaList = matchMedia("(max-width: 100px)"); |
16 var expectedValue = ""; | 18 var expectedValue = ""; |
17 | 19 |
18 var tests = []; | |
19 var currentTest = 0; | |
20 function runNextTest() { | |
21 tests[currentTest++](); | |
22 } | |
23 function listener(list) { | 20 function listener(list) { |
24 window.mediaListArgument = list; | 21 window.mediaListArgument = list; |
25 shouldBe("mediaList", "mediaListArgument"); | 22 shouldBe("mediaList", "mediaListArgument"); |
26 shouldBe("mediaList.matches", expectedValue); | 23 shouldBe("mediaList.matches", expectedValue); |
27 runNextTest(); | |
28 } | 24 } |
29 | 25 |
30 mediaList.addListener(listener); | 26 mediaList.addListener(listener); |
31 | 27 |
32 shouldBe("mediaList.matches", "true"); | 28 shouldBe("mediaList.matches", "true"); |
33 | 29 |
| 30 // FIXME: You shouldn't need to touch offsetTop to force these updates. |
| 31 |
34 // Should fire. | 32 // Should fire. |
35 iframe.style.width = "200px"; | 33 iframe.style.width = "200px"; |
36 expectedValue = "false"; | 34 expectedValue = "false"; |
| 35 iframe.offsetTop; |
37 | 36 |
38 tests.push(function() { | 37 // Should not fire. |
39 // Should not fire. | 38 iframe.style.width = "250px"; |
40 iframe.style.width = "250px"; | 39 expectedValue = "false"; |
41 expectedValue = "false"; | 40 iframe.offsetTop; |
42 | 41 |
43 setTimeout(runNextTest, 20); | 42 // Should fire. |
44 }); | 43 iframe.style.width = "80px"; |
| 44 expectedValue = "true"; |
| 45 iframe.offsetTop; |
45 | 46 |
46 tests.push(function() { | 47 // Should not fire. |
47 // Should fire. | 48 mediaList.removeListener(listener); |
48 iframe.style.width = "80px"; | 49 iframe.style.width = "200px"; |
49 expectedValue = "true"; | 50 iframe.offsetTop; |
50 }); | 51 shouldBe("mediaList.matches", "false"); |
51 | |
52 tests.push(function() { | |
53 // Should not fire. | |
54 mediaList.removeListener(listener); | |
55 iframe.style.width = "200px"; | |
56 iframe.offsetTop; | |
57 shouldBe("mediaList.matches", "false"); | |
58 | |
59 setTimeout(finishJSTest, 20); | |
60 }); | |
61 </script> | 52 </script> |
OLD | NEW |