OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../resources/js-test.js"></script> |
| 3 |
| 4 <div id="sandbox"></div> |
| 5 |
| 6 <script> |
| 7 description("Media query listeners should fire on changes to matches status.
"); |
| 8 |
| 9 if (window.testRunner) |
| 10 testRunner.dumpAsText(); |
| 11 |
| 12 var sandbox = document.getElementById("sandbox"); |
| 13 var iframe = document.createElement("iframe"); |
| 14 sandbox.appendChild(iframe); |
| 15 |
| 16 var matchMedia = iframe.contentWindow.matchMedia; |
| 17 var mediaList = matchMedia("(max-width: 100px)"); |
| 18 var expectedValue = ""; |
| 19 |
| 20 function listener(list) { |
| 21 window.mediaListArgument = list; |
| 22 shouldBe("mediaList", "mediaListArgument"); |
| 23 shouldBe("mediaList.matches", expectedValue); |
| 24 } |
| 25 |
| 26 mediaList.addListener(listener); |
| 27 |
| 28 shouldBe("mediaList.matches", "true"); |
| 29 |
| 30 // FIXME: You shouldn't need to touch offsetTop to force these updates. |
| 31 |
| 32 // Should fire. |
| 33 iframe.style.width = "200px"; |
| 34 expectedValue = "false"; |
| 35 iframe.offsetTop; |
| 36 |
| 37 // Should not fire. |
| 38 iframe.style.width = "250px"; |
| 39 expectedValue = "false"; |
| 40 iframe.offsetTop; |
| 41 |
| 42 // Should fire. |
| 43 iframe.style.width = "80px"; |
| 44 expectedValue = "true"; |
| 45 iframe.offsetTop; |
| 46 |
| 47 // Should not fire. |
| 48 mediaList.removeListener(listener); |
| 49 iframe.style.width = "200px"; |
| 50 iframe.offsetTop; |
| 51 shouldBe("mediaList.matches", "false"); |
| 52 </script> |
OLD | NEW |