widget/tests/test_bug428405.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4
michael@0 5 <window id="window1" title="Test Bug 428405"
michael@0 6 onload="setGlobals(); loadFirstTab();"
michael@0 7 xmlns:html="http://www.w3.org/1999/xhtml"
michael@0 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 9
michael@0 10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 11 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 12 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"/>
michael@0 13
michael@0 14 <tabbox id="tabbox" flex="100%">
michael@0 15 <tabs>
michael@0 16 <tab label="Tab 1"/>
michael@0 17 <tab label="Tab 2"/>
michael@0 18 </tabs>
michael@0 19 <tabpanels flex="100%">
michael@0 20 <browser onload="configureFirstTab();" id="tab1browser" flex="100%"/>
michael@0 21 <browser onload="configureSecondTab();" id="tab2browser" flex="100%"/>
michael@0 22 </tabpanels>
michael@0 23 </tabbox>
michael@0 24
michael@0 25 <script type="application/javascript"><![CDATA[
michael@0 26
michael@0 27 SimpleTest.waitForExplicitFinish();
michael@0 28
michael@0 29 var gCmdOptYReceived = false;
michael@0 30
michael@0 31 // Look for a cmd-opt-y event.
michael@0 32 function onKeyPress(aEvent) {
michael@0 33 gCmdOptYReceived = false;
michael@0 34 if (String.fromCharCode(aEvent.charCode) != 'y')
michael@0 35 return;
michael@0 36 if (aEvent.ctrlKey || aEvent.shiftKey || !aEvent.metaKey || !aEvent.altKey)
michael@0 37 return;
michael@0 38 gCmdOptYReceived = true;
michael@0 39 }
michael@0 40
michael@0 41 function setGlobals() {
michael@0 42 var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
michael@0 43 getService(Components.interfaces.nsIWindowMediator);
michael@0 44 gChromeWindow = wm.getMostRecentWindow("navigator:browser");
michael@0 45 // For some reason, a global <key> element's oncommand handler only gets
michael@0 46 // invoked if the focus is outside both of the <browser> elements
michael@0 47 // (tab1browser and tab2browser). So, to make sure we can see a
michael@0 48 // cmd-opt-y event in window1 (if one is available), regardless of where
michael@0 49 // the focus is in this window, we need to add a "keypress" event
michael@0 50 // listener to gChromeWindow, and then check (in onKeyPress()) to see if
michael@0 51 // it's a cmd-opt-y event.
michael@0 52 gChromeWindow.addEventListener("keypress", onKeyPress, false);
michael@0 53 }
michael@0 54
michael@0 55 // 1) Start loading first tab.
michael@0 56 // 6) Start reloading first tab.
michael@0 57 function loadFirstTab() {
michael@0 58 var browser = document.getElementById("tab1browser");
michael@0 59 browser.loadURI("data:text/html;charset=utf-8,<body><h2>First Tab</h2><p><input type='submit' value='Button' id='button1'/></body>", null, null);
michael@0 60 }
michael@0 61
michael@0 62 function configureFirstTab() {
michael@0 63 try {
michael@0 64 var button = document.getElementById("tab1browser").contentDocument.getElementById("button1");
michael@0 65 button.addEventListener("click", onFirstTabButtonClicked, false);
michael@0 66 button.focus();
michael@0 67 if (document.getElementById("tabbox").selectedIndex == 0) {
michael@0 68 // 2) When first tab has finished loading (while first tab is
michael@0 69 // focused), hit Return to trigger the action of first tab's
michael@0 70 // button.
michael@0 71 synthesizeNativeReturnKey();
michael@0 72 } else {
michael@0 73 // 7) When first tab has finished reloading (while second tab is
michael@0 74 // focused), start loading second tab.
michael@0 75 loadSecondTab();
michael@0 76 }
michael@0 77 } catch(e) {
michael@0 78 }
michael@0 79 }
michael@0 80
michael@0 81 // 8) Start loading second tab.
michael@0 82 function loadSecondTab() {
michael@0 83 var browser = document.getElementById("tab2browser");
michael@0 84 browser.loadURI("data:text/html;charset=utf-8,<body><h2>Second Tab</h2><p><input type='submit' value='Button' id='button1'/></body>", null, null);
michael@0 85 }
michael@0 86
michael@0 87 function configureSecondTab() {
michael@0 88 try {
michael@0 89 var button = document.getElementById("tab2browser").contentDocument.getElementById("button1");
michael@0 90 button.addEventListener("click", onSecondTabButtonClicked, false);
michael@0 91 button.focus();
michael@0 92 if (document.getElementById("tabbox").selectedIndex == 1) {
michael@0 93 // 9) When second tab has finished loading (while second tab is
michael@0 94 // focused), hit Return to trigger action of second tab's
michael@0 95 // button.
michael@0 96 synthesizeNativeReturnKey();
michael@0 97 }
michael@0 98 } catch(e) {
michael@0 99 }
michael@0 100 }
michael@0 101
michael@0 102 // 3) First tab's button clicked.
michael@0 103 function onFirstTabButtonClicked() {
michael@0 104 switchToSecondTabAndReloadFirst();
michael@0 105 }
michael@0 106
michael@0 107 // 10) Second tab's button clicked.
michael@0 108 function onSecondTabButtonClicked() {
michael@0 109 switchToFirstTab();
michael@0 110 }
michael@0 111
michael@0 112 function switchToSecondTabAndReloadFirst() {
michael@0 113 // 4) Switch to second tab.
michael@0 114 document.getElementById("tabbox").selectedIndex = 1;
michael@0 115 // 5) Start reloading first tab (while second tab is focused).
michael@0 116 loadFirstTab();
michael@0 117 }
michael@0 118
michael@0 119 function switchToFirstTab() {
michael@0 120 // 11) Switch back to first tab.
michael@0 121 document.getElementById("tabbox").selectedIndex = 0;
michael@0 122 finishTest();
michael@0 123 }
michael@0 124
michael@0 125 function finishTest() {
michael@0 126 // 12) Back in first tab, try cmd-y.
michael@0 127 gCmdOptYReceived = false;
michael@0 128 synthesizeNativeCmdOptY();
michael@0 129
michael@0 130 // 13) Check result.
michael@0 131 is(gCmdOptYReceived, true);
michael@0 132
michael@0 133 SimpleTest.finish();
michael@0 134 }
michael@0 135
michael@0 136 // synthesizeNativeReturnKey() and synthesizeNativeCmdOptY() are needed
michael@0 137 // because their synthesizeKey() counterparts don't work properly -- the
michael@0 138 // latter make this test succeed when it should fail.
michael@0 139
michael@0 140 // The 'aNativeKeyCode', 'aCharacters' and 'aUnmodifiedCharacters'
michael@0 141 // parameters used below (in synthesizeNativeReturnKey() and
michael@0 142 // synthesizeNativeCmdOptY()) were confirmed accurate using the
michael@0 143 // DebugEventsPlugin v1.01 from bmo bug 441880.
michael@0 144
michael@0 145 function synthesizeNativeReturnKey() {
michael@0 146 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_Return, {}, "\u000a", "\u000a");
michael@0 147 }
michael@0 148
michael@0 149 function synthesizeNativeCmdOptY() {
michael@0 150 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_Y, {metaKey:1, altKey:1}, "y", "y");
michael@0 151 }
michael@0 152
michael@0 153 ]]></script>
michael@0 154
michael@0 155 <!-- test results are displayed in the html:body -->
michael@0 156 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 157 <p id="display"></p>
michael@0 158 <div id="content" style="display: none"></div>
michael@0 159 <pre id="test"></pre>
michael@0 160 </body>
michael@0 161
michael@0 162 </window>

mercurial