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
Changes from 1 commit
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
124 changes: 124 additions & 0 deletions html/semantics/forms/the-input-element/text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!DOCTYPE html>
<html>
<head>
<title>Text input element</title>
<meta name=viewport content="width=device-width, maximum-scale=1.0, user-scalable=no" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary for the test? If not, there's no reason to keep it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto that.

<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]);
el.value = "1";
var exception;
try {
el.stepDown();
} catch (e) {
exception = e;
}
assert_equals(el.value, "1");
assert_equals(exception.name, "InvalidStateError");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not assert_throws?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably because most of the people in TTWF Tokyo just got a very quick crash course on testharness, that is probably why. This doesn't make the test invalid though. Do you want to veto for the test until it's properly done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't aware of assert_throws, it looks neat! I'll update my patch (will address other comments as well...)

}, "stepDown does not apply for " + types[i]);

test(
function() {
var el = document.getElementById(types[i]);
el.value = "1";
var exception;
try {
el.steUp();
} catch (e) {
exception = e;
}
assert_equals(el.value, "1");
assert_equals(exception.name, "InvalidStateError");
}, "stepUp does not apply for " + types[i]);
}

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double whitespace at end! :P (remove)