Skip to content

Commit

Permalink
Improve test coverage of sink values - part2.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=273763

Reviewed by Tim Nguyen.

Add checks on sink values.

* LayoutTests/imported/w3c/web-platform-tests/trusted-types/default-policy-callback-arguments.html:
* LayoutTests/imported/w3c/web-platform-tests/trusted-types/default-policy-report-only.html:
* LayoutTests/imported/w3c/web-platform-tests/trusted-types/default-policy.html:

Specifically for default policy test files.

Canonical link: https://commits.webkit.org/278804@main
  • Loading branch information
ziransun authored and lukewarlow committed May 15, 2024
1 parent d48536f commit bcace83
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
assert_equals(args[0], current_case[0], "Expecting the value.");
assert_equals(args[1], current_case[1], "Expecting the type name.");
assert_equals(args[2], current_case[2], "Expecting the sink name.");
switch (args[1]) {
case TrustedScriptURL:
assert_equals(args[2], 'HTMLScriptElement src');
break;
case TrustedHTML:
assert_equals(args[2], 'Element innerHTML');
break;
case TrustedScript:
assert_equals(args[2], 'HTMLScriptElement text');
break;
}
return args[0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
});

// A trusted type policy that forces a number of edge cases.
function policy(str) {
function policy(str, type, sink) {
if (str == "throw")
throw RangeError();
else if (str == "null")
Expand All @@ -65,8 +65,20 @@
return document.bla();
else if (str == "done")
return null;
else
else {
switch (type) {
case TrustedScriptURL:
assert_equals(sink, 'HTMLScriptElement src');
break;
case TrustedHTML:
assert_equals(sink, 'Element innerHTML');
break;
case TrustedScript:
assert_equals(sink, 'HTMLScriptElement text');
break;
}
return "sanitized: " + str;
}
}

trustedTypes.createPolicy("default", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
});

// A trusted type policy that forces a number of edge cases.
function policy(str) {
function policy(str, type, sink) {
if (str == "throw")
throw RangeError();
else if (str == "null")
Expand All @@ -65,8 +65,20 @@
return document.bla();
else if (str == "done")
return null;
else
else {
switch (type) {
case TrustedScriptURL:
assert_equals(sink, 'HTMLScriptElement src');
break;
case TrustedHTML:
assert_equals(sink, 'Element innerHTML');
break;
case TrustedScript:
assert_equals(sink, 'HTMLScriptElement text');
break;
}
return "sanitized: " + str;
}
}

trustedTypes.createPolicy("default", {
Expand Down

0 comments on commit bcace83

Please sign in to comment.