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