|
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 const DAY_MSEC = 86400000; |
|
8 const MIN_MSEC = 60000; |
|
9 const HOUR_MSEC = 3600000; |
|
10 // Jan 6 2008 at 8am is our begin edge of the query |
|
11 var beginTimeDate = new Date(2008, 0, 6, 8, 0, 0, 0); |
|
12 // Jan 15 2008 at 9:30pm is our ending edge of the query |
|
13 var endTimeDate = new Date(2008, 0, 15, 21, 30, 0, 0); |
|
14 |
|
15 // These as millisecond values |
|
16 var beginTime = beginTimeDate.getTime(); |
|
17 var endTime = endTimeDate.getTime(); |
|
18 |
|
19 // Some range dates inside our query - mult by 1000 to convert to PRTIME |
|
20 var jan7_800 = (beginTime + DAY_MSEC) * 1000; |
|
21 var jan6_815 = (beginTime + (MIN_MSEC * 15)) * 1000; |
|
22 var jan11_800 = (beginTime + (DAY_MSEC * 5)) * 1000; |
|
23 var jan14_2130 = (endTime - DAY_MSEC) * 1000; |
|
24 var jan15_2045 = (endTime - (MIN_MSEC * 45)) * 1000; |
|
25 var jan12_1730 = (endTime - (DAY_MSEC * 3) - (HOUR_MSEC*4)) * 1000; |
|
26 |
|
27 // Dates outside our query - mult by 1000 to convert to PRTIME |
|
28 var jan6_700 = (beginTime - HOUR_MSEC) * 1000; |
|
29 var jan5_800 = (beginTime - DAY_MSEC) * 1000; |
|
30 var dec27_800 = (beginTime - (DAY_MSEC * 10)) * 1000; |
|
31 var jan15_2145 = (endTime + (MIN_MSEC * 15)) * 1000; |
|
32 var jan16_2130 = (endTime + (DAY_MSEC)) * 1000; |
|
33 var jan25_2130 = (endTime + (DAY_MSEC * 10)) * 1000; |
|
34 |
|
35 // So that we can easily use these too, convert them to PRTIME |
|
36 beginTime *= 1000; |
|
37 endTime *= 1000; |
|
38 |
|
39 /** |
|
40 * Array of objects to build our test database |
|
41 */ |
|
42 var goodAnnoName = "moz-test-places/testing123"; |
|
43 var val = "test"; |
|
44 var badAnnoName = "text/foo"; |
|
45 |
|
46 // The test data for our database, note that the ordering of the results that |
|
47 // will be returned by the query (the isInQuery: true objects) is IMPORTANT. |
|
48 // see compareArrayToResult in head_queries.js for more info. |
|
49 var testData = [ |
|
50 |
|
51 // Test flat domain with annotation |
|
52 {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true, |
|
53 uri: "http://foo.com/", annoName: goodAnnoName, annoVal: val, |
|
54 lastVisit: jan14_2130, title: "moz"}, |
|
55 |
|
56 // Test begin edge of time |
|
57 {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla", |
|
58 uri: "http://foo.com/begin.html", lastVisit: beginTime}, |
|
59 |
|
60 // Test end edge of time |
|
61 {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla", |
|
62 uri: "http://foo.com/end.html", lastVisit: endTime}, |
|
63 |
|
64 // Test uri included with isRedirect=true, different transtype |
|
65 {isInQuery: true, isVisit: true, isDetails: true, title: "moz", |
|
66 isRedirect: true, uri: "http://foo.com/redirect", lastVisit: jan11_800, |
|
67 transType: PlacesUtils.history.TRANSITION_LINK}, |
|
68 |
|
69 // Test leading time edge with tag string is included |
|
70 {isInQuery: true, isVisit: true, isDetails: true, title: "taggariffic", |
|
71 uri: "http://foo.com/tagging/test.html", lastVisit: beginTime, isTag: true, |
|
72 tagArray: ["moz"] }, |
|
73 |
|
74 // Begin the invalid queries: |
|
75 // Test www. style URI is not included, with an annotation |
|
76 {isInQuery: false, isVisit: true, isDetails: true, isPageAnnotation: true, |
|
77 uri: "http://www.foo.com/yiihah", annoName: goodAnnoName, annoVal: val, |
|
78 lastVisit: jan7_800, title: "moz"}, |
|
79 |
|
80 // Test subdomain not inclued at the leading time edge |
|
81 {isInQuery: false, isVisit: true, isDetails: true, |
|
82 uri: "http://mail.foo.com/yiihah", title: "moz", lastVisit: jan6_815}, |
|
83 |
|
84 // Test https protocol |
|
85 {isInQuery: false, isVisit: true, isDetails: true, title: "moz", |
|
86 uri: "https://foo.com/", lastVisit: jan15_2045}, |
|
87 |
|
88 // Test ftp protocol |
|
89 {isInQuery: false, isVisit: true, isDetails: true, |
|
90 uri: "ftp://foo.com/ftp", lastVisit: jan12_1730, |
|
91 title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"}, |
|
92 |
|
93 // Test too early |
|
94 {isInQuery: false, isVisit:true, isDetails: true, title: "moz", |
|
95 uri: "http://foo.com/tooearly.php", lastVisit: jan6_700}, |
|
96 |
|
97 // Test Bad Annotation |
|
98 {isInQuery: false, isVisit:true, isDetails: true, isPageAnnotation: true, |
|
99 title: "moz", uri: "http://foo.com/badanno.htm", lastVisit: jan12_1730, |
|
100 annoName: badAnnoName, annoVal: val}, |
|
101 |
|
102 // Test afterward, one to update |
|
103 {isInQuery: false, isVisit:true, isDetails: true, title: "changeme", |
|
104 uri: "http://foo.com/changeme1.htm", lastVisit: jan12_1730}, |
|
105 |
|
106 // Test invalid title |
|
107 {isInQuery: false, isVisit:true, isDetails: true, title: "changeme2", |
|
108 uri: "http://foo.com/changeme2.htm", lastVisit: jan7_800}, |
|
109 |
|
110 // Test changing the lastVisit |
|
111 {isInQuery: false, isVisit:true, isDetails: true, title: "moz", |
|
112 uri: "http://foo.com/changeme3.htm", lastVisit: dec27_800}]; |
|
113 |
|
114 /** |
|
115 * This test will test a Query using several terms and do a bit of negative |
|
116 * testing for items that should be ignored while querying over history. |
|
117 * The Query:WHERE absoluteTime(matches) AND searchTerms AND URI |
|
118 * AND annotationIsNot(match) GROUP BY Domain, Day SORT BY uri,ascending |
|
119 * excludeITems(should be ignored) |
|
120 */ |
|
121 function run_test() |
|
122 { |
|
123 run_next_test(); |
|
124 } |
|
125 |
|
126 add_task(function test_abstime_annotation_uri() |
|
127 { |
|
128 //Initialize database |
|
129 yield task_populateDB(testData); |
|
130 |
|
131 // Query |
|
132 var query = PlacesUtils.history.getNewQuery(); |
|
133 query.beginTime = beginTime; |
|
134 query.endTime = endTime; |
|
135 query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH; |
|
136 query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH; |
|
137 query.searchTerms = "moz"; |
|
138 query.uri = uri("http://foo.com"); |
|
139 query.uriIsPrefix = true; |
|
140 query.annotation = "text/foo"; |
|
141 query.annotationIsNot = true; |
|
142 |
|
143 // Options |
|
144 var options = PlacesUtils.history.getNewQueryOptions(); |
|
145 options.sortingMode = options.SORT_BY_URI_ASCENDING; |
|
146 options.resultType = options.RESULTS_AS_URI; |
|
147 // The next two options should be ignored |
|
148 // can't use this one, breaks test - bug 419779 |
|
149 // options.excludeItems = true; |
|
150 |
|
151 // Results |
|
152 var result = PlacesUtils.history.executeQuery(query, options); |
|
153 var root = result.root; |
|
154 root.containerOpen = true; |
|
155 |
|
156 // Ensure the result set is correct |
|
157 compareArrayToResult(testData, root); |
|
158 |
|
159 // Make some changes to the result set |
|
160 // Let's add something first |
|
161 var addItem = [{isInQuery: true, isVisit: true, isDetails: true, title: "moz", |
|
162 uri: "http://foo.com/i-am-added.html", lastVisit: jan11_800}]; |
|
163 yield task_populateDB(addItem); |
|
164 LOG("Adding item foo.com/i-am-added.html"); |
|
165 do_check_eq(isInResult(addItem, root), true); |
|
166 |
|
167 // Let's update something by title |
|
168 var change1 = [{isDetails: true, uri: "http://foo.com/changeme1", |
|
169 lastVisit: jan12_1730, title: "moz moz mozzie"}]; |
|
170 yield task_populateDB(change1); |
|
171 LOG("LiveUpdate by changing title"); |
|
172 do_check_eq(isInResult(change1, root), true); |
|
173 |
|
174 // Let's update something by annotation |
|
175 // Updating a page by removing an annotation does not cause it to join this |
|
176 // query set. I tend to think that it should cause that page to join this |
|
177 // query set, because this visit fits all theother specified criteria once the |
|
178 // annotation is removed. Uncommenting this will fail the test. |
|
179 // This is bug 424050 - appears to happen for both domain and URI queries |
|
180 /*var change2 = [{isPageAnnotation: true, uri: "http://foo.com/badannotaion.html", |
|
181 annoName: "text/mozilla", annoVal: "test"}]; |
|
182 yield task_populateDB(change2); |
|
183 LOG("LiveUpdate by removing annotation"); |
|
184 do_check_eq(isInResult(change2, root), true);*/ |
|
185 |
|
186 // Let's update by adding a visit in the time range for an existing URI |
|
187 var change3 = [{isDetails: true, uri: "http://foo.com/changeme3.htm", |
|
188 title: "moz", lastVisit: jan15_2045}]; |
|
189 yield task_populateDB(change3); |
|
190 LOG("LiveUpdate by adding visit within timerange"); |
|
191 do_check_eq(isInResult(change3, root), true); |
|
192 |
|
193 // And delete something from the result set - using annotation |
|
194 // Once more, bug 424050 |
|
195 /*var change4 = [{isPageAnnotation: true, uri: "http://foo.com/", |
|
196 annoVal: "test", annoName: badAnnoName}]; |
|
197 yield task_populateDB(change4); |
|
198 LOG("LiveUpdate by deleting item from set by adding annotation"); |
|
199 do_check_eq(isInResult(change4, root), false);*/ |
|
200 |
|
201 // Delete something by changing the title |
|
202 var change5 = [{isDetails: true, uri: "http://foo.com/end.html", title: "deleted"}]; |
|
203 yield task_populateDB(change5); |
|
204 LOG("LiveUpdate by deleting item by changing title"); |
|
205 do_check_eq(isInResult(change5, root), false); |
|
206 |
|
207 root.containerOpen = false; |
|
208 }); |