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