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