2 waitForExplicitFinish();
4 var searchBar = BrowserSearch.searchBar;
5 var searchButton = document.getAnonymousElementByAttribute(searchBar,
6 "anonid", "search-go-button");
7 ok(searchButton, "got search-go-button");
9 searchBar.value = "test";
10 var preSelectedBrowser, preTabNo;
13 preSelectedBrowser = gBrowser.selectedBrowser;
14 preTabNo = gBrowser.mTabs.length;
20 function testReturn() {
22 EventUtils.synthesizeKey("VK_RETURN", {});
23 doOnloadOnce(function(event) {
25 is(gBrowser.mTabs.length, preTabNo, "Return key did not open new tab");
26 is(event.originalTarget, preSelectedBrowser.contentDocument,
27 "Return key loaded results in current tab");
33 function testAltReturn() {
35 EventUtils.synthesizeKey("VK_RETURN", { altKey: true });
36 doOnloadOnce(function(event) {
38 is(gBrowser.mTabs.length, preTabNo + 1, "Alt+Return key added new tab");
39 isnot(event.originalTarget, preSelectedBrowser.contentDocument,
40 "Alt+Return key loaded results in new tab");
41 is(event.originalTarget, gBrowser.selectedBrowser.contentDocument,
42 "Alt+Return key loaded results in foreground tab");
44 //Shift key has no effect for now, so skip it
45 //testShiftAltReturn();
50 function testShiftAltReturn() {
52 EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true, altKey: true });
53 doOnloadOnce(function(event) {
55 is(gBrowser.mTabs.length, preTabNo + 1, "Shift+Alt+Return key added new tab");
56 isnot(event.originalTarget, preSelectedBrowser.contentDocument,
57 "Shift+Alt+Return key loaded results in new tab");
58 isnot(event.originalTarget, gBrowser.selectedBrowser.contentDocument,
59 "Shift+Alt+Return key loaded results in background tab");
65 function testLeftClick() {
67 simulateClick({ button: 0 }, searchButton);
68 doOnloadOnce(function(event) {
70 is(gBrowser.mTabs.length, preTabNo, "LeftClick did not open new tab");
71 is(event.originalTarget, preSelectedBrowser.contentDocument,
72 "LeftClick loaded results in current tab");
78 function testMiddleClick() {
80 simulateClick({ button: 1 }, searchButton);
81 doOnloadOnce(function(event) {
83 is(gBrowser.mTabs.length, preTabNo + 1, "MiddleClick added new tab");
84 isnot(event.originalTarget, preSelectedBrowser.contentDocument,
85 "MiddleClick loaded results in new tab");
86 is(event.originalTarget, gBrowser.selectedBrowser.contentDocument,
87 "MiddleClick loaded results in foreground tab");
89 testShiftMiddleClick();
93 function testShiftMiddleClick() {
95 simulateClick({ button: 1, shiftKey: true }, searchButton);
96 doOnloadOnce(function(event) {
98 is(gBrowser.mTabs.length, preTabNo + 1, "Shift+MiddleClick added new tab");
99 isnot(event.originalTarget, preSelectedBrowser.contentDocument,
100 "Shift+MiddleClick loaded results in new tab");
101 isnot(event.originalTarget, gBrowser.selectedBrowser.contentDocument,
102 "Shift+MiddleClick loaded results in background tab");
108 function testRightClick() {
110 gBrowser.selectedBrowser.contentWindow.location.href = "about:blank";
111 simulateClick({ button: 2 }, searchButton);
112 setTimeout(function() {
114 is(gBrowser.mTabs.length, preTabNo, "RightClick did not open new tab");
115 is(gBrowser.currentURI.spec, "about:blank", "RightClick did nothing");
121 function finalize() {
122 searchBar.value = "";
123 while (gBrowser.mTabs.length != 1) {
124 gBrowser.removeTab(gBrowser.mTabs[0]);
126 gBrowser.selectedBrowser.contentWindow.location.href = "about:blank";
130 function doOnloadOnce(callback) {
131 gBrowser.addEventListener("DOMContentLoaded", function(event) {
132 gBrowser.removeEventListener("DOMContentLoaded", arguments.callee, true);
137 function simulateClick(aEvent, aTarget) {
138 var event = document.createEvent("MouseEvent");
139 var ctrlKeyArg = aEvent.ctrlKey || false;
140 var altKeyArg = aEvent.altKey || false;
141 var shiftKeyArg = aEvent.shiftKey || false;
142 var metaKeyArg = aEvent.metaKey || false;
143 var buttonArg = aEvent.button || 0;
144 event.initMouseEvent("click", true, true, window,
146 ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
148 aTarget.dispatchEvent(event);