1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/bookmarks/test_395593.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 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 + 1.11 +var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. 1.12 + getService(Ci.nsINavBookmarksService); 1.13 +var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. 1.14 + getService(Ci.nsINavHistoryService); 1.15 + 1.16 +function check_queries_results(aQueries, aOptions, aExpectedItemIds) { 1.17 + var result = hs.executeQueries(aQueries, aQueries.length, aOptions); 1.18 + var root = result.root; 1.19 + root.containerOpen = true; 1.20 + 1.21 + // Dump found nodes. 1.22 + for (let i = 0; i < root.childCount; i++) { 1.23 + dump("nodes[" + i + "]: " + root.getChild(0).title + "\n"); 1.24 + } 1.25 + 1.26 + do_check_eq(root.childCount, aExpectedItemIds.length); 1.27 + for (let i = 0; i < root.childCount; i++) { 1.28 + do_check_eq(root.getChild(i).itemId, aExpectedItemIds[i]); 1.29 + } 1.30 + 1.31 + root.containerOpen = false; 1.32 +} 1.33 + 1.34 +// main 1.35 +function run_test() { 1.36 + var id1 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"), 1.37 + bs.DEFAULT_INDEX, "123 0"); 1.38 + var id2 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"), 1.39 + bs.DEFAULT_INDEX, "456"); 1.40 + var id3 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"), 1.41 + bs.DEFAULT_INDEX, "123 456"); 1.42 + var id4 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"), 1.43 + bs.DEFAULT_INDEX, "789 456"); 1.44 + 1.45 + /** 1.46 + * All of the query objects are ORed together. Within a query, all the terms 1.47 + * are ANDed together. See nsINavHistory.idl. 1.48 + */ 1.49 + var queries = []; 1.50 + queries.push(hs.getNewQuery()); 1.51 + queries.push(hs.getNewQuery()); 1.52 + var options = hs.getNewQueryOptions(); 1.53 + options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; 1.54 + 1.55 + // Test 1 1.56 + dump("Test searching for 123 OR 789\n"); 1.57 + queries[0].searchTerms = "123"; 1.58 + queries[1].searchTerms = "789"; 1.59 + check_queries_results(queries, options, [id1, id3, id4]); 1.60 + 1.61 + // Test 2 1.62 + dump("Test searching for 123 OR 456\n"); 1.63 + queries[0].searchTerms = "123"; 1.64 + queries[1].searchTerms = "456"; 1.65 + check_queries_results(queries, options, [id1, id2, id3, id4]); 1.66 + 1.67 + // Test 3 1.68 + dump("Test searching for 00 OR 789\n"); 1.69 + queries[0].searchTerms = "00"; 1.70 + queries[1].searchTerms = "789"; 1.71 + check_queries_results(queries, options, [id4]); 1.72 +}