accessible/tests/mochitest/events/test_docload.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 <html>
     3 <head>
     4   <title>Accessible events testing for document</title>
     6   <link rel="stylesheet" type="text/css"
     7         href="chrome://mochikit/content/tests/SimpleTest/test.css" />
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    12   <script type="application/javascript"
    13           src="../common.js"></script>
    14   <script type="application/javascript"
    15           src="../role.js"></script>
    16   <script type="application/javascript"
    17           src="../states.js"></script>
    19   <script type="application/javascript">
    20     // Front end stuff sometimes likes to stuff things in the hidden window(s)
    21     // in which case there's accessibles for that content.
    22     Components.utils.import("resource://gre/modules/Services.jsm");
    24     // Force the creation of an accessible for the hidden window's document.
    25     var doc = Services.appShell.hiddenDOMWindow.document;
    26     gAccRetrieval.getAccessibleFor(doc);
    28     // The private hidden window will be lazily created that's why we need to do
    29     // it here *before* loading '../events.js' or else we'll have a duplicate
    30     // reorder event.
    31     var privateDoc = Services.appShell.hiddenPrivateDOMWindow.document;
    33     // Force the creation of an accessible for the private hidden window's doc.
    34     gAccRetrieval.getAccessibleFor(privateDoc);
    35   </script>
    37   <script type="application/javascript"
    38           src="../events.js"></script>
    40   <script type="application/javascript">
    41     ////////////////////////////////////////////////////////////////////////////
    42     // Invokers
    44     function changeIframeSrc(aIdentifier, aURL)
    45     {
    46       this.DOMNode = getNode(aIdentifier);
    48       this.eventSeq = [
    49         new invokerChecker(EVENT_REORDER, getAccessible(this.DOMNode)),
    50         new asyncInvokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, getIframeDoc)
    51       ];
    53       this.invoke = function changeIframeSrc_invoke()
    54       {
    55         this.DOMNode.src = aURL;
    56       }
    58       this.finalCheck = function changeIframeSrc_finalCheck()
    59       {
    60         var accTree = {
    61           role: ROLE_INTERNAL_FRAME,
    62           children: [
    63             {
    64               role: ROLE_DOCUMENT,
    65               name: aURL == "about:" ? "About:" : aURL
    66             }
    67           ]
    68         };
    70         testAccessibleTree(this.DOMNode, accTree);
    71       }
    73       this.getID = function changeIframeSrc_getID()
    74       {
    75         return "change iframe src on " + aURL;
    76       }
    78       function getIframeDoc()
    79       {
    80         return getAccessible(getNode(aIdentifier).contentDocument);
    81       }
    82     }
    84     const kHide = 1;
    85     const kShow = 2;
    86     const kRemove = 3;
    87     function morphIFrame(aIdentifier, aAction)
    88     {
    89       this.DOMNode = getNode(aIdentifier);
    90       this.IFrameContainerDOMNode = this.DOMNode.parentNode;
    92       this.eventSeq = [];
    94       var checker = null;
    95       if (aAction == kShow)
    96         checker = new invokerChecker(EVENT_SHOW, this.DOMNode);
    97       else
    98         checker = new invokerChecker(EVENT_HIDE, this.DOMNode);
    99       this.eventSeq.push(checker);
   101       var reorderChecker =
   102         new invokerChecker(EVENT_REORDER, this.IFrameContainerDOMNode);
   103       this.eventSeq.push(reorderChecker);
   105       this.invoke = function morphIFrame_invoke()
   106       {
   107         if (aAction == kHide) {
   108           this.DOMNode.style.display = "none";
   109         } else if (aAction == kShow) {
   110           this.DOMNode.style.display = "block";
   111         } else {
   112           this.IFrameContainerDOMNode.removeChild(this.DOMNode);
   113         }
   114       }
   116       this.finalCheck = function morphIFrame_finalCheck()
   117       {
   118         var accTree = {
   119           role: ROLE_SECTION,
   120           children: (aAction == kHide || aAction == kRemove) ? [ ] :
   121             [
   122               {
   123                 role: ROLE_INTERNAL_FRAME,
   124                 children: [
   125                   { role: ROLE_DOCUMENT }
   126                 ]
   127               }
   128             ]
   129         };
   131         testAccessibleTree(this.IFrameContainerDOMNode, accTree);
   132       }
   134       this.getID = function morphIFrame_getID()
   135       {
   136         if (aAction == kRemove)
   137           return "remove iframe";
   139         return "change display style of iframe to " +
   140           ((aAction == kHide) ? "none" : "block");
   141       }
   142     }
   144     function makeIFrameVisible(aID)
   145     {
   146       this.DOMNode = getNode(aID);
   148       this.eventSeq = [
   149         new invokerChecker(EVENT_REORDER, this.DOMNode.parentNode)
   150       ];
   152       this.invoke = function makeIFrameVisible_invoke()
   153       {
   154         this.DOMNode.style.visibility = "visible";
   155       }
   157       this.getID = function makeIFrameVisible_getID()
   158       {
   159         return "The accessible for DOM document loaded before it's shown shouldn't have busy state.";
   160       }
   161     }
   163     function openDialogWnd(aURL)
   164     {
   165       // Get application root accessible.
   166       var docAcc = getAccessible(document);
   167       while (docAcc) {
   168         this.mRootAcc = docAcc;
   169         try {
   170           docAcc = docAcc.parent;
   171         } catch (e) {
   172           ok(false, "Can't get parent for " + prettyName(docAcc));
   173           throw e;
   174         }
   175       }
   177       this.eventSeq = [
   178         new invokerChecker(EVENT_REORDER, this.mRootAcc)
   179       ];
   181       this.invoke = function openDialogWnd_invoke()
   182       {
   183         this.mDialog = window.openDialog(aURL);
   184       }
   186       this.finalCheck = function openDialogWnd_finalCheck()
   187       {
   188         this.finalCheckImpl();
   189       }
   191       this.finalCheckImpl = function openDialogWnd_finalCheckImpl()
   192       {
   193         var accTree = {
   194           role: ROLE_APP_ROOT,
   195           children: [
   196             {
   197               role: ROLE_CHROME_WINDOW
   198             },
   199             {
   200               role: ROLE_CHROME_WINDOW
   201             },
   202             {
   203               role: ROLE_CHROME_WINDOW
   204             },
   205             {
   206               role: ROLE_CHROME_WINDOW
   207             }
   208           ]
   209         };
   211         testAccessibleTree(this.mRootAcc, accTree);
   213         var dlgDoc = this.mDialog.document;
   214         ok(isAccessibleInCache(dlgDoc),
   215            "The document accessible for '" + aURL + "' is not in cache!");
   217         this.mDialog.close();
   219         // close() is asynchronous.
   220         SimpleTest.executeSoon(function() {
   221           ok(!isAccessibleInCache(dlgDoc),
   222              "The document accessible for '" + aURL + "' is in cache still!");
   223         });
   224       }
   226       this.getID = function openDialogWnd_getID()
   227       {
   228         return "open dialog '" + aURL + "'";
   229       }
   230     }
   232     function openWndShutdownDoc()
   233     {
   234       this.__proto__ =
   235         new openDialogWnd("../events/docload_wnd.html");
   237       var thisObj = this;
   238       var docChecker = {
   239         type: EVENT_HIDE,
   240         get target()
   241         {
   242           var iframe = this.invoker.mDialog.document.getElementById("iframe");
   243           this.invoker.iframeDoc = iframe.contentDocument;
   244           return iframe;
   245         },
   246         get targetDescr()
   247         {
   248           return "inner iframe of docload_wnd.html document";
   249         },
   250         invoker: thisObj
   251       };
   253       this.eventSeq.push(docChecker);
   255       this.finalCheck = function openWndShutdownDoc_finalCheck()
   256       {
   257         // After timeout after event hide for iframe was handled the document
   258         // accessible for iframe's document is in cache still.
   259         ok(!isAccessibleInCache(this.iframeDoc),
   260             "The document accessible for iframe is in cache still after iframe hide!");
   262         this.finalCheckImpl();
   264         // After the window is closed all alive subdocument accessibles should
   265         // be shut down.
   266         ok(!isAccessibleInCache(this.iframeDoc),
   267            "The document accessible for iframe is in cache still!");
   268       }
   269     }
   271     ////////////////////////////////////////////////////////////////////////////
   272     // Do tests
   274     var gQueue = null;
   276     // Debug stuff.
   277     // gA11yEventDumpID = "eventdump";
   278     //gA11yEventDumpToConsole = true;
   280     function doTests()
   281     {
   282       gQueue = new eventQueue();
   284       gQueue.push(new changeIframeSrc("iframe", "about:"));
   285       gQueue.push(new changeIframeSrc("iframe", "about:buildconfig"));
   286       gQueue.push(new morphIFrame("iframe", kHide));
   287       gQueue.push(new morphIFrame("iframe", kShow));
   288       gQueue.push(new morphIFrame("iframe", kRemove));
   289       gQueue.push(new makeIFrameVisible("iframe2"));
   290       gQueue.push(new openDialogWnd("about:"));
   291       gQueue.push(new openWndShutdownDoc());
   293       gQueue.onFinish = doLastCallTests;
   295       gQueue.invoke(); // Will call SimpleTest.finish();
   296     }
   298     function doLastCallTests()
   299     {
   300       //////////////////////////////////////////////////////////////////////////
   301       // makeIFrameVisible() test, part2
   303       // The document shouldn't have busy state (the DOM document was loaded
   304       // before its accessible was created). Do this test lately to make sure
   305       // the content of document accessible was created initially, prior to this
   306       // the document accessible keeps busy state. The initial creation happens
   307       // asynchronously after document creation, there are no events we could
   308       // use to catch it.
   309       var iframeDoc = getAccessible("iframe2").firstChild;
   310       testStates(iframeDoc, 0, 0, STATE_BUSY);
   311     }
   313     SimpleTest.waitForExplicitFinish();
   314     addA11yLoadEvent(doTests);
   315   </script>
   316 </head>
   318 <body>
   320   <a target="_blank"
   321      href="https://bugzilla.mozilla.org/show_bug.cgi?id=420845"
   322      title="Fire event_reorder on any embedded frames/iframes whos document has just loaded">
   323     Mozilla Bug 420845
   324   </a><br>
   325   <a target="_blank"
   326      href="https://bugzilla.mozilla.org/show_bug.cgi?id=506206"
   327      title="Fire event_reorder application root accessible">
   328     Mozilla Bug 506206
   329   </a><br>
   330   <a target="_blank"
   331      href="https://bugzilla.mozilla.org/show_bug.cgi?id=566103"
   332      title="Reorganize accessible document handling">
   333     Mozilla Bug 566103
   334   </a><br>
   335   <a target="_blank"
   336      href="https://bugzilla.mozilla.org/show_bug.cgi?id=571459"
   337      title="Shutdown document accessible when presshell goes away">
   338     Mozilla Bug 571459
   339   </a>
   340   <a target="_blank"
   341      href="https://bugzilla.mozilla.org/show_bug.cgi?id=658185"
   342      title="The DOM document loaded before it's shown shouldn't have busy state">
   343     Mozilla Bug 658185
   344   </a>
   345   <a target="_blank"
   346      href="https://bugzilla.mozilla.org/show_bug.cgi?id=754165"
   347      title="Fire document load events on iframes too">
   348     Mozilla Bug 754165
   349   </a>
   351   <p id="display"></p>
   352   <div id="content" style="display: none"></div>
   353   <pre id="test">
   354   </pre>
   356   <div id="testContainer"><iframe id="iframe"></iframe></div>
   357   <div id="testContainer2"><iframe id="iframe2" src="about:" style="visibility: hidden;"></iframe></div>
   358   <div id="eventdump"></div>
   359 </body>
   360 </html>

mercurial