toolkit/components/places/tests/unit/test_331487.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/unit/test_331487.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     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 +// Get history service
    1.11 +try {
    1.12 +  var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
    1.13 +} catch(ex) {
    1.14 +  do_throw("Could not get history service\n");
    1.15 +} 
    1.16 +
    1.17 +var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    1.18 +            getService(Ci.nsINavBookmarksService);
    1.19 +
    1.20 +// main
    1.21 +function run_test() {
    1.22 +  // add a folder
    1.23 +  var folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX);
    1.24 +
    1.25 +  // add a bookmark to the folder
    1.26 +  var b1 = bmsvc.insertBookmark(folder, uri("http://a1.com/"),
    1.27 +                                bmsvc.DEFAULT_INDEX, "1 title");
    1.28 +  // add a subfolder
    1.29 +  var sf1 = bmsvc.createFolder(folder, "subfolder 1", bmsvc.DEFAULT_INDEX);
    1.30 +
    1.31 +  // add a bookmark to the subfolder
    1.32 +  var b2 = bmsvc.insertBookmark(sf1, uri("http://a2.com/"),
    1.33 +                                bmsvc.DEFAULT_INDEX, "2 title");
    1.34 +
    1.35 +  // add a subfolder to the subfolder
    1.36 +  var sf2 = bmsvc.createFolder(sf1, "subfolder 2", bmsvc.DEFAULT_INDEX);
    1.37 +
    1.38 +  // add a bookmark to the subfolder of the subfolder
    1.39 +  var b3 = bmsvc.insertBookmark(sf2, uri("http://a3.com/"),
    1.40 +                                bmsvc.DEFAULT_INDEX, "3 title");
    1.41 +
    1.42 +  // bookmark query that should result in the "hierarchical" result
    1.43 +  // because there is one query, one folder,
    1.44 +  // no begin time, no end time, no domain, no uri, no search term
    1.45 +  // and no max results.  See GetSimpleBookmarksQueryFolder()
    1.46 +  // for more details.
    1.47 +  var options = histsvc.getNewQueryOptions();
    1.48 +  options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
    1.49 +  var query = histsvc.getNewQuery();
    1.50 +  query.setFolders([folder], 1);
    1.51 +  var result = histsvc.executeQuery(query, options);
    1.52 +  var root = result.root;
    1.53 +  root.containerOpen = true;
    1.54 +  do_check_eq(root.childCount, 2);
    1.55 +  do_check_eq(root.getChild(0).itemId, b1);
    1.56 +  do_check_eq(root.getChild(1).itemId, sf1);
    1.57 +
    1.58 +  // check the contents of the subfolder
    1.59 +  var sf1Node = root.getChild(1);
    1.60 +  sf1Node = sf1Node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
    1.61 +  sf1Node.containerOpen = true;
    1.62 +  do_check_eq(sf1Node.childCount, 2);
    1.63 +  do_check_eq(sf1Node.getChild(0).itemId, b2);
    1.64 +  do_check_eq(sf1Node.getChild(1).itemId, sf2);
    1.65 +
    1.66 +  // check the contents of the subfolder's subfolder
    1.67 +  var sf2Node = sf1Node.getChild(1);
    1.68 +  sf2Node = sf2Node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
    1.69 +  sf2Node.containerOpen = true;
    1.70 +  do_check_eq(sf2Node.childCount, 1);
    1.71 +  do_check_eq(sf2Node.getChild(0).itemId, b3);
    1.72 +
    1.73 +  sf2Node.containerOpen = false;
    1.74 +  sf1Node.containerOpen = false;
    1.75 +  root.containerOpen = false;
    1.76 +
    1.77 +  // bookmark query that should result in a flat list
    1.78 +  // because we specified max results
    1.79 +  var options = histsvc.getNewQueryOptions();
    1.80 +  options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
    1.81 +  options.maxResults = 10;
    1.82 +  var query = histsvc.getNewQuery();
    1.83 +  query.setFolders([folder], 1);
    1.84 +  var result = histsvc.executeQuery(query, options);
    1.85 +  var root = result.root;
    1.86 +  root.containerOpen = true;
    1.87 +  do_check_eq(root.childCount, 3);
    1.88 +  do_check_eq(root.getChild(0).itemId, b1);
    1.89 +  do_check_eq(root.getChild(1).itemId, b2);
    1.90 +  do_check_eq(root.getChild(2).itemId, b3);
    1.91 +  root.containerOpen = false;
    1.92 +
    1.93 +  // XXX TODO
    1.94 +  // test that if we have: more than one query, 
    1.95 +  // multiple folders, a begin time, an end time, a domain, a uri
    1.96 +  // or a search term, that we get the (correct) flat list results
    1.97 +  // (like we do when specified maxResults)
    1.98 +}

mercurial