forked from mirrors/gecko-dev
Bug 1367486 - Move common js stuff down in a11y broswer tests. r=surkov
MozReview-Commit-ID: GDDP0BpjRAv --HG-- rename : accessible/tests/browser/e10s/events.js => accessible/tests/browser/events.js
This commit is contained in:
parent
f091c1e98f
commit
8dc2d56240
5 changed files with 110 additions and 110 deletions
|
|
@ -1,6 +1,7 @@
|
|||
[DEFAULT]
|
||||
|
||||
support-files =
|
||||
events.js
|
||||
head.js
|
||||
shared-head.js
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
[DEFAULT]
|
||||
support-files =
|
||||
events.js
|
||||
head.js
|
||||
doc_treeupdate_ariadialog.html
|
||||
doc_treeupdate_ariaowns.html
|
||||
|
|
@ -8,6 +7,7 @@ support-files =
|
|||
doc_treeupdate_removal.xhtml
|
||||
doc_treeupdate_visibility.html
|
||||
doc_treeupdate_whitespace.html
|
||||
!/accessible/tests/browser/events.js
|
||||
!/accessible/tests/browser/shared-head.js
|
||||
!/accessible/tests/mochitest/*.js
|
||||
!/accessible/tests/mochitest/letters.gif
|
||||
|
|
|
|||
|
|
@ -4,122 +4,14 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
/* exported addAccessibleTask, findAccessibleChildByID, isDefunct */
|
||||
|
||||
// Load the shared-head file first.
|
||||
/* import-globals-from ../shared-head.js */
|
||||
Services.scriptloader.loadSubScript(
|
||||
'chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js',
|
||||
this);
|
||||
|
||||
/**
|
||||
* A wrapper around browser test add_task that triggers an accessible test task
|
||||
* as a new browser test task with given document, data URL or markup snippet.
|
||||
* @param {String} doc URL (relative to current directory) or
|
||||
* data URL or markup snippet that is used
|
||||
* to test content with
|
||||
* @param {Function|AsyncFunction} task a generator or a function with tests to
|
||||
* run
|
||||
*/
|
||||
function addAccessibleTask(doc, task) {
|
||||
add_task(async function() {
|
||||
let url;
|
||||
if (doc.includes('doc_')) {
|
||||
url = `${CURRENT_CONTENT_DIR}e10s/${doc}`;
|
||||
} else {
|
||||
// Assume it's a markup snippet.
|
||||
url = `data:text/html,
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Accessibility Test</title>
|
||||
</head>
|
||||
<body id="body">${doc}</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
let observers = Services.obs.enumerateObservers('accessible-event');
|
||||
while (observers.hasMoreElements()) {
|
||||
Services.obs.removeObserver(
|
||||
observers.getNext().QueryInterface(Ci.nsIObserver),
|
||||
'accessible-event');
|
||||
}
|
||||
});
|
||||
|
||||
let onDocLoad = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, 'body');
|
||||
|
||||
await BrowserTestUtils.withNewTab({
|
||||
gBrowser,
|
||||
url: url
|
||||
}, async function(browser) {
|
||||
registerCleanupFunction(() => {
|
||||
if (browser) {
|
||||
let tab = gBrowser.getTabForBrowser(browser);
|
||||
if (tab && !tab.closing && tab.linkedBrowser) {
|
||||
gBrowser.removeTab(tab);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await SimpleTest.promiseFocus(browser);
|
||||
|
||||
loadFrameScripts(browser,
|
||||
'let { document, window, navigator } = content;',
|
||||
{ name: 'common.js', dir: MOCHITESTS_DIR });
|
||||
|
||||
Logger.log(
|
||||
`e10s enabled: ${Services.appinfo.browserTabsRemoteAutostart}`);
|
||||
Logger.log(`Actually remote browser: ${browser.isRemoteBrowser}`);
|
||||
|
||||
let event = await onDocLoad;
|
||||
await task(browser, event.accessible);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an accessible object has a defunct test.
|
||||
* @param {nsIAccessible} accessible object to test defunct state for
|
||||
* @return {Boolean} flag indicating defunct state
|
||||
*/
|
||||
function isDefunct(accessible) {
|
||||
let defunct = false;
|
||||
try {
|
||||
let extState = {};
|
||||
accessible.getState({}, extState);
|
||||
defunct = extState.value & Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT;
|
||||
} catch (x) {
|
||||
defunct = true;
|
||||
} finally {
|
||||
if (defunct) {
|
||||
Logger.log(`Defunct accessible: ${prettyName(accessible)}`);
|
||||
}
|
||||
}
|
||||
return defunct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses the accessible tree starting from a given accessible as a root and
|
||||
* looks for an accessible that matches based on its DOMNode id.
|
||||
* @param {nsIAccessible} accessible root accessible
|
||||
* @param {String} id id to look up accessible for
|
||||
* @return {nsIAccessible?} found accessible if any
|
||||
*/
|
||||
function findAccessibleChildByID(accessible, id) {
|
||||
if (getAccessibleDOMNodeID(accessible) === id) {
|
||||
return accessible;
|
||||
}
|
||||
for (let i = 0; i < accessible.children.length; ++i) {
|
||||
let found = findAccessibleChildByID(accessible.getChildAt(i), id);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loading and common.js from accessible/tests/mochitest/ for all tests, as
|
||||
// well as events.js.
|
||||
/* import-globals-from ../../mochitest/common.js */
|
||||
/* import-globals-from events.js */
|
||||
loadScripts({ name: 'common.js', dir: MOCHITESTS_DIR }, 'e10s/events.js');
|
||||
loadScripts({ name: 'common.js', dir: MOCHITESTS_DIR }, 'events.js');
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
/* exported Logger, MOCHITESTS_DIR, invokeSetAttribute, invokeFocus,
|
||||
invokeSetStyle, getAccessibleDOMNodeID,
|
||||
addAccessibleTask, findAccessibleChildByID, isDefunct,
|
||||
CURRENT_CONTENT_DIR, loadScripts, loadFrameScripts, Cc, Cu */
|
||||
|
||||
const { interfaces: Ci, utils: Cu, classes: Cc } = Components;
|
||||
|
|
@ -187,3 +188,109 @@ function loadFrameScripts(browser, ...scripts) {
|
|||
mm.loadFrameScript(frameScript, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper around browser test add_task that triggers an accessible test task
|
||||
* as a new browser test task with given document, data URL or markup snippet.
|
||||
* @param {String} doc URL (relative to current directory) or
|
||||
* data URL or markup snippet that is used
|
||||
* to test content with
|
||||
* @param {Function|AsyncFunction} task a generator or a function with tests to
|
||||
* run
|
||||
*/
|
||||
function addAccessibleTask(doc, task) {
|
||||
add_task(async function() {
|
||||
let url;
|
||||
if (doc.includes('doc_')) {
|
||||
url = `${CURRENT_CONTENT_DIR}e10s/${doc}`;
|
||||
} else {
|
||||
// Assume it's a markup snippet.
|
||||
url = `data:text/html,
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Accessibility Test</title>
|
||||
</head>
|
||||
<body id="body">${doc}</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
let observers = Services.obs.enumerateObservers('accessible-event');
|
||||
while (observers.hasMoreElements()) {
|
||||
Services.obs.removeObserver(
|
||||
observers.getNext().QueryInterface(Ci.nsIObserver),
|
||||
'accessible-event');
|
||||
}
|
||||
});
|
||||
|
||||
let onDocLoad = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, 'body');
|
||||
|
||||
await BrowserTestUtils.withNewTab({
|
||||
gBrowser,
|
||||
url: url
|
||||
}, async function(browser) {
|
||||
registerCleanupFunction(() => {
|
||||
if (browser) {
|
||||
let tab = gBrowser.getTabForBrowser(browser);
|
||||
if (tab && !tab.closing && tab.linkedBrowser) {
|
||||
gBrowser.removeTab(tab);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await SimpleTest.promiseFocus(browser);
|
||||
|
||||
loadFrameScripts(browser,
|
||||
'let { document, window, navigator } = content;',
|
||||
{ name: 'common.js', dir: MOCHITESTS_DIR });
|
||||
|
||||
Logger.log(
|
||||
`e10s enabled: ${Services.appinfo.browserTabsRemoteAutostart}`);
|
||||
Logger.log(`Actually remote browser: ${browser.isRemoteBrowser}`);
|
||||
|
||||
let event = await onDocLoad;
|
||||
await task(browser, event.accessible);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an accessible object has a defunct test.
|
||||
* @param {nsIAccessible} accessible object to test defunct state for
|
||||
* @return {Boolean} flag indicating defunct state
|
||||
*/
|
||||
function isDefunct(accessible) {
|
||||
let defunct = false;
|
||||
try {
|
||||
let extState = {};
|
||||
accessible.getState({}, extState);
|
||||
defunct = extState.value & Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT;
|
||||
} catch (x) {
|
||||
defunct = true;
|
||||
} finally {
|
||||
if (defunct) {
|
||||
Logger.log(`Defunct accessible: ${prettyName(accessible)}`);
|
||||
}
|
||||
}
|
||||
return defunct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses the accessible tree starting from a given accessible as a root and
|
||||
* looks for an accessible that matches based on its DOMNode id.
|
||||
* @param {nsIAccessible} accessible root accessible
|
||||
* @param {String} id id to look up accessible for
|
||||
* @return {nsIAccessible?} found accessible if any
|
||||
*/
|
||||
function findAccessibleChildByID(accessible, id) {
|
||||
if (getAccessibleDOMNodeID(accessible) === id) {
|
||||
return accessible;
|
||||
}
|
||||
for (let i = 0; i < accessible.children.length; ++i) {
|
||||
let found = findAccessibleChildByID(accessible.getChildAt(i), id);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue