toolkit/components/places/tests/bookmarks/test_395593.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     8 var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
     9          getService(Ci.nsINavBookmarksService);
    10 var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
    11          getService(Ci.nsINavHistoryService);
    13 function check_queries_results(aQueries, aOptions, aExpectedItemIds) {
    14   var result = hs.executeQueries(aQueries, aQueries.length, aOptions);
    15   var root = result.root;
    16   root.containerOpen = true;
    18   // Dump found nodes.
    19   for (let i = 0; i < root.childCount; i++) {
    20     dump("nodes[" + i + "]: " + root.getChild(0).title + "\n");
    21   }
    23   do_check_eq(root.childCount, aExpectedItemIds.length);
    24   for (let i = 0; i < root.childCount; i++) {
    25     do_check_eq(root.getChild(i).itemId, aExpectedItemIds[i]);
    26   }
    28   root.containerOpen = false;
    29 }
    31 // main
    32 function run_test() {
    33   var id1 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"),
    34                               bs.DEFAULT_INDEX, "123 0");
    35   var id2 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"),
    36                               bs.DEFAULT_INDEX, "456");
    37   var id3 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"),
    38                               bs.DEFAULT_INDEX, "123 456");
    39   var id4 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"),
    40                               bs.DEFAULT_INDEX, "789 456");
    42   /**
    43    * All of the query objects are ORed together. Within a query, all the terms
    44    * are ANDed together. See nsINavHistory.idl.
    45    */
    46   var queries = [];
    47   queries.push(hs.getNewQuery());
    48   queries.push(hs.getNewQuery());
    49   var options = hs.getNewQueryOptions();
    50   options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
    52   // Test 1
    53   dump("Test searching for 123 OR 789\n");
    54   queries[0].searchTerms = "123";
    55   queries[1].searchTerms = "789";
    56   check_queries_results(queries, options, [id1, id3, id4]);
    58   // Test 2
    59   dump("Test searching for 123 OR 456\n");
    60   queries[0].searchTerms = "123";
    61   queries[1].searchTerms = "456";
    62   check_queries_results(queries, options, [id1, id2, id3, id4]);
    64   // Test 3
    65   dump("Test searching for 00 OR 789\n");
    66   queries[0].searchTerms = "00";
    67   queries[1].searchTerms = "789";
    68   check_queries_results(queries, options, [id4]);
    69 }

mercurial