michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: function tabAdded(event) { michael@0: let tab = event.target; michael@0: tabs.push(tab); michael@0: } michael@0: michael@0: let tabs = []; michael@0: michael@0: let container = gBrowser.tabContainer; michael@0: container.addEventListener("TabOpen", tabAdded, false); michael@0: michael@0: gBrowser.addTab("about:blank"); michael@0: BrowserSearch.loadSearchFromContext("mozilla"); michael@0: BrowserSearch.loadSearchFromContext("firefox"); michael@0: michael@0: is(tabs[0], gBrowser.tabs[3], "blank tab has been pushed to the end"); michael@0: is(tabs[1], gBrowser.tabs[1], "first search tab opens next to the current tab"); michael@0: is(tabs[2], gBrowser.tabs[2], "second search tab opens next to the first search tab"); michael@0: michael@0: container.removeEventListener("TabOpen", tabAdded, false); michael@0: tabs.forEach(gBrowser.removeTab, gBrowser); michael@0: michael@0: try { michael@0: let cm = Components.classes["@mozilla.org/categorymanager;1"] michael@0: .getService(Components.interfaces.nsICategoryManager); michael@0: cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider"); michael@0: } catch (ex) { michael@0: // Health Report disabled, or no SearchesProvider. michael@0: finish(); michael@0: return; michael@0: } michael@0: michael@0: let reporter = Components.classes["@mozilla.org/datareporting/service;1"] michael@0: .getService() michael@0: .wrappedJSObject michael@0: .healthReporter; michael@0: michael@0: // reporter should always be available in automation. michael@0: ok(reporter, "Health Reporter available."); michael@0: reporter.onInit().then(function onInit() { michael@0: let provider = reporter.getProvider("org.mozilla.searches"); michael@0: ok(provider, "Searches provider is available."); michael@0: michael@0: let m = provider.getMeasurement("counts", 3); michael@0: m.getValues().then(function onValues(data) { michael@0: let now = new Date(); michael@0: ok(data.days.hasDay(now), "Have data for today."); michael@0: let day = data.days.getDay(now); michael@0: michael@0: // Will need to be changed if Google isn't the default search engine. michael@0: let field = "google.contextmenu"; michael@0: ok(day.has(field), "Have search recorded for context menu."); michael@0: michael@0: // If any other mochitests perform a context menu search, this will fail. michael@0: // The solution will be to look up count at test start and ensure it is michael@0: // incremented by two. michael@0: is(day.get(field), 2, "2 searches recorded in FHR."); michael@0: finish(); michael@0: }); michael@0: }); michael@0: } michael@0: