summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/xslt/transformToFragment.tentative.window.js
blob: 7bb6a5685544bfea53613af5a539d870385e6df0 (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
39
const cases = {
  internal: '<script>window.internalScript = true;</script>',
  external: '<script src="externalScript.js"></script>',
};

const loaded = new Promise(resolve => {
  window.addEventListener('load', resolve);
});

Object.entries(cases).forEach(([k, v]) => {
  const xsltSrc = `<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" version="5"/>
<xsl:template match="/">
  <section>
    ${v}
  </section>
</xsl:template>
</xsl:stylesheet>`;

  const processor = new XSLTProcessor();
  const parser = new DOMParser();
  processor.importStylesheet(
    parser.parseFromString(xsltSrc, 'application/xml')
  );
  document.body.appendChild(
    processor.transformToFragment(
      parser.parseFromString('<x/>', 'application/xml'),
      document
    )
  );

  promise_test(async () => {
    await loaded;
    assert_true(
      window[`${k}Script`],
      'script element from XSLTProcessor.transformToFragment() is evaluated'
    );
  }, `${k} script`);
})