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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 function test() {
     6   waitForExplicitFinish();
     8   function tabAdded(event) {
     9     let tab = event.target;
    10     tabs.push(tab);
    11   }
    13   let tabs = [];
    15   let container = gBrowser.tabContainer;
    16   container.addEventListener("TabOpen", tabAdded, false);
    18   gBrowser.addTab("about:blank");
    19   BrowserSearch.loadSearchFromContext("mozilla");
    20   BrowserSearch.loadSearchFromContext("firefox");
    22   is(tabs[0], gBrowser.tabs[3], "blank tab has been pushed to the end");
    23   is(tabs[1], gBrowser.tabs[1], "first search tab opens next to the current tab");
    24   is(tabs[2], gBrowser.tabs[2], "second search tab opens next to the first search tab");
    26   container.removeEventListener("TabOpen", tabAdded, false);
    27   tabs.forEach(gBrowser.removeTab, gBrowser);
    29   try {
    30     let cm = Components.classes["@mozilla.org/categorymanager;1"]
    31                        .getService(Components.interfaces.nsICategoryManager);
    32     cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider");
    33   } catch (ex) {
    34     // Health Report disabled, or no SearchesProvider.
    35     finish();
    36     return;
    37   }
    39   let reporter = Components.classes["@mozilla.org/datareporting/service;1"]
    40                                    .getService()
    41                                    .wrappedJSObject
    42                                    .healthReporter;
    44   // reporter should always be available in automation.
    45   ok(reporter, "Health Reporter available.");
    46   reporter.onInit().then(function onInit() {
    47     let provider = reporter.getProvider("org.mozilla.searches");
    48     ok(provider, "Searches provider is available.");
    50     let m = provider.getMeasurement("counts", 3);
    51     m.getValues().then(function onValues(data) {
    52       let now = new Date();
    53       ok(data.days.hasDay(now), "Have data for today.");
    54       let day = data.days.getDay(now);
    56       // Will need to be changed if Google isn't the default search engine.
    57       let field = "google.contextmenu";
    58       ok(day.has(field), "Have search recorded for context menu.");
    60       // If any other mochitests perform a context menu search, this will fail.
    61       // The solution will be to look up count at test start and ensure it is
    62       // incremented by two.
    63       is(day.get(field), 2, "2 searches recorded in FHR.");
    64       finish();
    65     });
    66   });
    67 }

mercurial