File: image-modify-href-2.svg

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (38 lines) | stat: -rw-r--r-- 1,966 bytes parent folder | download | duplicates (12)
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
<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xmlns:h="http://www.w3.org/1999/xhtml" viewBox="0 0 4 4" width="200" height="200" class="reftest-wait">
  <metadata>
    <title>removing href from an SVG image that has a modified xlink:href</title>
    <h:link rel="match" href="reference/green-rect-100x100.svg"/>
  </metadata>
  <script href="/common/reftest-wait.js"></script>
  <script href="/common/rendering-utils.js"></script>
  <image width="2" onload="test()"
         href="data:image/svg+xml,&lt;svg xmlns='http://www.w3.org/2000/svg' width='50' height='50' &gt;&lt;rect width='50' height='50' fill='red'/&gt;&lt;/svg&gt;"
         xlink:href="data:image/svg+xml,&lt;svg xmlns='http://www.w3.org/2000/svg' width='50' height='50' &gt;&lt;rect width='50' height='50' fill='orange'/&gt;&lt;/svg&gt;"/>
  <script>
    const XLINK_NS = "http://www.w3.org/1999/xlink";
    const GREEN_DATA_URI = "data:image/svg+xml,&lt;svg xmlns='http://www.w3.org/2000/svg' width='50' height='50' &gt;&lt;rect width='50' height='50' fill='green'/&gt;&lt;/svg&gt;";
    // Our 'image' elem fires its load event twice: first for its 'href'
    // data-URI, and then again for its 'xlink:href' data-URI (after
    // our dynamic attribute-removal makes it switch to load that one).
    // But we only want test() to run for the first load, so we use
    // 'didStartTest' to nerf any invocations after the first.
    let didStartTest = false;
    async function test() {
      if (didStartTest) {
        return;
      }
      didStartTest = true;
      await waitForAtLeastOneFrame();
      let image = document.querySelector('image');
      image.setAttributeNS(XLINK_NS, 'href', GREEN_DATA_URI);
      await waitForAtLeastOneFrame();
      image.removeAttribute('href');

      /* Note: the xlink:href attribute should be left behind, intact. */
      await waitForAtLeastOneFrame();
      takeScreenshot();
    }
  </script>
</svg>