Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 /* ***** BEGIN LICENSE BLOCK *****
4 Any copyright is dedicated to the Public Domain.
5 http://creativecommons.org/publicdomain/zero/1.0/
6 * ***** END LICENSE BLOCK ***** */
8 // This test ensures that the date and site type of |place:| query maintains
9 // its quantifications correctly. Namely, it ensures that the date part of the
10 // query is not lost when the domain queries are made.
12 // We specifically craft these entries so that if a by Date and Site sorting is
13 // applied, we find one domain in the today range, and two domains in the older
14 // than six months range.
15 // The correspondence between item in |testData| and date range is stored in
16 // leveledTestData.
17 let testData = [
18 {
19 isVisit: true,
20 uri: "file:///directory/1",
21 lastVisit: today,
22 title: "test visit",
23 isInQuery: true
24 },
25 {
26 isVisit: true,
27 uri: "http://example.com/1",
28 lastVisit: today,
29 title: "test visit",
30 isInQuery: true
31 },
32 {
33 isVisit: true,
34 uri: "http://example.com/2",
35 lastVisit: today,
36 title: "test visit",
37 isInQuery: true
38 },
39 {
40 isVisit: true,
41 uri: "file:///directory/2",
42 lastVisit: olderthansixmonths,
43 title: "test visit",
44 isInQuery: true
45 },
46 {
47 isVisit: true,
48 uri: "http://example.com/3",
49 lastVisit: olderthansixmonths,
50 title: "test visit",
51 isInQuery: true
52 },
53 {
54 isVisit: true,
55 uri: "http://example.com/4",
56 lastVisit: olderthansixmonths,
57 title: "test visit",
58 isInQuery: true
59 },
60 {
61 isVisit: true,
62 uri: "http://example.net/1",
63 lastVisit: olderthansixmonths + 1,
64 title: "test visit",
65 isInQuery: true
66 }
67 ];
68 let domainsInRange = [2, 3];
69 let leveledTestData = [// Today
70 [[0], // Today, local files
71 [1,2]], // Today, example.com
72 // Older than six months
73 [[3], // Older than six months, local files
74 [4,5], // Older than six months, example.com
75 [6] // Older than six months, example.net
76 ]];
78 // This test data is meant for live updating. The |levels| property indicates
79 // date range index and then domain index.
80 let testDataAddedLater = [
81 {
82 isVisit: true,
83 uri: "http://example.com/5",
84 lastVisit: olderthansixmonths,
85 title: "test visit",
86 isInQuery: true,
87 levels: [1,1]
88 },
89 {
90 isVisit: true,
91 uri: "http://example.com/6",
92 lastVisit: olderthansixmonths,
93 title: "test visit",
94 isInQuery: true,
95 levels: [1,1]
96 },
97 {
98 isVisit: true,
99 uri: "http://example.com/7",
100 lastVisit: today,
101 title: "test visit",
102 isInQuery: true,
103 levels: [0,1]
104 },
105 {
106 isVisit: true,
107 uri: "file:///directory/3",
108 lastVisit: today,
109 title: "test visit",
110 isInQuery: true,
111 levels: [0,0]
112 }
113 ];
115 function run_test()
116 {
117 run_next_test();
118 }
120 add_task(function test_sort_date_site_grouping()
121 {
122 yield task_populateDB(testData);
124 // On Linux, the (local files) folder is shown after sites unlike Mac/Windows.
125 // Thus, we avoid running this test on Linux but this should be re-enabled
126 // after bug 624024 is resolved.
127 let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Components.classes);
128 if (isLinux)
129 return;
131 // In this test, there are three levels of results:
132 // 1st: Date queries. e.g., today, last week, or older than 6 months.
133 // 2nd: Domain queries restricted to a date. e.g. mozilla.com today.
134 // 3rd: Actual visits. e.g. mozilla.com/index.html today.
135 //
136 // We store all the third level result roots so that we can easily close all
137 // containers and test live updating into specific results.
138 let roots = [];
140 let query = PlacesUtils.history.getNewQuery();
141 let options = PlacesUtils.history.getNewQueryOptions();
142 options.resultType = Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_SITE_QUERY;
144 let root = PlacesUtils.history.executeQuery(query, options).root;
145 root.containerOpen = true;
147 // This corresponds to the number of date ranges.
148 do_check_eq(root.childCount, leveledTestData.length);
150 // We pass off to |checkFirstLevel| to check the first level of results.
151 for (let index = 0; index < leveledTestData.length; index++) {
152 let node = root.getChild(index);
153 checkFirstLevel(index, node, roots);
154 }
156 // Test live updating.
157 testDataAddedLater.forEach(function(visit) {
158 yield task_populateDB([visit]);
159 let oldLength = testData.length;
160 let i = visit.levels[0];
161 let j = visit.levels[1];
162 testData.push(visit);
163 leveledTestData[i][j].push(oldLength);
164 compareArrayToResult(leveledTestData[i][j].
165 map(function(x) testData[x]), roots[i][j]);
166 });
168 for (let i = 0; i < roots.length; i++) {
169 for (let j = 0; j < roots[i].length; j++)
170 roots[i][j].containerOpen = false;
171 }
173 root.containerOpen = false;
174 });
176 function checkFirstLevel(index, node, roots) {
177 PlacesUtils.asContainer(node).containerOpen = true;
179 do_check_true(PlacesUtils.nodeIsDay(node));
180 PlacesUtils.asQuery(node);
181 let queries = node.getQueries();
182 let options = node.queryOptions;
184 do_check_eq(queries.length, 1);
185 let query = queries[0];
187 do_check_true(query.hasBeginTime && query.hasEndTime);
189 // Here we check the second level of results.
190 let root = PlacesUtils.history.executeQuery(query, options).root;
191 roots.push([]);
192 root.containerOpen = true;
194 do_check_eq(root.childCount, leveledTestData[index].length);
195 for (var secondIndex = 0; secondIndex < root.childCount; secondIndex++) {
196 let child = PlacesUtils.asQuery(root.getChild(secondIndex));
197 checkSecondLevel(index, secondIndex, child, roots);
198 }
199 root.containerOpen = false;
200 node.containerOpen = false;
201 }
203 function checkSecondLevel(index, secondIndex, child, roots) {
204 let queries = child.getQueries();
205 let options = child.queryOptions;
207 do_check_eq(queries.length, 1);
208 let query = queries[0];
210 do_check_true(query.hasDomain);
211 do_check_true(query.hasBeginTime && query.hasEndTime);
213 let root = PlacesUtils.history.executeQuery(query, options).root;
214 // We should now have that roots[index][secondIndex] is set to the second
215 // level's results root.
216 roots[index].push(root);
218 // We pass off to compareArrayToResult to check the third level of
219 // results.
220 root.containerOpen = true;
221 compareArrayToResult(leveledTestData[index][secondIndex].
222 map(function(x) testData[x]), root);
223 // We close |root|'s container later so that we can test live
224 // updates into it.
225 }