toolkit/components/places/tests/unit/test_399264_query_to_string.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/. */
     7 /**
     8  * Obtains the id of the folder obtained from the query.
     9  *
    10  * @param aFolderID
    11  *        The id of the folder we want to generate a query for.
    12  * @returns the string representation of the query for the given folder.
    13  */
    14 function query_string(aFolderID)
    15 {
    16   var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
    17            getService(Ci.nsINavHistoryService);
    19   var query = hs.getNewQuery();
    20   query.setFolders([aFolderID], 1);
    21   var options = hs.getNewQueryOptions();
    22   return hs.queriesToQueryString([query], 1, options);
    23 }
    25 function run_test()
    26 {
    27   var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
    28            getService(Ci.nsINavHistoryService);
    29   var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    30            getService(Ci.nsINavBookmarksService);
    32   const QUERIES = [
    33       "folder=PLACES_ROOT"
    34     , "folder=BOOKMARKS_MENU"
    35     , "folder=TAGS"
    36     , "folder=UNFILED_BOOKMARKS"
    37     , "folder=TOOLBAR"
    38   ];
    39   const FOLDER_IDS = [
    40       bs.placesRoot
    41     , bs.bookmarksMenuFolder
    42     , bs.tagsFolder
    43     , bs.unfiledBookmarksFolder
    44     , bs.toolbarFolder
    45   ];
    48   for (var i = 0; i < QUERIES.length; i++) {
    49     var result = query_string(FOLDER_IDS[i]);
    50     dump("Looking for '" + QUERIES[i] + "' in '" + result + "'\n");
    51     do_check_neq(-1, result.indexOf(QUERIES[i]));
    52   }
    53 }

mercurial