current-request-microtask.html (1479B)
1 <!DOCTYPE html> 2 <title>An img's current request should be updated in a microtask after selecting an image source</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <div id=log></div> 6 7 <script> 8 async_test(function(t) { 9 const picture = document.createElement("picture"); 10 11 const nonMatchingSource = document.createElement("source"); 12 nonMatchingSource.media = "not all"; 13 nonMatchingSource.srcset = "data:,a"; 14 picture.append(nonMatchingSource); 15 16 const matchingSource = document.createElement("source"); 17 matchingSource.media = "all"; 18 matchingSource.srcset = "data:,b"; 19 picture.append(matchingSource); 20 21 const img = document.createElement("img"); 22 img.src = "data:,c"; 23 24 assert_equals(img.currentSrc, "", "after assigning to img.src but before the corresponding microtask is run"); 25 26 queueMicrotask(t.step_func(function() { 27 assert_equals(img.currentSrc, "data:,c", "after assigning to img.src and after corresponding microtask is run"); 28 29 picture.append(img); 30 assert_equals(img.currentSrc, "data:,c", "after appending img to picture but before the corresponding microtask is run"); 31 32 queueMicrotask(t.step_func(function() { 33 assert_equals(img.currentSrc, "data:,b", "after appending img to picture and after the corresponding microtask is run"); 34 t.done(); 35 })); 36 })); 37 }, "currentSrc is updated only after the microtask that updates the current request is run"); 38 </script>