mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
7956b1abc2
--HG-- rename : browser/components/search/test/browser_private_search.js => browser/components/search/test/browser_private_search_perwindowpb.js
116 lines
3.5 KiB
JavaScript
116 lines
3.5 KiB
JavaScript
// This test performs a search in a public window, then a different
|
|
// search in a private window, and then checks in the public window
|
|
// whether there is an autocomplete entry for the private search.
|
|
|
|
function test() {
|
|
waitForExplicitFinish();
|
|
|
|
let engineURL =
|
|
"http://mochi.test:8888/browser/browser/components/search/test/";
|
|
let windowsToClose = [];
|
|
registerCleanupFunction(function() {
|
|
let engine = Services.search.getEngineByName("Bug 426329");
|
|
Services.search.removeEngine(engine);
|
|
windowsToClose.forEach(function(win) {
|
|
win.close();
|
|
});
|
|
});
|
|
|
|
function onPageLoad(aWin, aCallback) {
|
|
aWin.gBrowser.addEventListener("DOMContentLoaded", function load(aEvent) {
|
|
let doc = aEvent.originalTarget;
|
|
info(doc.location.href);
|
|
if (doc.location.href.indexOf(engineURL) != -1) {
|
|
aWin.gBrowser.removeEventListener("DOMContentLoaded", load, false);
|
|
aCallback();
|
|
}
|
|
}, false);
|
|
}
|
|
|
|
function performSearch(aWin, aIsPrivate, aCallback) {
|
|
let searchBar = aWin.BrowserSearch.searchBar;
|
|
ok(searchBar, "got search bar");
|
|
onPageLoad(aWin, aCallback);
|
|
|
|
searchBar.value = aIsPrivate ? "private test" : "public test";
|
|
searchBar.focus();
|
|
EventUtils.synthesizeKey("VK_RETURN", {}, aWin);
|
|
}
|
|
|
|
function addEngine(aCallback) {
|
|
function observer(aSub, aTopic, aData) {
|
|
switch (aData) {
|
|
case "engine-current":
|
|
ok(Services.search.currentEngine.name == "Bug 426329",
|
|
"currentEngine set");
|
|
aCallback();
|
|
break;
|
|
}
|
|
}
|
|
|
|
Services.obs.addObserver(observer, "browser-search-engine-modified", false);
|
|
Services.search.addEngine(
|
|
engineURL + "426329.xml", Ci.nsISearchEngine.DATA_XML,
|
|
"data:image/x-icon,%00", false);
|
|
}
|
|
|
|
function testOnWindow(aIsPrivate, aCallback) {
|
|
let win = OpenBrowserWindow({ private: aIsPrivate });
|
|
win.addEventListener("load", function onLoad() {
|
|
win.removeEventListener("load", onLoad, false);
|
|
windowsToClose.push(win);
|
|
executeSoon(function() aCallback(win));
|
|
}, false);
|
|
}
|
|
|
|
addEngine(function() {
|
|
testOnWindow(false, function(win) {
|
|
performSearch(win, false, function() {
|
|
testOnWindow(true, function(win) {
|
|
performSearch(win, true, function() {
|
|
testOnWindow(false, function(win) {
|
|
checkSearchPopup(win, finish);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function checkSearchPopup(aWin, aCallback) {
|
|
let searchBar = aWin.BrowserSearch.searchBar;
|
|
searchBar.value = "p";
|
|
searchBar.focus();
|
|
|
|
let popup = searchBar.textbox.popup;
|
|
popup.addEventListener("popupshowing", function showing() {
|
|
popup.removeEventListener("popupshowing", showing, false);
|
|
|
|
let entries = getMenuEntries(searchBar);
|
|
for (let i = 0; i < entries.length; i++) {
|
|
isnot(entries[0], "private test",
|
|
"shouldn't see private autocomplete entries");
|
|
}
|
|
|
|
searchBar.textbox.toggleHistoryPopup();
|
|
searchBar.value = "";
|
|
aCallback();
|
|
}, false);
|
|
|
|
searchBar.textbox.showHistoryPopup();
|
|
}
|
|
|
|
function getMenuEntries(searchBar) {
|
|
let entries = [];
|
|
let autocompleteMenu = searchBar.textbox.popup;
|
|
// Could perhaps pull values directly from the controller, but it seems
|
|
// more reliable to test the values that are actually in the tree?
|
|
let column = autocompleteMenu.tree.columns[0];
|
|
let numRows = autocompleteMenu.tree.view.rowCount;
|
|
for (let i = 0; i < numRows; i++) {
|
|
entries.push(autocompleteMenu.tree.view.getValueAt(i, column));
|
|
}
|
|
return entries;
|
|
}
|