Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim:set ts=2 sw=2 sts=2 et:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 let gTabRestrictChar = prefs.getCharPref("browser.urlbar.restrict.openpage");
9 let kSearchParam = "enable-actions";
11 let kURIs = [
12 "http://abc.com/",
13 "moz-action:switchtab,http://abc.com/",
14 "http://xyz.net/",
15 "moz-action:switchtab,http://xyz.net/",
16 "about:mozilla",
17 "moz-action:switchtab,about:mozilla",
18 "data:text/html,test",
19 "moz-action:switchtab,data:text/html,test"
20 ];
22 let kTitles = [
23 "ABC rocks",
24 "xyz.net - we're better than ABC",
25 "about:mozilla",
26 "data:text/html,test"
27 ];
29 addPageBook(0, 0);
30 gPages[1] = [1, 0];
31 addPageBook(2, 1);
32 gPages[3] = [3, 1];
34 addOpenPages(0, 1);
36 // PAges that cannot be registered in history.
37 addOpenPages(4, 1);
38 gPages[5] = [5, 2];
39 addOpenPages(6, 1);
40 gPages[7] = [7, 3];
42 let gTests = [
43 ["0: single result, that is also a tab match",
44 "abc.com", [1]],
45 ["1: two results, one tab match",
46 "abc", [1,2]],
47 ["2: two results, both tab matches",
48 "abc", [1,3],
49 function() {
50 addOpenPages(2, 1);
51 }],
52 ["3: two results, both tab matches, one has multiple tabs",
53 "abc", [1,3],
54 function() {
55 addOpenPages(2, 5);
56 }],
57 ["4: two results, no tab matches",
58 "abc", [0,2],
59 function() {
60 removeOpenPages(0, 1);
61 removeOpenPages(2, 6);
62 }],
63 ["5: tab match search with restriction character",
64 gTabRestrictChar + " abc", [1],
65 function() {
66 addOpenPages(0, 1);
67 }],
68 ["6: tab match with not-addable pages",
69 "mozilla", [5]],
70 ["7: tab match with not-addable pages and restriction character",
71 gTabRestrictChar + " mozilla", [5]],
72 ["8: tab match with not-addable pages and only restriction character",
73 gTabRestrictChar, [1, 5, 7]],
74 ];
77 function addOpenPages(aUri, aCount) {
78 let num = aCount || 1;
79 let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"].
80 getService(Ci.mozIPlacesAutoComplete);
81 for (let i = 0; i < num; i++) {
82 acprovider.registerOpenPage(toURI(kURIs[aUri]));
83 }
84 }
86 function removeOpenPages(aUri, aCount) {
87 let num = aCount || 1;
88 let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"].
89 getService(Ci.mozIPlacesAutoComplete);
90 for (let i = 0; i < num; i++) {
91 acprovider.unregisterOpenPage(toURI(kURIs[aUri]));
92 }
93 }