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/tests/SimpleTest/SimpleTest.js"/>
11 <script type=
"text/javascript" src=
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
12 <script type=
"text/javascript" src=
"chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.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();
29 var gCmdOptYReceived = false;
31 // Look for a cmd-opt-y event.
32 function onKeyPress(aEvent) {
33 gCmdOptYReceived = false;
34 if (String.fromCharCode(aEvent.charCode) != 'y')
36 if (aEvent.ctrlKey || aEvent.shiftKey || !aEvent.metaKey || !aEvent.altKey)
38 gCmdOptYReceived = true;
41 function setGlobals() {
42 var wm = Cc[
"@mozilla.org/appshell/window-mediator;1"].
43 getService(Ci.nsIWindowMediator);
44 gChromeWindow = wm.getMostRecentWindow(
"navigator:browser");
45 // For some reason, a global
<key> element's oncommand handler only gets
46 // invoked if the focus is outside both of the
<browser> elements
47 // (tab1browser and tab2browser). So, to make sure we can see a
48 // cmd-opt-y event in window1 (if one is available), regardless of where
49 // the focus is in this window, we need to add a
"keypress" event
50 // listener to gChromeWindow, and then check (in onKeyPress()) to see if
51 // it's a cmd-opt-y event.
52 gChromeWindow.addEventListener(
"keypress", onKeyPress, false);
55 //
1) Start loading first tab.
56 //
6) Start reloading first tab.
57 function loadFirstTab() {
58 var browser = document.getElementById(
"tab1browser");
59 browser.loadURI(
"data:text/html;charset=utf-8,<body><h2>First Tab</h2><p><input type='submit' value='Button' id='button1'/></body>");
62 function configureFirstTab() {
64 var button = document.getElementById(
"tab1browser").contentDocument.getElementById(
"button1");
65 button.addEventListener(
"click", onFirstTabButtonClicked, false);
67 if (document.getElementById(
"tabbox").selectedIndex ==
0) {
68 //
2) When first tab has finished loading (while first tab is
69 // focused), hit Return to trigger the action of first tab's
71 synthesizeNativeReturnKey();
73 //
7) When first tab has finished reloading (while second tab is
74 // focused), start loading second tab.
81 //
8) Start loading second tab.
82 function loadSecondTab() {
83 var browser = document.getElementById(
"tab2browser");
84 browser.loadURI(
"data:text/html;charset=utf-8,<body><h2>Second Tab</h2><p><input type='submit' value='Button' id='button1'/></body>");
87 function configureSecondTab() {
89 var button = document.getElementById(
"tab2browser").contentDocument.getElementById(
"button1");
90 button.addEventListener(
"click", onSecondTabButtonClicked, false);
92 if (document.getElementById(
"tabbox").selectedIndex ==
1) {
93 //
9) When second tab has finished loading (while second tab is
94 // focused), hit Return to trigger action of second tab's
96 synthesizeNativeReturnKey();
102 //
3) First tab's button clicked.
103 function onFirstTabButtonClicked() {
104 switchToSecondTabAndReloadFirst();
107 //
10) Second tab's button clicked.
108 function onSecondTabButtonClicked() {
112 function switchToSecondTabAndReloadFirst() {
113 //
4) Switch to second tab.
114 document.getElementById(
"tabbox").selectedIndex =
1;
115 //
5) Start reloading first tab (while second tab is focused).
119 function switchToFirstTab() {
120 //
11) Switch back to first tab.
121 document.getElementById(
"tabbox").selectedIndex =
0;
126 //
12) Back in first tab, try cmd-y.
127 gCmdOptYReceived = false;
128 if (!synthesizeNativeCmdOptY(finishTest)) {
129 ok(false,
"Failed to synthesize native key");
134 function finishTest() {
136 is(gCmdOptYReceived, true);
141 // synthesizeNativeReturnKey() and synthesizeNativeCmdOptY() are needed
142 // because their synthesizeKey() counterparts don't work properly -- the
143 // latter make this test succeed when it should fail.
145 // The 'aNativeKeyCode', 'aCharacters' and 'aUnmodifiedCharacters'
146 // parameters used below (in synthesizeNativeReturnKey() and
147 // synthesizeNativeCmdOptY()) were confirmed accurate using the
148 // DebugEventsPlugin v1.01 from bmo bug
441880.
150 function synthesizeNativeReturnKey() {
151 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_Return, {},
"\u000a",
"\u000a");
154 function synthesizeNativeCmdOptY(aCallback) {
155 return synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_Y, {metaKey:
1, altKey:
1},
"y",
"y", aCallback);
160 <!-- test results are displayed in the html:body -->
161 <body xmlns=
"http://www.w3.org/1999/xhtml">
163 <div id=
"content" style=
"display: none"></div>
164 <pre id=
"test"></pre>