diff options
Diffstat (limited to 'testing/web-platform/tests/html/editing/focus')
16 files changed, 397 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/editing/focus/.gitkeep b/testing/web-platform/tests/html/editing/focus/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/.gitkeep diff --git a/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/.gitkeep b/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/.gitkeep diff --git a/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/document-level-apis.html b/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/document-level-apis.html new file mode 100644 index 000000000..2d8c49c7f --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/document-level-apis.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - document-level APIs</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#document-level-focus-apis"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<input id="test"> +<script> + +test(function () { + assert_equals(document.activeElement, document.body, "The active element should be the body element."); +}, "The body element must be the active element if no element is focused"); + +test(function () { + document.getElementById("test").focus(); + assert_equals(document.activeElement, document.getElementById("test"), "The active element should be the input element."); +}, "The element must be the active element if it is focused"); + +function frame_load () { + test(function () { + document.getElementById("fr").contentDocument.getElementById("ipt").focus(); + assert_equals(document.activeElement, document.getElementById("fr"), "The active element should be the iframe element."); + }, "When a child browsing context is focused, its browsing context container is also focused"); +} + +test(function () { + var doc = document.implementation.createHTMLDocument("test"); + assert_false(doc.hasFocus(), "The hasFocus() method should return false."); +}, "The hasFocus() method must return false if the Document has no browsing context"); + +</script> +<iframe id="fr" src="test.html" onload="frame_load()"></iframe> diff --git a/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/test.html b/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/test.html new file mode 100644 index 000000000..90d63e51e --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/document-level-focus-apis/test.html @@ -0,0 +1,5 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - document-level APIs</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<input id="ipt"> diff --git a/testing/web-platform/tests/html/editing/focus/element-level-focus-apis/.gitkeep b/testing/web-platform/tests/html/editing/focus/element-level-focus-apis/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/element-level-focus-apis/.gitkeep diff --git a/testing/web-platform/tests/html/editing/focus/focus-01-manual.html b/testing/web-platform/tests/html/editing/focus/focus-01-manual.html new file mode 100644 index 000000000..16e0b0f6c --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/focus-01-manual.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - key events</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#focus"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check if the key events received by document are targeted at the element when it is focused"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<h2>Steps:</h2> +<ol> + <li>Input any character into the textbox by keyboard in 10 seconds.</li> +</ol> +<h2>Expect results:</h2> +<p>PASS</p> +<div id="log"></div> +<input id="test"> +<script> + +//These tests can be automated once we have an uniform way to use webdriver. +var t1 = async_test("The keydown event must be targeted at the input element"), + t2 = async_test("The keypress event must be targeted at the input element"), + t3 = async_test("The keyup event must be targeted at the input element"), + testEle; + +setup(function () { + testEle = document.getElementById("test"); + testEle.focus(); +}, {timeout: 10000}); + +document.onkeydown = t1.step_func_done(function(evt){ + assert_equals(evt.target, testEle, "The keydown events must be targeted at the input element."); +}); + +document.onkeypress = t2.step_func_done(function(evt){ + assert_equals(evt.target, testEle, "The keypress events must be targeted at the input element."); +}); + +document.onkeyup = t3.step_func_done(function(evt){ + assert_equals(evt.target, testEle, "The keyup events must be targeted at the input element."); +}); + +</script> diff --git a/testing/web-platform/tests/html/editing/focus/focus-02-manual.html b/testing/web-platform/tests/html/editing/focus/focus-02-manual.html new file mode 100644 index 000000000..16dcfcf2a --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/focus-02-manual.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - key events</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#focus"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check if the key events received by document are targeted at the element when no element is focused"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<h2>Steps:</h2> +<ol> + <li>Press any key in [0-9a-zA-Z].</li> +</ol> +<h2>Expect results:</h2> +<p>PASS</p> +<div id="log"></div> +<script> + +//These tests can be automated once we have an uniform way to use webdriver. +var t1 = async_test("The keydown event must be targeted at the body element"), + t2 = async_test("The keypress event must be targeted at the body element"), + t3 = async_test("The keyup event must be targeted at the body element"); + +setup({timeout: 10000}); + +document.onkeydown = t1.step_func_done(function(evt){ + assert_equals(evt.target, document.body, "The keydown events must be targeted at the document's body."); +}); + +document.onkeypress = t2.step_func_done(function(evt){ + assert_equals(evt.target, document.body, "The keypress events must be targeted at the document's body."); +}); + +document.onkeyup = t3.step_func_done(function(evt){ + assert_equals(evt.target, document.body, "The keyup events must be targeted at the document's body."); +}); + +</script> diff --git a/testing/web-platform/tests/html/editing/focus/focus-management/.gitkeep b/testing/web-platform/tests/html/editing/focus/focus-management/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/focus-management/.gitkeep diff --git a/testing/web-platform/tests/html/editing/focus/focus-management/focus-event-targets-simple.html b/testing/web-platform/tests/html/editing/focus/focus-management/focus-event-targets-simple.html new file mode 100644 index 000000000..ab7bcfe6d --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/focus-management/focus-event-targets-simple.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Focus events fire at correct targets in correct order in simple case</title> + <link rel="author" title="Chris Rebert" href="http://chrisrebert.com"> + <link rel="help" href="https://html.spec.whatwg.org/#focus-update-steps"> + <link rel="help" href="https://html.spec.whatwg.org/#focus-chain"> + <meta name="flags" content="dom"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> + <input type="text" id="a"> + <script> +// Record all the focus event targets in an array. +// Modulo special cases in the "focus update steps" algorithm, +// this should be the same as the new focus chain, except in reverse order. +var newFocusChainReversedNotQuite = []; +var pushTarget = function (e) { + newFocusChainReversedNotQuite.push(e.target); +}; +// Window is the root node for event dispatch per https://html.spec.whatwg.org/multipage/webappapis.html#events-and-the-window-object +window.addEventListener('focus', pushTarget, true);// Use event capturing since focus event doesn't bubble +var input = document.getElementById('a'); +input.focus(); +window.removeEventListener('focus', pushTarget, true); +test(function() { + assert_array_equals(newFocusChainReversedNotQuite, [input], "Exactly 1 focus event should fire and its target should be the input"); +}, "Focus events fire at correct targets in correct order in simple case"); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/html/editing/focus/focus-management/focus-events.html b/testing/web-platform/tests/html/editing/focus/focus-management/focus-events.html new file mode 100644 index 000000000..d63362aaa --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/focus-management/focus-events.html @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Focus management</title> +<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> +<link rel=help href="https://html.spec.whatwg.org/multipage/#focus-management"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<input type=text id=i1> +<input type=text id=i2> +<script> + var i1 = document.getElementById('i1'), + i2 = document.getElementById('i2'), + t1 = async_test("focusing on a focusable element fires a focus event at the element"), + t2 = async_test("focusing on a focusable element fires a blur event at the previous focussed element"); + + i2.onfocus = t1.step_func_done(function(e){ + assert_true(e.isTrusted, "focus event is trusted"); + assert_false(e.bubbles, "focus event doesn't bubble"); + assert_false(e.cancelable, "focus event is not cancelable"); + assert_equals(document.activeElement, i2); + }); + + i1.onblur = t2.step_func_done(function(e){ + assert_true(e.isTrusted, "blur event is trusted"); + assert_false(e.bubbles, "blur event doesn't bubble"); + assert_false(e.cancelable, "blur event is not cancelable"); + }); + + i1.focus(); + i2.focus(); +</script> diff --git a/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/.gitkeep b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/.gitkeep diff --git a/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html new file mode 100644 index 000000000..25e359c2a --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - default value of tabindex</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<button id="test1">TEST1</button> +<div id="test2">TEST2</div> +<script> + +test(function() { + assert_equals(document.getElementById("test1").tabIndex, 0, "The value of tabIndex attribute should be 0."); +}, "The default value of tabIndex attribute must be 0 for elements that are focusable"); + +test(function() { + assert_equals(document.getElementById("test2").tabIndex, -1, "The value of tabIndex attribute should be -1."); +}, "The default value of tabIndex attribute must be -1 for elements that are not focusable"); + +</script> diff --git a/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-negative-manual.html b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-negative-manual.html new file mode 100644 index 000000000..506435074 --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-negative-manual.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - negative tabindex</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check if the tabindex attribute controls whether an element is supposed to be focusable"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<h2>Steps:</h2> +<ol> + <li>Press 'Tab' key in 10 seconds.</li> +</ol> +<h2>Expect results:</h2> +<p>PASS</p> +<div id="log"></div> +<form id="fm"> + <input id="test1" tabindex="-1"> + <input id="test2" tabindex="0"> +</form> +<script> + +//This test can be automated once we have an uniform way to use webdriver. +var t = async_test("The element with a negative tabindex must not be focused by press 'Tab' key"); + +setup({timeout: 10000}); + +document.forms.fm.addEventListener("focus", function (evt) { + t.step(function () { + var testEle = document.getElementById("test1"); + assert_equals(testEle.tabIndex, -1, "The tabIndex attribute of the first input element should be -1."); + assert_not_equals(evt.target, testEle, "The second input element must be focused."); + assert_equals(document.activeElement, document.getElementById("test2"), "The second input element must be activated."); + }); + t.done(); +}, true); + +document.addEventListener("keydown", function (evt) { + t.step(function () { + assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); + }); +}, true); + +</script> diff --git a/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-order-manual.html b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-order-manual.html new file mode 100644 index 000000000..c83762629 --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-order-manual.html @@ -0,0 +1,59 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - the sequential focus navigation order</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check the sequential focus navigation order"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<h2>Steps:</h2> +<ol> + <li>Press 'Tab' key at least 10 times in 20 seconds.(Long press the 'Tab' key will be better.)</li> +</ol> +<h2>Expect results:</h2> +<p>PASS</p> +<div id="log"></div> +<form id="fm"> + <button id="btn0">tabindex(omitted)</button> + <button id="btn1" tabindex="">tabindex(empty)</button> + <button id="btn2" tabindex="a">tabindex(a)</button> + <button id="btn3" tabindex="-1">tabindex(-1)</button> + <button id="btn4" tabindex="0">tabindex(0)</button> + <button id="btn5" tabindex="3">tabindex(3)</button> + <button id="btn6" tabindex="2">tabindex(2)</button> + <button id="btn7" tabindex="2">tabindex(2)</button> + <button id="btn8" tabindex="2">tabindex(2)</button> + <button id="btn9" tabindex="1">tabindex(1)</button> +</form> +<script> + +//This test can be automated once we have an uniform way to use webdriver. +var i = 0, + expectation = ["btn9", "btn6", "btn7", "btn8", "btn5", "btn0", "btn1", "btn2", "btn4"], + results = [], + t = async_test("The element with a zero tabindex must be focused by press 'Tab' key"); + +setup(function () { + document.body.focus(); +}, {timeout: 20000}); + +document.forms.fm.addEventListener("focus", function (evt) { + results.push(evt.target.id); + if (i >= 9) { + t.step(function () { + assert_array_equals(results, expectation); + }); + } +}, true); + +document.addEventListener("keydown", function (evt) { + if (evt.keyCode === 9) { + i += 1; + if (i === 10) { + t.done(); + } + } +}, true); + +</script> diff --git a/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-positive-manual.html b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-positive-manual.html new file mode 100644 index 000000000..012a3e7ee --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-positive-manual.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - positive tabindex</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check if the tabindex attribute controls whether an element is supposed to be focusable"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<h2>Steps:</h2> +<ol> + <li>Press 'Tab' key in 10 seconds.</li> +</ol> +<h2>Expect results:</h2> +<p>PASS</p> +<div id="log"></div> +<form id="fm"> + <input id="test" tabindex="1"> +</form> +<script> + +//This test can be automated once we have an uniform way to use webdriver. +var t = async_test("The element with a positive tabindex must be focused by press 'Tab' key"); + +setup({timeout: 10000}); + +document.forms.fm.addEventListener("focus", function (evt) { + t.step(function () { + var testEle = document.getElementById("test"); + assert_equals(testEle.tabIndex, 1, "The tabIndex attribute of the input element should be 1."); + assert_equals(evt.target, testEle, "The input element must be focused."); + assert_equals(document.activeElement, testEle, "The input element must be activated."); + }); + t.done(); +}, true); + +document.addEventListener("keydown", function (evt) { + t.step(function () { + assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); + }); +}, true); + +</script> diff --git a/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-zero-manual.html b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-zero-manual.html new file mode 100644 index 000000000..108b818b1 --- /dev/null +++ b/testing/web-platform/tests/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-zero-manual.html @@ -0,0 +1,45 @@ +<!DOCTYPE html> +<head> +<meta charset="utf-8"> +<title>HTML Test: focus - zero tabindex</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check if the tabindex attribute controls whether an element is supposed to be focusable"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<h2>Steps:</h2> +<ol> + <li>Press 'Tab' key in 10 seconds.</li> +</ol> +<h2>Expect results:</h2> +<p>PASS</p> +<div id="log"></div> +<form id="fm"> + <input id="test" tabindex="0"> +</form> +<script> + +//This test can be automated once we have an uniform way to use webdriver. +var t = async_test("The element with a zero tabindex must be focused by press 'Tab' key"); + +setup({timeout: 10000}); + +document.forms.fm.addEventListener("focus", function (evt) { + t.step(function () { + var testEle = document.getElementById("test"); + assert_equals(testEle.tabIndex, 0, "The tabIndex attribute of the input element should be 0."); + assert_equals(evt.target, testEle, "The input element must be focused."); + assert_equals(document.activeElement, testEle, "The input element must be activated."); + }); + t.done(); +}, true); + +document.addEventListener("keydown", function (evt) { + t.step(function () { + assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); + }); +}, true); + +</script> |