toolkit/components/places/tests/queries/test_searchTerms_includeHidden.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:4be05ffdd9b0
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/. */
6
7 // Tests the interaction of includeHidden and searchTerms search options.
8
9 let timeInMicroseconds = Date.now() * 1000;
10
11 const VISITS = [
12 { isVisit: true,
13 transType: TRANSITION_TYPED,
14 uri: "http://redirect.example.com/",
15 title: "example",
16 isRedirect: true,
17 lastVisit: timeInMicroseconds--
18 },
19 { isVisit: true,
20 transType: TRANSITION_TYPED,
21 uri: "http://target.example.com/",
22 title: "example",
23 lastVisit: timeInMicroseconds--
24 }
25 ];
26
27 const HIDDEN_VISITS = [
28 { isVisit: true,
29 transType: TRANSITION_FRAMED_LINK,
30 uri: "http://hidden.example.com/",
31 title: "red",
32 lastVisit: timeInMicroseconds--
33 },
34 ];
35
36 const TEST_DATA = [
37 { searchTerms: "example",
38 includeHidden: true,
39 expectedResults: 2
40 },
41 { searchTerms: "example",
42 includeHidden: false,
43 expectedResults: 1
44 },
45 { searchTerms: "red",
46 includeHidden: true,
47 expectedResults: 1
48 }
49 ];
50
51 function run_test()
52 {
53 run_next_test();
54 }
55
56 add_task(function test_initalize()
57 {
58 yield task_populateDB(VISITS);
59 });
60
61 add_task(function test_searchTerms_includeHidden()
62 {
63 for (let data of TEST_DATA) {
64 let query = PlacesUtils.history.getNewQuery();
65 query.searchTerms = data.searchTerms;
66 let options = PlacesUtils.history.getNewQueryOptions();
67 options.includeHidden = data.includeHidden;
68
69 let root = PlacesUtils.history.executeQuery(query, options).root;
70 root.containerOpen = true;
71
72 let cc = root.childCount;
73 // Live update with hidden visits.
74 yield task_populateDB(HIDDEN_VISITS);
75 let cc_update = root.childCount;
76
77 root.containerOpen = false;
78
79 do_check_eq(cc, data.expectedResults);
80 do_check_eq(cc_update, data.expectedResults + (data.includeHidden ? 1 : 0));
81
82 PlacesUtils.bhistory.removePage(uri("http://hidden.example.com/"));
83 }
84 });

mercurial