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

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:ed467919fb2b
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/. */
4
5 function test() {
6 waitForExplicitFinish();
7
8 function tabAdded(event) {
9 let tab = event.target;
10 tabs.push(tab);
11 }
12
13 let tabs = [];
14
15 let container = gBrowser.tabContainer;
16 container.addEventListener("TabOpen", tabAdded, false);
17
18 gBrowser.addTab("about:blank");
19 BrowserSearch.loadSearchFromContext("mozilla");
20 BrowserSearch.loadSearchFromContext("firefox");
21
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");
25
26 container.removeEventListener("TabOpen", tabAdded, false);
27 tabs.forEach(gBrowser.removeTab, gBrowser);
28
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 }
38
39 let reporter = Components.classes["@mozilla.org/datareporting/service;1"]
40 .getService()
41 .wrappedJSObject
42 .healthReporter;
43
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.");
49
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);
55
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.");
59
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 }
68

mercurial