Bug 972047 - Introduce AccessFu content integration mochitest. r=yzen

This commit is contained in:
Eitan Isaacson 2014-02-26 19:39:14 -05:00
parent fb07271785
commit dfe9e5cfa1
5 changed files with 333 additions and 0 deletions

View File

@ -400,6 +400,8 @@ addMessageListener(
eventManager = new EventManager(this);
}
eventManager.start();
sendAsyncMessage('AccessFu:ContentStarted');
});
addMessageListener(

View File

@ -3,8 +3,10 @@ support-files =
jsatcommon.js
output.js
doc_traversal.html
doc_content_integration.html
[test_alive.html]
[test_content_integration.html]
[test_explicit_names.html]
[test_landmarks.html]
[test_live_regions.html]

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Traversal Rule test document</title>
<meta charset="utf-8" />
<script>
var frameContents = '<html>' +
'<head><title>such app</title></head>' +
'<body>' +
'<h1>wow</h1>' +
'<label><input type="checkbox">many option</label>' +
'</body>' +
'</html>';
</script>
<style>
#windows > iframe {
width: 320px;
height: 480px;
}
</style>
</head>
<body>
<div>Phone status bar</div>
<div id="windows"></div>
<button>Home</button>
</body>
</html>

View File

@ -155,3 +155,117 @@ var AccessFuTest = {
SpecialPowers.setIntPref("accessibility.accessfu.notify_output", 1);
}
};
function AccessFuContentTest(aFuncResultPairs) {
this.queue = aFuncResultPairs;
}
AccessFuContentTest.prototype = {
currentPair: null,
start: function(aFinishedCallback) {
this.finishedCallback = aFinishedCallback;
var self = this;
// Get top content message manager, and set it up.
this.mms = [Utils.getMessageManager(currentBrowser())];
this.setupMessageManager(this.mms[0], function () {
// Get child message managers and set them up
var frames = currentTabDocument().querySelectorAll('iframe');
var toSetup = 0;
for (var i = 0; i < frames.length; i++ ) {
var mm = Utils.getMessageManager(frames[i]);
if (mm) {
toSetup++;
self.mms.push(mm);
self.setupMessageManager(mm, function () {
if (--toSetup === 0) {
// All message managers are loaded and ready to go.
self.pump();
}
});
}
}
});
},
setupMessageManager: function (aMessageManager, aCallback) {
function contentScript() {
addMessageListener('AccessFuTest:Focus', function (aMessage) {
var elem = content.document.querySelector(aMessage.json.selector);
if (elem) {
if (aMessage.json.blur) {
elem.blur();
} else {
elem.focus();
}
}
});
}
aMessageManager.addMessageListener('AccessFu:Present', this);
aMessageManager.addMessageListener('AccessFu:Ready', function (aMessage) {
aMessageManager.addMessageListener('AccessFu:ContentStarted', aCallback);
aMessageManager.sendAsyncMessage('AccessFu:Start', { buildApp: 'browser' });
});
aMessageManager.loadFrameScript(
'chrome://global/content/accessibility/content-script.js', false);
aMessageManager.loadFrameScript(
'data:,(' + contentScript.toString() + ')();', false);
},
pump: function() {
this.currentPair = this.queue.shift();
if (this.currentPair) {
if (this.currentPair[0] instanceof Function) {
this.currentPair[0](this.mms[0]);
} else {
this.mms[0].sendAsyncMessage(this.currentPair[0].name,
this.currentPair[0].json);
}
} else if (this.finishedCallback) {
for (var mm of this.mms) {
mm.sendAsyncMessage('AccessFu:Stop');
}
this.finishedCallback();
}
},
receiveMessage: function(aMessage) {
if (!this.currentPair) {
return;
}
var expected = this.currentPair[1];
if (expected) {
if (expected.speak !== undefined) {
var speech = this.extractUtterance(aMessage.json);
if (!speech) {
// Probably a visual highlight adjustment after a scroll.
return;
}
var checkFunc = SimpleTest[expected.speak_checkFunc] || is;
checkFunc(speech, expected.speak);
}
}
this.pump();
},
extractUtterance: function(aData) {
for (var output of aData) {
if (output && output.type === 'Speech') {
for (var action of output.details.actions) {
if (action && action.method == 'speak') {
return action.data;
}
}
}
}
return null;
}
};

View File

