Bug 1475307 [wpt PR 11943] - location.assign() and location.replace() changed to accept TrustedTypes, a=testonly

Automatic update from web-platform-testslocation.assign() and location.replace() changed to accept TrustedTypes

Previous versions of functions made private and named
assignFromString and replaceFromString,respectively.
assign wraps assignFromString.
replace wraps replaceFromString.

Bug: 739170
Change-Id: I3fd39a44fed1482f7e07524815297b9eec322b60
Reviewed-on: https://chromium-review.googlesource.com/1134987
Commit-Queue: Maja Kabus <kabusm@google.com>
Reviewed-by: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574907}

--

wpt-commits: d886715e456fb9a2e23e310ceaf8f9edc38f24b2
wpt-pr: 11943
This commit is contained in:
Maja Kabus 2018-07-25 15:36:59 +00:00 committed by James Graham
parent 4d128474f5
commit c7d1f926bf
5 changed files with 152 additions and 0 deletions

View File

@ -379759,12 +379759,24 @@
{}
]
],
"trusted-types/block-string-assignment-to-location-assign.tentative.html": [
[
"/trusted-types/block-string-assignment-to-location-assign.tentative.html",
{}
]
],
"trusted-types/block-string-assignment-to-location-href.tentative.html": [
[
"/trusted-types/block-string-assignment-to-location-href.tentative.html",
{}
]
],
"trusted-types/block-string-assignment-to-location-replace.tentative.html": [
[
"/trusted-types/block-string-assignment-to-location-replace.tentative.html",
{}
]
],
"trusted-types/block-string-assignment-to-outerHTML.tentative.html": [
[
"/trusted-types/block-string-assignment-to-outerHTML.tentative.html",
@ -379801,12 +379813,24 @@
{}
]
],
"trusted-types/location-assign.tentative.html": [
[
"/trusted-types/location-assign.tentative.html",
{}
]
],
"trusted-types/location-href.tentative.html": [
[
"/trusted-types/location-href.tentative.html",
{}
]
],
"trusted-types/location-replace.tentative.html": [
[
"/trusted-types/location-replace.tentative.html",
{}
]
],
"trusted-types/outerHTML.tentative.html": [
[
"/trusted-types/outerHTML.tentative.html",
@ -620460,10 +620484,18 @@
"739b7940a27a298ca05005e9549774f9e0c0122f",
"testharness"
],
"trusted-types/block-string-assignment-to-location-assign.tentative.html": [
"c50f889d7e517c42e8a490fcdc9e5e169b910876",
"testharness"
],
"trusted-types/block-string-assignment-to-location-href.tentative.html": [
"b4da566f7eab26c9156e7976714618c74fd405b0",
"testharness"
],
"trusted-types/block-string-assignment-to-location-replace.tentative.html": [
"2089fb7ca09b558d654d5e779a52f5acb61d4be8",
"testharness"
],
"trusted-types/block-string-assignment-to-outerHTML.tentative.html": [
"a5301e971af8a918df577a3c00cf5d4be2b1d413",
"testharness"
@ -620488,10 +620520,18 @@
"67298baa3acbfd88c9d867e60fc46ff8f9e2a2ca",
"testharness"
],
"trusted-types/location-assign.tentative.html": [
"a13e8e471524a854a729ff6724bf7b818f278719",
"testharness"
],
"trusted-types/location-href.tentative.html": [
"b6b009db2b50ef1a456762256c598b907cbdce81",
"testharness"
],
"trusted-types/location-replace.tentative.html": [
"a1aa171c4af1bab6e501504a0eb1ee9889e8ca26",
"testharness"
],
"trusted-types/outerHTML.tentative.html": [
"959d23151fe6fa7f049fac11336da8ab9d962d0a",
"testharness"

View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./support/helper.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>

View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./support/helper.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>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/helper.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>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/helper.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>