Commit 4ddc2ce8 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Convert some layout tests with W3C testharness

This patch converts some layout tests to use testharness instead of
plain text dump or js-test.js.

It is a preparation for crrev.com/c/1243119. The changed tests have
non-trivial text failures with that patch (due to flakes or non-trivial
dependency on js-test.js), so we convert them in this CL to reduce
noise there, and ensure that there are only newline text diffs in the
other CL.

Bug: 887148
Change-Id: I46d7508ddde62e32ddfa421e9975b39b73cc06df
Reviewed-on: https://chromium-review.googlesource.com/1246902
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594581}
parent 36469737
To manually test, click one of the buttons below. The result should be two 'PASS' events for either button.
Copy Cut
PASS successfullyParsed is true
TEST COMPLETE
PASS document.execCommand('copy') is true
PASS copyEventSeen is true
PASS document.execCommand('cut') is true
PASS cutEventSeen is true
<!DOCTYPE html> <!DOCTYPE html>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
var copyEventSeen; var copyEventSeen;
var cutEventSeen; var cutEventSeen;
function runTest() function runTest()
{ {
if (window.testRunner) test(() => {
assert_exists(window, 'testRunner');
testRunner.setJavaScriptCanAccessClipboard(false); testRunner.setJavaScriptCanAccessClipboard(false);
else
return;
clickButton("copy"); clickButton("copy");
}, 'Copy');
test(() => {
assert_exists(window, 'testRunner');
testRunner.setJavaScriptCanAccessClipboard(false);
clickButton("cut"); clickButton("cut");
}, 'Cut');
} }
function clickButton(id) function clickButton(id)
...@@ -25,15 +31,15 @@ function clickButton(id) ...@@ -25,15 +31,15 @@ function clickButton(id)
function onClickCopy() function onClickCopy()
{ {
copyEventSeen = false; copyEventSeen = false;
shouldBeTrue("document.execCommand('copy')"); assert_true(document.execCommand('copy'));
shouldBeTrue("copyEventSeen"); assert_true(copyEventSeen);
} }
function onClickCut() function onClickCut()
{ {
cutEventSeend = false; cutEventSeend = false;
shouldBeTrue("document.execCommand('cut')"); assert_true(document.execCommand('cut'));
shouldBeTrue("cutEventSeen"); assert_true(cutEventSeen);
} }
function onCopy() function onCopy()
...@@ -46,11 +52,13 @@ function onCut() ...@@ -46,11 +52,13 @@ function onCut()
cutEventSeen = true; cutEventSeen = true;
} }
</script> </script>
<body onload="runTest()" oncopy="onCopy()" oncut="onCut()"> <body oncopy="onCopy()" oncut="onCut()">
<p>To manually test, click one of the buttons below. The result should be two 'PASS' events for either button. <p>To manually test, click one of the buttons below. The result should be two 'PASS' events for either button.
<div> <div>
<button id="copy" onclick="onClickCopy()">Copy</button> <button id="copy" onclick="onClickCopy()">Copy</button>
<button id="cut" onclick="onClickCut()">Cut</button> <button id="cut" onclick="onClickCut()">Cut</button>
</div> </div>
<div id="console"></div> <script>
runTest();
</script>
</body> </body>
This test verifies the order of events fired by drag-and-drop.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
focus src
drop dst
input src
change src
blur src
focus dst
input dst
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head> </head>
<body onload="runTest()"> <body>
<input type="text" id="src" value="abc"> <input type="text" id="src" value="abc">
<input type="text" id="dst"> <input type="text" id="dst">
<div id="console"></div>
<script> <script>
description("This test verifies the order of events fired by drag-and-drop."); test(() => {
const expected = [
{name: 'focus', target: 'src'},
{name: 'drop', target: 'dst'},
{name: 'input', target: 'src'},
{name: 'change', target: 'src'},
{name: 'blur', target: 'src'},
{name: 'focus', target: 'dst'},
{name: 'input', target: 'dst'},
];
var fired = 0;
function checkEvent(name, target) {
assert_equals(name, expected[fired].name);
assert_equals(target, expected[fired].target);
++fired;
}
function runTest()
{
var src = document.getElementById('src'); var src = document.getElementById('src');
var dst = document.getElementById('dst'); var dst = document.getElementById('dst');
['blur', 'change', 'drop', 'focus', 'input'].forEach(function(event) { ['blur', 'change', 'drop', 'focus', 'input'].forEach(function(event) {
src.addEventListener(event, debug.bind(null, event + ' src')); src.addEventListener(event, () => checkEvent(event, 'src'));
dst.addEventListener(event, debug.bind(null, event + ' dst')); dst.addEventListener(event, () => checkEvent(event, 'dst'));
}); });
src.select(); src.select();
...@@ -26,7 +40,7 @@ function runTest() ...@@ -26,7 +40,7 @@ function runTest()
eventSender.leapForward(1000); eventSender.leapForward(1000);
eventSender.mouseMoveTo(dst.offsetLeft + dst.offsetWidth / 2, dst.offsetTop + dst.offsetHeight / 2); eventSender.mouseMoveTo(dst.offsetLeft + dst.offsetWidth / 2, dst.offsetTop + dst.offsetHeight / 2);
eventSender.mouseUp(); eventSender.mouseUp();
} }, 'Event order by drag-and-drop');
</script> </script>
</body> </body>
</html> </html>
This test checks select attribute of content element is valid.
null
PASS internals.isValidContentSelect(content) is true
PASS internals.isValidContentSelect(content) is true
*|div
PASS internals.isValidContentSelect(content) is true
|div
PASS internals.isValidContentSelect(content) is true
div
PASS internals.isValidContentSelect(content) is true
*|*
PASS internals.isValidContentSelect(content) is true
|*
PASS internals.isValidContentSelect(content) is true
*
PASS internals.isValidContentSelect(content) is true
.elem
PASS internals.isValidContentSelect(content) is true
p.elem
PASS internals.isValidContentSelect(content) is true
foo.elem
PASS internals.isValidContentSelect(content) is true
*.right
PASS internals.isValidContentSelect(content) is true
#elem
PASS internals.isValidContentSelect(content) is true
p#elem
PASS internals.isValidContentSelect(content) is true
foo#elem
PASS internals.isValidContentSelect(content) is true
*#something
PASS internals.isValidContentSelect(content) is true
div[title]
PASS internals.isValidContentSelect(content) is true
div[class="example"]
PASS internals.isValidContentSelect(content) is true
div[hello="Cleveland"][goodbye="Columbus"]
PASS internals.isValidContentSelect(content) is true
div[rel~="copyright"]
PASS internals.isValidContentSelect(content) is true
div[href="http://www.example.com/"]
PASS internals.isValidContentSelect(content) is true
div[hreflang|="en"]
PASS internals.isValidContentSelect(content) is true
div[character=romeo]
PASS internals.isValidContentSelect(content) is true
div, div
PASS internals.isValidContentSelect(content) is true
div, div
PASS internals.isValidContentSelect(content) is true
div:not(div)
PASS internals.isValidContentSelect(content) is true
div div
PASS internals.isValidContentSelect(content) is false
div > div
PASS internals.isValidContentSelect(content) is false
div + div
PASS internals.isValidContentSelect(content) is false
div ~ div
PASS internals.isValidContentSelect(content) is false
ns|div
PASS internals.isValidContentSelect(content) is false
ns|*
PASS internals.isValidContentSelect(content) is false
div:root
PASS internals.isValidContentSelect(content) is false
div:lang(en)
PASS internals.isValidContentSelect(content) is false
div::before
PASS internals.isValidContentSelect(content) is false
div::after
PASS internals.isValidContentSelect(content) is false
div::first-line
PASS internals.isValidContentSelect(content) is false
div::first-letter
PASS internals.isValidContentSelect(content) is false
div:active
PASS internals.isValidContentSelect(content) is false
div:hover
PASS internals.isValidContentSelect(content) is false
div:focus
PASS internals.isValidContentSelect(content) is false
div div:not(div)
PASS internals.isValidContentSelect(content) is false
div:not(div) div
PASS internals.isValidContentSelect(content) is false
div span div
PASS internals.isValidContentSelect(content) is false
div < div
PASS internals.isValidContentSelect(content) is false
div - dvi
PASS internals.isValidContentSelect(content) is false
< div
PASS internals.isValidContentSelect(content) is false
+div
PASS internals.isValidContentSelect(content) is false
~div
PASS internals.isValidContentSelect(content) is false
div:!
PASS internals.isValidContentSelect(content) is false
!:!
PASS internals.isValidContentSelect(content) is false
div::!
PASS internals.isValidContentSelect(content) is false
div::first_of_type
PASS internals.isValidContentSelect(content) is false
pe;ro
PASS internals.isValidContentSelect(content) is false
@screen
PASS internals.isValidContentSelect(content) is false
@import "style.css"
PASS internals.isValidContentSelect(content) is false
div :first-of-type
PASS internals.isValidContentSelect(content) is false
div::first-of-type
PASS internals.isValidContentSelect(content) is false
div, ,div
PASS internals.isValidContentSelect(content) is false
div ''
PASS internals.isValidContentSelect(content) is false
div:link
PASS internals.isValidContentSelect(content) is false
div:visited
PASS internals.isValidContentSelect(content) is false
div:target
PASS internals.isValidContentSelect(content) is false
div:enabled
PASS internals.isValidContentSelect(content) is false
div:checked
PASS internals.isValidContentSelect(content) is false
div:indeterminate
PASS internals.isValidContentSelect(content) is false
div:nth-child(1)
PASS internals.isValidContentSelect(content) is false
div:nth-last-child(1)
PASS internals.isValidContentSelect(content) is false
div:nth-of-type(1)
PASS internals.isValidContentSelect(content) is false
div:nth-last-of-type(1)
PASS internals.isValidContentSelect(content) is false
div:first-child
PASS internals.isValidContentSelect(content) is false
div:last-child
PASS internals.isValidContentSelect(content) is false
div:first-of-type
PASS internals.isValidContentSelect(content) is false
div:last-of-type
PASS internals.isValidContentSelect(content) is false
div:only-of-type
PASS internals.isValidContentSelect(content) is false
div:first-of-type:last-of-type
PASS internals.isValidContentSelect(content) is false
div.elem:visited
PASS internals.isValidContentSelect(content) is false
*:visited
PASS internals.isValidContentSelect(content) is false
div:first-of-type, div
PASS internals.isValidContentSelect(content) is false
div, div:first-of-type
PASS internals.isValidContentSelect(content) is false
div:first-of-type, div:last-of-type
PASS internals.isValidContentSelect(content) is false
div:not(:not(div))
PASS internals.isValidContentSelect(content) is false
div:not(:hover)
PASS internals.isValidContentSelect(content) is false
div:not(div div)
PASS internals.isValidContentSelect(content) is false
div:not(div div:not)
PASS internals.isValidContentSelect(content) is false
div:not(div div:hover)
PASS internals.isValidContentSelect(content) is false
div div:not(:hover)
PASS internals.isValidContentSelect(content) is false
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<script src="../../../resources/js-test.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
</head> </head>
<body> <body>
<p>This test checks select attribute of content element is valid.</p> <p>This test checks select attribute of content element is valid.</p>
...@@ -12,16 +13,16 @@ ...@@ -12,16 +13,16 @@
var container = document.getElementById("container"); var container = document.getElementById("container");
var content; var content;
function test(select, valid) { function runTest(select, valid) {
content = document.createElement('content'); content = document.createElement('content');
if (select != null) if (select != null)
content.setAttribute('select', select); content.setAttribute('select', select);
debug(select); test(() => {
if (valid) assert_exists(window, 'internals',
shouldBe("internals.isValidContentSelect(content)", "true"); 'This test requires internals.isValidContentSelect');
else assert_equals(internals.isValidContentSelect(content), valid);
shouldBe("internals.isValidContentSelect(content)", "false"); }, `${select} ${valid}`);
} }
var dataOfValidCases = [ var dataOfValidCases = [
...@@ -53,19 +54,15 @@ var dataOfInvalidCases = [ ...@@ -53,19 +54,15 @@ var dataOfInvalidCases = [
]; ];
function doTest() { function doTest() {
if (!window.internals)
return;
for (var i = 0; i < dataOfValidCases.length; ++i) { for (var i = 0; i < dataOfValidCases.length; ++i) {
test(dataOfValidCases[i], true); runTest(dataOfValidCases[i], true);
} }
for (var i = 0; i < dataOfInvalidCases.length; ++i) { for (var i = 0; i < dataOfInvalidCases.length; ++i) {
test(dataOfInvalidCases[i], false); runTest(dataOfInvalidCases[i], false);
} }
} }
doTest(); doTest();
var successfullyParsed = true;
</script> </script>
</body> </body>
</html> </html>
This test ensures that if an autoscroll starts from within a scrollable div, it does not propagate to its non-scrollable document body. Furthermore, it tests that if the body has only one of overflowX or overflowY set to hidden, the scrollable axis actually scrolls. Note that this test is pertaining to crbug.com/531525.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS Document didn't scroll.
PASS successfullyParsed is true
TEST COMPLETE
...@@ -14,32 +14,27 @@ ...@@ -14,32 +14,27 @@
width: 100px; width: 100px;
} }
</style> </style>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var scrollTopBefore; var scrollTopBefore;
var maxScrollLeft; var maxScrollLeft;
setPrintTestResultsLazily(); const testCase = async_test(
jsTestIsAsync = true; "If an autoscroll starts from within a " +
description("This test ensures that if an autoscroll starts from within a " +
"scrollable div, it does not propagate to its non-scrollable document " + "scrollable div, it does not propagate to its non-scrollable document " +
"body. Furthermore, it tests that if the body has only one of overflowX " + "body. Furthermore, it tests that if the body has only one of overflowX " +
"or overflowY set to hidden, the scrollable axis actually scrolls. Note " + "or overflowY set to hidden, the scrollable axis actually scrolls. Note " +
"that this test is pertaining to crbug.com/531525."); "that this test is pertaining to crbug.com/531525.");
function finishTest() { const finishTest = testCase.step_func_done(() => {
eventSender.mouseUp(); eventSender.mouseUp();
// Because only overflowY:hidden is set, horizontal scroll should happen and // Because only overflowY:hidden is set, horizontal scroll should happen and
// vertical scroll shouldn't. // vertical scroll shouldn't.
if (document.scrollingElement.scrollTop == scrollTopBefore && document.scrollingElement.scrollLeft == maxScrollLeft) { assert_equals(document.scrollingElement.scrollTop, scrollTopBefore);
testPassed("Document didn't scroll."); assert_equals(document.scrollingElement.scrollLeft, maxScrollLeft);
} else {
testFailed("Document scrolled although overflow:hidden.");
testFailed(document.scrollingElement.scrollTop + " " + scrollTopBefore + " " + document.scrollingElement.scrollLeft + " " + maxScrollLeft);
}
document.getElementById('text-wrapper').style.display = 'none'; document.getElementById('text-wrapper').style.display = 'none';
finishJSTest(); });
}
window.onload = function () { window.onload = function () {
scrollTopBefore = document.scrollingElement.scrollTop; scrollTopBefore = document.scrollingElement.scrollTop;
......
<html> <html>
<head> <head>
<script> <script src="../../resources/testharness.js"></script>
if (window.testRunner) { <script src="../../resources/testharnessreport.js"></script>
testRunner.dumpAsText();
}
</script>
</head> </head>
<body> <body>
<button id="testButton" style="text-indent: -99999999px;" onclick="btnClicked()">Move</button> <button id="testButton" style="text-indent: -99999999px;" onclick="btnClicked()">Move</button>
<p id="output"></p> <p id="output"></p>
<script> <script>
function btnClicked() const testCase = async_test('Button is clicked');
{
document.getElementById('output').innerHTML = "Button is clicked."; const btnClicked = testCase.step_func_done(() => {});
}
if (window.eventSender) { testCase.step(() => {
assert_exists(window, 'eventSender');
var testEle = document.getElementById('testButton'); var testEle = document.getElementById('testButton');
eventSender.mouseMoveTo(testEle.offsetLeft + testEle.offsetWidth / 2, testEle.offsetTop + testEle.offsetHeight / 2); eventSender.mouseMoveTo(testEle.offsetLeft + testEle.offsetWidth / 2, testEle.offsetTop + testEle.offsetHeight / 2);
eventSender.mouseDown(); eventSender.mouseDown();
eventSender.mouseUp(); eventSender.mouseUp();
} });
</script> </script>
</body> </body>
</html> </html>
This tests that we don't lose data dropped onto an input field that changes its content during a drop event
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS dragTarget.value is elementToDrag.href
PASS Didn't crash.
PASS successfullyParsed is true
TEST COMPLETE
<html> <html>
<head> <head>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
function resetField() function resetField()
...@@ -10,8 +11,10 @@ ...@@ -10,8 +11,10 @@
function runTest() function runTest()
{ {
if (window.testRunner) { test(() => {
testRunner.dumpAsText(); assert_exists(
window, 'eventSender',
'This test requires eventSender. To test this manually drag the link into the text field.');
elementToDrag = document.getElementById("elementToDrag"); elementToDrag = document.getElementById("elementToDrag");
x1 = elementToDrag.offsetLeft + elementToDrag.offsetWidth / 2; x1 = elementToDrag.offsetLeft + elementToDrag.offsetWidth / 2;
...@@ -26,14 +29,12 @@ ...@@ -26,14 +29,12 @@
eventSender.leapForward(400); eventSender.leapForward(400);
eventSender.mouseMoveTo(x2, y2); eventSender.mouseMoveTo(x2, y2);
eventSender.mouseUp(); eventSender.mouseUp();
shouldBe("dragTarget.value", "elementToDrag.href"); assert_equals(dragTarget.value, elementToDrag.href);
testPassed("Didn't crash.");
//clean up output //clean up output
elementToDrag.parentNode.removeChild(elementToDrag); elementToDrag.parentNode.removeChild(elementToDrag);
dragTarget.parentNode.removeChild(dragTarget); dragTarget.parentNode.removeChild(dragTarget);
} else { }, "This tests that we don't lose data dropped onto an input field that changes its content during a drop event");
debug('<br>To test this manually drag the link into the text field.')
}
} }
</script> </script>
</head> </head>
...@@ -43,7 +44,6 @@ ...@@ -43,7 +44,6 @@
<input id="dragTarget" type="text" value="Original Text" onfocus="resetField()" /> <input id="dragTarget" type="text" value="Original Text" onfocus="resetField()" />
<div id="console"></div> <div id="console"></div>
<script> <script>
description("This tests that we don't lose data dropped onto an input field that changes its content during a drop event");
runTest(); runTest();
</script> </script>
</body> </body>
......
Test that wheel and mouse events are dispatched to document and window even if they do not hit any element in the page.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
outside body, inside element
eventType: mousedown
PASS objectsToString(actualReceivers) is "HTMLDivElement,HTMLBodyElement,HTMLDocument,Window"
eventType: mouseup
PASS objectsToString(actualReceivers) is "HTMLDivElement,HTMLBodyElement,HTMLDocument,Window"
eventType: click
PASS objectsToString(actualReceivers) is "HTMLDivElement,HTMLBodyElement,HTMLDocument,Window"
eventType: wheel
PASS objectsToString(actualReceivers) is "HTMLDivElement,HTMLBodyElement,HTMLDocument,Window"
inside body, outside element
eventType: mousedown
PASS objectsToString(actualReceivers) is "HTMLBodyElement,HTMLDocument,Window"
eventType: mouseup
PASS objectsToString(actualReceivers) is "HTMLBodyElement,HTMLDocument,Window"
eventType: click
PASS objectsToString(actualReceivers) is "HTMLBodyElement,HTMLDocument,Window"
eventType: wheel
PASS objectsToString(actualReceivers) is "HTMLBodyElement,HTMLDocument,Window"
outside body, outside element, inside frame
eventType: mousedown
PASS objectsToString(actualReceivers) is "HTMLDocument,Window"
eventType: mouseup
PASS objectsToString(actualReceivers) is "HTMLDocument,Window"
eventType: click
PASS objectsToString(actualReceivers) is "HTMLDocument,Window"
eventType: wheel
PASS objectsToString(actualReceivers) is "HTMLDocument,Window"
PASS successfullyParsed is true
TEST COMPLETE
...@@ -33,18 +33,15 @@ div#child { ...@@ -33,18 +33,15 @@ div#child {
<div id='console'></div> <div id='console'></div>
</body> </body>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
jsTestIsAsync = true; const purpose =
setPrintTestResultsLazily(); 'Test that wheel and mouse events are dispatched to document' +
description('Test that wheel and mouse events are dispatched to document ' + 'and window even if they do not hit any element in the page.';
'and window even if they do not hit any element in the page.');
test(() => {
onload = function() { assert_exists(window, 'eventSender', 'window.eventSender is required for this test.');
if (!window.eventSender) {
testFailed('window.eventSender is required for this test.');
return;
}
window.receivers = new Map(); window.receivers = new Map();
var eventTypes = ['wheel', 'click', 'mousedown', 'mouseup']; var eventTypes = ['wheel', 'click', 'mousedown', 'mouseup'];
...@@ -57,20 +54,19 @@ onload = function() { ...@@ -57,20 +54,19 @@ onload = function() {
} }
} }
debug('outside body, inside element'); // received by element, body, doc, window // received by element, body, doc, window
generateEventsAndVerify(500, 500, [document.getElementById('child'), document.body, document, window]); generateEventsAndVerify(500, 500, [document.getElementById('child'), document.body, document, window], 'outside body, inside element.');
debug('inside body, outside element'); // received by body, doc, window // received by body, doc, window
generateEventsAndVerify(10, 10, [document.body, document, window]); generateEventsAndVerify(10, 10, [document.body, document, window], 'inside body, outside element.');
debug('outside body, outside element, inside frame'); // received by doc, window // received by doc, window
generateEventsAndVerify(10, 500, [document, window]); generateEventsAndVerify(10, 500, [document, window], 'outside body, outside element, inside frame.');
finishJSTest();
function registerEvent(e) { function registerEvent(e) {
window.receivers[e.type].push(this); window.receivers[e.type].push(this);
} }
function generateEventsAndVerify(x, y, expectedReceivers) { function generateEventsAndVerify(x, y, expectedReceivers, title) {
test(() => {
eventSender.mouseMoveTo(x, y); eventSender.mouseMoveTo(x, y);
eventSender.mouseDown(); eventSender.mouseDown();
verifyReceivers('mousedown', expectedReceivers); verifyReceivers('mousedown', expectedReceivers);
...@@ -81,16 +77,16 @@ onload = function() { ...@@ -81,16 +77,16 @@ onload = function() {
eventSender.mouseScrollBy(10, 10); eventSender.mouseScrollBy(10, 10);
verifyReceivers('wheel', expectedReceivers); verifyReceivers('wheel', expectedReceivers);
}, title + ' ' + purpose);
} }
function verifyReceivers(eventType, expectedReceivers) { function verifyReceivers(eventType, expectedReceivers) {
debug('eventType: ' + eventType);
window.actualReceivers = window.receivers[eventType]; window.actualReceivers = window.receivers[eventType];
shouldBeEqualToString('objectsToString(actualReceivers)', objectsToString(expectedReceivers)); assert_equals(objectsToString(actualReceivers), objectsToString(expectedReceivers), eventType);
window.receivers[eventType] = []; window.receivers[eventType] = [];
} }
} });
function objectsToString(objects) { function objectsToString(objects) {
return String(objects.map(function(o) {return o.constructor.name;})); return String(objects.map(function(o) {return o.constructor.name;}));
......
Type something into the first input and press tab. The browser should not crash.
PASSED
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div>Type something into the first input and press tab. The browser should not crash.</div> <div>Type something into the first input and press tab. The browser should not crash.</div>
<div id="parent"> <div id="parent">
<input id="a" /> <input id="a" />
<input id="b" /> <input id="b" />
</div> </div>
<div id="results"></div>
<script> <script>
document.getElementById("a").addEventListener("change", function(e) { document.getElementById("a").addEventListener("change", function(e) {
var parent = document.getElementById("parent"); var parent = document.getElementById("parent");
...@@ -11,17 +12,11 @@ document.getElementById("a").addEventListener("change", function(e) { ...@@ -11,17 +12,11 @@ document.getElementById("a").addEventListener("change", function(e) {
document.getElementById("c").select(); document.getElementById("c").select();
}, false); }, false);
function runTest() test(() => {
{
document.getElementById("a").focus(); document.getElementById("a").focus();
if (!window.testRunner) if (!window.testRunner)
return; return;
testRunner.dumpAsText();
eventSender.keyDown("x") eventSender.keyDown("x")
eventSender.keyDown("\t"); eventSender.keyDown("\t");
document.getElementById("results").innerText = "PASSED"; }, "Typing followed by focus change doesn't crash");
}
runTest();
</script> </script>
Click Here Click Here Too
PASS win is non-null.
PASS successfullyParsed is true
TEST COMPLETE
PASS win is non-null.
<html> <html>
<head> <head>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head> </head>
<body> <body>
<button id="button1" onclick="testButton1()">Click Here</button> <button id="button1" onclick="testButton1()">Click Here</button>
<button id="button2" onclick="testButton2()">Click Here Too</button> <button id="button2" onclick="testButton2()">Click Here Too</button>
<button id="test" onclick="popup()" style="display:none"></button> <button id="test" onclick="popup()" style="display:none"></button>
<div id="console"></div>
<script> <script>
setup({explicit_done: true});
var testNum = 0; var testNum = 0;
var win; var win;
function popup() { function popup() {
win = window.open("about:blank", "blank"); win = window.open("about:blank", "blank");
shouldBeNonNull("win"); assert_not_equals(win, null);
} }
function testButton1() { function testButton1() {
...@@ -44,28 +46,30 @@ ...@@ -44,28 +46,30 @@
function nextTest() { function nextTest() {
if (testNum == 0) { if (testNum == 0) {
test(() => {
var button1 = document.getElementById("button1"); var button1 = document.getElementById("button1");
eventSender.mouseMoveTo(button1.offsetLeft + button1.offsetWidth / 2, button1.offsetTop + button1.offsetHeight / 2); eventSender.mouseMoveTo(button1.offsetLeft + button1.offsetWidth / 2, button1.offsetTop + button1.offsetHeight / 2);
eventSender.mouseDown(); eventSender.mouseDown();
eventSender.mouseUp(); eventSender.mouseUp();
}, 'Click button1');
} else if (testNum == 1) { } else if (testNum == 1) {
test(() => {
var button2 = document.getElementById("button2"); var button2 = document.getElementById("button2");
eventSender.mouseMoveTo(button2.offsetLeft + button2.offsetWidth / 2, button2.offsetTop + button2.offsetHeight / 2); eventSender.mouseMoveTo(button2.offsetLeft + button2.offsetWidth / 2, button2.offsetTop + button2.offsetHeight / 2);
eventSender.mouseDown(); eventSender.mouseDown();
eventSender.mouseUp(); eventSender.mouseUp();
}, 'Click button2');
} else { } else {
testRunner.notifyDone(); done();
} }
++testNum; ++testNum;
closeWindowAndRunNextTest(); closeWindowAndRunNextTest();
} }
if (window.testRunner) { if (window.testRunner) {
testRunner.dumpAsText();
testRunner.setCanOpenWindows(); testRunner.setCanOpenWindows();
testRunner.setPopupBlockingEnabled(true); testRunner.setPopupBlockingEnabled(true);
testRunner.setCloseRemainingWindowsWhenComplete(true); testRunner.setCloseRemainingWindowsWhenComplete(true);
testRunner.waitUntilDone();
nextTest(); nextTest();
} }
......
<html> <html>
<head> <head>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head> </head>
<body> <body>
<button id="test" onclick="popup()" style="display:none"></button> <button id="test" onclick="popup()" style="display:none"></button>
...@@ -9,21 +10,16 @@ ...@@ -9,21 +10,16 @@
var win; var win;
function popup() { function popup() {
win = window.open("about:blank", "blank"); win = window.open("about:blank", "blank");
shouldBeNull("win"); assert_equals(win, null);
} }
if (window.testRunner) { if (window.testRunner) {
testRunner.dumpAsText();
testRunner.setCanOpenWindows(); testRunner.setCanOpenWindows();
testRunner.setPopupBlockingEnabled(true); testRunner.setPopupBlockingEnabled(true);
testRunner.setCloseRemainingWindowsWhenComplete(true); testRunner.setCloseRemainingWindowsWhenComplete(true);
testRunner.waitUntilDone();
} }
document.getElementById("test").click(); test(() => document.getElementById("test").click(), 'Fake button click');
if (window.testRunner)
testRunner.notifyDone();
</script> </script>
</body> </body>
</html> </html>
PASS win is null
PASS win is null
PASS successfullyParsed is true
TEST COMPLETE
<html> <html>
<head> <head>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head> </head>
<body> <body>
<textarea id="test" width="100" onfocus="popup()" onblur="popup()"></textarea> <textarea id="test" width="100" onfocus="popup()" onblur="popup()"></textarea>
<div id="console"></div>
<script> <script>
var win; var win;
function popup() { function popup() {
win = window.open("about:blank", "blank"); win = window.open("about:blank", "blank");
shouldBeNull("win"); assert_equals(win, null);
} }
if (window.testRunner) { if (window.testRunner) {
testRunner.dumpAsText();
testRunner.setCanOpenWindows(); testRunner.setCanOpenWindows();
testRunner.setPopupBlockingEnabled(true); testRunner.setPopupBlockingEnabled(true);
testRunner.setCloseRemainingWindowsWhenComplete(true); testRunner.setCloseRemainingWindowsWhenComplete(true);
testRunner.waitUntilDone();
} }
document.getElementById("test").focus(); test(() => document.getElementById("test").focus(), 'focus');
document.getElementById("test").blur(); test(() => document.getElementById("test").blur(), 'blur');
if (window.testRunner)
testRunner.notifyDone();
</script> </script>
</body> </body>
</html> </html>
<html> <html>
<head> <head>
<script src="../../resources/js-test.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head> </head>
<body> <body>
<a id=test href="javascript:popup()">test</a> <a id=test href="javascript:popup()">test</a>
...@@ -9,23 +10,18 @@ ...@@ -9,23 +10,18 @@
var win; var win;
function popup() { function popup() {
win = window.open('about:blank','blank','height=200,width=200'); win = window.open('about:blank','blank','height=200,width=200');
shouldBeNull("win"); assert_equals(win, null);
} }
if (window.testRunner) { if (window.testRunner) {
testRunner.dumpAsText();
testRunner.setCanOpenWindows(); testRunner.setCanOpenWindows();
testRunner.setPopupBlockingEnabled(true); testRunner.setPopupBlockingEnabled(true);
testRunner.setCloseRemainingWindowsWhenComplete(true); testRunner.setCloseRemainingWindowsWhenComplete(true);
testRunner.waitUntilDone();
} }
clickEvent = document.createEvent("MouseEvents"); clickEvent = document.createEvent("MouseEvents");
clickEvent.initEvent("click", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null); clickEvent.initEvent("click", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
document.getElementById("test").dispatchEvent(clickEvent); test(() => document.getElementById("test").dispatchEvent(clickEvent), 'Untrusted click');
if (window.testRunner)
testRunner.notifyDone();
</script> </script>
</body> </body>
</html> </html>
Target
Test user gesture behavior during touch events.
During a scroll, no touch events are user gestures
PASS openedPopup is false
PASS openedPopup is false
PASS openedPopup is false
During a drag that isn't a scroll, only touchend is a user gesture
PASS openedPopup is false
PASS openedPopup is false
PASS openedPopup is true
PASS successfullyParsed is true
TEST COMPLETE
<script src="../../../resources/js-test.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<div id="target">Target</div> <div id="target">Target</div>
<div id="description">Test user gesture behavior during touch events.</div> <div id="description">Test user gesture behavior during touch events.</div>
<div id="console"></div>
<script> <script>
...@@ -9,7 +9,7 @@ var cancelEvent = false; ...@@ -9,7 +9,7 @@ var cancelEvent = false;
var openedPopup = undefined; var openedPopup = undefined;
function handler(e) { function handler(e) {
if (openedPopup !== undefined) if (openedPopup !== undefined)
testFailed("Handler invoked multiple times"); assert_unreached("Handler invoked multiple times");
var w = window.open("about:blank", "_blank"); var w = window.open("about:blank", "_blank");
if (w) { if (w) {
...@@ -31,12 +31,9 @@ function testPopupOnEventDuring(eventType, expectPopup, operation) { ...@@ -31,12 +31,9 @@ function testPopupOnEventDuring(eventType, expectPopup, operation) {
operation(); operation();
if (openedPopup===undefined) assert_not_equals(openedPopup, undefined,
testFailed(eventType + ' handler was not invoked'); eventType + ' handler was not invoked');
else if (expectPopup) assert_equals(openedPopup, expectPopup);
shouldBeTrue("openedPopup");
else
shouldBeFalse("openedPopup");
target.removeEventListener(eventType, handler); target.removeEventListener(eventType, handler);
} }
...@@ -52,17 +49,19 @@ var rect = target.getBoundingClientRect(); ...@@ -52,17 +49,19 @@ var rect = target.getBoundingClientRect();
var targetX = rect.left + rect.width / 2; var targetX = rect.left + rect.width / 2;
var targetY = rect.top + rect.height / 2; var targetY = rect.top + rect.height / 2;
debug("During a scroll, no touch events are user gestures"); test(() => {
cancelEvent = false; cancelEvent = false;
eventSender.addTouchPoint(targetX, targetY); eventSender.addTouchPoint(targetX, targetY);
testPopupOnEventDuring('touchstart', false, function() { eventSender.touchStart(); }); testPopupOnEventDuring('touchstart', false, function() { eventSender.touchStart(); });
eventSender.updateTouchPoint(0, targetX + 10, targetY); eventSender.updateTouchPoint(0, targetX + 10, targetY);
testPopupOnEventDuring('touchmove', false, function() { eventSender.touchMove(); }); testPopupOnEventDuring('touchmove', false, function() { eventSender.touchMove(); });
eventSender.notifyStartOfTouchScroll(); eventSender.notifyStartOfTouchScroll();
eventSender.releaseTouchPoint(0); eventSender.releaseTouchPoint(0);
testPopupOnEventDuring('touchend', false, function() { eventSender.touchEnd(); }); testPopupOnEventDuring('touchend', false, function() { eventSender.touchEnd(); });
}, "During a scroll, no touch events are user gestures");
debug("During a drag that isn't a scroll, only touchend is a user gesture"); test(() => {
cancelEvent = true; cancelEvent = true;
eventSender.addTouchPoint(targetX, targetY); eventSender.addTouchPoint(targetX, targetY);
testPopupOnEventDuring('touchstart', false, function() { eventSender.touchStart(); }); testPopupOnEventDuring('touchstart', false, function() { eventSender.touchStart(); });
...@@ -70,5 +69,6 @@ eventSender.updateTouchPoint(0, targetX + 10, targetY); ...@@ -70,5 +69,6 @@ eventSender.updateTouchPoint(0, targetX + 10, targetY);
testPopupOnEventDuring('touchmove', false, function() { eventSender.touchMove(); }); testPopupOnEventDuring('touchmove', false, function() { eventSender.touchMove(); });
eventSender.releaseTouchPoint(0); eventSender.releaseTouchPoint(0);
testPopupOnEventDuring('touchend', true, function() { eventSender.touchEnd(); }); testPopupOnEventDuring('touchend', true, function() { eventSender.touchEnd(); });
}, "During a drag that isn't a scroll, only touchend is a user gesture");
</script> </script>
CONSOLE ERROR: line 248: Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
CONSOLE ERROR: Refused to load the image 'http://127.0.0.1:8000/security/resources/abe.png' because it violates the following Content Security Policy directive: "img-src 'none'".
ALERT: PASS (1/1)
This test ensures that blocking an image via CSP doesn't crash if GC executes before the error event fires.
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<script src="/js-test-resources/js-test.js"></script> <script src="/js-test-resources/testharness.js"></script>
<script src="/js-test-resources/testharnessreport.js"></script>
<meta http-equiv="Content-Security-Policy" content="img-src 'none'; script-src 'unsafe-inline'"> <meta http-equiv="Content-Security-Policy" content="img-src 'none'; script-src 'unsafe-inline'">
<script> <script>
if (window.testRunner) const testCase = async_test(
testRunner.waitUntilDone(); 'Blocking an image via CSP doesn\'t crash if GC executes before the error event fires');
function test() { function test() {
(function () { (function () {
var img = document.createElement('img'); var img = document.createElement('img');
img.onload = function () { img.onload = testCase.step_func_done(() => assert_unreached());
alert('FAIL (1/1)'); img.onerror = testCase.step_func_done(() => {});
finishTesting();
};
img.onerror = function () {
alert('PASS (1/1)');
finishTesting();
};
img.src = "../resources/abe.png"; img.src = "../resources/abe.png";
})(); })();
gc(); gc();
} }
function finishTesting() {
if (window.testRunner)
setTimeout(function () { testRunner.notifyDone(); }, 0);
return true;
}
</script> </script>
</head> </head>
<body onload='test();'> <body onload='test();'>
......
CONSOLE ERROR: line 95: Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-SKwGvORdKBYTYiM4lxIkanDyKH8J0qJ5Ix8LGkKsbhw='), or a nonce ('nonce-...') is required to enable inline execution.
CONSOLE ERROR: line 77: Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-E8Yv3p3nivzZKSVWxu7y2Pr+w7Nco7lvx8r5nBVoLFA='), or a nonce ('nonce-...') is required to enable inline execution.
PASS successfullyParsed is true
TEST COMPLETE
This test ensures that styles can be set by object.cloneNode()
PASS node1.style.background is "yellow"
PASS node2.style.background is "yellow"
PASS node3.style.background is "blue"
PASS node4.style.background is "blue"
PASS node1.style.color is "red"
PASS node2.style.color is "red"
PASS node3.style.color is "green"
PASS node4.style.color is "green"
PASS window.getComputedStyle(node1).background is window.getComputedStyle(node2).background
PASS window.getComputedStyle(node3).background is window.getComputedStyle(node4).background
PASS window.getComputedStyle(node1).color is window.getComputedStyle(node2).color
PASS window.getComputedStyle(node3).color is window.getComputedStyle(node4).color
PASS ops.style.background is ""
getComputedStyle(clonedOps).background: rgba(0, 0, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box
PASS ops.style.color is "red"
PASS clonedOps.style.background is ""
PASS violetOps.style.background is "rgb(238, 130, 238)"
PASS window.getComputedStyle(clonedOps).background is window.getComputedStyle(ops).background
PASS window.getComputedStyle(clonedOps).color is window.getComputedStyle(ops).color
getComputedStyle(violetOps).background: rgb(238, 130, 238) none repeat scroll 0% 0% / auto padding-box border-box
PASS window.getComputedStyle(ops).background is not window.getComputedStyle(violetOps).background
PASS window.getComputedStyle(clonedOps).background is not window.getComputedStyle(violetOps).background
PASS ops.id is "ops"
PASS ops.id is clonedOps.id
This is a div (nodes)
This is a div. (node 1 or 2)
This is a div. (node 1 or 2)
This is a div. (node 3 or 4)
Node #4
Yet another div.
Yet another div.
Yet another div.
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Security-Policy" content="style-src 'self';"> <meta http-equiv="Content-Security-Policy" content="style-src 'self';">
<script src="/js-test-resources/js-test.js"></script> <script src="/js-test-resources/testharness.js"></script>
<script src="/js-test-resources/testharnessreport.js"></script>
<script> <script>
window.onload = function () { const testCase = async_test('Styles can be set by object.cloneNode()');
debug("This test ensures that styles can be set by object.cloneNode()"); window.onload = testCase.step_func_done(() => {
window.nodes = document.getElementById('nodes'); window.nodes = document.getElementById('nodes');
window.node1 = document.getElementById('node1'); window.node1 = document.getElementById('node1');
window.node1.style.background = "yellow"; window.node1.style.background = "yellow";
...@@ -25,21 +25,21 @@ ...@@ -25,21 +25,21 @@
nodes.appendChild(node3); nodes.appendChild(node3);
nodes.appendChild(node4); nodes.appendChild(node4);
shouldBeEqualToString("node1.style.background", "yellow"); assert_equals(node1.style.background, "yellow");
shouldBeEqualToString("node2.style.background", "yellow"); assert_equals(node2.style.background, "yellow");
shouldBeEqualToString("node3.style.background", "blue"); assert_equals(node3.style.background, "blue");
shouldBeEqualToString("node4.style.background", "blue"); assert_equals(node4.style.background, "blue");
shouldBeEqualToString("node1.style.color", "red"); assert_equals(node1.style.color, "red");
shouldBeEqualToString("node2.style.color", "red"); assert_equals(node2.style.color, "red");
shouldBeEqualToString("node3.style.color", "green"); assert_equals(node3.style.color, "green");
shouldBeEqualToString("node4.style.color", "green"); assert_equals(node4.style.color, "green");
shouldBe("window.getComputedStyle(node1).background", "window.getComputedStyle(node2).background"); assert_equals(window.getComputedStyle(node1).background, window.getComputedStyle(node2).background);
shouldBe("window.getComputedStyle(node3).background", "window.getComputedStyle(node4).background"); assert_equals(window.getComputedStyle(node3).background, window.getComputedStyle(node4).background);
shouldBe("window.getComputedStyle(node1).color", "window.getComputedStyle(node2).color"); assert_equals(window.getComputedStyle(node1).color, window.getComputedStyle(node2).color);
shouldBe("window.getComputedStyle(node3).color", "window.getComputedStyle(node4).color"); assert_equals(window.getComputedStyle(node3).color, window.getComputedStyle(node4).color);
window.ops = document.getElementById('ops'); window.ops = document.getElementById('ops');
ops.style.color = 'red'; ops.style.color = 'red';
...@@ -49,21 +49,19 @@ ...@@ -49,21 +49,19 @@
violetOps.style.background = 'rgb(238, 130, 238)'; violetOps.style.background = 'rgb(238, 130, 238)';
document.getElementsByTagName('body')[0].appendChild(clonedOps); document.getElementsByTagName('body')[0].appendChild(clonedOps);
shouldBeEqualToString("ops.style.background", ""); assert_equals(ops.style.background, "");
debug("getComputedStyle(clonedOps).background: " + window.getComputedStyle(ops).background); assert_equals(ops.style.color, "red");
shouldBeEqualToString("ops.style.color", "red"); assert_equals(clonedOps.style.background, "");
shouldBeEqualToString("clonedOps.style.background", ""); assert_equals(violetOps.style.background, "rgb(238, 130, 238)");
shouldBeEqualToString("violetOps.style.background", "rgb(238, 130, 238)");
shouldBe("window.getComputedStyle(clonedOps).background", "window.getComputedStyle(ops).background"); assert_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(ops).background);
shouldBe("window.getComputedStyle(clonedOps).color", "window.getComputedStyle(ops).color"); assert_equals(window.getComputedStyle(clonedOps).color, window.getComputedStyle(ops).color);
debug("getComputedStyle(violetOps).background: " + window.getComputedStyle(violetOps).background); assert_not_equals(window.getComputedStyle(ops).background, window.getComputedStyle(violetOps).background);
shouldNotBe("window.getComputedStyle(ops).background", "window.getComputedStyle(violetOps).background"); assert_not_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(violetOps).background);
shouldNotBe("window.getComputedStyle(clonedOps).background", "window.getComputedStyle(violetOps).background");
shouldBeEqualToString("ops.id", "ops"); assert_equals(ops.id, "ops");
shouldBe("ops.id", "clonedOps.id"); assert_equals(ops.id, clonedOps.id);
}; });
</script> </script>
</head> </head>
<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