forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_abstime-annotation-domain.js
257 lines (220 loc) · 10.7 KB
/
test_abstime-annotation-domain.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Places Test Code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Clint Talbert <ctalbert@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const DAY_MSEC = 86400000;
const MIN_MSEC = 60000;
const HOUR_MSEC = 3600000;
// Jan 6 2008 at 8am is our begin edge of the query
var beginTimeDate = new Date(2008, 0, 6, 8, 0, 0, 0);
// Jan 15 2008 at 9:30pm is our ending edge of the query
var endTimeDate = new Date(2008, 0, 15, 21, 30, 0, 0);
// These as millisecond values
var beginTime = beginTimeDate.getTime();
var endTime = endTimeDate.getTime();
// Some range dates inside our query - mult by 1000 to convert to PRTIME
var jan7_800 = (beginTime + DAY_MSEC) * 1000;
var jan6_815 = (beginTime + (MIN_MSEC * 15)) * 1000;
var jan11_800 = (beginTime + (DAY_MSEC * 5)) * 1000;
var jan14_2130 = (endTime - DAY_MSEC) * 1000;
var jan15_2045 = (endTime - (MIN_MSEC * 45)) * 1000;
var jan12_1730 = (endTime - (DAY_MSEC * 3) - (HOUR_MSEC*4)) * 1000;
// Dates outside our query - mult by 1000 to convert to PRTIME
var jan6_700 = (beginTime - HOUR_MSEC) * 1000;
var jan5_800 = (beginTime - DAY_MSEC) * 1000;
var dec27_800 = (beginTime - (DAY_MSEC * 10)) * 1000;
var jan15_2145 = (endTime + (MIN_MSEC * 15)) * 1000;
var jan16_2130 = (endTime + (DAY_MSEC)) * 1000;
var jan25_2130 = (endTime + (DAY_MSEC * 10)) * 1000;
// So that we can easily use these too, convert them to PRTIME
beginTime *= 1000;
endTime *= 1000;
/**
* Array of objects to build our test database
*/
var goodAnnoName = "moz-test-places/testing123";
var val = "test";
var badAnnoName = "text/foo";
// The test data for our database, note that the ordering of the results that
// will be returned by the query (the isInQuery: true objects) is IMPORTANT.
// see compareArrayToResult in head_queries.js for more info.
var testData = [
// Test ftp protocol - vary the title length
{isInQuery: true, isVisit: true, isDetails: true,
uri: "ftp://foo.com/ftp", lastVisit: jan12_1730,
title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"},
// Test flat domain with annotation
{isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
uri: "http://foo.com/", annoName: goodAnnoName, annoVal: val,
lastVisit: jan14_2130, title: "moz"},
// Test subdomain included with isRedirect=true, different transtype
{isInQuery: true, isVisit: true, isDetails: true, title: "moz",
isRedirect: true, uri: "http://mail.foo.com/redirect", lastVisit: jan11_800,
transType: PlacesUtils.history.TRANSITION_LINK},
// Test subdomain inclued at the leading time edge
{isInQuery: true, isVisit: true, isDetails: true,
uri: "http://mail.foo.com/yiihah", title: "moz", lastVisit: jan6_815},
// Test www. style URI is included, with an annotation
{isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
uri: "http://www.foo.com/yiihah", annoName: goodAnnoName, annoVal: val,
lastVisit: jan7_800, title: "moz"},
// Test https protocol
{isInQuery: true, isVisit: true, isDetails: true, title: "moz",
uri: "https://foo.com/", lastVisit: jan15_2045},
// Test begin edge of time
{isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla",
uri: "https://foo.com/begin.html", lastVisit: beginTime},
//Test end edge of time
{isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla",
uri: "https://foo.com/end.html", lastVisit: endTime},
// Test an image link, with annotations
{isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
title: "mozzie the dino", uri: "https://foo.com/mozzie.png",
annoName: goodAnnoName, annoVal: val, lastVisit: jan14_2130},
// Begin the invalid queries: Test too early
{isInQuery: false, isVisit:true, isDetails: true, title: "moz",
uri: "http://foo.com/tooearly.php", lastVisit: jan6_700},
// Test Bad Annotation
{isInQuery: false, isVisit:true, isDetails: true, isPageAnnotation: true,
title: "moz", uri: "http://foo.com/badanno.htm", lastVisit: jan12_1730,
annoName: badAnnoName, annoVal: val},
// Test bad URI
{isInQuery: false, isVisit:true, isDetails: true, title: "moz",
uri: "http://somefoo.com/justwrong.htm", lastVisit: jan11_800},
// Test afterward, one to update
{isInQuery: false, isVisit:true, isDetails: true, title: "changeme",
uri: "http://foo.com/changeme1.htm", lastVisit: jan12_1730},
// Test invalid title
{isInQuery: false, isVisit:true, isDetails: true, title: "changeme2",
uri: "http://foo.com/changeme2.htm", lastVisit: jan7_800},
// Test changing the lastVisit
{isInQuery: false, isVisit:true, isDetails: true, title: "moz",
uri: "http://foo.com/changeme3.htm", lastVisit: dec27_800}];
/**
* This test will test a Query using several terms and do a bit of negative
* testing for items that should be ignored while querying over history.
* The Query:WHERE absoluteTime(matches) AND searchTerms AND URI
* AND annotationIsNot(match) GROUP BY Domain, Day SORT BY uri,ascending
* excludeITems(should be ignored)
*/
function run_test() {
//Initialize database
populateDB(testData);
// Query
var query = PlacesUtils.history.getNewQuery();
query.beginTime = beginTime;
query.endTime = endTime;
query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
query.searchTerms = "moz";
query.domain = "foo.com";
query.domainIsHost = false;
query.annotation = "text/foo";
query.annotationIsNot = true;
// Options
var options = PlacesUtils.history.getNewQueryOptions();
options.sortingMode = options.SORT_BY_URI_ASCENDING;
options.resultType = options.RESULTS_AS_URI;
// The next two options should be ignored
// can't use this one, breaks test - bug 419779
// options.excludeItems = true;
// Results
var result = PlacesUtils.history.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
// Ensure the result set is correct
compareArrayToResult(testData, root);
// Make some changes to the result set
// Let's add something first
var addItem = [{isInQuery: true, isVisit: true, isDetails: true, title: "moz",
uri: "http://www.foo.com/i-am-added.html", lastVisit: jan11_800}];
populateDB(addItem);
LOG("Adding item foo.com/i-am-added.html");
do_check_eq(isInResult(addItem, root), true);
// Let's update something by title
var change1 = [{isDetails: true, uri: "http://foo.com/changeme1",
lastVisit: jan12_1730, title: "moz moz mozzie"}];
populateDB(change1);
LOG("LiveUpdate by changing title");
do_check_eq(isInResult(change1, root), true);
// Let's update something by annotation
// Updating a page by removing an annotation does not cause it to join this
// query set. I tend to think that it should cause that page to join this
// query set, because this visit fits all theother specified criteria once the
// annotation is removed. Uncommenting this will fail the test.
// Bug 424050
/*var change2 = [{isPageAnnotation: true, uri: "http://foo.com/badannotaion.html",
annoName: "text/mozilla", annoVal: "test"}];
populateDB(change2);
LOG("LiveUpdate by removing annotation");
do_check_eq(isInResult(change2, root), true);*/
// Let's update by adding a visit in the time range for an existing URI
var change3 = [{isDetails: true, uri: "http://foo.com/changeme3.htm",
title: "moz", lastVisit: jan15_2045}];
populateDB(change3);
LOG("LiveUpdate by adding visit within timerange");
do_check_eq(isInResult(change3, root), true);
// And delete something from the result set - using annotation
// Once again, bug 424050 prevents this from passing
/*var change4 = [{isPageAnnotation: true, uri: "ftp://foo.com/ftp",
annoVal: "test", annoName: badAnnoName}];
populateDB(change4);
LOG("LiveUpdate by deleting item from set by adding annotation");
do_check_eq(isInResult(change4, root), false);*/
// Delete something by changing the title
var change5 = [{isDetails: true, uri: "http://foo.com/end.html", title: "deleted"}];
populateDB(change5);
LOG("LiveUpdate by deleting item by changing title");
do_check_eq(isInResult(change5, root), false);
// Update some in batch mode
// Adds http://foo.com/changeme2 to the result set and removes foo.com/begin.html
var updateBatch = {
runBatched: function (aUserData) {
var batchChange = [{isDetails: true, uri: "http://foo.com/changeme2",
title: "moz", lastVisit: jan7_800},
{isDetails: true, uri: "http://foo.com/begin.html",
isPageAnnotation: true,
annoName: badAnnoName, annoVal: val}];
populateDB(batchChange);
}
};
PlacesUtils.history.runInBatchMode(updateBatch, null);
LOG("LiveUpdate by updating title in batch mode");
do_check_eq(isInResult({uri: "http://foo.com/changeme2"}, root), true);
LOG("LiveUpdate by deleting item by setting annotation in batch mode");
do_check_eq(isInResult({uri: "http:/foo.com/begin.html"}, root), false);
root.containerOpen = false;
}