toolkit/components/places/tests/autocomplete/test_tabmatches.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/autocomplete/test_tabmatches.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim:set ts=2 sw=2 sts=2 et:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +let gTabRestrictChar = prefs.getCharPref("browser.urlbar.restrict.openpage");
    1.11 +
    1.12 +let kSearchParam = "enable-actions";
    1.13 +
    1.14 +let kURIs = [
    1.15 +  "http://abc.com/",
    1.16 +  "moz-action:switchtab,http://abc.com/",
    1.17 +  "http://xyz.net/",
    1.18 +  "moz-action:switchtab,http://xyz.net/",
    1.19 +  "about:mozilla",
    1.20 +  "moz-action:switchtab,about:mozilla",
    1.21 +  "data:text/html,test",
    1.22 +  "moz-action:switchtab,data:text/html,test"
    1.23 +];
    1.24 +
    1.25 +let kTitles = [
    1.26 +  "ABC rocks",
    1.27 +  "xyz.net - we're better than ABC",
    1.28 +  "about:mozilla",
    1.29 +  "data:text/html,test"
    1.30 +];
    1.31 +
    1.32 +addPageBook(0, 0);
    1.33 +gPages[1] = [1, 0];
    1.34 +addPageBook(2, 1);
    1.35 +gPages[3] = [3, 1];
    1.36 +
    1.37 +addOpenPages(0, 1);
    1.38 +
    1.39 +// PAges that cannot be registered in history.
    1.40 +addOpenPages(4, 1);
    1.41 +gPages[5] = [5, 2];
    1.42 +addOpenPages(6, 1);
    1.43 +gPages[7] = [7, 3];
    1.44 +
    1.45 +let gTests = [
    1.46 +  ["0: single result, that is also a tab match",
    1.47 +   "abc.com", [1]],
    1.48 +  ["1: two results, one tab match",
    1.49 +   "abc", [1,2]],
    1.50 +  ["2: two results, both tab matches",
    1.51 +   "abc", [1,3],
    1.52 +   function() {
    1.53 +     addOpenPages(2, 1);
    1.54 +   }],
    1.55 +  ["3: two results, both tab matches, one has multiple tabs",
    1.56 +   "abc", [1,3],
    1.57 +   function() {
    1.58 +     addOpenPages(2, 5);
    1.59 +   }],
    1.60 +  ["4: two results, no tab matches",
    1.61 +   "abc", [0,2],
    1.62 +   function() {
    1.63 +     removeOpenPages(0, 1);
    1.64 +     removeOpenPages(2, 6);
    1.65 +   }],
    1.66 +  ["5: tab match search with restriction character",
    1.67 +   gTabRestrictChar + " abc", [1],
    1.68 +   function() {
    1.69 +    addOpenPages(0, 1);
    1.70 +   }],
    1.71 +  ["6: tab match with not-addable pages",
    1.72 +   "mozilla", [5]],
    1.73 +  ["7: tab match with not-addable pages and restriction character",
    1.74 +   gTabRestrictChar + " mozilla", [5]],
    1.75 +  ["8: tab match with not-addable pages and only restriction character",
    1.76 +   gTabRestrictChar, [1, 5, 7]],
    1.77 +];
    1.78 +
    1.79 +
    1.80 +function addOpenPages(aUri, aCount) {
    1.81 +  let num = aCount || 1;
    1.82 +  let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"].
    1.83 +                   getService(Ci.mozIPlacesAutoComplete);
    1.84 +  for (let i = 0; i < num; i++) {
    1.85 +    acprovider.registerOpenPage(toURI(kURIs[aUri]));
    1.86 +  }
    1.87 +}
    1.88 +
    1.89 +function removeOpenPages(aUri, aCount) {
    1.90 +  let num = aCount || 1;
    1.91 +  let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"].
    1.92 +                   getService(Ci.mozIPlacesAutoComplete);
    1.93 +  for (let i = 0; i < num; i++) {
    1.94 +    acprovider.unregisterOpenPage(toURI(kURIs[aUri]));
    1.95 +  }
    1.96 +}

mercurial