Bug 850349 - Cleanup browser search tests while debugging intermittent failure in browser_contextmenu.js. r=gavin

* browser_426329.js - Fix exception in popupshowing event listener causing search history dropdown to remain open on subsequent tests.
* browser_contextmenu.js - Add some debug messages.
                         - Move |doOnloadOnce(checkSearchURL);| just before the search tab opens so there is less interference with later tests.
                         - Add nsISelectionListener to know when selection has finished.
* head.js - Consolidate duplicated doOnloadOnce function.
* test.html - Fix character set warning.
This commit is contained in:
Matthew Noorenberghe 2013-03-13 19:23:03 -07:00
Родитель f86723d135
Коммит 9a64baf98f
4 изменённых файлов: 48 добавлений и 30 удалений

Просмотреть файл

@ -201,11 +201,11 @@ function test() {
function testAutocomplete() {
var popup = searchBar.textbox.popup;
popup.addEventListener("popupshowing", function() {
popup.addEventListener("popupshowing", function testACPopupShowing() {
popup.removeEventListener("popupshowing", testACPopupShowing);
checkMenuEntries(searchEntries);
finalize();
popup.removeEventListener("popupshowing", this, false);
}, false);
SimpleTest.executeSoon(finalize);
});
searchBar.textbox.showHistoryPopup();
}
@ -219,13 +219,6 @@ function test() {
ss.removeEngine(engine);
}
function doOnloadOnce(callback) {
gBrowser.addEventListener("DOMContentLoaded", function(event) {
gBrowser.removeEventListener("DOMContentLoaded", arguments.callee, true);
callback(event);
}, true);
}
function simulateClick(aEvent, aTarget) {
var event = document.createEvent("MouseEvent");
var ctrlKeyArg = aEvent.ctrlKey || false;
@ -236,7 +229,7 @@ function test() {
event.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0,
ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
buttonArg, null);
buttonArg, null);
aTarget.dispatchEvent(event);
}
@ -252,7 +245,7 @@ function test() {
var actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, "Checking length of expected menu");
for (var i = 0; i < expectedValues.length; i++)
is(actualValues[i], expectedValues[i], "Checking menu entry #"+i);
is(actualValues[i], expectedValues[i], "Checking menu entry #" + i);
}
function getMenuEntries() {

Просмотреть файл

@ -30,6 +30,7 @@ function test() {
}
}
registerCleanupFunction(finalize);
Services.obs.addObserver(observer, "browser-search-engine-modified", false);
ss.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine_mozsearch.xml",
Ci.nsISearchEngine.DATA_XML, "data:image/x-icon,%00",
@ -46,6 +47,7 @@ function test() {
function testContextMenu() {
function rightClickOnDocument() {
info("rightClickOnDocument: " + content.window.location);
waitForBrowserContextMenu(checkContextMenu);
var clickTarget = content.document.body;
var eventDetails = { type: "contextmenu", button: 2 };
@ -54,30 +56,39 @@ function test() {
// check the search menu item and then perform a search
function checkContextMenu() {
info("checkContextMenu");
var searchItem = contextMenu.getElementsByAttribute("id", "context-searchselect")[0];
ok(searchItem, "Got search context menu item");
is(searchItem.label, 'Search ' + ENGINE_NAME + ' for "test search"', "Check context menu label");
is(searchItem.disabled, false, "Check that search context menu item is enabled");
doOnloadOnce(checkSearchURL);
searchItem.click();
contextMenu.hidePopup();
}
function checkSearchURL(event){
function checkSearchURL(event) {
is(event.originalTarget.URL,
"http://mochi.test:8888/browser/browser/components/search/test/?test=test+search&ie=utf-8&client=app&channel=contextsearch",
"Checking context menu search URL");
finalize();
}
doOnloadOnce(checkSearchURL);
var selectionListener = {
notifySelectionChanged: function(doc, sel, reason) {
if (reason != Ci.nsISelectionListener.SELECTALL_REASON || sel.toString() != "test search")
return;
info("notifySelectionChanged: Text selected");
content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate).
removeSelectionListener(selectionListener);
SimpleTest.executeSoon(rightClickOnDocument);
}
};
// add a listener to know when the selection takes effect
content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate).
addSelectionListener(selectionListener);
// select the text on the page
var selectAllItem = contextMenu.getElementsByAttribute("id", "context-selectall")[0];
ok(selectAllItem, "Got select all context menu item");
selectAllItem.click();
// wait for the selection to take effect
SimpleTest.executeSoon(rightClickOnDocument);
goDoCommand('cmd_selectAll');
}
function finalize() {
@ -86,13 +97,7 @@ function test() {
}
content.location.href = "about:blank";
var engine = ss.getEngineByName(ENGINE_NAME);
ss.removeEngine(engine);
}
function doOnloadOnce(callback) {
gBrowser.addEventListener("DOMContentLoaded", function handleLoad(event) {
gBrowser.removeEventListener("DOMContentLoaded", handleLoad, true);
callback(event);
}, true);
if (engine)
ss.removeEngine(engine);
}
}

Просмотреть файл

@ -20,13 +20,32 @@ function isSubObjectOf(expectedObj, actualObj, name) {
function waitForPopupShown(aPopupId, aCallback) {
let popup = document.getElementById(aPopupId);
info("waitForPopupShown: got popup: " + popup.id);
function onPopupShown() {
popup.removeEventListener("popupshown", onPopupShown);
info("onPopupShown");
removePopupShownListener();
SimpleTest.executeSoon(aCallback);
}
function removePopupShownListener() {
popup.removeEventListener("popupshown", onPopupShown);
}
popup.addEventListener("popupshown", onPopupShown);
registerCleanupFunction(removePopupShownListener);
}
function waitForBrowserContextMenu(aCallback) {
waitForPopupShown(gBrowser.selectedBrowser.contextMenu, aCallback);
}
function doOnloadOnce(aCallback) {
function doOnloadOnceListener(aEvent) {
info("doOnloadOnce: " + aEvent.originalTarget.location);
removeDoOnloadOnceListener();
aCallback(aEvent);
}
function removeDoOnloadOnceListener() {
gBrowser.removeEventListener("DOMContentLoaded", doOnloadOnceListener);
}
gBrowser.addEventListener("DOMContentLoaded", doOnloadOnceListener);
registerCleanupFunction(removeDoOnloadOnceListener);
}

Просмотреть файл

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Bug 426329</title>
</head>
<body></body>