test_doc_busy.html (4393B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>states of document</title> 5 <link rel="stylesheet" type="text/css" 6 href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 7 8 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 10 11 <script type="application/javascript" 12 src="../common.js"></script> 13 <script type="application/javascript" 14 src="../role.js"></script> 15 <script type="application/javascript" 16 src="../states.js"></script> 17 <script type="application/javascript" 18 src="../promisified-events.js"></script> 19 20 <script type="application/javascript"> 21 const { BrowserTestUtils } = ChromeUtils.importESModule( 22 "resource://testing-common/BrowserTestUtils.sys.mjs"); 23 const { Downloads } = ChromeUtils.importESModule( 24 "resource://gre/modules/Downloads.sys.mjs"); 25 26 function matchDocBusyChange(isBusy) { 27 return function(event) { 28 const scEvent = event.QueryInterface(nsIAccessibleStateChangeEvent); 29 return ( 30 event.DOMNode == document && 31 scEvent.state === STATE_BUSY && 32 scEvent.isEnabled === isBusy 33 ); 34 }; 35 } 36 37 function getDownloadStartedPromise() { 38 return Downloads.getList(Downloads.PUBLIC).then(list => { 39 return new Promise(resolve => { 40 list.addView({ 41 onDownloadAdded(download) { 42 resolve(download); 43 } 44 }) 45 }); 46 }); 47 } 48 49 async function downloadHandled(downloadResult) { 50 if (Window.isInstance(downloadResult)) { 51 return BrowserTestUtils.closeWindow(downloadResult); 52 } 53 // downloadResult is a download object. 54 await downloadResult.finalize(true); 55 return Downloads.getList(Downloads.PUBLIC).then(list => list.remove(downloadResult)); 56 } 57 58 async function doTest() { 59 // Because of variable timing, there are two acceptable possibilities: 60 // 1. We get an event for busy and an event for not busy. 61 // 2. The two events get coalesced, so no events are fired. 62 // However, we fail this test if we get the first event but not the 63 // second. 64 let gotBusy = false; 65 let gotNotBusy = false; 66 const busyEvents = async function() { 67 await waitForEvent(EVENT_STATE_CHANGE, matchDocBusyChange(true)); 68 info("Got busy event"); 69 gotBusy = true; 70 await waitForEvent(EVENT_STATE_CHANGE, matchDocBusyChange(false)); 71 info("Got not-busy event"); 72 gotNotBusy = true; 73 }(); 74 75 const downloadStarted = getDownloadStartedPromise(); 76 77 info("Clicking link to trigger download"); 78 synthesizeMouse(getNode("link"), 1, 1, {}); 79 info("Waiting for download prompt to open"); 80 const downloadResult = await downloadStarted; 81 82 // Once we no longer show a dialog for downloads, the not busy event 83 // might show up a bit later. 84 if (gotBusy && !gotNotBusy) { 85 await busyEvents; 86 } 87 88 // Any busy events should have been fired by the time the download 89 // prompt has opened. 90 if (gotBusy && gotNotBusy) { 91 ok(true, "Got both busy change and not-busy change"); 92 } else if (!gotBusy && !gotNotBusy) { 93 ok(true, "No busy events, coalesced"); 94 } else { 95 ok(false, "Got busy change but didn't get not-busy change!"); 96 } 97 testStates(document, 0, 0, STATE_BUSY, 0, "Document not busy"); 98 99 // Clean up. 100 info("Closing download prompt"); 101 await downloadHandled(downloadResult); 102 // We might still be waiting on busy events. Remove any pending observers. 103 for (let observer of Services.obs.enumerateObservers( 104 "accessible-event") 105 ) { 106 Services.obs.removeObserver(observer, "accessible-event"); 107 } 108 109 SimpleTest.finish(); 110 } 111 112 SimpleTest.waitForExplicitFinish(); 113 addA11yLoadEvent(doTest); 114 </script> 115 </head> 116 117 <body> 118 119 <a target="_blank" 120 title="Missing busy state change event when downloading files" 121 href="https://bugzilla.mozilla.org/show_bug.cgi?id=446469">Bug 446469</a> 122 123 <p id="display"></p> 124 <div id="content" style="display: none"></div> 125 <pre id="test"> 126 </pre> 127 128 <a id="link" href="http://example.com/a11y/accessible/tests/mochitest/dumbfile.zip">a file</a> 129 </body> 130 </html>