summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/queries/test_search_tags.js
blob: 4f8cface076c6e2b84d33a93a2e4c01e99171ff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

add_task(async function test_search_for_tagged_bookmarks() {
  const testURI = "http://a1.com";

  let folder = await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.menuGuid,
    title: "bug 395101 test",
    type: PlacesUtils.bookmarks.TYPE_FOLDER,
  });

  let bookmark = await PlacesUtils.bookmarks.insert({
    parentGuid: folder.guid,
    title: "1 title",
    url: testURI,
  });

  // tag the bookmarked URI
  PlacesUtils.tagging.tagURI(uri(testURI), [
    "elephant",
    "walrus",
    "giraffe",
    "turkey",
    "hiPPo",
    "BABOON",
    "alf",
  ]);

  // search for the bookmark, using a tag
  var query = PlacesUtils.history.getNewQuery();
  query.searchTerms = "elephant";
  var options = PlacesUtils.history.getNewQueryOptions();
  options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
  query.setParents([folder.guid]);

  var result = PlacesUtils.history.executeQuery(query, options);
  var rootNode = result.root;
  rootNode.containerOpen = true;

  Assert.equal(rootNode.childCount, 1);
  Assert.equal(rootNode.getChild(0).bookmarkGuid, bookmark.guid);
  rootNode.containerOpen = false;

  // partial matches are okay
  query.searchTerms = "wal";
  result = PlacesUtils.history.executeQuery(query, options);
  rootNode = result.root;
  rootNode.containerOpen = true;
  Assert.equal(rootNode.childCount, 1);
  rootNode.containerOpen = false;

  // case insensitive search term
  query.searchTerms = "WALRUS";
  result = PlacesUtils.history.executeQuery(query, options);
  rootNode = result.root;
  rootNode.containerOpen = true;
  Assert.equal(rootNode.childCount, 1);
  Assert.equal(rootNode.getChild(0).bookmarkGuid, bookmark.guid);
  rootNode.containerOpen = false;

  // case insensitive tag
  query.searchTerms = "baboon";
  result = PlacesUtils.history.executeQuery(query, options);
  rootNode = result.root;
  rootNode.containerOpen = true;
  Assert.equal(rootNode.childCount, 1);
  Assert.equal(rootNode.getChild(0).bookmarkGuid, bookmark.guid);
  rootNode.containerOpen = false;
});