toolkit/components/places/tests/unit/test_resolveNullBookmarkTitles.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_resolveNullBookmarkTitles.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     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 +function run_test() {
    1.11 +  run_next_test();
    1.12 +}
    1.13 +
    1.14 +add_test(function test_resolveNullBookmarkTitles() {
    1.15 +  let uri1 = uri("http://foo.tld/");
    1.16 +  let uri2 = uri("https://bar.tld/");
    1.17 +
    1.18 +  promiseAddVisits([
    1.19 +    { uri: uri1, title: "foo title" },
    1.20 +    { uri: uri2, title: "bar title" }
    1.21 +  ]).then(function () {
    1.22 +    PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId,
    1.23 +                                         uri1,
    1.24 +                                         PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.25 +                                         null);
    1.26 +    PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId,
    1.27 +                                         uri2,
    1.28 +                                         PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.29 +                                         null);
    1.30 +
    1.31 +    PlacesUtils.tagging.tagURI(uri1, ["tag 1"]);
    1.32 +    PlacesUtils.tagging.tagURI(uri2, ["tag 2"]);
    1.33 +
    1.34 +    let options = PlacesUtils.history.getNewQueryOptions();
    1.35 +    options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
    1.36 +    options.resultType = options.RESULTS_AS_TAG_CONTENTS;
    1.37 +
    1.38 +    let query = PlacesUtils.history.getNewQuery();
    1.39 +    // if we don't set a tag folder, RESULTS_AS_TAG_CONTENTS will return all
    1.40 +    // tagged URIs
    1.41 +    let root = PlacesUtils.history.executeQuery(query, options).root;
    1.42 +    root.containerOpen = true;
    1.43 +    do_check_eq(root.childCount, 2);
    1.44 +    // actually RESULTS_AS_TAG_CONTENTS return results ordered by place_id DESC
    1.45 +    // so they are reversed
    1.46 +    do_check_eq(root.getChild(0).title, "bar title");
    1.47 +    do_check_eq(root.getChild(1).title, "foo title");
    1.48 +    root.containerOpen = false;
    1.49 +
    1.50 +    run_next_test();
    1.51 +  });
    1.52 +});

mercurial