Commit a417a16c authored by Hugo Holgersson's avatar Hugo Holgersson Committed by Commit Bot

Snav: Convert all snav*iframe*.html tests to snav-testharness.js

The changes to snav-testharness.js lets us assert navigations
in and out of iframes:

 1) To be able to test focus movements in and out of iframes,
    we need to listen for 'keyup'-events on the document where
    focus is _about_to_go_.

    'keyup' targets the currently focused document. When 'keyup'
    comes, 'keydown' has already changed focus to the new document.

 2) Previously each movement had its own async_test(). Now we use
    one async_test() with many "test steps": one for each movement.
    This helps us avoid tricky (mis)usage of testharness.js's
    fetch_tests_from_window().

The changes to the HTML files are mostly mechanical except that
I gave some elements new or renamed ids so they become easier
to distinguish when debugging.

Once we've fixed Issue 801162, the tests' expectations will change:
We want spatnav to first _focus_ the iframe (before scrolling it
or searching inside of it).

Bug: 803086, 891658, 801162
Change-Id: Ib53bb224398510b5744927a5d892381870fa4690
Reviewed-on: https://chromium-review.googlesource.com/c/1314469
Commit-Queue: Hugo Holgersson <hugoh@vewd.com>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#604962}
parent 4dea3aba
<html>
<body>
<iframe width='80%' height="70px" frameborder="0" src="data:text/html,
<body>
<a id='1' href='%23'>b</a>
<a id='2' href='%23'>c</a>
<a id='3' href='%23'>d</a>
<a id='4' href='%23'>e</a>
<a id='5' href='%23'>f</a>
<a id='6' href='%23'>g</a>
<a id='7' href='%23'>h</a>
<a id='8' href='%23'>i</a>
</body>
"></iframe>
</body>
<html>
(function() {
"use strict";
let gAsyncTest;
// TODO: Use WebDriver's API instead of eventSender.
// Hopefully something like:
// test_driver.move_focus(direction).then(...)
function triggerMove(direction) {
switch (direction) {
case 'Up':
......@@ -18,33 +23,60 @@
}
}
function stepAndAssertMoves(expectedMoves, focusMoves) {
if (expectedMoves.length == 0)
function focusedDocument(currentDocument=document) {
let subframes = Array.from(currentDocument.defaultView.frames);
for (let frame of subframes) {
let focused = focusedDocument(frame.document);
if (focused)
return focused;
}
if (currentDocument.hasFocus())
return currentDocument;
return null;
}
// Allows us to query element ids also in iframes' documents.
function findElement(searchString) {
let searchPath = searchString.split(",");
let currentDocument = document;
let elem = undefined;
while (searchPath.length > 0) {
let id = searchPath.shift();
elem = currentDocument.getElementById(id);
assert_not_equals(elem, null, 'Could not find "' + searchString + '",');
if (elem.tagName == "IFRAME")
currentDocument = elem.contentDocument;
}
return elem;
}
function stepAndAssertMoves(expectedMoves) {
if (expectedMoves.length == 0) {
gAsyncTest.done();
return;
}
let move = expectedMoves.shift();
let direction = move[0];
let expectedId = move[1];
// TODO: Use WebDriver's API instead of eventSender.
// Hopefully something like:
// test_driver.move_focus(direction).then(...)
async_test(t => {
let checkFocus = t.step_func_done(function() {
let expectedElement = document.getElementById(expectedId);
assert_equals(document.activeElement, expectedElement);
// Kick off another async test before closing this one.
stepAndAssertMoves(expectedMoves, focusMoves + 1);
});
let wanted = findElement(expectedId);
let receivingDoc = wanted.ownerDocument;
let verifyAndAdvance = gAsyncTest.step_func(function() {
let focused = focusedDocument().activeElement;
assert_equals(focused, wanted);
// Kick off another async test step.
stepAndAssertMoves(expectedMoves);
});
// "... the default action MUST be to shift the document focus".
// https://www.w3.org/TR/uievents/#event-type-keydown
// Any focus movement must have happened during keydown, so once we got
// the succeeding keyup-event, it's safe to assert activeElement.
document.addEventListener('keyup', checkFocus, {once: true});
triggerMove(direction);
}, focusMoves + "th move: " + direction + '-key moves focus to ' +
'the element with id: ' + expectedId + '.');
// "... the default action MUST be to shift the document focus".
// https://www.w3.org/TR/uievents/#event-type-keydown
// Any focus movement must have happened during keydown, so once we got
// the succeeding keyup-event, it's safe to assert activeElement.
// The keyup-event targets the, perhaps newly, focused document.
receivingDoc.addEventListener('keyup', verifyAndAdvance, {once: true});
triggerMove(direction);
}
// TODO: Port all old spatial navigation layout tests to this method.
......@@ -59,7 +91,13 @@
assertFocusMoves: function(expectedMoves) {
snav.assertSnavEnabledAndTestable();
stepAndAssertMoves(expectedMoves, 0);
gAsyncTest = async_test("Focus movements:\n" +
JSON.stringify(expectedMoves).replace(/],/g, ']\n') + '\n');
// All iframes must be loaded before trying to navigate to them.
window.addEventListener('load', gAsyncTest.step_func(() => {
stepAndAssertMoves(expectedMoves);
}));
}
}
})();
Link
Link
Link
Here is a link.
Link
PASS successfullyParsed is true
TEST COMPLETE
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "4"
PASS gFocusedDocument.activeElement.getAttribute("id") is "5"
PASS gFocusedDocument.activeElement.getAttribute("id") is "6"
PASS gFocusedDocument.activeElement.getAttribute("id") is "7"
PASS gFocusedDocument.activeElement.getAttribute("id") is "8"
PASS gFocusedDocument.activeElement.getAttribute("id") is "9"
PASS gFocusedDocument.activeElement.getAttribute("id") is "8"
PASS gFocusedDocument.activeElement.getAttribute("id") is "7"
PASS gFocusedDocument.activeElement.getAttribute("id") is "6"
PASS gFocusedDocument.activeElement.getAttribute("id") is "5"
PASS gFocusedDocument.activeElement.getAttribute("id") is "4"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
<html>
<!--
This test ensures the cross iframe traversal correctness of spatial navigation:
focusable elements in nested inner frame should be accessible.
<table style="text-align: top;" border="0" cellpadding="3px" cellspacing="3px">
<tr>
<td valign="top" width="10%">
<a id="start" href="#">Link</a><br>
</td>
<td valign="top">
<iframe id="frameA" width="50%" height="100px" frameborder="1" srcdoc="
<body id='frameAbody'>
<iframe id='frameB' width='80%' height='70px' frameborder='0' srcdoc='
<body id=frameBbody>
<a id=1 href=www>b</a>
<a id=2 href=www>c</a>
<a id=3 href=www>d</a>
<a id=4 href=www>e</a>
<a id=5 href=www>f</a>
<a id=6 href=www>g</a>
<a id=7 href=www>h</a>
<a id=8 href=www>i</a>
</body>
'></iframe>
"></iframe><br>
</td>
<td valign="top" width="10%">
<a id="9" href="#">Link</a><br>
</td>
</tr>
<tr>
<td valign="top" width="10%">
<a id="10" href="#">Link</a><br>
</td>
<td valign="top">
<p><a id="11" href="#">Here</a> is a link.</p>
</td>
<td valign="top" width="10%">
<a id="12" href="#">Link</a><br>
</td>
</tr>
</table>
* Pre-conditions:
1) DRT support for spatial navigation enable/disable.
<p>Ensure spatnav can navigate in and out of nested iframes.</p>
* Navigation steps:
1) Loads this page, focus goes to "start" automatically.
2) Focus moves along the elements in the two level deep nested frame,
but going back to the main frame later on.
-->
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/spatial-navigation-utils.js"></script>
<script type="application/javascript">
var resultMap = [
["Right", "1"],
["Right", "2"],
["Right", "3"],
["Right", "4"],
["Right", "5"],
["Right", "6"],
["Right", "7"],
["Right", "8"],
["Right", "9"],
["Left", "8"],
["Left", "7"],
["Left", "6"],
["Left", "5"],
["Left", "4"],
["Left", "3"],
["Left", "2"],
["Left", "1"],
["Left", "start"],
["DONE", "DONE"]
];
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.overridePreference("WebKitTabToLinksPreferenceKey", 1);
testRunner.overridePreference("WebKitSpatialNavigationEnabled", 1);
testRunner.waitUntilDone();
}
function runTest()
{
// starting the test itself: get to a known place.
document.getElementById("start").focus();
initTest(resultMap, testCompleted);
}
function testCompleted()
{
if (window.testRunner)
testRunner.notifyDone();
}
window.onload = runTest;
</script>
</head>
<body>
<table style="text-align: top;" border="0" cellpadding="3px" cellspacing="3px">
<tr>
<td valign="top" width="10%">
<a id="start" href="#">Link</a><br>
</td>
<td valign="top">
<iframe width="50%" height="100px" frameborder="1" src="resources/iframe.html"></iframe><br>
</td>
<td valign="top" width="10%">
<a id="9" href="#">Link</a><br>
</td>
</tr>
<tr>
<td valign="top" width="10%">
<a id="10" href="#">Link</a><br>
</td>
<td valign="top">
<p><a id="11" href="#">Here</a> is a link.</p>
</td>
<td valign="top" width="10%">
<a id="12" href="#">Link</a><br>
</td>
</tr>
</table>
<div id="console"></div>
</body>
</html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/snav-testharness.js"></script>
<script>
var resultMap = [
// ["Right", "frameA,frameAbody"], crbug.com/801162
// ["Right", "frameA,frameB,frameBbody"], crbug.com/801162
["Right", "frameA,frameB,1"],
["Right", "frameA,frameB,2"],
["Right", "frameA,frameB,3"],
["Right", "frameA,frameB,4"],
["Right", "frameA,frameB,5"],
["Right", "frameA,frameB,6"],
["Right", "frameA,frameB,7"],
["Right", "frameA,frameB,8"],
["Right", "9"],
// ["Left", "frameA,frameAbody"], crbug.com/801162
// ["Left", "frameA,frameB,frameBbody"], crbug.com/801162
["Left", "frameA,frameB,8"],
["Left", "frameA,frameB,7"],
["Left", "frameA,frameB,6"],
["Left", "frameA,frameB,5"],
["Left", "frameA,frameB,4"],
["Left", "frameA,frameB,3"],
["Left", "frameA,frameB,2"],
["Left", "frameA,frameB,1"],
["Left", "start"],
];
// Start at a known place.
document.getElementById("start").focus();
snav.assertFocusMoves(resultMap);
</script>
a
e
PASS successfullyParsed is true
TEST COMPLETE
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
This is to test that an iframe with no focusable content still scrolls
<html>
<!--
This test ensures the basic traversal correctness of Spatial Navigation
algorithm: iframes without any focusable content should be ignored.
<div><a id="start" href="a">a</a></div>
* Pre-conditions:
1) DRT support for SNav enable/disable.
* Navigation steps:
1) Loads this page, focus goes to "start" automatically.
2) Focus moves from "start" to "end" bypassing the two iframes
in between them, once both have no focusable elements inside.
-->
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/spatial-navigation-utils.js"></script>
<script type="application/javascript">
var resultMap = [
["Down", "start"],
["Down", "start"],
["Down", "start"],
["Down", "start"],
["Down", "start"],
["Down", "start"],
["Down", "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "start"],
["DONE", "DONE"]
];
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.overridePreference("WebKitTabToLinksPreferenceKey", 1);
testRunner.overridePreference("WebKitSpatialNavigationEnabled", 1);
testRunner.waitUntilDone();
}
function runTest()
{
// starting the test itself: get to a known place.
document.getElementById("start").focus();
initTest(resultMap, testCompleted);
}
function testCompleted()
{
if (window.testRunner)
testRunner.notifyDone();
}
window.onload = runTest;
</script>
</head>
<body id="some-content" xmlns="http://www.w3.org/1999/xhtml">
<div><a id="start" href="a">a</a></div>
<iframe width="80" height="80" scrolling="auto" src="data:text/html,
<body>
<img width=120 height=200 src='resources/green.png'>
</body>
"></iframe><br>
<iframe scrolling="auto" src="data:text/html,
<body>
<img width=120 height=200 src='resources/green.png'>
</body>
"></iframe><br>
<iframe id="frameA" width="80" height="80" scrolling="auto" src="data:text/html,
<body id='frameAbody'>
<img width=120 height=200 src='resources/green.png'>
</body>
"></iframe><br>
<a id="end" href="a">e</a>
<div id="console"></div>
This is to test that an iframe with no focusable content still scrolls
<iframe id="frameB" scrolling="auto" src="data:text/html,
<body id='frameBbody'>
<img width=120 height=200 src='resources/green.png'>
</body>
</html>
"></iframe><br>
<a id="end" href="a">e</a>
<p>Iframes with no focusable content still scrolls.</p>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/snav-testharness.js"></script>
<script>
/*
Once crbug.com/801162 is fixed, the expectation will change:
The iframe can only be scrolled when being focused.
*/
var resultMap = [
["Down", "start"],
["Down", "start"],
["Down", "start"],
["Down", "start"],
["Down", "start"],
["Down", "start"],
["Down", "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "end"],
["Up" , "start"],
];
// Start at a known place.
document.getElementById("start").focus();
snav.assertFocusMoves(resultMap);
</script>
a
a
PASS successfullyParsed is true
TEST COMPLETE
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "7"
PASS gFocusedDocument.activeElement.getAttribute("id") is "6"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "4"
PASS gFocusedDocument.activeElement.getAttribute("id") is "5"
PASS gFocusedDocument.activeElement.getAttribute("id") is "6"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "7"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
<html>
<!--
This test ensures the basic iframe traversal correctness of Spatial Navigation
algorithm: focusable elements in a <iframe> should be accessible.
* Pre-conditions:
1) DRT support for SNav enable/disable.
* Navigation steps:
1) Loads this page, focus goes to "start" automatically.
2) Focus moves along the elements in the two iframes in the
Web page, eventually going to outer an southward link, but
going back to the iframe on the top later on.
-->
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/spatial-navigation-utils.js"></script>
<script type="application/javascript">
var resultMap = [
["Down", "1"],
["Down", "2"],
["Down", "3"],
["Down", "7"],
["Down", "6"],
["Down", "end"],
["Up", "4"],
["Right", "5"],
["Right", "6"],
["Up", "3"],
["Right", "7"],
["Up", "3"],
["Up", "2"],
["Up", "1"],
["DONE", "DONE"]
];
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.overridePreference("WebKitTabToLinksPreferenceKey", 1);
testRunner.overridePreference("WebKitSpatialNavigationEnabled", 1);
testRunner.waitUntilDone();
}
function runTest()
{
// starting the test itself: get to a known place.
document.getElementById("start").focus();
initTest(resultMap, testCompleted);
}
function testCompleted()
{
if (window.testRunner)
testRunner.notifyDone();
}
window.onload = runTest;
</script>
</head>
<body id="some-content" xmlns="http://www.w3.org/1999/xhtml">
<div><a id="start" href="a">a</a></div>
<iframe src="data:text/html,
<body>
<a id='1' href='a'>b</a><br>
<a id='2' href='a'>c</a><br>
<a id='3' href='a'>d</a><br>
<div style='margin-left:80px'>
<a id='7' href='a'>e</a>
</div>
</body>
"></iframe><br>
<iframe src="data:text/html,
<body>
<a id='4' href='a'>g</a>
<a id='5' href='a'>h</a>
<a id='6' href='a'>i</a>
</body>
"></iframe><br>
<div><a id="start" href="a">a</a></div>
<iframe id="frameA" src="data:text/html,
<body id='frameAbody'>
<a id='1' href='a'>b</a><br>
<a id='2' href='a'>c</a><br>
<a id='3' href='a'>d</a><br>
<div style='margin-left:80px'>
<a id='7' href='a'>e</a>
</div>
</body>
"></iframe><br>
<a id="end" href="a">a</a>
<div id="console"></div>
<iframe id="frameB" src="data:text/html,
<body id='frameBbody'>
<a id='4' href='a'>g</a>
<a id='5' href='a'>h</a>
<a id='6' href='a'>i</a>
</body>
</html>
"></iframe><br>
<a id="end" href="a">a</a>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/snav-testharness.js"></script>
<script>
/*
Once crbug.com/801162 is fixed, the expectation will change:
Spatnav must focus the iframe before it can search it.
*/
var resultMap = [
["Down", "frameA,1"],
["Down", "frameA,2"],
["Down", "frameA,3"],
["Down", "frameA,7"],
["Down", "frameB,6"],
["Down", "end"],
["Up", "frameB,4"],
["Right", "frameB,5"],
["Right", "frameB,6"],
["Up", "frameA,3"],
["Right", "frameA,7"],
["Up", "frameA,3"],
["Up", "frameA,2"],
["Up", "frameA,1"],
];
// Start at a known place.
document.getElementById("start").focus();
snav.assertFocusMoves(resultMap);
</script>
Link
PASS successfullyParsed is true
TEST COMPLETE
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
<html>
<!--
This test ensures the cross iframe traversal correctness of Spatial Navigation
algorithm: focusable elements in an <iframe> should be accessible even when
the current focused element is in another <iframe> in the same page.
* Pre-conditions:
1) DRT support for SNav enable/disable.
* Navigation steps:
1) Loads this page, focus goes to "start" automatically.
2) Focus moves along the elements in the two iframes in the
Web page, eventually going to outer an southward link, but
going back to the iframe on the top later on.
-->
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/spatial-navigation-utils.js"></script>
<script type="application/javascript">
var resultMap = [
["Right", "1"],
["Right", "2"],
["Right", "3"],
["Left", "2"],
["Left", "1"],
["Left", "start"],
["DONE", "DONE"]
];
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.overridePreference("WebKitTabToLinksPreferenceKey", 1);
testRunner.overridePreference("WebKitSpatialNavigationEnabled", 1);
testRunner.waitUntilDone();
}
function runTest()
{
// starting the test itself: get to a known place.
document.getElementById("start").focus();
initTest(resultMap, testCompleted);
}
function testCompleted()
{
if (window.testRunner)
testRunner.notifyDone();
}
window.onload = runTest;
</script>
</head>
<body>
<table style="text-align: top;" border="0" cellpadding="3px" cellspacing="3px">
<tr>
<td valign="top" width="10%">
<a id="start" href="http://google.com">Link</a><br>
</td>
<td valign="top">
<iframe width="50%" height="100px" frameborder="1" src="data:text/html,
<body>
<a id='1' href='http://a'>b</a>
<a id='2' href='http://a'>c</a>
<a id='3' href='http://a'>d</a>
</body>
"></iframe><br>
</td>
</tr>
</table>
<div id="console"></div>
</body>
</html>
<table style="text-align: top;" border="0" cellpadding="3px" cellspacing="3px">
<tr>
<td valign="top" width="10%">
<a id="start" href="http://google.com">Link</a><br>
</td>
<td valign="top">
<iframe id="frameA" width="50%" height="100px" frameborder="1" src="data:text/html,
<body id='frameAbody'>
<a id='1' href='http://a'>b</a>
<a id='2' href='http://a'>c</a>
<a id='3' href='http://a'>d</a>
</body>
"></iframe><br>
</td>
</tr>
</table>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/snav-testharness.js"></script>
<script>
var resultMap = [
// ["Right", "frameA,frameAbody"], crbug.com/801162
["Right", "frameA,1"],
["Right", "frameA,2"],
["Right", "frameA,3"],
["Left", "frameA,2"],
["Left", "frameA,1"],
["Left", "start"],
];
// Start at a known place.
document.getElementById("start").focus();
snav.assertFocusMoves(resultMap);
</script>
PASS successfullyParsed is true
TEST COMPLETE
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "start"
<html>
<!--
This test ensures the cross iframe traversal correctness of Spatial Navigation
algorithm: focusable elements in an <iframe> should be accessible even when
the current focused element is in another <iframe> in the same page.
* Pre-conditions:
1) DRT support for SNav enable/disable.
* Navigation steps:
1) Loads this page, focus goes to "start" automatically.
2) Focus moves along the elements in the two iframes in the
Web page, eventually going to outer an southward link, but
going back to the iframe on the top later on.
-->
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/spatial-navigation-utils.js"></script>
<script type="application/javascript">
var resultMap = [
["Down", "1"],
["Down", "1"],
["Down", "1"],
["Down", "1"],
["Down", "1"],
["Down", "1"],
["Down", "1"],
["Down", "2"],
["Down", "end"],
["Up", "2"],
["Up", "2"],
["Up", "2"],
["Up", "2"],
["Up", "2"],
["Up", "2"],
["Up", "2"],
["Up", "1"],
["Up", "start"],
["DONE", "DONE"]
];
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.overridePreference("WebKitTabToLinksPreferenceKey", 1);
testRunner.overridePreference("WebKitSpatialNavigationEnabled", 1);
testRunner.waitUntilDone();
}
function runTest()
{
// starting the test itself: get to a known place.
document.getElementById("start").focus();
initTest(resultMap, testCompleted);
}
function testCompleted()
{
if (window.testRunner)
testRunner.notifyDone();
}
window.onload = runTest;
</script>
</head>
<body id="some-content" xmlns="http://www.w3.org/1999/xhtml">
<div><a id="start" href="a"><img src="resources/green.png" width=30 height=30></a></div>
<iframe width="80" height="80" scrolling="auto" src="data:text/html,
<body>
<a id='1' href='a'><img src='no_image' width=30 height=30></a>
<div>
<img src='no_image' width=50 height=300>
<a id='2' href='a'><img src='no_image' width=30 height=30></a>
</div>
</body>
"></iframe><br>
<div><a id="end" href="a"><img src="resources/green.png" width=30 height=30></a></div>
<div id="console"></div>
<div><a id="start" href="a"><img src="resources/green.png" width=30 height=30></a></div>
<iframe id="frameA" width="80" height="80" scrolling="auto" src="data:text/html,
<body id='frameAbody'>
<a id='1' href='a'><img src='no_image' width=30 height=30></a>
<div>
<img src='no_image' width=50 height=300>
<a id='2' href='a'><img src='no_image' width=30 height=30></a>
</div>
</body>
</html>
"></iframe><br>
<div><a id="end" href="a"><img src="resources/green.png" width=30 height=30></a></div>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/snav-testharness.js"></script>
<script>
var resultMap = [
// ["Down", "frameA,frameAbody"], crbug.com/801162
["Down", "frameA,1"],
["Down", "frameA,1"],
["Down", "frameA,1"],
["Down", "frameA,1"],
["Down", "frameA,1"],
["Down", "frameA,1"],
["Down", "frameA,1"],
["Down", "frameA,2"],
["Down", "end"],
// ["Up", "frameA,frameAbody"], crbug.com/801162
["Up", "frameA,2"],
["Up", "frameA,2"],
["Up", "frameA,2"],
["Up", "frameA,2"],
["Up", "frameA,2"],
["Up", "frameA,2"],
["Up", "frameA,2"],
["Up", "frameA,1"],
["Up", "start"],
];
// Start at a known place.
document.getElementById("start").focus();
snav.assertFocusMoves(resultMap);
</script>
Start
b End
PASS successfullyParsed is true
TEST COMPLETE
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "end"
<script src="../../resources/js-test.js"></script>
<script src="resources/spatial-navigation-utils.js"></script>
<script type="application/javascript">
var resultMap = [
["Down", "1"],
["Down", "end"],
["DONE", "DONE"]
];
<a id="start" href="#">Start</a><br>
<iframe id="frameA" src="data:text/html,
<body id='frameAbody'>
<a id='a' href='%23' style='margin-left: 125px'>a</a>
</body>"
></iframe><br>
<a id="b" href="#">b</a>
<a id="c" href="#" style="margin-left: 125px;">c</a>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.overridePreference("WebKitTabToLinksPreferenceKey", 1);
testRunner.overridePreference("WebKitSpatialNavigationEnabled", 1);
testRunner.waitUntilDone();
}
<p>When spatnav exits an iframe, it goes to the closest focusable. Here: c.</p>
function runTest()
{
// Start the test after going to a known place.
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/snav-testharness.js"></script>
<script>
var resultMap = [
// ["Down", "frameA,frameAbody"], crbug.com/801162
["Down", "frameA,a"],
["Down", "c"],
];
// Start at a known place.
document.getElementById("start").focus();
initTest(resultMap, testCompleted);
}
function testCompleted()
{
if (window.testRunner)
testRunner.notifyDone();
}
window.onload = runTest;
snav.assertFocusMoves(resultMap);
</script>
<a id="start" href="#">Start</a><br>
<iframe src="data:text/html,
<a id='1' href='%23' style='margin-left: 125px'>a</a>"
></iframe><br>
<a id="2" href="#">b</a>
<a id="end" href="#" style="margin-left: 125px;">End</a>
<div id="console"></div>
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