summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/update-the-image-data/current-request-microtask.html
blob: 125b37eadb4b793425814bf30052e3e5fb0b3f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<title>An img's current request should be updated in a microtask after selecting an image source</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>

<script>
async_test(function(t) {
  const picture = document.createElement("picture");

  const nonMatchingSource = document.createElement("source");
  nonMatchingSource.media = "not all";
  nonMatchingSource.srcset = "data:,a";
  picture.append(nonMatchingSource);

  const matchingSource = document.createElement("source");
  matchingSource.media = "all";
  matchingSource.srcset = "data:,b";
  picture.append(matchingSource);

  const img = document.createElement("img");
  img.src = "data:,c";

  assert_equals(img.currentSrc, "", "after assigning to img.src but before the corresponding microtask is run");

  queueMicrotask(t.step_func(function() {
    assert_equals(img.currentSrc, "data:,c", "after assigning to img.src and after corresponding microtask is run");

    picture.append(img);
    assert_equals(img.currentSrc, "data:,c", "after appending img to picture but before the corresponding microtask is run");

    queueMicrotask(t.step_func(function() {
      assert_equals(img.currentSrc, "data:,b", "after appending img to picture and after the corresponding microtask is run");
      t.done();
    }));
  }));
}, "currentSrc is updated only after the microtask that updates the current request is run");
</script>