Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test cases for input type="text" and type="search" (4.10.7.1.2) #153

Merged
merged 3 commits into from
Jun 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 30 additions & 49 deletions html/semantics/forms/the-input-element/hidden.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<title>Hidden input element</title>
<meta name=viewport content="width=device-width, maximum-scale=1.0, user-scalable=no" />
<link rel="author" title="Kinuko Yasuda" href="mailto:kinuko@chromium.org">
<link rel="help" href="http://www.w3.org/html/wg/drafts/html/master/forms.html#hidden-state-(type=hidden)">
<script src="/resources/testharness.js"></script>
Expand All @@ -21,69 +20,51 @@ <h1>Hidden input element</h1>
<script type="text/javascript">

test(
function() {
assert_equals(document.getElementById("hidden").value, "");
assert_equals(document.getElementById("hidden_with_value").value, "foo");
}, "Value returns the current value for hidden");
function() {
assert_equals(document.getElementById("hidden").value, "");
assert_equals(document.getElementById("hidden_with_value").value, "foo");
}, "Value returns the current value for hidden");

test(
function() {
document.getElementById("hidden").value = "A";
assert_equals(document.getElementById("hidden").value, "A");
document.getElementById("hidden").value = "B";
assert_equals(document.getElementById("hidden").value, "B");
}, "Setting value changes the current value for hidden");
function() {
document.getElementById("hidden").value = "A";
assert_equals(document.getElementById("hidden").value, "A");
document.getElementById("hidden").value = "B";
assert_equals(document.getElementById("hidden").value, "B");
}, "Setting value changes the current value for hidden");

test(
function() {
assert_equals(document.getElementById("hidden").files, null);
}, "files attribute must return null for hidden");
function() {
assert_equals(document.getElementById("hidden").files, null);
}, "files attribute must return null for hidden");

test(
function() {
assert_equals(document.getElementById("hidden").valueAsDate, null);
}, "valueAsDate attribute must return null for hidden");
function() {
assert_equals(document.getElementById("hidden").valueAsDate, null);
}, "valueAsDate attribute must return null for hidden");

test(
function() {
assert_equals(document.getElementById("hidden").valueAsNumber, NaN);
}, "valueAsNumber attribute must return NaN for hidden");
function() {
assert_equals(document.getElementById("hidden").valueAsNumber, NaN);
}, "valueAsNumber attribute must return NaN for hidden");

test(
function() {
assert_equals(document.getElementById("hidden").list, null);
}, "list attribute must return null for hidden");
function() {
assert_equals(document.getElementById("hidden").list, null);
}, "list attribute must return null for hidden");

test(
function() {
var el = document.getElementById("hidden");
el.value = "1";
var exception;
try {
el.stepDown();
} catch (e) {
exception = e;
}
assert_equals(el.value, "1");
assert_equals(exception.name, "InvalidStateError");
}, "stepDown does not apply for hidden");
function() {
var el = document.getElementById("hidden");
assert_throws("InvalidStateError", function() { el.stepDown(); }, "");
}, "stepDown does not apply for hidden");

test(
function() {
var el = document.getElementById("hidden");
el.value = "1";
var exception;
try {
el.stepUp();
} catch (e) {
exception = e;
}
assert_equals(el.value, "1");
assert_equals(exception.name, "InvalidStateError");
}, "stepUp does not apply for hidden");
function() {
var el = document.getElementById("hidden");
assert_throws("InvalidStateError", function() { el.stepUp(); }, "");
}, "stepUp does not apply for hidden");

</script>
</body>
</html>


104 changes: 104 additions & 0 deletions html/semantics/forms/the-input-element/text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!DOCTYPE html>
<html>
<head>
<title>Text input element</title>
<link rel="author" title="Kinuko Yasuda" href="mailto:kinuko@chromium.org">
<link rel="help" href="http://www.w3.org/html/wg/drafts/html/master/forms.html#text-(type=text)-state-and-search-state-(type=search)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<h1>Text input element</h1>
<div style="display: none">

<input id="text" type="text" />
<input id="text_with_value" type="text" value="foo" />

<input id="search" type="search" />
<input id="search_with_value" type="search" value="foo" />

</div>
<div id="log"></div>
<script type="text/javascript">
var types = [ 'text', 'search' ];

for (var i = 0; i < types.length; ++i) {
test(
function() {
assert_equals(document.getElementById(types[i]).value, "");
assert_equals(document.getElementById(types[i] + "_with_value").value, "foo");
}, "Value returns the current value for " + types[i]);

test(
function() {
document.getElementById(types[i]).value = "A";
assert_equals(document.getElementById(types[i]).value, "A");
document.getElementById(types[i]).value = "B";
}, "Setting value changes the current value for " + types[i]);

test(
function() {
// Any LF (\n) must be stripped.
document.getElementById(types[i]).value = "\nAB";
assert_equals(document.getElementById(types[i]).value, "AB");
document.getElementById(types[i]).value = "A\nB";
assert_equals(document.getElementById(types[i]).value, "AB");
document.getElementById(types[i]).value = "AB\n";
assert_equals(document.getElementById(types[i]).value, "AB");

// Any CR (\r) must be stripped.
document.getElementById(types[i]).value = "\rAB";
assert_equals(document.getElementById(types[i]).value, "AB");
document.getElementById(types[i]).value = "A\rB";
assert_equals(document.getElementById(types[i]).value, "AB");
document.getElementById(types[i]).value = "AB\r";
assert_equals(document.getElementById(types[i]).value, "AB");

// Any combinations of LF CR must be stripped.
document.getElementById(types[i]).value = "\r\nAB";
assert_equals(document.getElementById(types[i]).value, "AB");
document.getElementById(types[i]).value = "A\r\nB";
assert_equals(document.getElementById(types[i]).value, "AB");
document.getElementById(types[i]).value = "AB\r\n";
assert_equals(document.getElementById(types[i]).value, "AB");
document.getElementById(types[i]).value = "\r\nA\n\rB\r\n";
assert_equals(document.getElementById(types[i]).value, "AB");
}, "Value sanitization algorithm should strip line breaks for " + types[i]);

test(
function() {
assert_equals(document.getElementById(types[i]).files, null);
}, "files attribute must return null for " + types[i]);

test(
function() {
assert_equals(document.getElementById(types[i]).valueAsDate, null);
}, "valueAsDate attribute must return null for " + types[i]);

test(
function() {
assert_equals(document.getElementById(types[i]).valueAsNumber, NaN);
}, "valueAsNumber attribute must return NaN for " + types[i]);

test(
function() {
assert_equals(document.getElementById("text").list, null);
}, "list attribute must return null for " + types[i]);

test(
function() {
var el = document.getElementById(types[i]);
assert_throws("InvalidStateError", function() { el.stepDown(); }, "");
}, "stepDown does not apply for " + types[i]);

test(
function() {
var el = document.getElementById(types[i]);
assert_throws("InvalidStateError", function() { el.stepUp(); }, "");
}, "stepUp does not apply for " + types[i]);
}

</script>
</body>
</html>