summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/trusted-types/trusted-types-duplicate-names-without-enforcement.tentative.html
blob: afef457a9c2328c69c9856a045a94613629a44f7 (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
<!DOCTYPE html>
<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
const policy = { createHTML: a => a };

test(t => {
  // The spec demands that duplicate policies are allowed when TT is not
  // enforced in the CSP.
  let a = trustedTypes.createPolicy("duplicatename", policy);
  let b = trustedTypes.createPolicy("duplicatename", policy);
  assert_not_equals(a, b);
  assert_true(a instanceof TrustedTypePolicy);
  assert_true(b instanceof TrustedTypePolicy);
}, "createPolicy - duplicate policies are allowed when Trusted Types are not enforced.");

test(t => {
  // The spec demands that duplicate "default" policy creation fails, even
  // when TT is not enforced.
  let p = trustedTypes.createPolicy("default", policy);
  assert_true(p instanceof TrustedTypePolicy);

  // The second instance should throw:
  assert_throws_js(TypeError, _ => trustedTypes.createPolicy("default", policy));
}, "createPolicy - duplicate \"default\" policy is never allowed.");
</script>
</body>