gecko/accessible/tests/mochitest/events/test_docload.html

282 lines
8.0 KiB
HTML
Raw Normal View History

<html>
<head>
<title>Accessible events testing for document</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/common.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/role.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/states.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/events.js"></script>
<script type="application/javascript">
////////////////////////////////////////////////////////////////////////////
// Invokers
function changeIframeSrc(aIdentifier, aURL)
{
this.DOMNode = getNode(aIdentifier);
this.eventSeq = [
new invokerChecker(EVENT_REORDER, getAccessible(this.DOMNode))
];
this.invoke = function changeIframeSrc_invoke()
{
this.DOMNode.src = aURL;
}
this.finalCheck = function changeIframeSrc_finalCheck()
{
var accTree = {
role: ROLE_INTERNAL_FRAME,
children: [
{
role: ROLE_DOCUMENT,
name: aURL == "about:" ? "About:" : aURL
}
]
};
testAccessibleTree(this.DOMNode, accTree);
}
this.getID = function changeIframeSrc_getID()
{
return "change iframe src on " + aURL;
}
}
const kHide = 1;
const kShow = 2;
const kRemove = 3;
function morphIFrame(aIdentifier, aAction)
{
this.DOMNode = getNode(aIdentifier);
this.IFrameContainerDOMNode = this.DOMNode.parentNode;
this.eventSeq = [];
var checker = null;
if (aAction == kShow)
checker = new invokerChecker(EVENT_SHOW, this.DOMNode);
else
checker = new invokerChecker(EVENT_HIDE, this.DOMNode);
this.eventSeq.push(checker);
var reorderChecker =
new invokerChecker(EVENT_REORDER, this.IFrameContainerDOMNode);
this.eventSeq.push(reorderChecker);
this.invoke = function morphIFrame_invoke()
{
if (aAction == kHide) {
this.DOMNode.style.display = "none";
} else if (aAction == kShow) {
this.DOMNode.style.display = "block";
} else {
this.IFrameContainerDOMNode.removeChild(this.DOMNode);
}
}
this.finalCheck = function morphIFrame_finalCheck()
{
var accTree = {
role: ROLE_SECTION,
children: (aAction == kHide || aAction == kRemove) ? [ ] :
[
{
role: ROLE_INTERNAL_FRAME,
children: [
{ role: ROLE_DOCUMENT }
]
}
]
};
testAccessibleTree(this.IFrameContainerDOMNode, accTree);
}
this.getID = function morphIFrame_getID()
{
if (aAction == kRemove)
return "remove iframe";
return "change display style of iframe to " +
((aAction == kHide) ? "none" : "block");
}
}
function openDialogWnd(aURL)
{
// Get application root accessible.
var docAcc = getAccessible(document);
while (docAcc) {
this.mRootAcc = docAcc;
try {
docAcc = docAcc.parent;
} catch (e) {
// XXX: it may randomaly fail on propertypage accessible of browser's
// tabbbrowser if nsIAccessible::parent returns cached parent only.
// This should gone after bug 572951.
// Error: failed | Can't get parent for [ 'panel1277435313424' ,
// role: propertypage]
ok(false, "Can't get parent for " + prettyName(docAcc));
throw e;
}
}
this.eventSeq = [
new invokerChecker(EVENT_REORDER, this.mRootAcc)
];
this.invoke = function openDialogWnd_invoke()
{
this.mDialog = window.openDialog(aURL);
}
this.finalCheck = function openDialogWnd_finalCheck()
{
this.finalCheckImpl();
}
this.finalCheckImpl = function openDialogWnd_finalCheckImpl()
{
var accTree = {
role: ROLE_APP_ROOT,
children: [
{
role: ROLE_CHROME_WINDOW
},
{
role: ROLE_CHROME_WINDOW
}
]
};
testAccessibleTree(this.mRootAcc, accTree);
var dlgDoc = this.mDialog.document;
ok(isAccessibleInCache(dlgDoc),
"The document accessible for '" + aURL + "' is not in cache!");
this.mDialog.close();
ok(!isAccessibleInCache(dlgDoc),
"The document accessible for '" + aURL + "' is in cache still!");
}
this.getID = function openDialogWnd_getID()
{
return "open dialog '" + aURL + "'";
}
}
function openWndShutdownDoc()
{
this.__proto__ =
new openDialogWnd("chrome://mochikit/content/a11y/accessible/events/docload_wnd.html");
var thisObj = this;
var docChecker = {
type: EVENT_HIDE,
get target()
{
var iframe = this.invoker.mDialog.document.getElementById("iframe");
this.invoker.iframeDoc = iframe.contentDocument;
return iframe;
},
invoker: thisObj
};
this.eventSeq.push(docChecker);
this.finalCheck = function openWndShutdownDoc_finalCheck()
{
// After timeout after event hide for iframe was handled the document
// accessible for iframe's document is in cache still.
ok(!isAccessibleInCache(this.iframeDoc),
"The document accessible for iframe is in cache still after iframe hide!");
this.finalCheckImpl();
// After the window is closed all alive subdocument accessibles should
// be shut down.
ok(!isAccessibleInCache(this.iframeDoc),
"The document accessible for iframe is in cache still!");
}
}
////////////////////////////////////////////////////////////////////////////
// Do tests
var gQueue = null;
// Debug stuff.
// gA11yEventDumpID = "eventdump";
// gA11yEventDumpToConsole = true;
function doTests()
{
gQueue = new eventQueue();
gQueue.push(new changeIframeSrc("iframe", "about:"));
gQueue.push(new changeIframeSrc("iframe", "about:buildconfig"));
gQueue.push(new morphIFrame("iframe", kHide));
gQueue.push(new morphIFrame("iframe", kShow));
gQueue.push(new morphIFrame("iframe", kRemove));
gQueue.push(new openDialogWnd("about:"));
gQueue.push(new openWndShutdownDoc());
gQueue.invoke(); // Will call SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTests);
</script>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=420845"
title="Fire event_reorder on any embedded frames/iframes whos document has just loaded">
Mozilla Bug 420845
</a><br>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=506206"
title="Fire event_reorder application root accessible">
Mozilla Bug 506206
</a><br>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=566103"
title="Reorganize accessible document handling">
Mozilla Bug 566103
</a><br>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=571459"
title="Shutdown document accessible when presshell goes away">
Mozilla Bug 571459
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<div id="testContainer"><iframe id="iframe"></iframe></div>
<div id="eventdump"></div>
</body>
</html>