Bug 1368182 - Port non-e10s compatible parts of states/test_visibility.html to browser test. r=surkov

This commit is contained in:
Eitan Isaacson 2017-05-25 16:33:59 -07:00
parent b5e156f5c2
commit 6c98e296e9
3 changed files with 53 additions and 111 deletions

View File

@ -5,4 +5,5 @@ support-files =
!/accessible/tests/browser/shared-head.js
!/accessible/tests/mochitest/*.js
[browser_test_link.js]
[browser_test_link.js]
[browser_test_visibility.js]

View File

@ -0,0 +1,48 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';
/* import-globals-from ../../mochitest/role.js */
/* import-globals-from ../../mochitest/states.js */
loadScripts({ name: 'role.js', dir: MOCHITESTS_DIR },
{ name: 'states.js', dir: MOCHITESTS_DIR });
async function runTest(browser, accDoc) {
let getAcc = id => findAccessibleChildByID(accDoc, id);
testStates(getAcc("div"), 0, 0, STATE_INVISIBLE | STATE_OFFSCREEN);
let input = getAcc("input_scrolledoff");
testStates(input, STATE_OFFSCREEN, 0, STATE_INVISIBLE);
// scrolled off item (twice)
let lastLi = getAcc("li_last");
testStates(lastLi, STATE_OFFSCREEN, 0, STATE_INVISIBLE);
// scroll into view the item
await ContentTask.spawn(browser, {}, () => {
content.document.getElementById('li_last').scrollIntoView(true);
});
testStates(lastLi, 0, 0, STATE_OFFSCREEN | STATE_INVISIBLE);
// first item is scrolled off now (testcase for bug 768786)
let firstLi = getAcc("li_first");
testStates(firstLi, STATE_OFFSCREEN, 0, STATE_INVISIBLE);
let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
// Accessibles in background tab should have offscreen state and no
// invisible state.
testStates(getAcc("div"), STATE_OFFSCREEN, 0, STATE_INVISIBLE);
await BrowserTestUtils.removeTab(newTab);
}
addAccessibleTask(`
<div id="div" style="border:2px solid blue; width: 500px; height: 110vh;"></div>
<input id="input_scrolledoff">
<ul style="border:2px solid red; width: 100px; height: 50px; overflow: auto;">
<li id="li_first">item1</li><li>item2</li><li>item3</li>
<li>item4</li><li>item5</li><li id="li_last">item6</li>
</ul>`, runTest
);

View File

@ -14,111 +14,10 @@
src="../role.js"></script>
<script type="application/javascript"
src="../states.js"></script>
<script type="application/javascript"
src="../events.js"></script>
<script type="application/javascript"
src="../browser.js"></script>
<script type="application/javascript">
////////////////////////////////////////////////////////////////////////////
// Invokers
function loadURIInvoker(aURI, aFunc)
{
this.invoke = function loadURIInvoker_invoke()
{
tabBrowser().loadURI(aURI);
}
this.eventSeq = [
new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument)
];
this.finalCheck = function loadURIInvoker_finalCheck()
{
aFunc.call();
}
this.getID = function loadURIInvoker_getID()
{
return "load uri " + aURI;
}
}
function addTabInvoker(aURL, aFunc)
{
this.eventSeq = [
new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, tabDocumentAt, 1)
];
this.invoke = function addTabInvoker_invoke()
{
tabBrowser().loadOneTab(aURL, {
referrerURI: null,
charset: "",
postData: null,
inBackground: false,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
}
this.finalCheck = function addTabInvoker_finalCheck()
{
aFunc.call();
}
this.getID = function addTabInvoker_getID()
{
return "add tab: " + aURL;
}
}
////////////////////////////////////////////////////////////////////////////
// Tests
function testBackgroundTab()
{
// Accessibles in background tab should have offscreen state and no
// invisible state.
var tabDoc = tabDocumentAt(0);
var input = getAccessible(tabDoc.getElementById("input"));
testStates(input, STATE_OFFSCREEN, 0, STATE_INVISIBLE);
}
function testScrolledOff()
{
var tabDoc = tabDocumentAt(1);
// scrolled off
input = getAccessible(tabDoc.getElementById("input_scrolledoff"));
testStates(input, STATE_OFFSCREEN, 0, STATE_INVISIBLE);
// scrolled off item (twice)
var lastLiNode = tabDoc.getElementById("li_last");
var lastLi = getAccessible(lastLiNode);
testStates(lastLi, STATE_OFFSCREEN, 0, STATE_INVISIBLE);
// scroll into view the item
lastLiNode.scrollIntoView(true);
testStates(lastLi, 0, 0, STATE_OFFSCREEN | STATE_INVISIBLE);
// first item is scrolled off now (testcase for bug 768786)
var firstLi = getAccessible(tabDoc.getElementById("li_first"));
testStates(firstLi, STATE_OFFSCREEN, 0, STATE_INVISIBLE);
}
var gInputDocURI = "data:text/html,<html><body>";
gInputDocURI += "<input id='input'></body></html>";
var gDocURI = "data:text/html,<html><body>";
gDocURI += "<div style='border:2px solid blue; width: 500px; height: 600px;'></div>";
gDocURI += "<input id='input_scrolledoff'>";
gDocURI += "<ul style='border:2px solid red; width: 100px; height: 50px; overflow: auto;'>";
gDocURI += " <li id='li_first'>item1</li><li>item2</li><li>item3</li>";
gDocURI += " <li>item4</li><li>item5</li><li id='li_last'>item6</li>";
gDocURI += "</ul>";
gDocURI += "</body></html>";
function doTests()
{
testStates("div", 0, 0, STATE_INVISIBLE | STATE_OFFSCREEN);
@ -126,17 +25,11 @@
testStates("div_transformed", STATE_OFFSCREEN, 0, STATE_INVISIBLE);
testStates("div_abschild", 0, 0, STATE_INVISIBLE | STATE_OFFSCREEN);
gQueue = new eventQueue();
gQueue.push(new addTabInvoker("about:blank", testBackgroundTab));
gQueue.push(new loadURIInvoker(gDocURI, testScrolledOff));
gQueue.onFinish = function() { closeBrowserWindow(); }
gQueue.invoke(); // Will call SimpleTest.finish();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
openBrowserWindow(doTests, gInputDocURI, { width: 600, height: 600 });
addA11yLoadEvent(doTests);
</script>
</head>