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