1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_399264_query_to_string.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,53 @@ 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 + * Obtains the id of the folder obtained from the query. 1.12 + * 1.13 + * @param aFolderID 1.14 + * The id of the folder we want to generate a query for. 1.15 + * @returns the string representation of the query for the given folder. 1.16 + */ 1.17 +function query_string(aFolderID) 1.18 +{ 1.19 + var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. 1.20 + getService(Ci.nsINavHistoryService); 1.21 + 1.22 + var query = hs.getNewQuery(); 1.23 + query.setFolders([aFolderID], 1); 1.24 + var options = hs.getNewQueryOptions(); 1.25 + return hs.queriesToQueryString([query], 1, options); 1.26 +} 1.27 + 1.28 +function run_test() 1.29 +{ 1.30 + var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. 1.31 + getService(Ci.nsINavHistoryService); 1.32 + var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. 1.33 + getService(Ci.nsINavBookmarksService); 1.34 + 1.35 + const QUERIES = [ 1.36 + "folder=PLACES_ROOT" 1.37 + , "folder=BOOKMARKS_MENU" 1.38 + , "folder=TAGS" 1.39 + , "folder=UNFILED_BOOKMARKS" 1.40 + , "folder=TOOLBAR" 1.41 + ]; 1.42 + const FOLDER_IDS = [ 1.43 + bs.placesRoot 1.44 + , bs.bookmarksMenuFolder 1.45 + , bs.tagsFolder 1.46 + , bs.unfiledBookmarksFolder 1.47 + , bs.toolbarFolder 1.48 + ]; 1.49 + 1.50 + 1.51 + for (var i = 0; i < QUERIES.length; i++) { 1.52 + var result = query_string(FOLDER_IDS[i]); 1.53 + dump("Looking for '" + QUERIES[i] + "' in '" + result + "'\n"); 1.54 + do_check_neq(-1, result.indexOf(QUERIES[i])); 1.55 + } 1.56 +}