2 <?xml-stylesheet href=
"chrome://global/skin" type=
"text/css"?>
3 <?xml-stylesheet href=
"chrome://mochikit/content/tests/SimpleTest/test.css" type=
"text/css"?>
5 <window id=
"window1" title=
"Test Bug 428405"
6 onload=
"setGlobals(); loadFirstTab();"
7 xmlns:
html=
"http://www.w3.org/1999/xhtml"
8 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
10 <script type=
"application/javascript" src=
"chrome://mochikit/content/MochiKit/packed.js"/>
11 <script type=
"application/javascript" src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
12 <script type=
"text/javascript" src=
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
14 <tabbox id=
"tabbox" flex=
"100%">
19 <tabpanels flex=
"100%">
20 <browser onload=
"configureFirstTab();" id=
"tab1browser" flex=
"100%"/>
21 <browser onload=
"configureSecondTab();" id=
"tab2browser" flex=
"100%"/>
25 <script type=
"application/javascript"><![CDATA[
27 SimpleTest.waitForExplicitFinish();
31 var gCmdOptYReceived = false;
33 // Look for a cmd-opt-y event.
34 function onKeyPress(aEvent) {
35 gCmdOptYReceived = false;
36 if (String.fromCharCode(aEvent.charCode) != 'y')
38 if (aEvent.ctrlKey || aEvent.shiftKey || !aEvent.metaKey || !aEvent.altKey)
40 gCmdOptYReceived = true;
43 function setGlobals() {
44 gUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
45 getInterface(Components.interfaces.nsIDOMWindowUtils);
46 var wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"].
47 getService(Components.interfaces.nsIWindowMediator);
48 gChromeWindow = wm.getMostRecentWindow(
"navigator:browser");
49 // For some reason, a global
<key> element's oncommand handler only gets
50 // invoked if the focus is outside both of the
<browser> elements
51 // (tab1browser and tab2browser). So, to make sure we can see a
52 // cmd-opt-y event in window1 (if one is available), regardless of where
53 // the focus is in this window, we need to add a
"keypress" event
54 // listener to gChromeWindow, and then check (in onKeyPress()) to see if
55 // it's a cmd-opt-y event.
56 gChromeWindow.addEventListener(
"keypress", onKeyPress, false);
59 //
1) Start loading first tab.
60 //
6) Start reloading first tab.
61 function loadFirstTab() {
62 var browser = document.getElementById(
"tab1browser");
63 browser.loadURI(
"data:text/html;charset=utf-8,<body><h2>First Tab</h2><p><input type='submit' value='Button' id='button1'/></body>", null, null);
66 function configureFirstTab() {
68 var button = document.getElementById(
"tab1browser").contentDocument.getElementById(
"button1");
69 button.addEventListener(
"click", onFirstTabButtonClicked, false);
71 if (document.getElementById(
"tabbox").selectedIndex ==
0) {
72 //
2) When first tab has finished loading (while first tab is
73 // focused), hit Return to trigger the action of first tab's
75 synthesizeNativeReturnKey();
77 //
7) When first tab has finished reloading (while second tab is
78 // focused), start loading second tab.
85 //
8) Start loading second tab.
86 function loadSecondTab() {
87 var browser = document.getElementById(
"tab2browser");
88 browser.loadURI(
"data:text/html;charset=utf-8,<body><h2>Second Tab</h2><p><input type='submit' value='Button' id='button1'/></body>", null, null);
91 function configureSecondTab() {
93 var button = document.getElementById(
"tab2browser").contentDocument.getElementById(
"button1");
94 button.addEventListener(
"click", onSecondTabButtonClicked, false);
96 if (document.getElementById(
"tabbox").selectedIndex ==
1) {
97 //
9) When second tab has finished loading (while second tab is
98 // focused), hit Return to trigger action of second tab's
100 synthesizeNativeReturnKey();
106 //
3) First tab's button clicked.
107 function onFirstTabButtonClicked() {
108 switchToSecondTabAndReloadFirst();
111 //
10) Second tab's button clicked.
112 function onSecondTabButtonClicked() {
116 function switchToSecondTabAndReloadFirst() {
117 //
4) Switch to second tab.
118 document.getElementById(
"tabbox").selectedIndex =
1;
119 //
5) Start reloading first tab (while second tab is focused).
123 function switchToFirstTab() {
124 //
11) Switch back to first tab.
125 document.getElementById(
"tabbox").selectedIndex =
0;
129 function finishTest() {
130 //
12) Back in first tab, try cmd-y.
131 gCmdOptYReceived = false;
132 synthesizeNativeCmdOptY();
135 is(gCmdOptYReceived, true);
140 // synthesizeNativeReturnKey() and synthesizeNativeCmdOptY() are needed
141 // because their synthesizeKey() counterparts don't work properly -- the
142 // latter make this test succeed when it should fail.
144 // The 'aNativeKeyCode', 'aCharacters' and 'aUnmodifiedCharacters'
145 // parameters used below (in synthesizeNativeReturnKey() and
146 // synthesizeNativeCmdOptY()) were confirmed accurate using the
147 // DebugEventsPlugin v1.01 from bmo bug
441880.
149 function synthesizeNativeReturnKey() {
150 gUtils.sendNativeKeyEvent(
0,
36,
0,
"\u000a",
"\u000a");
153 function synthesizeNativeCmdOptY() {
154 gUtils.sendNativeKeyEvent(
0,
16,
0x5000,
"y",
"y");
159 <!-- test results are displayed in the html:body -->
160 <body xmlns=
"http://www.w3.org/1999/xhtml">
162 <div id=
"content" style=
"display: none"></div>
163 <pre id=
"test"></pre>