2014-06-24 22:12:07 -07:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
2010-03-26 14:59:02 -07:00
|
|
|
* vim:set ts=2 sw=2 sts=2 et:
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-26 14:59:02 -07:00
|
|
|
|
2015-02-04 13:24:00 -08:00
|
|
|
let gTabRestrictChar = "%";
|
|
|
|
prefs.setCharPref("browser.urlbar.restrict.openpage", gTabRestrictChar);
|
|
|
|
do_register_cleanup(() => {
|
|
|
|
prefs.clearUserPref("browser.urlbar.restrict.openpage");
|
|
|
|
});
|
2010-03-26 14:59:02 -07:00
|
|
|
|
|
|
|
let kSearchParam = "enable-actions";
|
|
|
|
|
|
|
|
let kURIs = [
|
|
|
|
"http://abc.com/",
|
|
|
|
"moz-action:switchtab,http://abc.com/",
|
|
|
|
"http://xyz.net/",
|
2010-11-19 16:39:55 -08:00
|
|
|
"moz-action:switchtab,http://xyz.net/",
|
2012-02-25 17:38:26 -08:00
|
|
|
"about:mozilla",
|
|
|
|
"moz-action:switchtab,about:mozilla",
|
2010-11-19 16:39:55 -08:00
|
|
|
"data:text/html,test",
|
|
|
|
"moz-action:switchtab,data:text/html,test"
|
2010-03-26 14:59:02 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
let kTitles = [
|
|
|
|
"ABC rocks",
|
2010-11-19 16:39:55 -08:00
|
|
|
"xyz.net - we're better than ABC",
|
2012-02-25 17:38:26 -08:00
|
|
|
"about:mozilla",
|
2010-11-19 16:39:55 -08:00
|
|
|
"data:text/html,test"
|
2010-03-26 14:59:02 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
addPageBook(0, 0);
|
|
|
|
gPages[1] = [1, 0];
|
|
|
|
addPageBook(2, 1);
|
|
|
|
gPages[3] = [3, 1];
|
|
|
|
|
|
|
|
addOpenPages(0, 1);
|
|
|
|
|
2010-11-19 16:39:55 -08:00
|
|
|
// PAges that cannot be registered in history.
|
|
|
|
addOpenPages(4, 1);
|
|
|
|
gPages[5] = [5, 2];
|
|
|
|
addOpenPages(6, 1);
|
|
|
|
gPages[7] = [7, 3];
|
2010-03-26 14:59:02 -07:00
|
|
|
|
|
|
|
let gTests = [
|
|
|
|
["0: single result, that is also a tab match",
|
2010-06-14 11:51:53 -07:00
|
|
|
"abc.com", [1]],
|
2010-03-26 14:59:02 -07:00
|
|
|
["1: two results, one tab match",
|
2010-06-14 11:51:53 -07:00
|
|
|
"abc", [1,2]],
|
2010-03-26 14:59:02 -07:00
|
|
|
["2: two results, both tab matches",
|
2010-06-14 11:51:53 -07:00
|
|
|
"abc", [1,3],
|
2010-03-26 14:59:02 -07:00
|
|
|
function() {
|
|
|
|
addOpenPages(2, 1);
|
|
|
|
}],
|
|
|
|
["3: two results, both tab matches, one has multiple tabs",
|
2010-06-14 11:51:53 -07:00
|
|
|
"abc", [1,3],
|
2010-03-26 14:59:02 -07:00
|
|
|
function() {
|
|
|
|
addOpenPages(2, 5);
|
|
|
|
}],
|
|
|
|
["4: two results, no tab matches",
|
|
|
|
"abc", [0,2],
|
|
|
|
function() {
|
|
|
|
removeOpenPages(0, 1);
|
|
|
|
removeOpenPages(2, 6);
|
|
|
|
}],
|
|
|
|
["5: tab match search with restriction character",
|
|
|
|
gTabRestrictChar + " abc", [1],
|
|
|
|
function() {
|
|
|
|
addOpenPages(0, 1);
|
2010-11-19 16:39:55 -08:00
|
|
|
}],
|
|
|
|
["6: tab match with not-addable pages",
|
2012-02-25 17:38:26 -08:00
|
|
|
"mozilla", [5]],
|
2010-11-19 16:39:55 -08:00
|
|
|
["7: tab match with not-addable pages and restriction character",
|
2012-02-25 17:38:26 -08:00
|
|
|
gTabRestrictChar + " mozilla", [5]],
|
2010-11-19 16:39:55 -08:00
|
|
|
["8: tab match with not-addable pages and only restriction character",
|
|
|
|
gTabRestrictChar, [1, 5, 7]],
|
2010-03-26 14:59:02 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
function addOpenPages(aUri, aCount) {
|
|
|
|
let num = aCount || 1;
|
2010-11-19 16:39:55 -08:00
|
|
|
let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"].
|
|
|
|
getService(Ci.mozIPlacesAutoComplete);
|
2010-03-26 14:59:02 -07:00
|
|
|
for (let i = 0; i < num; i++) {
|
2010-11-19 16:39:55 -08:00
|
|
|
acprovider.registerOpenPage(toURI(kURIs[aUri]));
|
2010-03-26 14:59:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeOpenPages(aUri, aCount) {
|
|
|
|
let num = aCount || 1;
|
2010-11-19 16:39:55 -08:00
|
|
|
let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"].
|
|
|
|
getService(Ci.mozIPlacesAutoComplete);
|
2010-03-26 14:59:02 -07:00
|
|
|
for (let i = 0; i < num; i++) {
|
2010-11-19 16:39:55 -08:00
|
|
|
acprovider.unregisterOpenPage(toURI(kURIs[aUri]));
|
2010-03-26 14:59:02 -07:00
|
|
|
}
|
|
|
|
}
|