browser/components/search/test/browser_private_search_perwindowpb.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/search/test/browser_private_search_perwindowpb.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     1.4 +// This test performs a search in a public window, then a different
     1.5 +// search in a private window, and then checks in the public window
     1.6 +// whether there is an autocomplete entry for the private search.
     1.7 +
     1.8 +function test() {
     1.9 +  // Don't use about:home as the homepage for new windows
    1.10 +  Services.prefs.setIntPref("browser.startup.page", 0);
    1.11 +  registerCleanupFunction(function() Services.prefs.clearUserPref("browser.startup.page"));
    1.12 +
    1.13 +  waitForExplicitFinish();
    1.14 +
    1.15 +  let engineURL =
    1.16 +    "http://mochi.test:8888/browser/browser/components/search/test/";
    1.17 +  let windowsToClose = [];
    1.18 +  registerCleanupFunction(function() {
    1.19 +    let engine = Services.search.getEngineByName("Bug 426329");
    1.20 +    Services.search.removeEngine(engine);
    1.21 +    windowsToClose.forEach(function(win) {
    1.22 +      win.close();
    1.23 +    });
    1.24 +  });
    1.25 +
    1.26 +  function onPageLoad(aWin, aCallback) {
    1.27 +    aWin.gBrowser.addEventListener("DOMContentLoaded", function load(aEvent) {
    1.28 +      let doc = aEvent.originalTarget;
    1.29 +      info(doc.location.href);
    1.30 +      if (doc.location.href.indexOf(engineURL) != -1) {
    1.31 +        aWin.gBrowser.removeEventListener("DOMContentLoaded", load, false);
    1.32 +        aCallback();
    1.33 +      }
    1.34 +    }, false);
    1.35 +  }
    1.36 +
    1.37 +  function performSearch(aWin, aIsPrivate, aCallback) {
    1.38 +    let searchBar = aWin.BrowserSearch.searchBar;
    1.39 +    ok(searchBar, "got search bar");
    1.40 +    onPageLoad(aWin, aCallback);
    1.41 +
    1.42 +    searchBar.value = aIsPrivate ? "private test" : "public test";
    1.43 +    searchBar.focus();
    1.44 +    EventUtils.synthesizeKey("VK_RETURN", {}, aWin);
    1.45 +  }
    1.46 +
    1.47 +  function addEngine(aCallback) {
    1.48 +    let installCallback = {
    1.49 +      onSuccess: function (engine) {
    1.50 +        Services.search.currentEngine = engine;
    1.51 +        aCallback();
    1.52 +      },
    1.53 +      onError: function (errorCode) {
    1.54 +        ok(false, "failed to install engine: " + errorCode);
    1.55 +      }
    1.56 +    };
    1.57 +    Services.search.addEngine(engineURL + "426329.xml",
    1.58 +                              Ci.nsISearchEngine.DATA_XML,
    1.59 +                              "data:image/x-icon,%00", false, installCallback);
    1.60 +  }
    1.61 +
    1.62 +  function testOnWindow(aIsPrivate, aCallback) {
    1.63 +    let win = whenNewWindowLoaded({ private: aIsPrivate }, aCallback);
    1.64 +    windowsToClose.push(win);
    1.65 +  }
    1.66 +
    1.67 +  addEngine(function() {
    1.68 +    testOnWindow(false, function(win) {
    1.69 +      performSearch(win, false, function() {
    1.70 +        testOnWindow(true, function(win) {
    1.71 +          performSearch(win, true, function() {
    1.72 +            testOnWindow(false, function(win) {
    1.73 +              checkSearchPopup(win, finish);
    1.74 +            });
    1.75 +          });
    1.76 +        });
    1.77 +      });
    1.78 +    });
    1.79 +  });
    1.80 +}
    1.81 +
    1.82 +function checkSearchPopup(aWin, aCallback) {
    1.83 +  let searchBar = aWin.BrowserSearch.searchBar;
    1.84 +  searchBar.value = "p";
    1.85 +  searchBar.focus();
    1.86 +
    1.87 +  let popup = searchBar.textbox.popup;
    1.88 +  popup.addEventListener("popupshowing", function showing() {
    1.89 +    popup.removeEventListener("popupshowing", showing, false);
    1.90 +
    1.91 +    let entries = getMenuEntries(searchBar);
    1.92 +    for (let i = 0; i < entries.length; i++) {
    1.93 +      isnot(entries[i], "private test",
    1.94 +            "shouldn't see private autocomplete entries");
    1.95 +    }
    1.96 +
    1.97 +    searchBar.textbox.toggleHistoryPopup();
    1.98 +    searchBar.value = "";
    1.99 +    aCallback();
   1.100 +  }, false);
   1.101 +
   1.102 +  searchBar.textbox.showHistoryPopup();
   1.103 +}
   1.104 +
   1.105 +function getMenuEntries(searchBar) {
   1.106 +  let entries = [];
   1.107 +  let autocompleteMenu = searchBar.textbox.popup;
   1.108 +  // Could perhaps pull values directly from the controller, but it seems
   1.109 +  // more reliable to test the values that are actually in the tree?
   1.110 +  let column = autocompleteMenu.tree.columns[0];
   1.111 +  let numRows = autocompleteMenu.tree.view.rowCount;
   1.112 +  for (let i = 0; i < numRows; i++) {
   1.113 +    entries.push(autocompleteMenu.tree.view.getValueAt(i, column));
   1.114 +  }
   1.115 +  return entries;
   1.116 +}

mercurial