browser/base/content/test/general/browser_contextSearchTabPosition.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_contextSearchTabPosition.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function test() {
     1.9 +  waitForExplicitFinish();
    1.10 +
    1.11 +  function tabAdded(event) {
    1.12 +    let tab = event.target;
    1.13 +    tabs.push(tab);
    1.14 +  }
    1.15 +
    1.16 +  let tabs = [];
    1.17 +
    1.18 +  let container = gBrowser.tabContainer;
    1.19 +  container.addEventListener("TabOpen", tabAdded, false);
    1.20 +
    1.21 +  gBrowser.addTab("about:blank");
    1.22 +  BrowserSearch.loadSearchFromContext("mozilla");
    1.23 +  BrowserSearch.loadSearchFromContext("firefox");
    1.24 +
    1.25 +  is(tabs[0], gBrowser.tabs[3], "blank tab has been pushed to the end");
    1.26 +  is(tabs[1], gBrowser.tabs[1], "first search tab opens next to the current tab");
    1.27 +  is(tabs[2], gBrowser.tabs[2], "second search tab opens next to the first search tab");
    1.28 +
    1.29 +  container.removeEventListener("TabOpen", tabAdded, false);
    1.30 +  tabs.forEach(gBrowser.removeTab, gBrowser);
    1.31 +
    1.32 +  try {
    1.33 +    let cm = Components.classes["@mozilla.org/categorymanager;1"]
    1.34 +                       .getService(Components.interfaces.nsICategoryManager);
    1.35 +    cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider");
    1.36 +  } catch (ex) {
    1.37 +    // Health Report disabled, or no SearchesProvider.
    1.38 +    finish();
    1.39 +    return;
    1.40 +  }
    1.41 +
    1.42 +  let reporter = Components.classes["@mozilla.org/datareporting/service;1"]
    1.43 +                                   .getService()
    1.44 +                                   .wrappedJSObject
    1.45 +                                   .healthReporter;
    1.46 +
    1.47 +  // reporter should always be available in automation.
    1.48 +  ok(reporter, "Health Reporter available.");
    1.49 +  reporter.onInit().then(function onInit() {
    1.50 +    let provider = reporter.getProvider("org.mozilla.searches");
    1.51 +    ok(provider, "Searches provider is available.");
    1.52 +
    1.53 +    let m = provider.getMeasurement("counts", 3);
    1.54 +    m.getValues().then(function onValues(data) {
    1.55 +      let now = new Date();
    1.56 +      ok(data.days.hasDay(now), "Have data for today.");
    1.57 +      let day = data.days.getDay(now);
    1.58 +
    1.59 +      // Will need to be changed if Google isn't the default search engine.
    1.60 +      let field = "google.contextmenu";
    1.61 +      ok(day.has(field), "Have search recorded for context menu.");
    1.62 +
    1.63 +      // If any other mochitests perform a context menu search, this will fail.
    1.64 +      // The solution will be to look up count at test start and ensure it is
    1.65 +      // incremented by two.
    1.66 +      is(day.get(field), 2, "2 searches recorded in FHR.");
    1.67 +      finish();
    1.68 +    });
    1.69 +  });
    1.70 +}
    1.71 +

mercurial