viewport-change.html (1985B)
1 <!doctype html> 2 <title>img viewport change</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/utils.js"></script> 6 <style> 7 .narrow { width:50px } 8 .wide { width:1000px } 9 </style> 10 <div id=log></div> 11 <script> 12 setup({explicit_done:true}); 13 14 function resolve(url) { 15 if (url === "") { 16 return url; 17 } 18 var a = document.createElement('a'); 19 a.href = url; 20 return a.href; 21 } 22 23 function insertIframe(className) { 24 var iframe = document.createElement('iframe'); 25 iframe.className = className; 26 iframe.src = 'iframed.sub.html?id=' + token(); 27 document.body.appendChild(iframe); 28 } 29 insertIframe('narrow'); 30 insertIframe('wide'); 31 32 var start_date = new Date(); 33 34 onload = function() { 35 var load_time = new Date() - start_date; 36 var iframes = document.getElementsByTagName('iframe'); 37 [].forEach.call(iframes, function(iframe) { 38 [].forEach.call(iframe.contentDocument.images, function(img) { 39 var expected = {wide:resolve(img.dataset.wide), narrow:resolve(img.dataset.narrow)}; 40 var current = iframe.className; 41 var next = current === 'wide' ? 'narrow' : 'wide'; 42 var expect_change = expected[next].indexOf('broken.png') === -1 && !('noChange' in img.dataset); 43 44 test(function() { 45 assert_equals(img.currentSrc, expected[current]); 46 }, img.dataset.desc + ', onload, ' + current); 47 48 async_test(function() { 49 img.onload = this.unreached_func('Got unexpected load event'); 50 img.onerror = this.unreached_func('Got unexpected error event'); 51 if (expect_change) { 52 img.onload = this.step_func_done(function() { 53 assert_equals(img.currentSrc, expected[next]); 54 }); 55 } else { 56 setTimeout(this.step_func_done(), 500 + load_time); 57 } 58 }, img.dataset.desc + ', resize to ' + next); 59 }); 60 iframe.classList.toggle('wide'); 61 iframe.classList.toggle('narrow'); 62 }); 63 done(); 64 } 65 </script>