| <!DOCTYPE html> |
| <title>Make sure the image's display dimensions adapt to viewport changes even if the picked resource wasn't changed</title> |
| <script src="../../../resources/testharness.js"></script> |
| <script src="../../../resources/testharnessreport.js"></script> |
| <iframe style="width: 70px;"></iframe> |
| <script> |
| async_test(function(t) { |
| var iframe = document.querySelector('iframe'); |
| var iframeDoc = iframe.contentWindow.document; |
| |
| document.body.offsetTop; |
| iframeDoc.body.innerHTML = '<img id="srcset" srcset="resources/blue_rect.jpg 75w, resources/image-set-4x.png 120w">'; |
| iframeDoc.body.offsetTop; |
| |
| img = iframeDoc.getElementById('srcset'); |
| |
| var first = true; |
| img.onload = t.step_func(function() { |
| assert_true(first); |
| first = false; |
| assert_not_equals(img.currentSrc.indexOf("blue_rect.jpg"), -1); |
| assert_true(iframe.contentWindow.matchMedia('(width: 70px)').matches); |
| assert_equals(img.width, 70); |
| |
| iframe.style.width = '75px'; |
| // Make sure that once 2 RAFs have passed, the image is set to the right dimensions. |
| requestAnimationFrame(function() { |
| requestAnimationFrame(function() { |
| setTimeout(t.step_func(function() { |
| assert_not_equals(img.currentSrc.indexOf("blue_rect.jpg"), -1); |
| assert_equals(img.width, 75); |
| t.done(); |
| }), 0); |
| }); |
| }); |
| }); |
| }); |
| </script> |