gecko/accessible/tests/mochitest/test_events_mutation.html
Alexander Surkov f77c4d89e7 Bug 473765 - Intermittent test failure in bug 469985 test_events_mutation.html, r=davidb, marcoz
--HG--
rename : accessible/tests/mochitest/common.js => accessible/tests/mochitest/events.js
2009-01-25 12:42:21 +08:00

275 lines
9.3 KiB
HTML

<html>
<head>
<title>Accessible mutation events testing</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<style>
div.displayNone a { display:none; }
div.visibilityHidden a { visibility:hidden; }
</style>
<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/tests/SimpleTest/EventUtils.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/events.js"></script>
<script type="application/javascript">
/**
* Invokers.
*/
var kNoEvents = 0;
var kShowEvent = 1;
var kHideEvent = 2;
var kReorderEvent = 4;
var kShowEvents = kShowEvent | kReorderEvent;
var kHideEvents = kHideEvent | kReorderEvent;
var kHideAndShowEvents = kHideEvents | kShowEvent;
function mutateA11yTree(aNodeOrID, aEventTypes, aDoNotExpectEvents,
aIsDOMChange)
{
this.DOMNode = getNode(aNodeOrID);
this.eventSeq = [];
if (aIsDOMChange) {
if (aEventTypes & kHideEvent)
this.eventSeq.push([nsIAccessibleEvent.EVENT_DOM_DESTROY,
this.DOMNode]);
if (aEventTypes & kShowEvent)
this.eventSeq.push([nsIAccessibleEvent.EVENT_DOM_CREATE,
this.DOMNode]);
} else {
if (aEventTypes & kHideEvent)
this.eventSeq.push([nsIAccessibleEvent.EVENT_ASYNCH_HIDE,
this.DOMNode]);
if (aEventTypes & kShowEvent)
this.eventSeq.push([nsIAccessibleEvent.EVENT_ASYNCH_SHOW,
this.DOMNode]);
}
if (aEventTypes & kReorderEvent)
this.eventSeq.push([nsIAccessibleEvent.EVENT_REORDER,
this.DOMNode.parentNode]);
this.doNotExpectEvents = aDoNotExpectEvents;
}
function changeStyle(aNodeOrID, aProp, aValue, aEventTypes)
{
this.__proto__ = new mutateA11yTree(aNodeOrID, aEventTypes, false, false);
this.invoke = function changeStyle_invoke()
{
this.DOMNode.style[aProp] = aValue;
}
this.getID = function changeStyle_getID()
{
return aNodeOrID + " change style " + aProp + " on value " + aValue;
}
}
function changeClass(aParentNodeOrID, aNodeOrID, aClassName, aEventTypes)
{
this.__proto__ = new mutateA11yTree(aNodeOrID, aEventTypes, false, false);
this.invoke = function changeClass_invoke()
{
this.parentDOMNode.className = aClassName;
}
this.getID = function changeClass_getID()
{
return aNodeOrID + " change class " + aClassName;
}
this.parentDOMNode = getNode(aParentNodeOrID);
}
function cloneAndAppendToDOM(aNodeOrID, aEventTypes)
{
var eventTypes = aEventTypes || kShowEvents;
var doNotExpectEvents = (aEventTypes == kNoEvents);
this.__proto__ = new mutateA11yTree(aNodeOrID, eventTypes,
doNotExpectEvents, true);
this.invoke = function cloneAndAppendToDOM_invoke()
{
var newElm = this.DOMNode.cloneNode(true);
newElm.removeAttribute('id');
this.eventSeq[0][1] = newElm;
this.DOMNode.parentNode.appendChild(newElm);
}
this.getID = function cloneAndAppendToDOM_getID()
{
return aNodeOrID + " clone and append to DOM.";
}
}
function removeFromDOM(aNodeOrID, aEventTypes)
{
var eventTypes = aEventTypes || kHideEvents;
var doNotExpectEvents = (aEventTypes == kNoEvents);
this.__proto__ = new mutateA11yTree(aNodeOrID, eventTypes,
doNotExpectEvents, true);
this.invoke = function removeFromDOM_invoke()
{
this.DOMNode.parentNode.removeChild(this.DOMNode);
}
this.getID = function removeFromDOM_getID()
{
return aNodeOrID + " remove from DOM.";
}
}
function cloneAndReplaceInDOM(aNodeOrID)
{
this.__proto__ = new mutateA11yTree(aNodeOrID, kHideAndShowEvents,
false, true);
this.invoke = function cloneAndReplaceInDOM_invoke()
{
var newElm = this.DOMNode.cloneNode(true);
newElm.removeAttribute('id');
this.eventSeq[1][1] = newElm;
this.DOMNode.parentNode.replaceChild(newElm, this.DOMNode);
}
this.getID = function cloneAndReplaceInDOM_getID()
{
return aNodeOrID + " clone and replace in DOM.";
}
}
/**
* Do tests.
*/
var gQueue = null;
// var gA11yEventDumpID = "eventdump"; // debug stuff
function doTests()
{
gQueue = new eventQueue();
// Show/hide events by changing of display style of accessible DOM node
// from 'inline' to 'none', 'none' to 'inline'.
var id = "link1";
getAccessible(id); // ensure accessible is created
gQueue.push(new changeStyle(id, "display", "none", kHideEvents));
// XXX: bug 472662 - there is no expected reorder event
gQueue.push(new changeStyle(id, "display", "inline", kShowEvent));
// Show/hide events by changing of visibility style of accessible DOM node
// from 'visible' to 'hidden', 'hidden' to 'visible'.
var id = "link2";
getAccessible(id);
gQueue.push(new changeStyle(id, "visibility", "hidden", kHideEvents));
gQueue.push(new changeStyle(id, "visibility", "visible", kShowEvents));
// Show/hide events by changing of display style of accessible DOM node
// from 'inline' to 'block', 'block' to 'inline'.
var id = "link3";
getAccessible(id); // ensure accessible is created
gQueue.push(new changeStyle(id, "display", "block", kHideAndShowEvents));
gQueue.push(new changeStyle(id, "display", "inline", kHideAndShowEvents));
// Show/hide events by changing of visibility style of accessible DOM node
// from 'collapse' to 'visible', 'visible' to 'collapse'.
var id = "link4";
gQueue.push(new changeStyle(id, "visibility", "visible", kShowEvents));
gQueue.push(new changeStyle(id, "visibility", "collapse", kHideEvents));
// Show/hide events by adding new accessible DOM node and removing old one.
var id = "link5";
// XXX: bug 472662 - there is no expected reorder event
gQueue.push(new cloneAndAppendToDOM(id, kShowEvent));
gQueue.push(new removeFromDOM(id));
// No show/hide events by adding new not accessible DOM node and removing
// old one, no reorder event for their parent.
var id = "child1";
gQueue.push(new cloneAndAppendToDOM(id, kNoEvents));
gQueue.push(new removeFromDOM(id, kNoEvents));
// Show/hide events by adding new accessible DOM node and removing
// old one, there is reorder event for their parent.
var id = "child2";
gQueue.push(new cloneAndAppendToDOM(id, kShowEvent));
gQueue.push(new removeFromDOM(id));
// Show/hide events by creating new accessible DOM node and replacing
// old one.
// XXX: bug 472810
// gQueue.push(new cloneAndReplaceInDOM("link6"));
// Show/hide events by changing class name on the parent node.
// XXX: bug 472662 - there is no expected reorder event
gQueue.push(new changeClass("container2", "link7", "", kShowEvent));
gQueue.push(new changeClass("container2", "link7", "displayNone",
kHideEvents));
gQueue.push(new changeClass("container3", "link8", "", kShowEvents));
gQueue.push(new changeClass("container3", "link8", "visibilityHidden",
kHideEvents));
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=469985"
title=" turn the test from bug 354745 into mochitest">
Mozilla Bug 469985
</a>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=472662"
title="no reorder event when html:link display property is changed from 'none' to 'inline'">
Mozilla Bug 472662
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<div id="eventdump"/>
<a id="link1" href="http://www.google.com">Link #1</a>
<a id="link2" href="http://www.google.com">Link #2</a>
<a id="link3" href="http://www.google.com">Link #3</a>
<a id="link4" href="http://www.google.com" style="visibility:collapse">Link #4</a>
<a id="link5" href="http://www.google.com">Link #5</a>
<div id="container" role="list"><span id="child1"></span><span id="child2" role="listitem"></span></div>
<a id="link6" href="http://www.google.com">Link #6</a>
<div id="container2" class="displayNone"><a id="link7">Link #7</a></div>
<div id="container3" class="visibilityHidden"><a id="link8">Link #8</a></div>
</body>
</html>