@ -0,0 +1,186 @@
<!DOCTYPE html>
<html>
<head>
<title>Tests AccessFu content integration</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js">
</script>
<script type="application/javascript"
src="chrome://mochikit/content/chrome-harness.js">
</script>
<script type="application/javascript" src="../common.js"></script>
<script type="application/javascript" src="../browser.js"></script>
<script type="application/javascript" src="../events.js"></script>
<script type="application/javascript" src="../role.js"></script>
<script type="application/javascript" src="../states.js"></script>
<script type="application/javascript" src="../layout.js"></script>
<script type="application/javascript" src="jsatcommon.js"></script>
<script type="application/javascript">
function doTest() {
var doc = currentTabDocument();
var iframe = doc.createElement("iframe");
iframe.mozbrowser = true;
iframe.addEventListener("mozbrowserloadend", function () {
var simpleMoveNext = { name: 'AccessFu:MoveCursor',
json: { action: 'moveNext',
rule: 'Simple',
inputType: 'gesture',
origin: 'top' }
};
var simpleMovePrevious = { name: 'AccessFu:MoveCursor',
json: { action: 'movePrevious',
rule: 'Simple',
inputType: 'gesture',
origin: 'top' }
};
var activateCurrent = { name: 'AccessFu:Activate',
json: { origin: 'top' } };
var simpleMoveLast = { name: 'AccessFu:MoveCursor',
json: { action: 'moveLast',
rule: 'Simple',
inputType: 'gesture',
origin: 'top' }
};
var simpleMoveFirst = { name: 'AccessFu:MoveCursor',
json: { action: 'moveFirst',
rule: 'Simple',
inputType: 'gesture',
origin: 'top' }
};
var clearCursor = { name: 'AccessFu:ClearCursor',
json: { origin: 'top' }
};
function focusFunc(aSelector, aBlur) {
return function (mm) {
mm.sendAsyncMessage(
'AccessFuTest:Focus', { selector: aSelector, blur: aBlur });
};
}
var contentTest = new AccessFuContentTest(
[
// Simple traversal forward
[simpleMoveNext,
{ speak: 'Phone status bar Traversal Rule test document' }],
[simpleMoveNext,
{ speak: 'wow heading level 1 such app' }],
[simpleMoveNext,
{ speak: 'many option not checked check button' }],
// check checkbox
[activateCurrent,
{ speak: 'checked' }],
[null,
{ speak: 'checked', speak_checkFunc: 'todo_isnot' }],
// uncheck checkbox
[simpleMoveNext,
{ speak: 'Home button' }],
// Simple traversal backward
[simpleMovePrevious,
{ speak: 'many option checked check button such app' }],
[activateCurrent,
{ speak: 'unchecked' }],
[null,
{ speak: 'unchecked', speak_checkFunc: 'todo_isnot' }],
[simpleMovePrevious,
{ speak: 'wow heading level 1' }],
[simpleMovePrevious,
{ speak: 'Phone status bar' }],
// Moving to the absolute last item from an embedded document fails.
// Bug 972035.
[simpleMoveNext,
{ speak: 'wow heading level 1 such app' }],
// Move from an inner frame to the last element in the parent doc
[simpleMoveLast,
{ speak: 'Home button', speak_checkFunc: 'todo_is' }],
[clearCursor, null], // Reset cursors
// Moving to the absolute first item from an embedded document fails.
// Bug 972035.
[simpleMoveNext,
{ speak: 'Phone status bar Traversal Rule test document' }],
[simpleMoveNext,
{ speak: 'wow heading level 1 such app' }],
[simpleMoveNext,
{ speak: 'many option not checked check button' }],
[simpleMoveFirst,
{ speak: 'Phone status bar', speak_checkFunc: 'todo_is' }],
// Reset cursors
[clearCursor, null],
// Move cursor with focus in outside document
[simpleMoveNext,
{ speak: 'Phone status bar Traversal Rule test document' }],
[ focusFunc('button', false), { speak: 'Home button' }],
// Blur button and reset cursor
[focusFunc('button', true), null],
[clearCursor, null],
// Set focus on element outside of embedded frame while cursor is in frame
[simpleMoveNext,
{ speak: 'Phone status bar Traversal Rule test document' }],
[simpleMoveNext,
{ speak: 'wow heading level 1 such app' }],
[focusFunc('button', false), { speak: 'Home button' }]
// XXX: Set focus on iframe itself.
// XXX: Set focus on element in iframe when cursor is outside of it.
// XXX: Set focus on element in iframe when cursor is in iframe.
]);
contentTest.start(function () {
closeBrowserWindow();
SimpleTest.finish();
});
});
iframe.src = 'data:text/html;charset=utf-8,' + doc.defaultView.frameContents;
doc.querySelector('#windows').appendChild(iframe);
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(
function () {
openBrowserWindow(
function () {
SpecialPowers.pushPrefEnv({
"set": [
// TODO: remove this as part of bug 820712
["network.disable.ipc.security", true],
["dom.ipc.browser_frames.oop_by_default", true],
["dom.mozBrowserFramesEnabled", true],
["browser.pagethumbnails.capturing_disabled", true]
]
}, doTest) },
getRootDirectory(window.location.href) + "doc_content_integration.html");
});
</script>
</head>
<body id="body">
<a target="_blank"
title="Add tests for OOP message handling and general integration"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=972047">Mozilla Bug 933808</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
</body>
</html>