summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/trusted-types/TrustedTypePolicyFactory-getAttributeType-namespace.html
blob: 0f0d820e289fd12d2c3c7200a1ebb944f4b4b58a (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<script src="/resources/testharness.js" ></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Tests for getAttributeType with namespaces, based on
// https://crbug.com/1305293 (attachment on comment 0).

const parser = new DOMParser();
[
  parser.parseFromString(
    '<!doctype html><html><head><script src="./foo.js"><'+'/script></head></html>',
    'text/html'),
  parser.parseFromString(
    '<html xmlns="http://www.w3.org/1999/xhtml"><head><script src="./foo.js" /></head></html>',
    'application/xhtml+xml'),
  parser.parseFromString(
  '<xml xmlns:html="http://www.w3.org/1999/xhtml"><html:script src="./foo.js" /></xml>',
  'application/xml')
].forEach((doc, index) => {
  const element = doc.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", 'script')[0];
  const attribute = element.getAttributeNode("src");

  test(_ => {
    assert_equals(trustedTypes.getAttributeType(
      element.localName, attribute.name, element.namespaceURI, attribute.namespaceURI),
      "TrustedScriptURL");
  }, `${index}: getAttributeType with full namespace info.`);

  test(_ => {
    assert_equals(trustedTypes.getAttributeType(
      element.localName, attribute.name, element.namespaceURI, undefined),
      "TrustedScriptURL");
  },`${index}: getAttributeType with element namespace and empty attribute namespace`);

  test(_ => {
    assert_equals(trustedTypes.getAttributeType(
        element.localName, attribute.name, undefined, undefined), "TrustedScriptURL");
  }, `${index}: getAttributeType without namespaces.`);

  test(_ => {
    assert_equals(trustedTypes.getAttributeType(
        element.localName, attribute.name, undefined, ""), "TrustedScriptURL");
  }, `${index}: getAttributeType with undefined and empty namespace.`);

  test(_ => {
    assert_equals(trustedTypes.getAttributeType(
      element.localName, attribute.name, "", undefined), "TrustedScriptURL");
  }, `${index}: getAttributeType with empty and undefined namespace.`);

  test(_ => {
    assert_equals(trustedTypes.getAttributeType(
        element.localName, attribute.name, "", ""), "TrustedScriptURL");
  }, `${index}: getAttributeType with empty namespaces.`);

  test(_ => {
    assert_equals(trustedTypes.getAttributeType(
        element.localName, attribute.name, element.namespaceURI, ""), "TrustedScriptURL");
  }, `${index}: getAttributeType with element namespace and empty attribute namespace.`);
});
</script>
</body>