summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/trusted-types/no-require-trusted-types-for.tentative.html
blob: 651bf0a7199beab43e4f00d3c72462ffda1905f2 (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
40
41
42
43
44
<!DOCTYPE html>
<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
  const testCases = [
    ["script", "src"],
    ["div", "innerHTML"],
    ["script", "text"],
  ];

  testCases.forEach(c => {
    const name = `${c[0]}.${c[1]} `;
    test(t => {
      s = document.createElement(c[0]);
      s[c[1]] = "https://example.com/";
      assert_equals("https://example.com/", s[c[1]].toString());
    }, name + "without trusted types");
  });

  p = trustedTypes.createPolicy("policyA",
      {createScript: s => s + 1, createHTML: s => s + 1, createScriptURL: s => s + 1});
  testCases.forEach(c => {
    const name = `${c[0]}.${c[1]} `;
    test(t => {
      s = document.createElement("script");
      script = p.createScript("1");
      s.innerText = script;
      assert_equals(script.toString(), s.innerText.toString());
    }, name + "with trusted types");
  });

  trustedTypes.createPolicy("default", {});
  testCases.forEach(c => {
    const name = `${c[0]}.${c[1]} `;
    test(t => {
      s = document.createElement("script");
      s.innerText = "1";
      assert_equals(s.innerText.toString(), "1");
    }, name + "empty default");
  });
</script>