|
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 ***** */ |
|
7 var beginTime = Date.now(); |
|
8 var testData = [ |
|
9 { |
|
10 isVisit: true, |
|
11 title: "page 0", |
|
12 uri: "http://mozilla.com/", |
|
13 transType: Ci.nsINavHistoryService.TRANSITION_TYPED |
|
14 }, |
|
15 { |
|
16 isVisit: true, |
|
17 title: "page 1", |
|
18 uri: "http://google.com/", |
|
19 transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
|
20 }, |
|
21 { |
|
22 isVisit: true, |
|
23 title: "page 2", |
|
24 uri: "http://microsoft.com/", |
|
25 transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
|
26 }, |
|
27 { |
|
28 isVisit: true, |
|
29 title: "page 3", |
|
30 uri: "http://en.wikipedia.org/", |
|
31 transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK |
|
32 }, |
|
33 { |
|
34 isVisit: true, |
|
35 title: "page 4", |
|
36 uri: "http://fr.wikipedia.org/", |
|
37 transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
|
38 }, |
|
39 { |
|
40 isVisit: true, |
|
41 title: "page 5", |
|
42 uri: "http://apple.com/", |
|
43 transType: Ci.nsINavHistoryService.TRANSITION_TYPED |
|
44 }, |
|
45 { |
|
46 isVisit: true, |
|
47 title: "page 6", |
|
48 uri: "http://campus-bike-store.com/", |
|
49 transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
|
50 }, |
|
51 { |
|
52 isVisit: true, |
|
53 title: "page 7", |
|
54 uri: "http://uwaterloo.ca/", |
|
55 transType: Ci.nsINavHistoryService.TRANSITION_TYPED |
|
56 }, |
|
57 { |
|
58 isVisit: true, |
|
59 title: "page 8", |
|
60 uri: "http://pugcleaner.com/", |
|
61 transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK |
|
62 }, |
|
63 { |
|
64 isVisit: true, |
|
65 title: "page 9", |
|
66 uri: "http://de.wikipedia.org/", |
|
67 transType: Ci.nsINavHistoryService.TRANSITION_TYPED |
|
68 }, |
|
69 { |
|
70 isVisit: true, |
|
71 title: "arewefastyet", |
|
72 uri: "http://arewefastyet.com/", |
|
73 transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
|
74 }, |
|
75 { |
|
76 isVisit: true, |
|
77 title: "arewefastyet", |
|
78 uri: "http://arewefastyet.com/", |
|
79 transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK |
|
80 }]; |
|
81 // sets of indices of testData array by transition type |
|
82 var testDataTyped = [0, 5, 7, 9]; |
|
83 var testDataDownload = [1, 2, 4, 6, 10]; |
|
84 var testDataBookmark = [3, 8, 11]; |
|
85 |
|
86 /** |
|
87 * run_test is where the magic happens. This is automatically run by the test |
|
88 * harness. It is where you do the work of creating the query, running it, and |
|
89 * playing with the result set. |
|
90 */ |
|
91 function run_test() |
|
92 { |
|
93 run_next_test(); |
|
94 } |
|
95 |
|
96 add_task(function test_transitions() |
|
97 { |
|
98 let timeNow = Date.now(); |
|
99 for each (let item in testData) { |
|
100 yield promiseAddVisits({ |
|
101 uri: uri(item.uri), |
|
102 transition: item.transType, |
|
103 visitDate: timeNow++ * 1000, |
|
104 title: item.title |
|
105 }); |
|
106 } |
|
107 |
|
108 //dump_table("moz_places"); |
|
109 //dump_table("moz_historyvisits"); |
|
110 |
|
111 var numSortFunc = function (a,b) { return (a - b); }; |
|
112 var arrs = testDataTyped.concat(testDataDownload).concat(testDataBookmark) |
|
113 .sort(numSortFunc); |
|
114 |
|
115 // Four tests which compare the result of a query to an expected set. |
|
116 var data = arrs.filter(function (index) { |
|
117 return (testData[index].uri.match(/arewefastyet\.com/) && |
|
118 testData[index].transType == |
|
119 Ci.nsINavHistoryService.TRANSITION_DOWNLOAD); |
|
120 }); |
|
121 |
|
122 compareQueryToTestData("place:domain=arewefastyet.com&transition=" + |
|
123 Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, |
|
124 data.slice()); |
|
125 |
|
126 compareQueryToTestData("place:transition=" + |
|
127 Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, |
|
128 testDataDownload.slice()); |
|
129 |
|
130 compareQueryToTestData("place:transition=" + |
|
131 Ci.nsINavHistoryService.TRANSITION_TYPED, |
|
132 testDataTyped.slice()); |
|
133 |
|
134 compareQueryToTestData("place:transition=" + |
|
135 Ci.nsINavHistoryService.TRANSITION_DOWNLOAD + |
|
136 "&transition=" + |
|
137 Ci.nsINavHistoryService.TRANSITION_BOOKMARK, |
|
138 data); |
|
139 |
|
140 // Tests the live update property of transitions. |
|
141 var query = {}; |
|
142 var options = {}; |
|
143 PlacesUtils.history. |
|
144 queryStringToQueries("place:transition=" + |
|
145 Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, |
|
146 query, {}, options); |
|
147 query = (query.value)[0]; |
|
148 options = PlacesUtils.history.getNewQueryOptions(); |
|
149 var result = PlacesUtils.history.executeQuery(query, options); |
|
150 var root = result.root; |
|
151 root.containerOpen = true; |
|
152 do_check_eq(testDataDownload.length, root.childCount); |
|
153 yield promiseAddVisits({ |
|
154 uri: uri("http://getfirefox.com"), |
|
155 transition: TRANSITION_DOWNLOAD |
|
156 }); |
|
157 do_check_eq(testDataDownload.length + 1, root.childCount); |
|
158 root.containerOpen = false; |
|
159 }); |
|
160 |
|
161 /* |
|
162 * Takes a query and a set of indices. The indices correspond to elements |
|
163 * of testData that are the result of the query. |
|
164 */ |
|
165 function compareQueryToTestData(queryStr, data) { |
|
166 var query = {}; |
|
167 var options = {}; |
|
168 PlacesUtils.history.queryStringToQueries(queryStr, query, {}, options); |
|
169 query = query.value[0]; |
|
170 options = options.value; |
|
171 var result = PlacesUtils.history.executeQuery(query, options); |
|
172 var root = result.root; |
|
173 for (var i = 0; i < data.length; i++) { |
|
174 data[i] = testData[data[i]]; |
|
175 data[i].isInQuery = true; |
|
176 } |
|
177 compareArrayToResult(data, root); |
|
178 } |