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