TrustedTypes tests updated to match newest API version.
Bug: 739170
Change-Id: Ia0ec627627b8ad6b208eb9351f3e7786e6d2c9b2
Reviewed-on: https://chromium-review.googlesource.com/1177752
Commit-Queue: Maja Kabus <kabusm@google.com>
Reviewed-by: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584108}
diff --git a/trusted-types/DOMParser-parseFromString.tentative.html b/trusted-types/DOMParser-parseFromString.tentative.html
new file mode 100644
index 0000000..2fe9b31
--- /dev/null
+++ b/trusted-types/DOMParser-parseFromString.tentative.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<script>
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+ let parser = new DOMParser();
+ let doc = parser.parseFromString(html, "text/html");
+ assert_equals(doc.body.innerText, RESULTS.HTML);
+ }));
+ }, "document.innerText assigned via policy (successful HTML transformation).");
+
+ test(t => {
+ var parser = new DOMParser();
+ var doc = parser.parseFromString(null, "text/html");
+ assert_equals(doc.body.innerText, "null");
+ }, "document.innerText = null.");
+</script>
diff --git a/trusted-types/DOMParser-requiresTrustedTypes.tentative.html b/trusted-types/DOMParser-requiresTrustedTypes.tentative.html
deleted file mode 100644
index 7e21fea..0000000
--- a/trusted-types/DOMParser-requiresTrustedTypes.tentative.html
+++ /dev/null
@@ -1,41 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-
-<meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-<body>
-<script>
- //HTML assignments don't throw
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var parser = new DOMParser();
- var doc = parser.parseFromString(html, "text/html");
- assert_equals(doc.body.innerText, STRINGS.unescapedHTML);
- }, "innerTextOfDoc = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var parser = new DOMParser();
- var doc = parser.parseFromString(html, "text/html");
- assert_equals(doc.body.innerText, STRINGS.unescapedText);
- }, "innerTextOfDoc = TrustedHTML.unsafelyCreate().");
-
- //Null assignment throws
- test(t => {
- var parser = new DOMParser();
- assert_throws(new TypeError(), _ => {
- var doc = parser.parseFromString(null, "text/html");
- });
- }, "'innerTextOfDoc = null' throws");
-
- // String assignments throw.
- test(t => {
- var parser = new DOMParser();
- assert_throws(new TypeError(), _ => {
- var doc = parser.parseFromString("Fail", "text/html");
- });
- }, "`innerTextOfDoc = string` throws.");
-</script>
diff --git a/trusted-types/DOMParser.tentative.html b/trusted-types/DOMParser.tentative.html
deleted file mode 100644
index 53d2b44..0000000
--- a/trusted-types/DOMParser.tentative.html
+++ /dev/null
@@ -1,28 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var parser = new DOMParser();
- var doc = parser.parseFromString(html, "text/html");
- assert_equals(doc.body.innerText, STRINGS.unescapedHTML);
- }, "innerTextOfDoc = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var parser = new DOMParser();
- var doc = parser.parseFromString(html, "text/html");
- assert_equals(doc.body.innerText, STRINGS.unescapedText);
- }, "innerTextOfDoc = TrustedHTML.unsafelyCreate().");
-
- test(t => {
- var parser = new DOMParser();
- var doc = parser.parseFromString(null, "text/html");
- assert_equals(doc.body.innerText, "null");
- }, "innerTextOfDoc = null.");
-</script>
diff --git a/trusted-types/Document-write.tentative.html b/trusted-types/Document-write.tentative.html
new file mode 100644
index 0000000..3a63e92
--- /dev/null
+++ b/trusted-types/Document-write.tentative.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<script>
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+ document.write(html);
+ assert_equals(document.body.innerText, RESULTS.HTML);
+ }));
+ }, "document.write with html assigned via policy (successful URL transformation).");
+</script>
diff --git a/trusted-types/Element-insertAdjacentHTML.tentative.html b/trusted-types/Element-insertAdjacentHTML.tentative.html
new file mode 100644
index 0000000..599ade4
--- /dev/null
+++ b/trusted-types/Element-insertAdjacentHTML.tentative.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<div id="container"></div>
+<script>
+ var container = document.querySelector('#container');
+
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+
+ var d = document.createElement('div');
+ container.appendChild(d);
+
+ d.insertAdjacentHTML('beforebegin', html);
+ assert_equals(d.previousSibling.nodeType, Node.TEXT_NODE);
+ assert_equals(d.previousSibling.data, RESULTS.HTML);
+
+ d.insertAdjacentHTML('afterbegin', html);
+ assert_equals(d.firstChild.nodeType, Node.TEXT_NODE);
+ assert_equals(d.firstChild.data, RESULTS.HTML);
+
+ d.insertAdjacentHTML('beforeend', html);
+ assert_equals(d.lastChild.nodeType, Node.TEXT_NODE);
+ assert_equals(d.lastChild.data, RESULTS.HTML);
+
+ d.insertAdjacentHTML('afterend', html);
+ assert_equals(d.nextSibling.nodeType, Node.TEXT_NODE);
+ assert_equals(d.nextSibling.data, RESULTS.HTML);
+
+ while (container.firstChild)
+ container.firstChild.remove();
+ }));
+ }, "insertAdjacentHTML with html assigned via policy (successful HTML transformation).");
+</script>
diff --git a/trusted-types/Element-outerHTML.tentative.html b/trusted-types/Element-outerHTML.tentative.html
new file mode 100644
index 0000000..a0bb6c1
--- /dev/null
+++ b/trusted-types/Element-outerHTML.tentative.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<div id="container"></div>
+<script>
+ var container = document.querySelector('#container')
+
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+
+ var d = document.createElement('div');
+ document.querySelector('#container').appendChild(d);
+ d.outerHTML = html;
+ assert_equals(container.innerText, RESULTS.HTML);
+
+ while (container.firstChild)
+ container.firstChild.remove();
+ }));
+ }, "outerHTML with html assigned via policy (successful HTML transformation).");
+</script>
diff --git a/trusted-types/HTMLElement-generic.tentative.html b/trusted-types/HTMLElement-generic.tentative.html
index 486b008..cea32a5 100644
--- a/trusted-types/HTMLElement-generic.tentative.html
+++ b/trusted-types/HTMLElement-generic.tentative.html
@@ -6,7 +6,7 @@
</head>
<body>
<script>
- //TrustedURL Assignments
+ // TrustedURL Assignments
let testCases = [
[ 'a', 'href' ],
[ 'area', 'href' ],
@@ -24,20 +24,32 @@
];
testCases.forEach(c => {
- test(t => {
- assert_accepts_trusted_url(c[0], c[1]);
- }, c[0] + "." + c[1] + " accepts TrustedURL");
+ async_test(t => {
+ assert_element_accepts_trusted_url(window, t, c[0], c[1], RESULTS.URL);
+ }, c[0] + "." + c[1] + " assigned via policy (successful URL transformation)");
});
- //TrustedScriptURL Assignments
+ // TrustedScriptURL Assignments
let scriptTestCases = [
[ 'embed', 'src' ],
[ 'script', 'src' ]
];
scriptTestCases.forEach(c => {
- test(t => {
- assert_accepts_trusted_script_url(c[0], c[1]);
- }, c[0] + "." + c[1] + " accepts TrustedScriptURL");
+ async_test(t => {
+ assert_element_accepts_trusted_script_url(window, t, c[0], c[1], RESULTS.SCRIPTURL);
+ }, c[0] + "." + c[1] + " assigned via policy (successful ScriptURL transformation)");
+ });
+
+ // TrustedHTML Assignments
+ let HTMLTestCases = [
+ [ 'div', 'innerHTML' ],
+ [ 'iframe', 'srcdoc' ]
+ ];
+
+ HTMLTestCases.forEach(c => {
+ async_test(t => {
+ assert_element_accepts_trusted_html(window, t, c[0], c[1], RESULTS.HTML);
+ }, c[0] + "." + c[1] + " assigned via policy (successful HTML transformation)");
});
</script>
diff --git a/trusted-types/Location-assign.tentative.html b/trusted-types/Location-assign.tentative.html
new file mode 100644
index 0000000..13cca56
--- /dev/null
+++ b/trusted-types/Location-assign.tentative.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<script>
+ async_test(t => {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(location.href + "#xxx");
+ location.assign(url);
+ assert_equals("" + url, location.href, "location href");
+ }));
+ }, "location.assign via policy (successful URL transformation).");
+</script>
diff --git a/trusted-types/Location-href.tentative.html b/trusted-types/Location-href.tentative.html
new file mode 100644
index 0000000..d759d28
--- /dev/null
+++ b/trusted-types/Location-href.tentative.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<script>
+ async_test(t => {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(location.href + "#xxx");
+ location.href = url;
+ assert_equals("" + url, location.href, "location href");
+ }));
+ }, "location.href assigned via policy (successful URL transformation).");
+</script>
diff --git a/trusted-types/Location-replace.tentative.html b/trusted-types/Location-replace.tentative.html
new file mode 100644
index 0000000..7d84905
--- /dev/null
+++ b/trusted-types/Location-replace.tentative.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<script>
+ async_test(t => {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(location.href + "#xxx");
+ location.replace(url);
+ assert_equals("" + url, location.href, "location href");
+ }));
+ }, "location.replace via policy (successful URL transformation).");
+</script>
diff --git a/trusted-types/Range-createContextualFragment.tentative.html b/trusted-types/Range-createContextualFragment.tentative.html
new file mode 100644
index 0000000..3d45b33
--- /dev/null
+++ b/trusted-types/Range-createContextualFragment.tentative.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<script>
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+ var range = document.createRange();
+ range.selectNodeContents(document.documentElement);
+ var result = range.createContextualFragment(html);
+ assert_equals(result.textContent, RESULTS.HTML);
+ }));
+ }, "range.createContextualFragment assigned via policy (successful HTML transformation).");
+</script>
diff --git a/trusted-types/TrustedHTML.tentative.html b/trusted-types/TrustedHTML.tentative.html
deleted file mode 100644
index a8d4e78..0000000
--- a/trusted-types/TrustedHTML.tentative.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<script>
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- assert_equals(html.toString(), STRINGS.escapedHTML);
- }, "Basic escaping.");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- assert_equals(html.toString(), STRINGS.unescapedHTML);
- }, "Basic unsafe construction.");
-</script>
diff --git a/trusted-types/TrustedScriptURL.tentative.html b/trusted-types/TrustedScriptURL.tentative.html
deleted file mode 100644
index 92bc87f..0000000
--- a/trusted-types/TrustedScriptURL.tentative.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<script>
- test(t => {
- var url = TrustedScriptURL.unsafelyCreate(URLS.safe);
-
- assert_equals(url.toString(), URLS.safe);
- }, "Basic processing: safe URL, unsafe construction.");
-
- test(t => {
- var url = TrustedScriptURL.unsafelyCreate(URLS.javascript);
-
- assert_equals(url.toString(), URLS.javascript);
- }, "Basic processing: javascript URL, unsafe construction.");
-
- test(t => {
- var url = TrustedScriptURL.unsafelyCreate(URLS.external);
-
- assert_equals(url.toString(), URLS.external);
- }, "Basic processing: external protocol URL, unsafe construction.");
-</script>
diff --git a/trusted-types/TrustedTypePolicyFactory-createPolicy.tentative.html b/trusted-types/TrustedTypePolicyFactory-createPolicy.tentative.html
index a37b5a7..d6f6b35 100644
--- a/trusted-types/TrustedTypePolicyFactory-createPolicy.tentative.html
+++ b/trusted-types/TrustedTypePolicyFactory-createPolicy.tentative.html
@@ -6,7 +6,7 @@
<script>
//Policy name test
async_test(t => {
- let policy = window.trustedTypes.createPolicy('SomeName', { createHTML: s => s } )
+ window.trustedTypes.createPolicy('SomeName', { createHTML: s => s } )
.then(t.step_func_done(policy => {
assert_true(policy instanceof TrustedTypePolicy);
assert_equals(policy.name, 'SomeName');
@@ -15,7 +15,7 @@
//HTML tests
function createHTMLTest(policy, expectedHTML, t) {
- let p = window.trustedTypes.createPolicy('SomeName', policy)
+ window.trustedTypes.createPolicy('SomeName', policy)
.then(t.step_func_done(p => {
assert_true(p.createHTML('whatever') instanceof TrustedHTML);
assert_equals(p.createHTML('whatever') + "", expectedHTML);
@@ -37,7 +37,7 @@
var HTMLx = 'global';
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', {
+ window.trustedTypes.createPolicy('SomeName', {
createHTML: s => { HTMLx = s; return s; }
})
.then(t.step_func_done(p => {
@@ -48,7 +48,7 @@
}, "html = identity function, global string changed");
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', {
+ window.trustedTypes.createPolicy('SomeName', {
createHTML: s => { throw new Error(); }
})
.then(t.step_func_done(p => {
@@ -78,7 +78,7 @@
}, "html = this without bind");
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', null)
+ window.trustedTypes.createPolicy('SomeName', null)
.then(t.step_func_done(p => {
assert_equals(p.createHTML('whatever'), null);
}));
@@ -86,45 +86,45 @@
//ScriptURL tests
function createScriptURLTest(policy, expectedScriptURL, t) {
- let p = window.trustedTypes.createPolicy('SomeName', policy)
+ window.trustedTypes.createPolicy('SomeName', policy)
.then(t.step_func_done(p => {
- assert_true(p.createScriptURL(URLS.safe) instanceof TrustedScriptURL);
- assert_equals(p.createScriptURL(URLS.safe) + "", expectedScriptURL);
+ assert_true(p.createScriptURL(INPUTS.SCRIPTURL) instanceof TrustedScriptURL);
+ assert_equals(p.createScriptURL(INPUTS.SCRIPTURL) + "", expectedScriptURL);
}));
}
async_test(t => {
- createScriptURLTest( { createScriptURL: s => s }, URLS.safe, t);
+ createScriptURLTest( { createScriptURL: s => s }, INPUTS.SCRIPTURL, t);
}, "script_url = identity function");
async_test(t => {
createScriptURLTest( { createScriptURL: s => null }, "", t);
}, "script_url = null");
- var scriptURLstr = 'duck';
+ var scriptURLstr = '#duck';
async_test(t => {
- createScriptURLTest( { createScriptURL: s => s + scriptURLstr }, URLS.safe + scriptURLstr, t);
+ createScriptURLTest( { createScriptURL: s => s + scriptURLstr }, INPUTS.SCRIPTURL + scriptURLstr, t);
}, "script_url = string + global string");
var scriptURLx = 'global';
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', {
+ window.trustedTypes.createPolicy('SomeName', {
createScriptURL: s => { ScriptURLx = s; return s; }
})
.then(t.step_func_done(p => {
- assert_true(p.createScriptURL(URLS.safe) instanceof TrustedScriptURL);
- assert_equals(p.createScriptURL(URLS.safe) + "", URLS.safe);
- assert_equals(ScriptURLx, URLS.safe);
+ assert_true(p.createScriptURL(INPUTS.SCRIPTURL) instanceof TrustedScriptURL);
+ assert_equals(p.createScriptURL(INPUTS.SCRIPTURL) + "", INPUTS.SCRIPTURL);
+ assert_equals(ScriptURLx, INPUTS.SCRIPTURL);
}));
}, "script_url = identity function, global string changed");
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', {
+ window.trustedTypes.createPolicy('SomeName', {
createScriptURL: s => { throw new Error(); }
})
.then(t.step_func_done(p => {
assert_throws(new Error(), _ => {
- p.createScriptURL(URLS.safe);
+ p.createScriptURL(INPUTS.SCRIPTURL);
});
}));
}, "script_url = callback that throws");
@@ -134,39 +134,38 @@
}
var obj = {
- "baz": "duck"
+ "baz": "#duck"
}
async_test(t => {
createScriptURLTest( {
createScriptURL: getScriptURL.bind(obj)},
- URLS.safe + "duck", t);
+ INPUTS.SCRIPTURL + "#duck", t);
}, "script_url = this bound to an object");
- var baz = "duck";
-
+ var baz = "#duck";
async_test(t => {
- createScriptURLTest( { createScriptURL: s => getScriptURL(s) }, URLS.safe + baz, t);
+ createScriptURLTest( { createScriptURL: s => getScriptURL(s) }, INPUTS.SCRIPTURL + baz, t);
}, "script_url = this without bind");
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', null)
+ window.trustedTypes.createPolicy('SomeName', null)
.then(t.step_func_done(p => {
- assert_equals(p.createScriptURL('whatever'), null);
+ assert_equals(p.createScriptURL(INPUTS.SCRIPTURL), null);
}));
}, "script_url - calling undefined callback");
//URL tests
function createURLTest(policy, expectedURL, t) {
- let p = window.trustedTypes.createPolicy('SomeName', policy)
+ window.trustedTypes.createPolicy('SomeName', policy)
.then(t.step_func_done(p => {
- assert_true(p.createURL(URLS.safe) instanceof TrustedURL);
- assert_equals(p.createURL(URLS.safe) + "", expectedURL);
+ assert_true(p.createURL(INPUTS.URL) instanceof TrustedURL);
+ assert_equals(p.createURL(INPUTS.URL) + "", expectedURL);
}));
}
async_test(t => {
- createURLTest( { createURL: s => s }, URLS.safe, t);
+ createURLTest( { createURL: s => s }, INPUTS.URL, t);
}, "url = identity function");
async_test(t => {
@@ -175,28 +174,28 @@
var URLstr = '#x';
async_test(t => {
- createURLTest( { createURL: s => s + URLstr }, URLS.safe + URLstr, t);
+ createURLTest( { createURL: s => s + URLstr }, INPUTS.URL + URLstr, t);
}, "url = string + global string");
var URLx = 'global';
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', {
+ window.trustedTypes.createPolicy('SomeName', {
createURL: s => { URLx = s; return s; }
})
.then(t.step_func_done(p => {
- assert_true(p.createURL(URLS.safe) instanceof TrustedURL);
- assert_equals(p.createURL(URLS.safe) + "", URLS.safe);
- assert_equals(URLx, URLS.safe);
+ assert_true(p.createURL(INPUTS.URL) instanceof TrustedURL);
+ assert_equals(p.createURL(INPUTS.URL) + "", INPUTS.URL);
+ assert_equals(URLx, INPUTS.URL);
}));
}, "url = identity function, global string changed");
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', {
+ window.trustedTypes.createPolicy('SomeName', {
createURL: s => { throw new Error(); }
})
.then(t.step_func_done(p => {
assert_throws(new Error(), _ => {
- p.createURL(URLS.safe);
+ p.createURL(INPUTS.URL);
});
}));
}, "url = callback that throws");
@@ -212,18 +211,18 @@
async_test(t => {
createURLTest( {
createURL: getURL.bind(obj)},
- URLS.safe + "#x", t);
+ INPUTS.URL + "#x", t);
}, "url = this bound to an object");
var bar = "#x";
async_test(t => {
- createURLTest( { createURL: s => getURL(s) }, URLS.safe + bar, t);
+ createURLTest( { createURL: s => getURL(s) }, INPUTS.URL + bar, t);
}, "url = this without bind");
async_test(t => {
- let p = window.trustedTypes.createPolicy('SomeName', null)
+ window.trustedTypes.createPolicy('SomeName', null)
.then(t.step_func_done(p => {
- assert_equals(p.createURL('whatever'), null);
+ assert_equals(p.createURL(INPUTS.URL), null);
}));
}, "url - calling undefined callback");
</script>
diff --git a/trusted-types/TrustedURL.tentative.html b/trusted-types/TrustedURL.tentative.html
deleted file mode 100644
index 5048326..0000000
--- a/trusted-types/TrustedURL.tentative.html
+++ /dev/null
@@ -1,41 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<script>
- test(t => {
- var url = TrustedURL.create(URLS.safe);
-
- assert_equals(url.toString(), URLS.safe);
- }, "Basic processing: safe URL, safe construction.");
-
- test(t => {
- var url = TrustedURL.unsafelyCreate(URLS.safe);
-
- assert_equals(url.toString(), URLS.safe);
- }, "Basic processing: safe URL, unsafe construction.");
-
- test(t => {
- var url = TrustedURL.create(URLS.javascript);
-
- assert_equals(url.toString(), URLS.sanitized);
- }, "Basic processing: javascript URL, safe construction.");
-
- test(t => {
- var url = TrustedURL.unsafelyCreate(URLS.javascript);
-
- assert_equals(url.toString(), URLS.javascript);
- }, "Basic processing: javascript URL, unsafe construction.");
-
- test(t => {
- var url = TrustedURL.create(URLS.external);
-
- assert_equals(url.toString(), URLS.sanitized);
- }, "Basic processing: external protocol URL, safe construction.");
-
- test(t => {
- var url = TrustedURL.unsafelyCreate(URLS.external);
-
- assert_equals(url.toString(), URLS.external);
- }, "Basic processing: external protocol URL, unsafe construction.");
-</script>
diff --git a/trusted-types/Window-open.tentative.html b/trusted-types/Window-open.tentative.html
new file mode 100644
index 0000000..c005fbb
--- /dev/null
+++ b/trusted-types/Window-open.tentative.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+<body>
+<script>
+ // helper functions for the tests
+ function testWindowOpen(t, win) {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(INPUTS.URL);
+ let child_window = win.open(url, "", "");
+ child_window.onload = t.step_func_done(_ => {
+ assert_equals(child_window.location.href, "" + url);
+ child_window.close();
+ });
+ }));
+ }
+
+ async_test(t => {
+ testWindowOpen(t, window);
+ }, "window.open via policy (successful URL transformation).");
+
+ async_test(t => {
+ testWindowOpen(t, document);
+ }, "document.open via policy (successful URL transformation).");
+</script>
diff --git a/trusted-types/block-string-assignment-to-DOMParser-parseFromString.tentative.html b/trusted-types/block-string-assignment-to-DOMParser-parseFromString.tentative.html
new file mode 100644
index 0000000..cc575dc
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-DOMParser-parseFromString.tentative.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+
+<meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+<body>
+<script>
+ // Trusted HTML assignments do not throw.
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+ let parser = new DOMParser();
+ let doc = parser.parseFromString(html, "text/html");
+ assert_equals(doc.body.innerText, RESULTS.HTML);
+ }));
+ }, "document.innerText assigned via policy (successful HTML transformation).");
+
+ // String assignments throw.
+ test(t => {
+ var parser = new DOMParser();
+ assert_throws(new TypeError(), _ => {
+ var doc = parser.parseFromString("Fail", "text/html");
+ });
+ }, "`document.innerText = string` throws.");
+
+ // Null assignment throws.
+ test(t => {
+ var parser = new DOMParser();
+ assert_throws(new TypeError(), _ => {
+ var doc = parser.parseFromString(null, "text/html");
+ });
+ }, "'document.innerText = null' throws");
+</script>
diff --git a/trusted-types/block-string-assignment-to-Document-write.tentative.html b/trusted-types/block-string-assignment-to-Document-write.tentative.html
new file mode 100644
index 0000000..28813d7
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-Document-write.tentative.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="support/helper.sub.js"></script>
+
+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+</head>
+<body>
+<script>
+ // TrustedURL assignments do not throw.
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+ document.write(html);
+ assert_equals(document.body.innerText, RESULTS.HTML);
+ }));
+ }, "document.write with html assigned via policy (successful URL transformation).");
+
+ // String assignments throw.
+ test(t => {
+ assert_throws(new TypeError(), _ => {
+ document.write('A string');
+ });
+ }, "`document.write(string)` throws");
+
+ // Null assignment throws.
+ test(t => {
+ assert_throws(new TypeError(), _ => {
+ document.write(null);
+ });
+ }, "`document.write(null)` throws");
+</script>
diff --git a/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML.tentative.html b/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML.tentative.html
new file mode 100644
index 0000000..ad94b44
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML.tentative.html
@@ -0,0 +1,97 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="support/helper.sub.js"></script>
+
+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+</head>
+<body>
+<div id="container"></div>
+<script>
+ var container = document.querySelector('#container');
+
+ // Trusted HTML assignments do not throw.
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+
+ var d = document.createElement('div');
+ container.appendChild(d);
+
+ d.insertAdjacentHTML('beforebegin', html);
+ assert_equals(d.previousSibling.nodeType, Node.TEXT_NODE);
+ assert_equals(d.previousSibling.data, RESULTS.HTML);
+
+ d.insertAdjacentHTML('afterbegin', html);
+ assert_equals(d.firstChild.nodeType, Node.TEXT_NODE);
+ assert_equals(d.firstChild.data, RESULTS.HTML);
+
+ d.insertAdjacentHTML('beforeend', html);
+ assert_equals(d.lastChild.nodeType, Node.TEXT_NODE);
+ assert_equals(d.lastChild.data, RESULTS.HTML);
+
+ d.insertAdjacentHTML('afterend', html);
+ assert_equals(d.nextSibling.nodeType, Node.TEXT_NODE);
+ assert_equals(d.nextSibling.data, RESULTS.HTML);
+
+ while (container.firstChild)
+ container.firstChild.remove();
+ }));
+ }, "insertAdjacentHTML with html assigned via policy (successful HTML transformation).");
+
+ // String assignments throw.
+ test(t => {
+ var d = document.createElement('div');
+ container.appendChild(d);
+
+ assert_throws(new TypeError(), _ => {
+ d.insertAdjacentHTML('beforebegin', "<p>Fail</p>");
+ });
+ assert_throws(new TypeError(), _ => {
+ d.insertAdjacentHTML('afterbegin', "<p>Fail</p>");
+ });
+ assert_throws(new TypeError(), _ => {
+ d.insertAdjacentHTML('beforeend', "<p>Fail</p>");
+ });
+ assert_throws(new TypeError(), _ => {
+ d.insertAdjacentHTML('afterend', "<p>Fail</p>");
+ });
+
+ assert_equals(d.previousSibling, null);
+ assert_equals(d.firstChild, null);
+ assert_equals(d.lastChild, null);
+ assert_equals(d.nextSibling, null);
+
+ while (container.firstChild)
+ container.firstChild.remove();
+ }, "`insertAdjacentHTML(string)` throws.");
+
+ // Null assignment throws.
+ test(t => {
+ var d = document.createElement('div');
+ container.appendChild(d);
+
+ assert_throws(new TypeError(), _ => {
+ d.insertAdjacentHTML('beforebegin', null);
+ });
+ assert_throws(new TypeError(), _ => {
+ d.insertAdjacentHTML('afterbegin', null);
+ });
+ assert_throws(new TypeError(), _ => {
+ d.insertAdjacentHTML('beforeend', null);
+ });
+ assert_throws(new TypeError(), _ => {
+ d.insertAdjacentHTML('afterend', null);
+ });
+
+ assert_equals(d.previousSibling, null);
+ assert_equals(d.firstChild, null);
+ assert_equals(d.lastChild, null);
+ assert_equals(d.nextSibling, null);
+ }, "`insertAdjacentHTML(null)` throws.");
+</script>
+</body>
+</html>
diff --git a/trusted-types/block-string-assignment-to-Element-outerHTML.tentative.html b/trusted-types/block-string-assignment-to-Element-outerHTML.tentative.html
new file mode 100644
index 0000000..47f1165
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-Element-outerHTML.tentative.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="support/helper.sub.js"></script>
+
+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+</head>
+<body>
+<div id="container"></div>
+<script>
+ var container = document.querySelector('#container')
+
+ // TrustedHTML assignments do not throw.
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+
+ var d = document.createElement('div');
+ document.querySelector('#container').appendChild(d);
+ d.outerHTML = html;
+ assert_equals(container.innerText, RESULTS.HTML);
+
+ while (container.firstChild)
+ container.firstChild.remove();
+ }));
+ }, "outerHTML with html assigned via policy (successful HTML transformation).");
+
+ // String assignments throw.
+ test(t => {
+ var d = document.createElement('div');
+ container.appendChild(d);
+ assert_throws(new TypeError(), _ => {
+ d.outerHTML = "Fail.";
+ });
+ assert_equals(container.innerText, "");
+ while (container.firstChild)
+ container.firstChild.remove();
+ }, "`outerHTML = string` throws.");
+
+ // Null assignment throws.
+ test(t => {
+ var d = document.createElement('div');
+ container.appendChild(d);
+ assert_throws(new TypeError(), _ => {
+ d.outerHTML = null;
+ });
+ assert_equals(container.innerText, "");
+ while (container.firstChild)
+ container.firstChild.remove();
+ }, "`outerHTML = null` throws.");
+</script>
+</body>
+</html>
diff --git a/trusted-types/block-string-assignment-to-HTMLElement-generic.tentative.html b/trusted-types/block-string-assignment-to-HTMLElement-generic.tentative.html
index 79bbb24..eae5262 100644
--- a/trusted-types/block-string-assignment-to-HTMLElement-generic.tentative.html
+++ b/trusted-types/block-string-assignment-to-HTMLElement-generic.tentative.html
@@ -9,7 +9,7 @@
</head>
<body>
<script>
- //TrustedURL Assignments
+ // TrustedURL Assignments
let testCases = [
[ 'a', 'href' ],
[ 'area', 'href' ],
@@ -27,24 +27,38 @@
];
testCases.forEach(c => {
- test(t => {
- assert_accepts_trusted_url(c[0], c[1]);
+ async_test(t => {
+ assert_element_accepts_trusted_url(window, t, c[0], c[1], RESULTS.URL);
assert_throws_no_trusted_type(c[0], c[1], 'A string');
assert_throws_no_trusted_type(c[0], c[1], null);
- }, c[0] + "." + c[1] + " accepts TrustedURL");
+ }, c[0] + "." + c[1] + " accepts only TrustedURL");
});
- //TrustedScriptURL Assignments
+ // TrustedScriptURL Assignments
let scriptTestCases = [
[ 'embed', 'src' ],
[ 'script', 'src' ]
];
scriptTestCases.forEach(c => {
- test(t => {
- assert_accepts_trusted_script_url(c[0], c[1]);
+ async_test(t => {
+ assert_element_accepts_trusted_script_url(window, t, c[0], c[1], RESULTS.SCRIPTURL);
assert_throws_no_trusted_type(c[0], c[1], 'A string');
assert_throws_no_trusted_type(c[0], c[1], null);
- }, c[0] + "." + c[1] + " accepts TrustedScriptURL");
+ }, c[0] + "." + c[1] + " accepts only TrustedScriptURL");
+ });
+
+ // TrustedHTML Assignments
+ let HTMLTestCases = [
+ [ 'div', 'innerHTML' ],
+ [ 'iframe', 'srcdoc' ]
+ ];
+
+ HTMLTestCases.forEach(c => {
+ async_test(t => {
+ assert_element_accepts_trusted_html(window, t, c[0], c[1], RESULTS.HTML);
+ assert_throws_no_trusted_type(c[0], c[1], 'A string');
+ assert_throws_no_trusted_type(c[0], c[1], null);
+ }, c[0] + "." + c[1] + " accepts only TrustedHTML");
});
</script>
diff --git a/trusted-types/block-string-assignment-to-Location-assign.tentative.html b/trusted-types/block-string-assignment-to-Location-assign.tentative.html
new file mode 100644
index 0000000..8079335
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-Location-assign.tentative.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="support/helper.sub.js"></script>
+
+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+</head>
+<body>
+<script>
+ // TrustedURL assignments do not throw.
+ async_test(t => {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(location.href + "#xxx");
+ location.assign(url);
+ assert_equals("" + url, location.href, "location href");
+ }));
+ }, "location.assign via policy (successful URL transformation).");
+
+ // String assignments throw.
+ test(t => {
+ assert_throws(new TypeError(), _ => {
+ location.assign("A string");
+ });
+ }, "`location.assign = string` throws");
+
+ // Null assignment throws.
+ test(t => {
+ assert_throws(new TypeError(), _ => {
+ location.assign(null);
+ });
+ }, "`location.assign = null` throws");
+</script>
diff --git a/trusted-types/block-string-assignment-to-Location-href.tentative.html b/trusted-types/block-string-assignment-to-Location-href.tentative.html
new file mode 100644
index 0000000..4e393f9
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-Location-href.tentative.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="support/helper.sub.js"></script>
+
+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+</head>
+<body>
+<script>
+ // TrustedURL assignments do not throw.
+ async_test(t => {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(location.href + "#xxx");
+ location.href = url;
+ assert_equals("" + url, location.href, "location href");
+ }));
+ }, "location.href assigned via policy (successful URL transformation).");
+
+ // String assignments throw.
+ test(t => {
+ assert_throws(new TypeError(), _ => {
+ location.href = 'A string';
+ });
+ }, "`location.href = string` throws");
+
+ // Null assignment throws.
+ test(t => {
+ assert_throws(new TypeError(), _ => {
+ location.href = null;
+ });
+ }, "`location.href = null` throws");
+</script>
diff --git a/trusted-types/block-string-assignment-to-Location-replace.tentative.html b/trusted-types/block-string-assignment-to-Location-replace.tentative.html
new file mode 100644
index 0000000..872f14e
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-Location-replace.tentative.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="support/helper.sub.js"></script>
+
+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+</head>
+<body>
+<script>
+ // TrustedURL replacements do not throw.
+ async_test(t => {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(location.href + "#xxx");
+ location.replace(url);
+ assert_equals("" + url, location.href, "location href");
+ }));
+ }, "location.replace via policy (successful URL transformation).");
+
+ // String replacements throw.
+ test(t => {
+ assert_throws(new TypeError(), _ => {
+ location.replace("A string");
+ });
+ }, "`location.replace = string` throws");
+
+ // Null replacement throws.
+ test(t => {
+ assert_throws(new TypeError(), _ => {
+ location.replace(null);
+ });
+ }, "`location.replace = null` throws");
+</script>
diff --git a/trusted-types/block-string-assignment-to-Range-createContextualFragment.tentative.html b/trusted-types/block-string-assignment-to-Range-createContextualFragment.tentative.html
new file mode 100644
index 0000000..2afa257
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-Range-createContextualFragment.tentative.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/helper.sub.js"></script>
+
+<meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+<body>
+<script>
+ // TrustedHTML assignments do not throw.
+ async_test(t => {
+ createHTML_policy(window)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+ var range = document.createRange();
+ range.selectNodeContents(document.documentElement);
+ var result = range.createContextualFragment(html);
+ assert_equals(result.textContent, RESULTS.HTML);
+ }));
+ }, "range.createContextualFragment assigned via policy (successful HTML transformation).");
+
+ // String assignments throw.
+ test(t => {
+ var range = document.createRange();
+ range.selectNodeContents(document.documentElement);
+ assert_throws(new TypeError(), _ => {
+ var result = range.createContextualFragment("A string");
+ });
+ }, "`range.createContextualFragment(string)` throws.");
+
+ // Null assignment throws.
+ test(t => {
+ var range = document.createRange();
+ range.selectNodeContents(document.documentElement);
+ assert_throws(new TypeError(), _ => {
+ var result = range.createContextualFragment(null);
+ });
+ }, "`range.createContextualFragment(null)` throws.");
+</script>
diff --git a/trusted-types/block-string-assignment-to-Window-open.tentative.html b/trusted-types/block-string-assignment-to-Window-open.tentative.html
new file mode 100644
index 0000000..f571229
--- /dev/null
+++ b/trusted-types/block-string-assignment-to-Window-open.tentative.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="support/helper.sub.js"></script>
+
+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
+</head>
+<body>
+<script>
+ // helper functions for the tests
+ function testWindowOpen(t, win) {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(INPUTS.URL);
+ let child_window = win.open(url, "", "");
+ child_window.onload = t.step_func_done(_ => {
+ assert_equals(child_window.location.href, "" + url);
+ child_window.close();
+ });
+ }));
+ }
+
+ function testWindowThrows(t, url, win) {
+ createURL_policy(window)
+ .then(t.step_func_done(p => {
+ assert_throws(new TypeError(), _ => {
+ let child_window = win.open(url, "", "");
+ child_window.close();
+ });
+ }));
+ }
+
+ // TrustedURL assignments do not throw.
+ async_test(t => {
+ testWindowOpen(t, window);
+ }, "window.open via policy (successful URL transformation).");
+
+ async_test(t => {
+ testWindowOpen(t, document);
+ }, "document.open via policy (successful URL transformation).");
+
+ // String assignments throw.
+ async_test(t => {
+ testWindowThrows(t, 'A string', window);
+ }, "`window.open(string)` throws.");
+
+ async_test(t => {
+ testWindowThrows(t, 'A string', document);
+ }, "`document.open(string)` throws.");
+
+ // Null assignment throws.
+ async_test(t => {
+ testWindowThrows(t, null, window);
+ }, "`window.open(null)` throws.");
+
+ async_test(t => {
+ testWindowThrows(t, null, document);
+ }, "`document.open(null)` throws.");
+</script>
+</body>
+</html>
diff --git a/trusted-types/block-string-assignment-to-createContextualFragment.tentative.html b/trusted-types/block-string-assignment-to-createContextualFragment.tentative.html
deleted file mode 100644
index 1d67a51..0000000
--- a/trusted-types/block-string-assignment-to-createContextualFragment.tentative.html
+++ /dev/null
@@ -1,43 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-
-<meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-<body>
-<script>
- //TrustedHTML assignments work
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
- var range = document.createRange();
- range.selectNodeContents(document.documentElement);
- var result = range.createContextualFragment(html);
- assert_equals(result.textContent, STRINGS.unescapedHTML);
- }, "DocumentFragment.textContent = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
- var range = document.createRange();
- range.selectNodeContents(document.documentElement);
- var result = range.createContextualFragment(html);
- assert_equals(result.textContent, STRINGS.unescapedText);
- }, "DocumentFragment.textContent = TrustedHTML.unsafelyCreate().");
-
- //Null assignment throws
- test(t => {
- var range = document.createRange();
- range.selectNodeContents(document.documentElement);
- assert_throws(new TypeError(), _ => {
- var result = range.createContextualFragment(null);
- });
- }, "`DocumentFragment.textContent = null` throws.");
-
- // String assignments throw.
- test(t => {
- var range = document.createRange();
- range.selectNodeContents(document.documentElement);
- assert_throws(new TypeError(), _ => {
- var result = range.createContextualFragment("A string");
- });
- }, "`DocumentFragment.textContent = string` throws.");
-</script>
diff --git a/trusted-types/block-string-assignment-to-innerHTML.tentative.html b/trusted-types/block-string-assignment-to-innerHTML.tentative.html
deleted file mode 100644
index 67faf6e..0000000
--- a/trusted-types/block-string-assignment-to-innerHTML.tentative.html
+++ /dev/null
@@ -1,36 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <script src="/resources/testharness.js"></script>
- <script src="/resources/testharnessreport.js"></script>
- <script src="support/helper.sub.js"></script>
-
- <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-</head>
-<body>
-<script>
- // String assignments throw.
- test(t => {
- var d = document.createElement('div');
- assert_throws(new TypeError(), _ => {
- d.innerHTML = "Fail.";
- });
- }, "`innerHTML = string` throws.");
-
- // TrustedHTML assignments work.
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
- var d = document.createElement('div');
- d.innerHTML = html;
- assert_equals(d.innerText, STRINGS.unescapedHTML);
- }, "innerHTML = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
- var d = document.createElement('div');
- d.innerHTML = html;
- assert_equals(d.innerText, STRINGS.unescapedText);
- }, "innerHTML = TrustedHTML.unsafelyCreate().");
-</script>
-</body>
-</html>
diff --git a/trusted-types/block-string-assignment-to-insertAdjacentHTML.tentative.html b/trusted-types/block-string-assignment-to-insertAdjacentHTML.tentative.html
deleted file mode 100644
index 70bb803..0000000
--- a/trusted-types/block-string-assignment-to-insertAdjacentHTML.tentative.html
+++ /dev/null
@@ -1,93 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <script src="/resources/testharness.js"></script>
- <script src="/resources/testharnessreport.js"></script>
- <script src="support/helper.sub.js"></script>
-
- <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-</head>
-<body>
-<div id="container"></div>
-<script>
- var container = document.querySelector('#container');
-
- // String assignments throw.
- test(t => {
- var d = document.createElement('div');
- container.appendChild(d);
-
- assert_throws(new TypeError(), _ => {
- d.insertAdjacentHTML('beforebegin', "<p>Fail</p>");
- });
- assert_throws(new TypeError(), _ => {
- d.insertAdjacentHTML('afterbegin', "<p>Fail</p>");
- });
- assert_throws(new TypeError(), _ => {
- d.insertAdjacentHTML('beforeend', "<p>Fail</p>");
- });
- assert_throws(new TypeError(), _ => {
- d.insertAdjacentHTML('afterend', "<p>Fail</p>");
- });
-
- assert_equals(d.previousSibling, null);
- assert_equals(d.firstChild, null);
- assert_equals(d.lastChild, null);
- assert_equals(d.nextSibling, null);
- }, "`insertAdjacentHTML(string)` throws.");
-
- // TrustedHTML assignments work.
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- container.appendChild(d);
-
- d.insertAdjacentHTML('beforebegin', html);
- assert_equals(d.previousSibling.nodeType, Node.TEXT_NODE);
- assert_equals(d.previousSibling.data, STRINGS.unescapedHTML);
-
- d.insertAdjacentHTML('afterbegin', html);
- assert_equals(d.firstChild.nodeType, Node.TEXT_NODE);
- assert_equals(d.firstChild.data, STRINGS.unescapedHTML);
-
- d.insertAdjacentHTML('beforeend', html);
- assert_equals(d.lastChild.nodeType, Node.TEXT_NODE);
- assert_equals(d.lastChild.data, STRINGS.unescapedHTML);
-
- d.insertAdjacentHTML('afterend', html);
- assert_equals(d.nextSibling.nodeType, Node.TEXT_NODE);
- assert_equals(d.nextSibling.data, STRINGS.unescapedHTML);
-
- while (container.firstChild)
- container.firstChild.remove();
- }, "insertAdjacentHTML = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- container.appendChild(d);
-
- d.insertAdjacentHTML('beforebegin', html);
- assert_equals(d.previousSibling.nodeType, Node.TEXT_NODE);
- assert_equals(d.previousSibling.data, STRINGS.unescapedText);
-
- d.insertAdjacentHTML('afterbegin', html);
- assert_equals(d.firstChild.nodeType, Node.TEXT_NODE);
- assert_equals(d.firstChild.data, STRINGS.unescapedText);
-
- d.insertAdjacentHTML('beforeend', html);
- assert_equals(d.lastChild.nodeType, Node.TEXT_NODE);
- assert_equals(d.lastChild.data, STRINGS.unescapedText);
-
- d.insertAdjacentHTML('afterend', html);
- assert_equals(d.nextSibling.nodeType, Node.TEXT_NODE);
- assert_equals(d.nextSibling.data, STRINGS.unescapedText);
-
- while (container.firstChild)
- container.firstChild.remove();
- }, "insertAdjacentHTML = TrustedHTML.unsafelyCreate().");
-</script>
-</body>
-</html>
diff --git a/trusted-types/block-string-assignment-to-location-assign.tentative.html b/trusted-types/block-string-assignment-to-location-assign.tentative.html
deleted file mode 100644
index 76725da..0000000
--- a/trusted-types/block-string-assignment-to-location-assign.tentative.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <script src="/resources/testharness.js"></script>
- <script src="/resources/testharnessreport.js"></script>
- <script src="support/helper.sub.js"></script>
-
- <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-</head>
-<body>
-<script>
- //TrustedURL assignments work
- test(t => {
- var url = TrustedURL.create(location.href + "#xxx");
- location.assign(url);
- assert_equals("" + url, location.href, "location href");
- }, "Basic processing: safe URL, safe construction.");
-
- test(t => {
- var url = TrustedURL.unsafelyCreate(location.href + "#xxx");
- location.assign(url);
- assert_equals("" + url, location.href, "location href");
- }, "Basic processing: safe URL, unsafe construction.");
-
- // String assignments throw.
- test(t => {
- assert_throws(new TypeError(), _ => {
- location.assign("A string");
- });
- }, "`location.assign = string` throws");
-
- //Null assignment throws
- test(t => {
- assert_throws(new TypeError(), _ => {
- location.assign(null);
- });
- }, "`location.assign = null` throws");
-</script>
diff --git a/trusted-types/block-string-assignment-to-location-href.tentative.html b/trusted-types/block-string-assignment-to-location-href.tentative.html
deleted file mode 100644
index 07cc4d5..0000000
--- a/trusted-types/block-string-assignment-to-location-href.tentative.html
+++ /dev/null
@@ -1,41 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <script src="/resources/testharness.js"></script>
- <script src="/resources/testharnessreport.js"></script>
- <script src="support/helper.sub.js"></script>
-
- <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-</head>
-<body>
-<script>
- // String assignments throw.
- promise_test(t => {
- return promise_rejects(t, new TypeError(), createFrameAndHref("about:blank"));
- }, "`location.href = string` throws");
-
- // TrustedURL assignments work.
- promise_test(t => {
- var url = TrustedURL.create(URLS.safe);
- return createFrameAndHref(url);
- }, "Basic processing: safe URL, safe construction.");
-
- promise_test(t => {
- var url = TrustedURL.unsafelyCreate(URLS.safe);
- return createFrameAndHref(url);
- }, "Basic processing: safe URL, unsafe construction.");
-
- promise_test(t => {
- var url = TrustedURL.create(URLS.javascript);
- return createFrameAndHref(url).then(i => {
- assert_equals(i.contentDocument.body.innerText, "");
- });
- }, "Basic processing: javascript URL, safe construction.");
-
- promise_test(t => {
- var url = TrustedURL.unsafelyCreate(URLS.javascript);
- return createFrameAndHref(url).then(i => {
- assert_equals(i.contentDocument.body.innerText, "scripted");
- });
- }, "Basic processing: javascript URL, unsafe construction.");
-</script>
diff --git a/trusted-types/block-string-assignment-to-location-replace.tentative.html b/trusted-types/block-string-assignment-to-location-replace.tentative.html
deleted file mode 100644
index 9736a84..0000000
--- a/trusted-types/block-string-assignment-to-location-replace.tentative.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <script src="/resources/testharness.js"></script>
- <script src="/resources/testharnessreport.js"></script>
- <script src="support/helper.sub.js"></script>
-
- <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-</head>
-<body>
-<script>
- //TrustedURL replacements work
- test(t => {
- var url = TrustedURL.create(location.href + "#xxx");
- location.replace(url);
- assert_equals("" + url, location.href, "location href");
- }, "Basic processing: safe URL, safe construction.");
-
- test(t => {
- var url = TrustedURL.unsafelyCreate(location.href + "#xxx");
- location.replace(url);
- assert_equals("" + url, location.href, "location href");
- }, "Basic processing: safe URL, unsafe construction.");
-
- // String replacements throw.
- test(t => {
- assert_throws(new TypeError(), _ => {
- location.replace("A string");
- });
- }, "`location.replace = string` throws");
-
- //Null replacement throws
- test(t => {
- assert_throws(new TypeError(), _ => {
- location.replace(null);
- });
- }, "`location.replace = null` throws");
-</script>
diff --git a/trusted-types/block-string-assignment-to-outerHTML.tentative.html b/trusted-types/block-string-assignment-to-outerHTML.tentative.html
deleted file mode 100644
index 8cf6c4b..0000000
--- a/trusted-types/block-string-assignment-to-outerHTML.tentative.html
+++ /dev/null
@@ -1,53 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <script src="/resources/testharness.js"></script>
- <script src="/resources/testharnessreport.js"></script>
- <script src="support/helper.sub.js"></script>
-
- <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-</head>
-<body>
-<div id="container"></div>
-<script>
- var container = document.querySelector('#container')
-
- // String assignments throw.
- test(t => {
- var d = document.createElement('div');
- container.appendChild(d);
- assert_throws(new TypeError(), _ => {
- d.outerHTML = "Fail.";
- });
- assert_equals(container.innerText, "");
- while (container.firstChild)
- container.firstChild.remove();
- }, "`outerHTML = string` throws.");
-
- // TrustedHTML assignments work.
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- document.querySelector('#container').appendChild(d);
- d.outerHTML = html;
- assert_equals(container.innerText, STRINGS.unescapedHTML);
-
- while (container.firstChild)
- container.firstChild.remove();
- }, "outerHTML = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- container.appendChild(d);
- d.outerHTML = html;
- assert_equals(container.innerText, STRINGS.unescapedText);
-
- while (container.firstChild)
- container.firstChild.remove();
- }, "outerHTML = TrustedHTML.unsafelyCreate().");
-</script>
-</body>
-</html>
diff --git a/trusted-types/block-string-assignment-to-window-open.tentative.html b/trusted-types/block-string-assignment-to-window-open.tentative.html
deleted file mode 100644
index 2c3a8ce..0000000
--- a/trusted-types/block-string-assignment-to-window-open.tentative.html
+++ /dev/null
@@ -1,68 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <script src="/resources/testharness.js"></script>
- <script src="/resources/testharnessreport.js"></script>
- <script src="support/helper.sub.js"></script>
-
- <meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-</head>
-<body>
-<script>
- //helper functions for the tests
- function testWindowOpen(t, url, win) {
- let child_window = win.open(url, "", "");
- child_window.onload = t.step_func_done(_ => {
- assert_equals(child_window.location.href, "" + url);
- child_window.close();
- });
- }
-
- function testWindowThrows(t, url, win) {
- let child_window = win.open(TrustedURL.create(URLS.safe), "", "");
- child_window.onload = t.step_func_done(_ => {
- assert_throws(new TypeError(), _ => {
- child_window = win.open(url, "", "");
- child_window.close();
- });
- });
- }
-
- //TrustedURL assignments do not throw
- async_test(t => {
- testWindowOpen(t, TrustedURL.create(URLS.safe), window);
- }, "window.open: safe URL, safe construction.");
-
- async_test(t => {
- testWindowOpen(t, TrustedURL.unsafelyCreate(URLS.safe), window);
- }, "window.open: safe URL, unsafe construction.");
-
- async_test(t => {
- testWindowOpen(t, TrustedURL.create(URLS.safe), document);
- }, "document.open: safe URL, safe construction.");
-
- async_test(t => {
- testWindowOpen(t, TrustedURL.unsafelyCreate(URLS.safe), document);
- }, "document.open: safe URL, unsafe construction.");
-
- //String assignments throw
- async_test(t => {
- testWindowThrows(t, 'A string', window);
- }, "`window.open(string)` throws.");
-
- async_test(t => {
- testWindowThrows(t, 'A string', document);
- }, "`document.open(string)` throws.");
-
- //Null assignment throws
- async_test(t => {
- testWindowThrows(t, null, window);
- }, "`window.open(null)` throws.");
-
- //Null assignment throws
- async_test(t => {
- testWindowThrows(t, null, document);
- }, "`document.open(null)` throws.");
-</script>
-</body>
-</html>
diff --git a/trusted-types/createContextualFragment.tentative.html b/trusted-types/createContextualFragment.tentative.html
deleted file mode 100644
index 5e50acc..0000000
--- a/trusted-types/createContextualFragment.tentative.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var range = document.createRange();
- range.selectNodeContents(document.documentElement);
- var result = range.createContextualFragment(html);
- assert_equals(result.textContent, STRINGS.unescapedHTML);
- }, "DocumentFragment.textContent = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var range = document.createRange();
- range.selectNodeContents(document.documentElement);
- var result = range.createContextualFragment(html);
- assert_equals(result.textContent, STRINGS.unescapedText);
- }, "DocumentFragment.textContent = TrustedHTML.unsafelyCreate().");
-
- test(t => {
- var range = document.createRange();
- range.selectNodeContents(document.documentElement);
- var result = range.createContextualFragment(null);
- assert_equals(result.textContent, "null");
- }, "DocumentFragment.textContent = null.");
-</script>
diff --git a/trusted-types/document-write.tentative.html b/trusted-types/document-write.tentative.html
deleted file mode 100644
index 1279419..0000000
--- a/trusted-types/document-write.tentative.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- promise_test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
- return createFrameAndWrite(html).then(i => {
- assert_equals(i.contentDocument.body.innerText, STRINGS.unescapedHTML, "innerText");
- i.remove();
- });
- }, "document.write(TrustedHTML).");
-</script>
diff --git a/trusted-types/innerHTML.tentative.html b/trusted-types/innerHTML.tentative.html
deleted file mode 100644
index f9f32d4..0000000
--- a/trusted-types/innerHTML.tentative.html
+++ /dev/null
@@ -1,22 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- d.innerHTML = html;
- assert_equals(d.innerText, STRINGS.unescapedHTML);
- }, "innerHTML = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- d.innerHTML = html;
- assert_equals(d.innerText, STRINGS.unescapedText);
- }, "innerHTML = TrustedHTML.unsafelyCreate().");
-</script>
diff --git a/trusted-types/insertAdjacentHTML.tentative.html b/trusted-types/insertAdjacentHTML.tentative.html
deleted file mode 100644
index a95dd6c..0000000
--- a/trusted-types/insertAdjacentHTML.tentative.html
+++ /dev/null
@@ -1,61 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<div id="container"></div>
-<script>
- var container = document.querySelector('#container');
-
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- container.appendChild(d);
-
- d.insertAdjacentHTML('beforebegin', html);
- assert_equals(d.previousSibling.nodeType, Node.TEXT_NODE);
- assert_equals(d.previousSibling.data, STRINGS.unescapedHTML);
-
- d.insertAdjacentHTML('afterbegin', html);
- assert_equals(d.firstChild.nodeType, Node.TEXT_NODE);
- assert_equals(d.firstChild.data, STRINGS.unescapedHTML);
-
- d.insertAdjacentHTML('beforeend', html);
- assert_equals(d.lastChild.nodeType, Node.TEXT_NODE);
- assert_equals(d.lastChild.data, STRINGS.unescapedHTML);
-
- d.insertAdjacentHTML('afterend', html);
- assert_equals(d.nextSibling.nodeType, Node.TEXT_NODE);
- assert_equals(d.nextSibling.data, STRINGS.unescapedHTML);
-
- while (container.firstChild)
- container.firstChild.remove();
- }, "insertAdjacentHTML = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- container.appendChild(d);
-
- d.insertAdjacentHTML('beforebegin', html);
- assert_equals(d.previousSibling.nodeType, Node.TEXT_NODE);
- assert_equals(d.previousSibling.data, STRINGS.unescapedText);
-
- d.insertAdjacentHTML('afterbegin', html);
- assert_equals(d.firstChild.nodeType, Node.TEXT_NODE);
- assert_equals(d.firstChild.data, STRINGS.unescapedText);
-
- d.insertAdjacentHTML('beforeend', html);
- assert_equals(d.lastChild.nodeType, Node.TEXT_NODE);
- assert_equals(d.lastChild.data, STRINGS.unescapedText);
-
- d.insertAdjacentHTML('afterend', html);
- assert_equals(d.nextSibling.nodeType, Node.TEXT_NODE);
- assert_equals(d.nextSibling.data, STRINGS.unescapedText);
-
- while (container.firstChild)
- container.firstChild.remove();
- }, "insertAdjacentHTML = TrustedHTML.unsafelyCreate().");
-</script>
diff --git a/trusted-types/location-assign.tentative.html b/trusted-types/location-assign.tentative.html
deleted file mode 100644
index 07cb4a8..0000000
--- a/trusted-types/location-assign.tentative.html
+++ /dev/null
@@ -1,18 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- test(t => {
- var url = TrustedURL.create(location.href + "#xxx");
- location.assign(url);
- assert_equals("" + url, location.href, "location href");
- }, "Basic processing: safe URL, safe construction.");
-
- test(t => {
- var url = TrustedURL.unsafelyCreate(location.href + "#xxx");
- location.assign(url);
- assert_equals("" + url, location.href, "location href");
- }, "Basic processing: safe URL, unsafe construction.");
-</script>
diff --git a/trusted-types/location-href.tentative.html b/trusted-types/location-href.tentative.html
deleted file mode 100644
index 2527fbf..0000000
--- a/trusted-types/location-href.tentative.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- promise_test(t => {
- var url = TrustedURL.create(URLS.safe);
- return createFrameAndHref(url);
- }, "Basic processing: safe URL, safe construction.");
-
- promise_test(t => {
- var url = TrustedURL.unsafelyCreate(URLS.safe);
- return createFrameAndHref(url);
- }, "Basic processing: safe URL, unsafe construction.");
-
- promise_test(t => {
- var url = TrustedURL.create(URLS.javascript);
- return createFrameAndHref(url).then(i => {
- assert_equals(i.contentDocument.body.innerText, "");
- });
- }, "Basic processing: javascript URL, safe construction.");
-
- promise_test(t => {
- var url = TrustedURL.unsafelyCreate(URLS.javascript);
- return createFrameAndHref(url).then(i => {
- assert_equals(i.contentDocument.body.innerText, "scripted");
- });
- }, "Basic processing: javascript URL, unsafe construction.");
-</script>
diff --git a/trusted-types/location-replace.tentative.html b/trusted-types/location-replace.tentative.html
deleted file mode 100644
index 097c24d..0000000
--- a/trusted-types/location-replace.tentative.html
+++ /dev/null
@@ -1,18 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- test(t => {
- var url = TrustedURL.create(location.href + "#xxx");
- location.replace(url);
- assert_equals("" + url, location.href, "location href");
- }, "Basic processing: safe URL, safe construction.");
-
- test(t => {
- var url = TrustedURL.unsafelyCreate(location.href + "#xxx");
- location.replace(url);
- assert_equals("" + url, location.href, "location href");
- }, "Basic processing: safe URL, unsafe construction.");
-</script>
diff --git a/trusted-types/outerHTML.tentative.html b/trusted-types/outerHTML.tentative.html
deleted file mode 100644
index 1deb46b..0000000
--- a/trusted-types/outerHTML.tentative.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<div id="container"></div>
-<script>
- var container = document.querySelector('#container')
- test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- document.querySelector('#container').appendChild(d);
- d.outerHTML = html;
- assert_equals(container.innerText, STRINGS.unescapedHTML);
- while (container.firstChild)
- container.firstChild.remove();
- }, "outerHTML = TrustedHTML.escape().");
-
- test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var d = document.createElement('div');
- container.appendChild(d);
- d.outerHTML = html;
- assert_equals(container.innerText, STRINGS.unescapedText);
- while (container.firstChild)
- container.firstChild.remove();
- }, "outerHTML = TrustedHTML.unsafelyCreate().");
-</script>
diff --git a/trusted-types/srcDoc-requiresTrustedTypes.tentative.html b/trusted-types/srcDoc-requiresTrustedTypes.tentative.html
deleted file mode 100644
index b957488..0000000
--- a/trusted-types/srcDoc-requiresTrustedTypes.tentative.html
+++ /dev/null
@@ -1,40 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-
-<meta http-equiv="Content-Security-Policy" content="require-trusted-types">
-<body>
-<script>
- //HTML assignments don't throw
- async_test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var frame = document.createElement('iframe');
- frame.srcdoc = html;
- frame.onload = t.step_func_done(_ => {
- assert_equals(frame.srcdoc, STRINGS.escapedHTML);
- });
- document.body.appendChild(frame);
- }, "srcdoc = TrustedHTML.escape().");
-
- async_test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var frame = document.createElement('iframe');
- frame.srcdoc = html;
- frame.onload = t.step_func_done(_ => {
- assert_equals(frame.srcdoc, STRINGS.unescapedHTML);
- });
- document.body.appendChild(frame);
- }, "srcdoc = TrustedHTML.unsafelyCreate().");
-
- //String assignment throws
- test(t => {
- var frame = document.createElement('iframe');
- assert_throws(new TypeError(), _ => {
- frame.srcdoc = "Fail";
- });
- document.body.appendChild(frame);
- }, "'srcdoc = string' throws.");
-</script>
diff --git a/trusted-types/srcDoc.tentative.html b/trusted-types/srcDoc.tentative.html
deleted file mode 100644
index b23703e..0000000
--- a/trusted-types/srcDoc.tentative.html
+++ /dev/null
@@ -1,28 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- async_test(t => {
- var html = TrustedHTML.escape(STRINGS.unescapedHTML);
-
- var frame = document.createElement('iframe');
- frame.srcdoc = html;
- frame.onload = t.step_func_done(_ => {
- assert_equals(frame.srcdoc, STRINGS.escapedHTML);
- });
- document.body.appendChild(frame);
- }, "srcdoc = TrustedHTML.escape().");
-
- async_test(t => {
- var html = TrustedHTML.unsafelyCreate(STRINGS.unescapedHTML);
-
- var frame = document.createElement('iframe');
- frame.srcdoc = html;
- frame.onload = t.step_func_done(_ => {
- assert_equals(frame.srcdoc, STRINGS.unescapedHTML);
- });
- document.body.appendChild(frame);
- }, "srcdoc = TrustedHTML.unsafelyCreate().");
-</script>
diff --git a/trusted-types/support/helper.sub.js b/trusted-types/support/helper.sub.js
index 91112d8..07e8902 100644
--- a/trusted-types/support/helper.sub.js
+++ b/trusted-types/support/helper.sub.js
@@ -1,70 +1,69 @@
-var STRINGS = {
- unescapedHTML: "<html>This has ', \", >, <, & & characters!</html>",
- escapedHTML: "<html>This has ', ", >, <, &amp; & characters!</html>",
- unescapedText: "This has ', \", >, <, & & characters!",
+var INPUTS = {
+ HTML: "Hi, I want to be transformed!",
+ SCRIPTURL: "http://this.is.a.scripturl.test/",
+ URL: "http://hello.i.am.an.url/"
};
-var URLS = {
- safe: "http://{{host}}:{{ports[http][0]}}/",
- javascript: "javascript:'scripted'",
- external: "custom-handler:whatever",
- sanitized: "about:invalid"
+var RESULTS = {
+ HTML: "Quack, I want to be a duck!",
+ SCRIPTURL: "http://this.is.a.successful.test/",
+ URL: "http://hooray.i.am.successfully.transformed/"
};
-function createFrameAndWrite(html) {
- return new Promise((resolve, reject) => {
- var i = document.createElement('iframe');
- i.onload = e => {
- i.contentDocument.open();
- try {
- i.contentDocument.write(html);
- } catch (e) {
- i.remove();
- reject(e);
- }
- i.contentDocument.close();
- resolve(i);
- };
- document.body.appendChild(i);
- });
+function createHTMLJS(html) {
+ return html.replace("Hi", "Quack")
+ .replace("transformed", "a duck");
}
-function createFrameAndHref(href) {
- return new Promise((resolve, reject) => {
- var i = document.createElement('iframe');
- i.onload = _ => {
- i.onload = null;
- try {
- i.onload = _ => resolve(i);
- i.contentWindow.location.href = href;
- } catch (ex) {
- i.remove();
- reject(ex);
- }
- };
- document.body.appendChild(i);
- });
+function createScriptURLJS(scripturl) {
+ return scripturl.replace("scripturl", "successful");
}
-let trustedHTML = TrustedHTML.escape(STRINGS.unescapedHTML);
-function assert_accepts_trusted_html(tag, attribute) {
+function createURLJS(url) {
+ return url.replace("hello", "hooray")
+ .replace("an.url", "successfully.transformed");
+}
+
+function createHTML_policy(win) {
+ return win.trustedTypes.createPolicy('SomeName', { createHTML: createHTMLJS });
+}
+
+function createScriptURL_policy(win) {
+ return win.trustedTypes.createPolicy('SomeName', { createScriptURL: createScriptURLJS });
+}
+
+function createURL_policy(win) {
+ return win.trustedTypes.createPolicy('SomeName', { createURL: createURLJS });
+}
+
+function assert_element_accepts_trusted_html(win, t, tag, attribute, expected) {
+ createHTML_policy(win)
+ .then(t.step_func_done(p => {
+ let html = p.createHTML(INPUTS.HTML);
+ assert_element_accepts_trusted_type(tag, attribute, html, expected);
+ }));
+}
+
+function assert_element_accepts_trusted_script_url(win, t, tag, attribute, expected) {
+ createScriptURL_policy(win)
+ .then(t.step_func_done(p => {
+ let scripturl = p.createScriptURL(INPUTS.SCRIPTURL);
+ assert_element_accepts_trusted_type(tag, attribute, scripturl, expected);
+ }));
+}
+
+function assert_element_accepts_trusted_url(win, t, tag, attribute, expected) {
+ createURL_policy(win)
+ .then(t.step_func_done(p => {
+ let url = p.createURL(INPUTS.URL);
+ assert_element_accepts_trusted_type(tag, attribute, url, expected);
+ }));
+}
+
+function assert_element_accepts_trusted_type(tag, attribute, value, expected) {
let elem = document.createElement(tag);
- elem[attribute] = trustedHTML;
- assert_equals(elem[attribute] + "", STRINGS.unescapedHTML);
-}
-
-let trustedURL = TrustedURL.create(URLS.safe);
-function assert_accepts_trusted_url(tag, attribute) {
- let elem = document.createElement(tag);
- elem[attribute] = trustedURL;
- assert_equals(elem[attribute] + "", URLS.safe);
-}
-
-let trustedScriptURL = TrustedScriptURL.unsafelyCreate(URLS.safe);
-function assert_accepts_trusted_script_url(tag, attribute) {
- let elem = document.createElement(tag);
- elem[attribute] = trustedScriptURL;
- assert_equals(elem[attribute] + "", URLS.safe);
+ elem[attribute] = value;
+ assert_equals(elem[attribute] + "", expected);
}
function assert_throws_no_trusted_type(tag, attribute, value) {
diff --git a/trusted-types/window-open.tentative.html b/trusted-types/window-open.tentative.html
deleted file mode 100644
index 66ffbd7..0000000
--- a/trusted-types/window-open.tentative.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="support/helper.sub.js"></script>
-<body>
-<script>
- //helper functions for the tests
- function testWindowOpen(t, url, win) {
- let child_window = win.open(url, "", "");
- child_window.onload = t.step_func_done(_ => {
- assert_equals(child_window.location.href, "" + url);
- child_window.close();
- });
- }
-
- async_test(t => {
- testWindowOpen(t, TrustedURL.create(URLS.safe), window);
- }, "window.open: safe URL, safe construction.");
-
- async_test(t => {
- testWindowOpen(t, TrustedURL.unsafelyCreate(URLS.safe), window);
- }, "window.open: safe URL, unsafe construction.");
-
- async_test(t => {
- testWindowOpen(t, TrustedURL.create(URLS.safe), document);
- }, "document.open: safe URL, safe construction.");
-
- async_test(t => {
- testWindowOpen(t, TrustedURL.unsafelyCreate(URLS.safe), document);
- }, "document.open: safe URL, unsafe construction.");
-</script>