Commit 2b2cc416 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

html: Fix a sanitization issue of type-change-state.html

type-change-state.html assumed sanitized value for "  foo\rbar  " was
fixed per a input type, and it was specified by 'sanitizedValue' field.

However, it depends on the previous type.  For example, the new input
types of the following A and B are same, initial value setter arguments
are same, but sanitized values of A and B should be different due to the
sanitizer difference between 'hidden' and 'url':

A)
  input.type = "hidden";
  input.value = "  foo\rbar  ";
  // input.value is "  foo\rbar  "
  input.type = "text";
  // input.value is "  foobar  ".

B)
  input.type = "url";
  input.value = "  foo\rbar  ";
  // input.value is "foobar"
  input.type = "text";
  // input.value is "foobar".

This CL fixes this issue by replacing 'sanitizedValue' field with
'sanitizer' field, which specifies a simple sanitizer implementation.

This fixes five test cases, which have failed with all major browsers.

Change-Id: I1b5f75e610138b1d117e93723471427ee655c300
Reviewed-on: https://chromium-review.googlesource.com/c/1326203
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606730}
parent 2ebf5946
This is a testharness.js-based test.
Found 462 tests; 436 PASS, 26 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 462 tests; 441 PASS, 21 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS change state from hidden to text
PASS change state from hidden to search
PASS change state from hidden to tel
......@@ -85,11 +85,11 @@ PASS change state from tel to image
PASS change state from tel to reset
PASS change state from tel to button
PASS change state from url to hidden
FAIL change state from url to text assert_equals: input.value should be ' foobar ' after change of state expected " foobar " but got "foobar"
FAIL change state from url to search assert_equals: input.value should be ' foobar ' after change of state expected " foobar " but got "foobar"
FAIL change state from url to tel assert_equals: input.value should be ' foobar ' after change of state expected " foobar " but got "foobar"
PASS change state from url to text
PASS change state from url to search
PASS change state from url to tel
PASS change state from url to email
FAIL change state from url to password assert_equals: input.value should be ' foobar ' after change of state expected " foobar " but got "foobar"
PASS change state from url to password
PASS change state from url to datetime-local
PASS change state from url to date
PASS change state from url to month
......@@ -106,11 +106,11 @@ PASS change state from url to image
PASS change state from url to reset
PASS change state from url to button
PASS change state from email to hidden
FAIL change state from email to text assert_equals: input.value should be ' foobar ' after change of state expected " foobar " but got "foobar"
FAIL change state from email to search assert_equals: input.value should be ' foobar ' after change of state expected " foobar " but got "foobar"
FAIL change state from email to tel assert_equals: input.value should be ' foobar ' after change of state expected " foobar " but got "foobar"
FAIL change state from email to text assert_equals: selectionStart should be 0 expected 0 but got 6
FAIL change state from email to search assert_equals: selectionStart should be 0 expected 0 but got 6
FAIL change state from email to tel assert_equals: selectionStart should be 0 expected 0 but got 6
FAIL change state from email to url assert_equals: selectionStart should be 0 expected 0 but got 6
FAIL change state from email to password assert_equals: input.value should be ' foobar ' after change of state expected " foobar " but got "foobar"
FAIL change state from email to password assert_equals: selectionStart should be 0 expected 0 but got 6
PASS change state from email to datetime-local
PASS change state from email to date
PASS change state from email to month
......@@ -285,7 +285,7 @@ PASS change state from range to date
PASS change state from range to month
PASS change state from range to week
PASS change state from range to time
FAIL change state from range to number assert_equals: input.value should be '' after change of state expected "" but got "50"
PASS change state from range to number
PASS change state from range to color
PASS change state from range to checkbox
PASS change state from range to radio
......
......@@ -7,22 +7,70 @@
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
const INITIAL_VALUE = " foo\rbar ";
// Sanitize algorithm implementations only for values used in this test.
function sanitizeText(value) {
switch (value) {
case INITIAL_VALUE: return " foobar ";
case " foobar ": return value;
case "foobar": return value;
case "50": return value;
case "#000000": return value;
case "": return value;
default: throw new DOMException(`Internal Error: Should add support of "${value}"`, "NotSupportedError");
}
}
function sanitizeEmailOrUrl(value) {
switch (value) {
case INITIAL_VALUE: return "foobar";
case " foobar ": return "foobar";
case "foobar": return value;
case "50": return value;
case "#000000": return value;
case "": return value;
default: throw new DOMException(`Internal Error: Should add support of "${value}"`, "NotSupportedError");
}
}
function sanitizeTemporal(value) {
// We have no test cases using valid temporal values.
return "";
}
function sanitizeNumber(value) {
switch (value) {
case "50": return value;
default:
// We have no test cases using valid numbers other than "50".
return "";
}
}
function sanitizeRange(value) {
// We have no test cases using valid numbers other than "50".
return "50";
}
function sanitizeColor(value) {
// We have no test cases using valid colors other than "#000000".
return "#000000";
}
var types = [
{ type: "hidden" },
{ type: "text", sanitizedValue: " foobar " },
{ type: "search", sanitizedValue: " foobar " },
{ type: "tel", sanitizedValue: " foobar " },
{ type: "url", sanitizedValue: "foobar" },
{ type: "email", sanitizedValue: "foobar" },
{ type: "password", sanitizedValue: " foobar " },
{ type: "datetime-local", sanitizedValue: "", overridesSanitization: true },
{ type: "date", sanitizedValue: "", overridesSanitization: true },
{ type: "month", sanitizedValue: "", overridesSanitization: true },
{ type: "week", sanitizedValue: "", overridesSanitization: true },
{ type: "time", sanitizedValue: "", overridesSanitization: true },
{ type: "number", sanitizedValue: "", overridesSanitization: true },
{ type: "range", sanitizedValue: "50", overridesSanitization: true },
{ type: "color", sanitizedValue: "#000000", overridesSanitization: true },
{ type: "text", sanitizer: sanitizeText },
{ type: "search", sanitizer: sanitizeText },
{ type: "tel", sanitizer: sanitizeText },
{ type: "url", sanitizer: sanitizeEmailOrUrl },
{ type: "email", sanitizer: sanitizeEmailOrUrl },
{ type: "password", sanitizer: sanitizeText },
{ type: "datetime-local", sanitizer: sanitizeTemporal },
{ type: "date", sanitizer: sanitizeTemporal },
{ type: "month", sanitizer: sanitizeTemporal },
{ type: "week", sanitizer: sanitizeTemporal },
{ type: "time", sanitizer: sanitizeTemporal },
{ type: "number", sanitizer: sanitizeNumber },
{ type: "range", sanitizer: sanitizeRange },
{ type: "color", sanitizer: sanitizeColor },
{ type: "checkbox", defaultValue: "on" },
{ type: "radio", defaultValue: "on" },
{ type: "file" },
......@@ -52,7 +100,7 @@
if (types[i] != types[j]) {
test(function() {
var input = document.createElement("input");
var expected = " foo\rbar ";
var expected = INITIAL_VALUE;
input.type = types[i].type;
if (types[i].type === "file") {
assert_throws("INVALID_STATE_ERR", function() {
......@@ -65,6 +113,7 @@
assert_equals(input.value, "");
} else {
input.value = expected;
expected = input.value;
const previouslySelectable = (input.selectionStart !== null);
......@@ -74,16 +123,9 @@
input.type = types[j].type; // change state
// type[i] sanitization
if (types[i].sanitizedValue || types[i].sanitizedValue === "") {
expected = types[i].sanitizedValue;
}
// type[j] sanitization
if (types[j].sanitizedValue || types[j].sanitizedValue === "") {
if ((expected !== "" && !types[i].overridesSanitization) || types[j].overridesSanitization) {
expected = types[j].sanitizedValue;
}
if (types[j].sanitizer) {
expected = types[j].sanitizer(expected);
}
// type[j] defaultValue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment