Commit bda2e67c authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Convert some fast/form/ layout tests with testharness

This patch converts some layout tests with testharness to reduce usage
of deprecated js-test.js.

It's also a preparation for using Element.innerText as layout test text
dump to avoid confusiong text dumps. These tests contain <option> with
text like "failure", which doesn't appear in old text dump but appears in
innerText. By converting with testharness, we don't have such confusing
text dumps.

Bug: 887148
Change-Id: I38cc38cb395318bb9ddd38d655c99bd4f47bb846
Reviewed-on: https://chromium-review.googlesource.com/c/1314131Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604978}
parent 2aafb006
Test for bug 25379: Selecting a bank in American Express Pay Bill fails.
Both SELECT elements below should say PASS.
PASS
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=25379">bug 25379<a>:
Selecting a bank in American Express Pay Bill fails.</p>
......@@ -8,16 +10,15 @@ Selecting a bank in American Express Pay Bill fails.</p>
</select>
<div id=paymentoptions></div>
<script>
if (window.testRunner)
testRunner.dumpAsText();
test(() => {
document.getElementById('paymentoptions').innerHTML =
'<select>' +
'<option selected>FAIL</option>' +
'<option selected>PASS</option>' +
'</select>'
document.getElementById("paymentoptions").innerHTML =
'<select>' +
'<option selected>FAIL</option>' +
'<option selected>PASS</option>' +
'</select>'
if (window.testRunner && document.getElementsByTagName("select")[0].value == "PASS" && document.getElementsByTagName("select")[1].value == "PASS")
document.write("PASS");
assert_equals(document.getElementsByTagName('select')[0].value, 'PASS');
assert_equals(document.getElementsByTagName('select')[1].value, 'PASS');
}, 'Both SELECT elements should say PASS');
</script>
</body>
Test for bug 13287: Cannot change SELECT to a dynamically created option.
Results:
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=13287">bug 13287</a>:
Cannot change SELECT to a dynamically created option.</p>
<form>
......@@ -13,96 +15,83 @@ Cannot change SELECT to a dynamically created option.</p>
<select onchange="onChange()" size=2><option>FAILURE</option></select>
</form>
<script>
function onChange() {
document.write("<p>FAILURE: onChange fired</p>");
}
function testResults(expectedArr, sl)
{
var resultsArr = new Array(sl.options.length);
var i;
for (i=0; i < sl.options.length; i++) {
resultsArr[i] = sl.options[i].selected;
}
var successString = "Failed";
var success = false;
if (expectedArr.join() == resultsArr.join()) {
success = true;
successString = "Passed";
}
log(successString);
if (!success) {
log("<pre> Expected: " + expectedArr.join() + "<br>" + " Actual: " + resultsArr.join() + "</pre>");
}
}
if (window.testRunner)
testRunner.dumpAsText();
var results = document.createElement('div');
results.id = "res";
results.appendChild(document.createTextNode("Results:"));
document.body.appendChild(results);
function log(msg)
{
var r = document.getElementById('res');
r.innerHTML = r.innerHTML + "<br>" + msg;
}
try {
var theSelect = document.forms[0].elements[0];
theSelect.options.add(new Option("SUCCESS", "SUCCESS", false, true), 0);
testResults([true, false], theSelect);
theSelect = document.forms[0].elements[1];
theSelect.insertBefore(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
testResults([true, false], theSelect);
// defaultSelected doesn't make the element selected when inserted.
theSelect = document.forms[0].elements[2];
theSelect.options.add(new Option("FAILURE", "FAILURE", true, false), 0);
testResults([false, true], theSelect);
theSelect = document.forms[0].elements[3];
theSelect.options[0].selected = 1;
theSelect.options.add(new Option("SUCCESS", "SUCCESS", false, true), 0);
testResults([true, false], theSelect);
theSelect = document.forms[0].elements[4];
theSelect.options[0].selected = 1;
theSelect.insertBefore(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
testResults([true, false], theSelect);
// defaultSelected doesn't make the element selected when inserted.
theSelect = document.forms[0].elements[5];
theSelect.options[0].selected = 1;
theSelect.options.add(new Option("FAILURE", "FAILURE", true, false), 0);
testResults([false, true], theSelect);
theSelect = document.forms[0].elements[6];
theSelect.options.add(new Option("SELECTED", "SELECTED", false, true), 0);
testResults([true, true], theSelect);
theSelect = document.forms[0].elements[7];
theSelect.insertBefore(new Option("SELECTED", "SELECTED", false, true), theSelect.firstChild);
testResults([true, true], theSelect);
theSelect = document.forms[0].elements[8];
theSelect.replaceChild(new Option("SUCCESS", "SUCCESS", false, true), theSelect.firstChild);
testResults([true, false], theSelect);
theSelect = document.forms[0].elements[9];
theSelect.appendChild(new Option("SUCCESS", "SUCCESS", false, true));
testResults([false, true], theSelect);
} catch (ex) {
alert(ex);
}
function onChange() {
assert_unreached('onChange fired');
}
function testResults(expectedArr, sl) {
let resultsArr = new Array(sl.options.length);
for (let i=0; i < sl.options.length; i++) {
resultsArr[i] = sl.options[i].selected;
}
assert_array_equals(resultsArr, expectedArr);
}
let theSelect;
test(() => {
theSelect = document.forms[0].elements[0];
theSelect.options.add(new Option('SUCCESS', 'SUCCESS', false, true), 0);
testResults([true, false], theSelect);
});
test(() => {
theSelect = document.forms[0].elements[1];
theSelect.insertBefore(new Option('SUCCESS', 'SUCCESS', false, true), theSelect.firstChild);
testResults([true, false], theSelect);
});
test(() => {
// defaultSelected doesn't make the element selected when inserted.
theSelect = document.forms[0].elements[2];
theSelect.options.add(new Option('FAILURE', 'FAILURE', true, false), 0);
testResults([false, true], theSelect);
});
test(() => {
theSelect = document.forms[0].elements[3];
theSelect.options[0].selected = 1;
theSelect.options.add(new Option('SUCCESS', 'SUCCESS', false, true), 0);
testResults([true, false], theSelect);
});
test(() => {
theSelect = document.forms[0].elements[4];
theSelect.options[0].selected = 1;
theSelect.insertBefore(new Option('SUCCESS', 'SUCCESS', false, true), theSelect.firstChild);
testResults([true, false], theSelect);
});
test(() => {
// defaultSelected doesn't make the element selected when inserted.
theSelect = document.forms[0].elements[5];
theSelect.options[0].selected = 1;
theSelect.options.add(new Option('FAILURE', 'FAILURE', true, false), 0);
testResults([false, true], theSelect);
});
test(() => {
theSelect = document.forms[0].elements[6];
theSelect.options.add(new Option('SELECTED', 'SELECTED', false, true), 0);
testResults([true, true], theSelect);
});
test(() => {
theSelect = document.forms[0].elements[7];
theSelect.insertBefore(new Option('SELECTED', 'SELECTED', false, true), theSelect.firstChild);
testResults([true, true], theSelect);
});
test(() => {
theSelect = document.forms[0].elements[8];
theSelect.replaceChild(new Option('SUCCESS', 'SUCCESS', false, true), theSelect.firstChild);
testResults([true, false], theSelect);
});
test(() => {
theSelect = document.forms[0].elements[9];
theSelect.appendChild(new Option('SUCCESS', 'SUCCESS', false, true));
testResults([false, true], theSelect);
});
</script>
This test verifies a drop-down menu can refine the selection when we send keydown events consisting of Cyrillic characters.
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
<html>
<head>
<title></title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
</head>
<body>
<p>This test verifies a drop-down menu can refine the selection when we send keydown events consisting of Cyrillic characters.</p>
......@@ -42,30 +44,19 @@
<ul id="console"></ul>
</body>
<script>
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
if (window.testRunner)
testRunner.dumpAsText();
// Set the input focus to the <select> element.
var node = document.getElementById("test");
node.focus();
var base = 0x0430;
for (var i = base; i <= 0x044F; i++) {
test(() => {
// Send a key event consisting of a Cyrillic small character.
eventSender.keyDown(String.fromCharCode(i));
// Compare the value of this <select> element with the expected result.
if (node.value == i - base)
log('SUCCEEDED');
else
log('FAILED: expected="' + i + '", actual="' + node.value + '".');
assert_equals(node.value, (i - base).toString());
});
}
</script>
</html>
This test verifies a drop-down menu can refine the selection when we send keydown events consisting of Greek small characters.
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
SUCCEEDED
<html>
<head>
<title></title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
</head>
<body>
<p>This test verifies a drop-down menu can refine the selection when we send keydown events consisting of Greek small characters.</p>
......@@ -34,33 +36,22 @@
<ul id="console"></ul>
</body>
<script>
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
if (window.testRunner)
testRunner.dumpAsText();
// Set the input focus to the <select> element.
var node = document.getElementById("test");
node.focus();
var base = 0x03B1;
for (var i = base; i <= 0x03C9; i++) {
test(() => {
// We don't have to send U+03C2 (Greek Small Letter Final Sigma).
if (i != 0x03C2) {
// Send a key event consisting of a Greek small character.
eventSender.keyDown(String.fromCharCode(i));
// Compare the value of this <select> element with the expected result.
if (node.value == i - base)
log('SUCCEEDED');
else
log('FAILED: expected="' + i + '", actual="' + node.value + '".');
assert_equals(node.value, (i - base).toString());
}
});
}
</script>
</html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<select id="select">
<option>FAIL</option>
<option>PASS</option>
<option selected="true">Did not run</option>
</select>
<p id="result">
</p>
<script>
if (window.testRunner)
testRunner.dumpAsText();
test(() => {
select.selectedIndex = 1;
result.innerText = select.selectedIndex == 1 ? "PASS" : "FAIL";
assert_equals(select.selectedIndex, 1);
});
</script>
Test for bug 13278: REGRESSION: cannot change SELECT option.
SUCCESS
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<body>
<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=13278">bug 13278</a>: REGRESSION: cannot change SELECT option.</p>
<form>
......@@ -14,18 +16,14 @@
</form>
<div id=result></div>
<script>
test(() => {
document.forms[0].elements[0].options[1].selected = true;
document.forms[0].elements[1].options[1].selected = true;
if (window.testRunner)
testRunner.dumpAsText();
document.forms[0].elements[0].options[1].selected = true;
document.forms[0].elements[1].options[1].selected = true;
document.forms[0].elements[0].options[2].selected = true;
document.forms[0].elements[1].options[2].selected = true;
if (document.forms[0].elements[0].value != "SUCCESS" || document.forms[0].elements[1].options[1].selected)
document.getElementById("result").innerHTML = "FAILURE";
else
document.getElementById("result").innerHTML = "SUCCESS";
document.forms[0].elements[0].options[2].selected = true;
document.forms[0].elements[1].options[2].selected = true;
assert_equals(document.forms[0].elements[0].value, 'SUCCESS');
assert_false(document.forms[0].elements[1].options[1].selected);
});
</script>
</body>
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