summaryrefslogtreecommitdiff
path: root/accessible/tests/mochitest/events/test_docload.html
blob: a530592ee29b35ebad57b4f111f3cef3eed953cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<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/tests/SimpleTest/SimpleTest.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../states.js"></script>

  <script type="application/javascript">
    // Front end stuff sometimes likes to stuff things in the hidden window(s)
    // in which case there's accessibles for that content.
    Components.utils.import("resource://gre/modules/Services.jsm");

    // Force the creation of an accessible for the hidden window's document.
    var doc = Services.appShell.hiddenDOMWindow.document;
    gAccService.getAccessibleFor(doc);

    // The private hidden window will be lazily created that's why we need to do
    // it here *before* loading '../events.js' or else we'll have a duplicate
    // reorder event.
    var privateDoc = Services.appShell.hiddenPrivateDOMWindow.document;

    // Force the creation of an accessible for the private hidden window's doc.
    gAccService.getAccessibleFor(privateDoc);
  </script>

  <script type="application/javascript"
          src="../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)),
        new asyncInvokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, getIframeDoc)
      ];

      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;
      }

      function getIframeDoc()
      {
        return getAccessible(getNode(aIdentifier).contentDocument);
      }
    }

    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 makeIFrameVisible(aID)
    {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new invokerChecker(EVENT_REORDER, this.DOMNode.parentNode)
      ];

      this.invoke = function makeIFrameVisible_invoke()
      {
        this.DOMNode.style.visibility = "visible";
      }

      this.getID = function makeIFrameVisible_getID()
      {
        return "The accessible for DOM document loaded before it's shown shouldn't have busy state.";
      }
    }

    function openDialogWnd(aURL)
    {
      // Get application root accessible.
      var docAcc = getAccessible(document);
      while (docAcc) {
        this.mRootAcc = docAcc;
        try {
          docAcc = docAcc.parent;
        } catch (e) {
          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
            },
            {
              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();

        // close() is asynchronous.
        SimpleTest.executeSoon(function() {
          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("../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;
        },
        get targetDescr()
        {
          return "inner iframe of docload_wnd.html document";
        },
        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 makeIFrameVisible("iframe2"));
      gQueue.push(new openDialogWnd("about:"));
      gQueue.push(new openWndShutdownDoc());

      gQueue.onFinish = doLastCallTests;

      gQueue.invoke(); // Will call SimpleTest.finish();
    }

    function doLastCallTests()
    {
      //////////////////////////////////////////////////////////////////////////
      // makeIFrameVisible() test, part2

      // The document shouldn't have busy state (the DOM document was loaded
      // before its accessible was created). Do this test lately to make sure
      // the content of document accessible was created initially, prior to this
      // the document accessible keeps busy state. The initial creation happens
      // asynchronously after document creation, there are no events we could
      // use to catch it.
      var iframeDoc = getAccessible("iframe2").firstChild;
      testStates(iframeDoc, 0, 0, STATE_BUSY);
    }

    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>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=658185"
     title="The DOM document loaded before it's shown shouldn't have busy state">
    Mozilla Bug 658185
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=754165"
     title="Fire document load events on iframes too">
    Mozilla Bug 754165
  </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="testContainer2"><iframe id="iframe2" src="about:" style="visibility: hidden;"></iframe></div>
  <div id="eventdump"></div>
</body>
</html>