Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // This test performs a search in a public window, then a different |
michael@0 | 2 | // search in a private window, and then checks in the public window |
michael@0 | 3 | // whether there is an autocomplete entry for the private search. |
michael@0 | 4 | |
michael@0 | 5 | function test() { |
michael@0 | 6 | // Don't use about:home as the homepage for new windows |
michael@0 | 7 | Services.prefs.setIntPref("browser.startup.page", 0); |
michael@0 | 8 | registerCleanupFunction(function() Services.prefs.clearUserPref("browser.startup.page")); |
michael@0 | 9 | |
michael@0 | 10 | waitForExplicitFinish(); |
michael@0 | 11 | |
michael@0 | 12 | let engineURL = |
michael@0 | 13 | "http://mochi.test:8888/browser/browser/components/search/test/"; |
michael@0 | 14 | let windowsToClose = []; |
michael@0 | 15 | registerCleanupFunction(function() { |
michael@0 | 16 | let engine = Services.search.getEngineByName("Bug 426329"); |
michael@0 | 17 | Services.search.removeEngine(engine); |
michael@0 | 18 | windowsToClose.forEach(function(win) { |
michael@0 | 19 | win.close(); |
michael@0 | 20 | }); |
michael@0 | 21 | }); |
michael@0 | 22 | |
michael@0 | 23 | function onPageLoad(aWin, aCallback) { |
michael@0 | 24 | aWin.gBrowser.addEventListener("DOMContentLoaded", function load(aEvent) { |
michael@0 | 25 | let doc = aEvent.originalTarget; |
michael@0 | 26 | info(doc.location.href); |
michael@0 | 27 | if (doc.location.href.indexOf(engineURL) != -1) { |
michael@0 | 28 | aWin.gBrowser.removeEventListener("DOMContentLoaded", load, false); |
michael@0 | 29 | aCallback(); |
michael@0 | 30 | } |
michael@0 | 31 | }, false); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function performSearch(aWin, aIsPrivate, aCallback) { |
michael@0 | 35 | let searchBar = aWin.BrowserSearch.searchBar; |
michael@0 | 36 | ok(searchBar, "got search bar"); |
michael@0 | 37 | onPageLoad(aWin, aCallback); |
michael@0 | 38 | |
michael@0 | 39 | searchBar.value = aIsPrivate ? "private test" : "public test"; |
michael@0 | 40 | searchBar.focus(); |
michael@0 | 41 | EventUtils.synthesizeKey("VK_RETURN", {}, aWin); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function addEngine(aCallback) { |
michael@0 | 45 | let installCallback = { |
michael@0 | 46 | onSuccess: function (engine) { |
michael@0 | 47 | Services.search.currentEngine = engine; |
michael@0 | 48 | aCallback(); |
michael@0 | 49 | }, |
michael@0 | 50 | onError: function (errorCode) { |
michael@0 | 51 | ok(false, "failed to install engine: " + errorCode); |
michael@0 | 52 | } |
michael@0 | 53 | }; |
michael@0 | 54 | Services.search.addEngine(engineURL + "426329.xml", |
michael@0 | 55 | Ci.nsISearchEngine.DATA_XML, |
michael@0 | 56 | "data:image/x-icon,%00", false, installCallback); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function testOnWindow(aIsPrivate, aCallback) { |
michael@0 | 60 | let win = whenNewWindowLoaded({ private: aIsPrivate }, aCallback); |
michael@0 | 61 | windowsToClose.push(win); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | addEngine(function() { |
michael@0 | 65 | testOnWindow(false, function(win) { |
michael@0 | 66 | performSearch(win, false, function() { |
michael@0 | 67 | testOnWindow(true, function(win) { |
michael@0 | 68 | performSearch(win, true, function() { |
michael@0 | 69 | testOnWindow(false, function(win) { |
michael@0 | 70 | checkSearchPopup(win, finish); |
michael@0 | 71 | }); |
michael@0 | 72 | }); |
michael@0 | 73 | }); |
michael@0 | 74 | }); |
michael@0 | 75 | }); |
michael@0 | 76 | }); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function checkSearchPopup(aWin, aCallback) { |
michael@0 | 80 | let searchBar = aWin.BrowserSearch.searchBar; |
michael@0 | 81 | searchBar.value = "p"; |
michael@0 | 82 | searchBar.focus(); |
michael@0 | 83 | |
michael@0 | 84 | let popup = searchBar.textbox.popup; |
michael@0 | 85 | popup.addEventListener("popupshowing", function showing() { |
michael@0 | 86 | popup.removeEventListener("popupshowing", showing, false); |
michael@0 | 87 | |
michael@0 | 88 | let entries = getMenuEntries(searchBar); |
michael@0 | 89 | for (let i = 0; i < entries.length; i++) { |
michael@0 | 90 | isnot(entries[i], "private test", |
michael@0 | 91 | "shouldn't see private autocomplete entries"); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | searchBar.textbox.toggleHistoryPopup(); |
michael@0 | 95 | searchBar.value = ""; |
michael@0 | 96 | aCallback(); |
michael@0 | 97 | }, false); |
michael@0 | 98 | |
michael@0 | 99 | searchBar.textbox.showHistoryPopup(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function getMenuEntries(searchBar) { |
michael@0 | 103 | let entries = []; |
michael@0 | 104 | let autocompleteMenu = searchBar.textbox.popup; |
michael@0 | 105 | // Could perhaps pull values directly from the controller, but it seems |
michael@0 | 106 | // more reliable to test the values that are actually in the tree? |
michael@0 | 107 | let column = autocompleteMenu.tree.columns[0]; |
michael@0 | 108 | let numRows = autocompleteMenu.tree.view.rowCount; |
michael@0 | 109 | for (let i = 0; i < numRows; i++) { |
michael@0 | 110 | entries.push(autocompleteMenu.tree.view.getValueAt(i, column)); |
michael@0 | 111 | } |
michael@0 | 112 | return entries; |
michael@0 | 113 | } |