|
12 | 12 | // This is a regression test for https://g-issues.chromium.org/issues/333739948 |
13 | 13 | // The test should hold true for any browser that supports Trusted Types. |
14 | 14 |
|
15 | | - let target = "data-x"; |
| 15 | + let iframeAttributeRemovedInCallback = null; |
16 | 16 | trustedTypes.createPolicy("default", { |
17 | 17 | createHTML: (s, _, sink) => { |
18 | | - assert_equals(sink, 'HTMLIFrameElement srcdoc'); |
19 | | - iframe.removeAttribute(target); |
| 18 | + if (iframeAttributeRemovedInCallback) { |
| 19 | + assert_equals(sink, 'HTMLIFrameElement srcdoc'); |
| 20 | + iframe.removeAttribute(iframeAttributeRemovedInCallback); |
| 21 | + } |
20 | 22 | return s; |
21 | 23 | }, |
22 | 24 | createScript: (s) => { |
|
29 | 31 | } |
30 | 32 | }); |
31 | 33 |
|
| 34 | + function cleanUpIFrameTest() { |
| 35 | + iframeAttributeRemovedInCallback = null; |
| 36 | + iframe.setAttribute("srcdoc", "content"); |
| 37 | + iframe.setAttribute("data-x", ""); |
| 38 | + } |
| 39 | + |
32 | 40 | test(t => { |
33 | 41 | // Original bug report: Delete an attribute *before* the current one. |
| 42 | + t.add_cleanup(cleanUpIFrameTest); |
| 43 | + iframeAttributeRemovedInCallback = "data-x"; |
34 | 44 | assert_equals(iframe.srcdoc, "content"); |
35 | 45 | assert_equals(iframe.getAttribute("onmouseover"), ""); |
36 | 46 | iframe.setAttribute("srcdoc", "alert(1)"); |
|
40 | 50 |
|
41 | 51 | test(t => { |
42 | 52 | // Second case: Delete the exact attribute. It still gets set. |
43 | | - target = "srcdoc"; |
44 | | - assert_equals(iframe.srcdoc, "alert(1)"); |
| 53 | + t.add_cleanup(cleanUpIFrameTest); |
| 54 | + iframeAttributeRemovedInCallback = "srcdoc"; |
| 55 | + assert_equals(iframe.srcdoc, "content"); |
45 | 56 | iframe.setAttribute("srcdoc", "new srcdoc value"); |
46 | 57 | assert_equals(iframe.srcdoc, "new srcdoc value"); |
47 | 58 | }, "Ensure the deleted attributes is modified."); |
48 | 59 |
|
49 | 60 | test(t => { |
| 61 | + t.add_cleanup(cleanUpIFrameTest); |
| 62 | + iframeAttributeRemovedInCallback = "data-x"; |
| 63 | + assert_equals(iframe.srcdoc, "content"); |
| 64 | + assert_equals(iframe.getAttribute("onmouseover"), ""); |
| 65 | + iframe.setAttributeNS(null, "srcdoc", "alert(1)"); |
| 66 | + assert_equals(iframe.srcdoc, "alert(1)"); |
| 67 | + assert_equals(iframe.getAttribute("onmouseover"), ""); |
| 68 | + }, "Ensure the right attributes are modified (setAttributeNS)."); |
| 69 | + |
| 70 | + test(t => { |
| 71 | + t.add_cleanup(cleanUpIFrameTest); |
| 72 | + iframeAttributeRemovedInCallback = "srcdoc"; |
| 73 | + assert_equals(iframe.srcdoc, "content"); |
| 74 | + iframe.setAttributeNS(null, "srcdoc", "new srcdoc value"); |
| 75 | + assert_equals(iframe.srcdoc, "new srcdoc value"); |
| 76 | + }, "Ensure the deleted attributes is modified (setAttributeNS)."); |
| 77 | + |
| 78 | + function cleanUpDivTest() { |
| 79 | + div.removeAttribute('onmouseover'); |
| 80 | + } |
| 81 | + const expectedAttributeCount = 2; // id and onmouseover. |
| 82 | + |
| 83 | + test(t => { |
| 84 | + t.add_cleanup(cleanUpDivTest); |
50 | 85 | div.toggleAttribute('onmouseover'); |
51 | | - assert_equals(div.attributes.length, 2); |
| 86 | + assert_equals(div.attributes.length, expectedAttributeCount); |
52 | 87 | assert_equals(div.attributes.onmouseover.value, ''); |
53 | | - div.removeAttribute('onmouseover'); |
54 | 88 | }, "Ensure toggleAttribute results in an empty attribute."); |
55 | 89 |
|
56 | 90 | test(t => { |
| 91 | + t.add_cleanup(cleanUpDivTest); |
57 | 92 | div.setAttribute('onmouseover', 'foo'); |
58 | | - assert_equals(div.attributes.length, 2); |
| 93 | + assert_equals(div.attributes.length, expectedAttributeCount); |
59 | 94 | assert_equals(div.attributes.onmouseover.value, 'foo'); |
60 | | - div.removeAttribute('onmouseover'); |
61 | 95 | }, "Ensure setAttribute results in right attribute value."); |
62 | 96 |
|
63 | 97 | test(t => { |
| 98 | + t.add_cleanup(cleanUpDivTest); |
64 | 99 | div.setAttributeNS(null, 'onmouseover', 'foo'); |
65 | | - assert_equals(div.attributes.length, 2); |
| 100 | + assert_equals(div.attributes.length, expectedAttributeCount); |
66 | 101 | assert_equals(div.attributes.onmouseover.value, 'foo'); |
67 | | - div.removeAttribute('onmouseover'); |
68 | 102 | }, "Ensure setAttributeNS results in right attribute value."); |
69 | 103 |
|
70 | 104 | </script> |
0 commit comments