michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim:set ts=2 sw=2 sts=2 et: 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: let gTabRestrictChar = prefs.getCharPref("browser.urlbar.restrict.openpage"); michael@0: michael@0: let kSearchParam = "enable-actions"; michael@0: michael@0: let kURIs = [ michael@0: "http://abc.com/", michael@0: "moz-action:switchtab,http://abc.com/", michael@0: "http://xyz.net/", michael@0: "moz-action:switchtab,http://xyz.net/", michael@0: "about:mozilla", michael@0: "moz-action:switchtab,about:mozilla", michael@0: "data:text/html,test", michael@0: "moz-action:switchtab,data:text/html,test" michael@0: ]; michael@0: michael@0: let kTitles = [ michael@0: "ABC rocks", michael@0: "xyz.net - we're better than ABC", michael@0: "about:mozilla", michael@0: "data:text/html,test" michael@0: ]; michael@0: michael@0: addPageBook(0, 0); michael@0: gPages[1] = [1, 0]; michael@0: addPageBook(2, 1); michael@0: gPages[3] = [3, 1]; michael@0: michael@0: addOpenPages(0, 1); michael@0: michael@0: // PAges that cannot be registered in history. michael@0: addOpenPages(4, 1); michael@0: gPages[5] = [5, 2]; michael@0: addOpenPages(6, 1); michael@0: gPages[7] = [7, 3]; michael@0: michael@0: let gTests = [ michael@0: ["0: single result, that is also a tab match", michael@0: "abc.com", [1]], michael@0: ["1: two results, one tab match", michael@0: "abc", [1,2]], michael@0: ["2: two results, both tab matches", michael@0: "abc", [1,3], michael@0: function() { michael@0: addOpenPages(2, 1); michael@0: }], michael@0: ["3: two results, both tab matches, one has multiple tabs", michael@0: "abc", [1,3], michael@0: function() { michael@0: addOpenPages(2, 5); michael@0: }], michael@0: ["4: two results, no tab matches", michael@0: "abc", [0,2], michael@0: function() { michael@0: removeOpenPages(0, 1); michael@0: removeOpenPages(2, 6); michael@0: }], michael@0: ["5: tab match search with restriction character", michael@0: gTabRestrictChar + " abc", [1], michael@0: function() { michael@0: addOpenPages(0, 1); michael@0: }], michael@0: ["6: tab match with not-addable pages", michael@0: "mozilla", [5]], michael@0: ["7: tab match with not-addable pages and restriction character", michael@0: gTabRestrictChar + " mozilla", [5]], michael@0: ["8: tab match with not-addable pages and only restriction character", michael@0: gTabRestrictChar, [1, 5, 7]], michael@0: ]; michael@0: michael@0: michael@0: function addOpenPages(aUri, aCount) { michael@0: let num = aCount || 1; michael@0: let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"]. michael@0: getService(Ci.mozIPlacesAutoComplete); michael@0: for (let i = 0; i < num; i++) { michael@0: acprovider.registerOpenPage(toURI(kURIs[aUri])); michael@0: } michael@0: } michael@0: michael@0: function removeOpenPages(aUri, aCount) { michael@0: let num = aCount || 1; michael@0: let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"]. michael@0: getService(Ci.mozIPlacesAutoComplete); michael@0: for (let i = 0; i < num; i++) { michael@0: acprovider.unregisterOpenPage(toURI(kURIs[aUri])); michael@0: } michael@0: }