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

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:3521a801c7ec
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 var tests = [];
8
9 ////////////////////////////////////////////////////////////////////////////////
10
11 tests.push({
12 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_NONE,
13
14 setup: function() {
15 LOG("Sorting test 1: SORT BY NONE");
16
17 this._unsortedData = [
18 { isBookmark: true,
19 uri: "http://example.com/b",
20 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
21 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
22 title: "y",
23 keyword: "b",
24 isInQuery: true },
25
26 { isBookmark: true,
27 uri: "http://example.com/a",
28 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
29 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
30 title: "z",
31 keyword: "a",
32 isInQuery: true },
33
34 { isBookmark: true,
35 uri: "http://example.com/c",
36 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
37 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
38 title: "x",
39 keyword: "c",
40 isInQuery: true },
41 ];
42
43 this._sortedData = this._unsortedData;
44
45 // This function in head_queries.js creates our database with the above data
46 yield task_populateDB(this._unsortedData);
47 },
48
49 check: function() {
50 // Query
51 var query = PlacesUtils.history.getNewQuery();
52 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
53 query.onlyBookmarked = true;
54
55 // query options
56 var options = PlacesUtils.history.getNewQueryOptions();
57 options.sortingMode = this._sortingMode;
58
59 // Results - this gets the result set and opens it for reading and modification.
60 var result = PlacesUtils.history.executeQuery(query, options);
61 var root = result.root;
62 root.containerOpen = true;
63 compareArrayToResult(this._sortedData, root);
64 root.containerOpen = false;
65 },
66
67 check_reverse: function() {
68 // no reverse sorting for SORT BY NONE
69 }
70 });
71
72 ////////////////////////////////////////////////////////////////////////////////
73
74 tests.push({
75 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_ASCENDING,
76
77 setup: function() {
78 LOG("Sorting test 2: SORT BY TITLE");
79
80 this._unsortedData = [
81 { isBookmark: true,
82 uri: "http://example.com/b1",
83 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
84 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
85 title: "y",
86 isInQuery: true },
87
88 { isBookmark: true,
89 uri: "http://example.com/a",
90 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
91 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
92 title: "z",
93 isInQuery: true },
94
95 { isBookmark: true,
96 uri: "http://example.com/c",
97 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
98 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
99 title: "x",
100 isInQuery: true },
101
102 // if titles are equal, should fall back to URI
103 { isBookmark: true,
104 uri: "http://example.com/b2",
105 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
106 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
107 title: "y",
108 isInQuery: true },
109 ];
110
111 this._sortedData = [
112 this._unsortedData[2],
113 this._unsortedData[0],
114 this._unsortedData[3],
115 this._unsortedData[1],
116 ];
117
118 // This function in head_queries.js creates our database with the above data
119 yield task_populateDB(this._unsortedData);
120 },
121
122 check: function() {
123 // Query
124 var query = PlacesUtils.history.getNewQuery();
125 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
126 query.onlyBookmarked = true;
127
128 // query options
129 var options = PlacesUtils.history.getNewQueryOptions();
130 options.sortingMode = this._sortingMode;
131
132 // Results - this gets the result set and opens it for reading and modification.
133 var result = PlacesUtils.history.executeQuery(query, options);
134 var root = result.root;
135 root.containerOpen = true;
136 compareArrayToResult(this._sortedData, root);
137 root.containerOpen = false;
138 },
139
140 check_reverse: function() {
141 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_DESCENDING;
142 this._sortedData.reverse();
143 this.check();
144 }
145 });
146
147 ////////////////////////////////////////////////////////////////////////////////
148
149 tests.push({
150 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_ASCENDING,
151
152 setup: function() {
153 LOG("Sorting test 3: SORT BY DATE");
154
155 var timeInMicroseconds = Date.now() * 1000;
156 this._unsortedData = [
157 { isVisit: true,
158 isDetails: true,
159 isBookmark: true,
160 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
161 index: 0,
162 uri: "http://example.com/c1",
163 lastVisit: timeInMicroseconds - 2,
164 title: "x1",
165 isInQuery: true },
166
167 { isVisit: true,
168 isDetails: true,
169 isBookmark: true,
170 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
171 index: 1,
172 uri: "http://example.com/a",
173 lastVisit: timeInMicroseconds - 1,
174 title: "z",
175 isInQuery: true },
176
177 { isVisit: true,
178 isDetails: true,
179 isBookmark: true,
180 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
181 index: 2,
182 uri: "http://example.com/b",
183 lastVisit: timeInMicroseconds - 3,
184 title: "y",
185 isInQuery: true },
186
187 // if dates are equal, should fall back to title
188 { isVisit: true,
189 isDetails: true,
190 isBookmark: true,
191 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
192 index: 3,
193 uri: "http://example.com/c2",
194 lastVisit: timeInMicroseconds - 2,
195 title: "x2",
196 isInQuery: true },
197
198 // if dates and title are equal, should fall back to bookmark index
199 { isVisit: true,
200 isDetails: true,
201 isBookmark: true,
202 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
203 index: 4,
204 uri: "http://example.com/c2",
205 lastVisit: timeInMicroseconds - 2,
206 title: "x2",
207 isInQuery: true },
208 ];
209
210 this._sortedData = [
211 this._unsortedData[2],
212 this._unsortedData[0],
213 this._unsortedData[3],
214 this._unsortedData[4],
215 this._unsortedData[1],
216 ];
217
218 // This function in head_queries.js creates our database with the above data
219 yield task_populateDB(this._unsortedData);
220 },
221
222 check: function() {
223 // Query
224 var query = PlacesUtils.history.getNewQuery();
225 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
226 query.onlyBookmarked = true;
227
228 // query options
229 var options = PlacesUtils.history.getNewQueryOptions();
230 options.sortingMode = this._sortingMode;
231
232 // Results - this gets the result set and opens it for reading and modification.
233 var result = PlacesUtils.history.executeQuery(query, options);
234 var root = result.root;
235 root.containerOpen = true;
236 compareArrayToResult(this._sortedData, root);
237 root.containerOpen = false;
238 },
239
240 check_reverse: function() {
241 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
242 this._sortedData.reverse();
243 this.check();
244 }
245 });
246
247 ////////////////////////////////////////////////////////////////////////////////
248
249 tests.push({
250 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_URI_ASCENDING,
251
252 setup: function() {
253 LOG("Sorting test 4: SORT BY URI");
254
255 var timeInMicroseconds = Date.now() * 1000;
256 this._unsortedData = [
257 { isBookmark: true,
258 isDetails: true,
259 lastVisit: timeInMicroseconds,
260 uri: "http://example.com/b",
261 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
262 index: 0,
263 title: "y",
264 isInQuery: true },
265
266 { isBookmark: true,
267 uri: "http://example.com/c",
268 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
269 index: 1,
270 title: "x",
271 isInQuery: true },
272
273 { isBookmark: true,
274 uri: "http://example.com/a",
275 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
276 index: 2,
277 title: "z",
278 isInQuery: true },
279
280 // if URIs are equal, should fall back to date
281 { isBookmark: true,
282 isDetails: true,
283 lastVisit: timeInMicroseconds + 1,
284 uri: "http://example.com/c",
285 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
286 index: 3,
287 title: "x",
288 isInQuery: true },
289
290 // if no URI (e.g., node is a folder), should fall back to title
291 { isFolder: true,
292 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
293 index: 4,
294 title: "a",
295 isInQuery: true },
296
297 // if URIs and dates are equal, should fall back to bookmark index
298 { isBookmark: true,
299 isDetails: true,
300 lastVisit: timeInMicroseconds + 1,
301 uri: "http://example.com/c",
302 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
303 index: 5,
304 title: "x",
305 isInQuery: true },
306
307 // if no URI and titles are equal, should fall back to bookmark index
308 { isFolder: true,
309 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
310 index: 6,
311 title: "a",
312 isInQuery: true },
313 ];
314
315 this._sortedData = [
316 this._unsortedData[4],
317 this._unsortedData[6],
318 this._unsortedData[2],
319 this._unsortedData[0],
320 this._unsortedData[1],
321 this._unsortedData[3],
322 this._unsortedData[5],
323 ];
324
325 // This function in head_queries.js creates our database with the above data
326 yield task_populateDB(this._unsortedData);
327 },
328
329 check: function() {
330 // Query
331 var query = PlacesUtils.history.getNewQuery();
332 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
333
334 // query options
335 var options = PlacesUtils.history.getNewQueryOptions();
336 options.sortingMode = this._sortingMode;
337
338 // Results - this gets the result set and opens it for reading and modification.
339 var result = PlacesUtils.history.executeQuery(query, options);
340 var root = result.root;
341 root.containerOpen = true;
342 compareArrayToResult(this._sortedData, root);
343 root.containerOpen = false;
344 },
345
346 check_reverse: function() {
347 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_URI_DESCENDING;
348 this._sortedData.reverse();
349 this.check();
350 }
351 });
352
353 ////////////////////////////////////////////////////////////////////////////////
354
355 tests.push({
356 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_ASCENDING,
357
358 setup: function() {
359 LOG("Sorting test 5: SORT BY VISITCOUNT");
360
361 var timeInMicroseconds = Date.now() * 1000;
362 this._unsortedData = [
363 { isBookmark: true,
364 uri: "http://example.com/a",
365 lastVisit: timeInMicroseconds,
366 title: "z",
367 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
368 index: 0,
369 isInQuery: true },
370
371 { isBookmark: true,
372 uri: "http://example.com/c",
373 lastVisit: timeInMicroseconds,
374 title: "x",
375 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
376 index: 1,
377 isInQuery: true },
378
379 { isBookmark: true,
380 uri: "http://example.com/b1",
381 lastVisit: timeInMicroseconds,
382 title: "y1",
383 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
384 index: 2,
385 isInQuery: true },
386
387 // if visitCounts are equal, should fall back to date
388 { isBookmark: true,
389 uri: "http://example.com/b2",
390 lastVisit: timeInMicroseconds + 1,
391 title: "y2a",
392 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
393 index: 3,
394 isInQuery: true },
395
396 // if visitCounts and dates are equal, should fall back to bookmark index
397 { isBookmark: true,
398 uri: "http://example.com/b2",
399 lastVisit: timeInMicroseconds + 1,
400 title: "y2b",
401 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
402 index: 4,
403 isInQuery: true },
404 ];
405
406 this._sortedData = [
407 this._unsortedData[0],
408 this._unsortedData[2],
409 this._unsortedData[3],
410 this._unsortedData[4],
411 this._unsortedData[1],
412 ];
413
414 // This function in head_queries.js creates our database with the above data
415 yield task_populateDB(this._unsortedData);
416 // add visits to increase visit count
417 yield promiseAddVisits([
418 { uri: uri("http://example.com/a"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
419 { uri: uri("http://example.com/b1"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
420 { uri: uri("http://example.com/b1"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
421 { uri: uri("http://example.com/b2"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds + 1 },
422 { uri: uri("http://example.com/b2"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds + 1 },
423 { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
424 { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
425 { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
426 ]);
427 },
428
429 check: function() {
430 // Query
431 var query = PlacesUtils.history.getNewQuery();
432 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
433 query.onlyBookmarked = true;
434
435 // query options
436 var options = PlacesUtils.history.getNewQueryOptions();
437 options.sortingMode = this._sortingMode;
438
439 // Results - this gets the result set and opens it for reading and modification.
440 var result = PlacesUtils.history.executeQuery(query, options);
441 var root = result.root;
442 root.containerOpen = true;
443 compareArrayToResult(this._sortedData, root);
444 root.containerOpen = false;
445 },
446
447 check_reverse: function() {
448 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING;
449 this._sortedData.reverse();
450 this.check();
451 }
452 });
453
454 ////////////////////////////////////////////////////////////////////////////////
455
456 tests.push({
457 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_KEYWORD_ASCENDING,
458
459 setup: function() {
460 LOG("Sorting test 6: SORT BY KEYWORD");
461
462 this._unsortedData = [
463 { isBookmark: true,
464 uri: "http://example.com/a",
465 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
466 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
467 title: "z",
468 keyword: "a",
469 isInQuery: true },
470
471 { isBookmark: true,
472 uri: "http://example.com/c",
473 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
474 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
475 title: "x",
476 keyword: "c",
477 isInQuery: true },
478
479 { isBookmark: true,
480 uri: "http://example.com/b1",
481 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
482 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
483 title: "y9",
484 keyword: "b",
485 isInQuery: true },
486
487 // without a keyword, should fall back to title
488 { isBookmark: true,
489 uri: "http://example.com/null2",
490 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
491 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
492 title: "null8",
493 keyword: null,
494 isInQuery: true },
495
496 // without a keyword, should fall back to title
497 { isBookmark: true,
498 uri: "http://example.com/null1",
499 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
500 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
501 title: "null9",
502 keyword: null,
503 isInQuery: true },
504
505 // if keywords are equal, should fall back to title
506 { isBookmark: true,
507 uri: "http://example.com/b2",
508 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
509 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
510 title: "y8",
511 keyword: "b",
512 isInQuery: true },
513 ];
514
515 this._sortedData = [
516 this._unsortedData[3],
517 this._unsortedData[4],
518 this._unsortedData[0],
519 this._unsortedData[5],
520 this._unsortedData[2],
521 this._unsortedData[1],
522 ];
523
524 // This function in head_queries.js creates our database with the above data
525 yield task_populateDB(this._unsortedData);
526 },
527
528 check: function() {
529 // Query
530 var query = PlacesUtils.history.getNewQuery();
531 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
532 query.onlyBookmarked = true;
533
534 // query options
535 var options = PlacesUtils.history.getNewQueryOptions();
536 options.sortingMode = this._sortingMode;
537
538 // Results - this gets the result set and opens it for reading and modification.
539 var result = PlacesUtils.history.executeQuery(query, options);
540 var root = result.root;
541 root.containerOpen = true;
542 compareArrayToResult(this._sortedData, root);
543 root.containerOpen = false;
544 },
545
546 check_reverse: function() {
547 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_KEYWORD_DESCENDING;
548 this._sortedData.reverse();
549 this.check();
550 }
551 });
552
553 ////////////////////////////////////////////////////////////////////////////////
554
555 tests.push({
556 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_ASCENDING,
557
558 setup: function() {
559 LOG("Sorting test 7: SORT BY DATEADDED");
560
561 var timeInMicroseconds = Date.now() * 1000;
562 this._unsortedData = [
563 { isBookmark: true,
564 uri: "http://example.com/b1",
565 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
566 index: 0,
567 title: "y1",
568 dateAdded: timeInMicroseconds -1,
569 isInQuery: true },
570
571 { isBookmark: true,
572 uri: "http://example.com/a",
573 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
574 index: 1,
575 title: "z",
576 dateAdded: timeInMicroseconds - 2,
577 isInQuery: true },
578
579 { isBookmark: true,
580 uri: "http://example.com/c",
581 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
582 index: 2,
583 title: "x",
584 dateAdded: timeInMicroseconds,
585 isInQuery: true },
586
587 // if dateAddeds are equal, should fall back to title
588 { isBookmark: true,
589 uri: "http://example.com/b2",
590 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
591 index: 3,
592 title: "y2",
593 dateAdded: timeInMicroseconds - 1,
594 isInQuery: true },
595
596 // if dateAddeds and titles are equal, should fall back to bookmark index
597 { isBookmark: true,
598 uri: "http://example.com/b3",
599 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
600 index: 4,
601 title: "y3",
602 dateAdded: timeInMicroseconds - 1,
603 isInQuery: true },
604 ];
605
606 this._sortedData = [
607 this._unsortedData[1],
608 this._unsortedData[0],
609 this._unsortedData[3],
610 this._unsortedData[4],
611 this._unsortedData[2],
612 ];
613
614 // This function in head_queries.js creates our database with the above data
615 yield task_populateDB(this._unsortedData);
616 },
617
618 check: function() {
619 // Query
620 var query = PlacesUtils.history.getNewQuery();
621 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
622 query.onlyBookmarked = true;
623
624 // query options
625 var options = PlacesUtils.history.getNewQueryOptions();
626 options.sortingMode = this._sortingMode;
627
628 // Results - this gets the result set and opens it for reading and modification.
629 var result = PlacesUtils.history.executeQuery(query, options);
630 var root = result.root;
631 root.containerOpen = true;
632 compareArrayToResult(this._sortedData, root);
633 root.containerOpen = false;
634 },
635
636 check_reverse: function() {
637 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING;
638 this._sortedData.reverse();
639 this.check();
640 }
641 });
642
643 ////////////////////////////////////////////////////////////////////////////////
644
645 tests.push({
646 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_ASCENDING,
647
648 setup: function() {
649 LOG("Sorting test 8: SORT BY LASTMODIFIED");
650
651 var timeInMicroseconds = Date.now() * 1000;
652 this._unsortedData = [
653 { isBookmark: true,
654 uri: "http://example.com/b1",
655 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
656 index: 0,
657 title: "y1",
658 lastModified: timeInMicroseconds -1,
659 isInQuery: true },
660
661 { isBookmark: true,
662 uri: "http://example.com/a",
663 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
664 index: 1,
665 title: "z",
666 lastModified: timeInMicroseconds - 2,
667 isInQuery: true },
668
669 { isBookmark: true,
670 uri: "http://example.com/c",
671 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
672 index: 2,
673 title: "x",
674 lastModified: timeInMicroseconds,
675 isInQuery: true },
676
677 // if lastModifieds are equal, should fall back to title
678 { isBookmark: true,
679 uri: "http://example.com/b2",
680 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
681 index: 3,
682 title: "y2",
683 lastModified: timeInMicroseconds - 1,
684 isInQuery: true },
685
686 // if lastModifieds and titles are equal, should fall back to bookmark
687 // index
688 { isBookmark: true,
689 uri: "http://example.com/b3",
690 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
691 index: 4,
692 title: "y3",
693 lastModified: timeInMicroseconds - 1,
694 isInQuery: true },
695 ];
696
697 this._sortedData = [
698 this._unsortedData[1],
699 this._unsortedData[0],
700 this._unsortedData[3],
701 this._unsortedData[4],
702 this._unsortedData[2],
703 ];
704
705 // This function in head_queries.js creates our database with the above data
706 yield task_populateDB(this._unsortedData);
707 },
708
709 check: function() {
710 // Query
711 var query = PlacesUtils.history.getNewQuery();
712 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
713 query.onlyBookmarked = true;
714
715 // query options
716 var options = PlacesUtils.history.getNewQueryOptions();
717 options.sortingMode = this._sortingMode;
718
719 // Results - this gets the result set and opens it for reading and modification.
720 var result = PlacesUtils.history.executeQuery(query, options);
721 var root = result.root;
722 root.containerOpen = true;
723 compareArrayToResult(this._sortedData, root);
724 root.containerOpen = false;
725 },
726
727 check_reverse: function() {
728 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_DESCENDING;
729 this._sortedData.reverse();
730 this.check();
731 }
732 });
733
734 ////////////////////////////////////////////////////////////////////////////////
735
736 tests.push({
737 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_ASCENDING,
738
739 setup: function() {
740 LOG("Sorting test 9: SORT BY TAGS");
741
742 this._unsortedData = [
743 { isBookmark: true,
744 uri: "http://url2.com/",
745 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
746 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
747 title: "title x",
748 isTag: true,
749 tagArray: ["x", "y", "z"],
750 isInQuery: true },
751
752 { isBookmark: true,
753 uri: "http://url1a.com/",
754 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
755 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
756 title: "title y1",
757 isTag: true,
758 tagArray: ["a", "b"],
759 isInQuery: true },
760
761 { isBookmark: true,
762 uri: "http://url3a.com/",
763 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
764 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
765 title: "title w1",
766 isInQuery: true },
767
768 { isBookmark: true,
769 uri: "http://url0.com/",
770 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
771 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
772 title: "title z",
773 isTag: true,
774 tagArray: ["a", "y", "z"],
775 isInQuery: true },
776
777 // if tags are equal, should fall back to title
778 { isBookmark: true,
779 uri: "http://url1b.com/",
780 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
781 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
782 title: "title y2",
783 isTag: true,
784 tagArray: ["b", "a"],
785 isInQuery: true },
786
787 // if tags are equal, should fall back to title
788 { isBookmark: true,
789 uri: "http://url3b.com/",
790 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
791 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
792 title: "title w2",
793 isInQuery: true },
794 ];
795
796 this._sortedData = [
797 this._unsortedData[2],
798 this._unsortedData[5],
799 this._unsortedData[1],
800 this._unsortedData[4],
801 this._unsortedData[3],
802 this._unsortedData[0],
803 ];
804
805 // This function in head_queries.js creates our database with the above data
806 yield task_populateDB(this._unsortedData);
807 },
808
809 check: function() {
810 // Query
811 var query = PlacesUtils.history.getNewQuery();
812 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
813 query.onlyBookmarked = true;
814
815 // query options
816 var options = PlacesUtils.history.getNewQueryOptions();
817 options.sortingMode = this._sortingMode;
818
819 // Results - this gets the result set and opens it for reading and modification.
820 var result = PlacesUtils.history.executeQuery(query, options);
821 var root = result.root;
822 root.containerOpen = true;
823 compareArrayToResult(this._sortedData, root);
824 root.containerOpen = false;
825 },
826
827 check_reverse: function() {
828 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_DESCENDING;
829 this._sortedData.reverse();
830 this.check();
831 }
832 });
833
834 ////////////////////////////////////////////////////////////////////////////////
835 // SORT_BY_ANNOTATION_* (int32)
836
837 tests.push({
838 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
839
840 setup: function() {
841 LOG("Sorting test 10: SORT BY ANNOTATION (int32)");
842
843 var timeInMicroseconds = Date.now() * 1000;
844 this._unsortedData = [
845 { isVisit: true,
846 isDetails: true,
847 lastVisit: timeInMicroseconds,
848 uri: "http://example.com/b1",
849 title: "y1",
850 isPageAnnotation: true,
851 annoName: "sorting",
852 annoVal: 2,
853 annoFlags: 0,
854 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
855 isInQuery: true },
856
857 { isVisit: true,
858 isDetails: true,
859 lastVisit: timeInMicroseconds,
860 uri: "http://example.com/a",
861 title: "z",
862 isPageAnnotation: true,
863 annoName: "sorting",
864 annoVal: 1,
865 annoFlags: 0,
866 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
867 isInQuery: true },
868
869 { isVisit: true,
870 isDetails: true,
871 lastVisit: timeInMicroseconds,
872 uri: "http://example.com/c",
873 title: "x",
874 isPageAnnotation: true,
875 annoName: "sorting",
876 annoVal: 3,
877 annoFlags: 0,
878 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
879 isInQuery: true },
880
881 // if annotations are equal, should fall back to title
882 { isVisit: true,
883 isDetails: true,
884 lastVisit: timeInMicroseconds,
885 uri: "http://example.com/b2",
886 title: "y2",
887 isPageAnnotation: true,
888 annoName: "sorting",
889 annoVal: 2,
890 annoFlags: 0,
891 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
892 isInQuery: true },
893 ];
894
895 this._sortedData = [
896 this._unsortedData[1],
897 this._unsortedData[0],
898 this._unsortedData[3],
899 this._unsortedData[2],
900 ];
901
902 // This function in head_queries.js creates our database with the above data
903 yield task_populateDB(this._unsortedData);
904 },
905
906 check: function() {
907 // Query
908 var query = PlacesUtils.history.getNewQuery();
909
910 // query options
911 var options = PlacesUtils.history.getNewQueryOptions();
912 options.sortingAnnotation = "sorting";
913 options.sortingMode = this._sortingMode;
914
915 // Results - this gets the result set and opens it for reading and modification.
916 var result = PlacesUtils.history.executeQuery(query, options);
917 var root = result.root;
918 root.containerOpen = true;
919 compareArrayToResult(this._sortedData, root);
920 root.containerOpen = false;
921 },
922
923 check_reverse: function() {
924 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
925 this._sortedData.reverse();
926 this.check();
927 }
928 });
929
930 ////////////////////////////////////////////////////////////////////////////////
931 // SORT_BY_ANNOTATION_* (int64)
932
933 tests.push({
934 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
935
936 setup: function() {
937 LOG("Sorting test 11: SORT BY ANNOTATION (int64)");
938
939 var timeInMicroseconds = Date.now() * 1000;
940 this._unsortedData = [
941 { isVisit: true,
942 isDetails: true,
943 uri: "http://moz.com/",
944 lastVisit: timeInMicroseconds,
945 title: "I",
946 isPageAnnotation: true,
947 annoName: "sorting",
948 annoVal: 0xffffffff1,
949 annoFlags: 0,
950 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
951 isInQuery: true },
952
953 { isVisit: true,
954 isDetails: true,
955 uri: "http://is.com/",
956 lastVisit: timeInMicroseconds,
957 title: "love",
958 isPageAnnotation: true,
959 annoName: "sorting",
960 annoVal: 0xffffffff0,
961 annoFlags: 0,
962 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
963 isInQuery: true },
964
965 { isVisit: true,
966 isDetails: true,
967 uri: "http://best.com/",
968 lastVisit: timeInMicroseconds,
969 title: "moz",
970 isPageAnnotation: true,
971 annoName: "sorting",
972 annoVal: 0xffffffff2,
973 annoFlags: 0,
974 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
975 isInQuery: true },
976 ];
977
978 this._sortedData = [
979 this._unsortedData[1],
980 this._unsortedData[0],
981 this._unsortedData[2],
982 ];
983
984 // This function in head_queries.js creates our database with the above data
985 yield task_populateDB(this._unsortedData);
986 },
987
988 check: function() {
989 // Query
990 var query = PlacesUtils.history.getNewQuery();
991
992 // query options
993 var options = PlacesUtils.history.getNewQueryOptions();
994 options.sortingAnnotation = "sorting";
995 options.sortingMode = this._sortingMode;
996
997 // Results - this gets the result set and opens it for reading and modification.
998 var result = PlacesUtils.history.executeQuery(query, options);
999 var root = result.root;
1000 root.containerOpen = true;
1001 compareArrayToResult(this._sortedData, root);
1002 root.containerOpen = false;
1003 },
1004
1005 check_reverse: function() {
1006 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
1007 this._sortedData.reverse();
1008 this.check();
1009 }
1010 });
1011
1012 ////////////////////////////////////////////////////////////////////////////////
1013 // SORT_BY_ANNOTATION_* (string)
1014
1015 tests.push({
1016 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
1017
1018 setup: function() {
1019 LOG("Sorting test 12: SORT BY ANNOTATION (string)");
1020
1021 var timeInMicroseconds = Date.now() * 1000;
1022 this._unsortedData = [
1023 { isVisit: true,
1024 isDetails: true,
1025 uri: "http://moz.com/",
1026 lastVisit: timeInMicroseconds,
1027 title: "I",
1028 isPageAnnotation: true,
1029 annoName: "sorting",
1030 annoVal: "a",
1031 annoFlags: 0,
1032 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
1033 isInQuery: true },
1034
1035 { isVisit: true,
1036 isDetails: true,
1037 uri: "http://is.com/",
1038 lastVisit: timeInMicroseconds,
1039 title: "love",
1040 isPageAnnotation: true,
1041 annoName: "sorting",
1042 annoVal: "",
1043 annoFlags: 0,
1044 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
1045 isInQuery: true },
1046
1047 { isVisit: true,
1048 isDetails: true,
1049 uri: "http://best.com/",
1050 lastVisit: timeInMicroseconds,
1051 title: "moz",
1052 isPageAnnotation: true,
1053 annoName: "sorting",
1054 annoVal: "z",
1055 annoFlags: 0,
1056 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
1057 isInQuery: true },
1058 ];
1059
1060 this._sortedData = [
1061 this._unsortedData[1],
1062 this._unsortedData[0],
1063 this._unsortedData[2],
1064 ];
1065
1066 // This function in head_queries.js creates our database with the above data
1067 yield task_populateDB(this._unsortedData);
1068 },
1069
1070 check: function() {
1071 // Query
1072 var query = PlacesUtils.history.getNewQuery();
1073
1074 // query options
1075 var options = PlacesUtils.history.getNewQueryOptions();
1076 options.sortingAnnotation = "sorting";
1077 options.sortingMode = this._sortingMode;
1078
1079 // Results - this gets the result set and opens it for reading and modification.
1080 var result = PlacesUtils.history.executeQuery(query, options);
1081 var root = result.root;
1082 root.containerOpen = true;
1083 compareArrayToResult(this._sortedData, root);
1084 root.containerOpen = false;
1085 },
1086
1087 check_reverse: function() {
1088 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
1089 this._sortedData.reverse();
1090 this.check();
1091 }
1092 });
1093
1094 ////////////////////////////////////////////////////////////////////////////////
1095 // SORT_BY_ANNOTATION_* (double)
1096
1097 tests.push({
1098 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
1099
1100 setup: function() {
1101 LOG("Sorting test 13: SORT BY ANNOTATION (double)");
1102
1103 var timeInMicroseconds = Date.now() * 1000;
1104 this._unsortedData = [
1105 { isVisit: true,
1106 isDetails: true,
1107 uri: "http://moz.com/",
1108 lastVisit: timeInMicroseconds,
1109 title: "I",
1110 isPageAnnotation: true,
1111 annoName: "sorting",
1112 annoVal: 1.2,
1113 annoFlags: 0,
1114 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
1115 isInQuery: true },
1116
1117 { isVisit: true,
1118 isDetails: true,
1119 uri: "http://is.com/",
1120 lastVisit: timeInMicroseconds,
1121 title: "love",
1122 isPageAnnotation: true,
1123 annoName: "sorting",
1124 annoVal: 1.1,
1125 annoFlags: 0,
1126 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
1127 isInQuery: true },
1128
1129 { isVisit: true,
1130 isDetails: true,
1131 uri: "http://best.com/",
1132 lastVisit: timeInMicroseconds,
1133 title: "moz",
1134 isPageAnnotation: true,
1135 annoName: "sorting",
1136 annoVal: 1.3,
1137 annoFlags: 0,
1138 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
1139 isInQuery: true },
1140 ];
1141
1142 this._sortedData = [
1143 this._unsortedData[1],
1144 this._unsortedData[0],
1145 this._unsortedData[2],
1146 ];
1147
1148 // This function in head_queries.js creates our database with the above data
1149 yield task_populateDB(this._unsortedData);
1150 },
1151
1152 check: function() {
1153 // Query
1154 var query = PlacesUtils.history.getNewQuery();
1155
1156 // query options
1157 var options = PlacesUtils.history.getNewQueryOptions();
1158 options.sortingAnnotation = "sorting";
1159 options.sortingMode = this._sortingMode;
1160
1161 // Results - this gets the result set and opens it for reading and modification.
1162 var result = PlacesUtils.history.executeQuery(query, options);
1163 var root = result.root;
1164 root.containerOpen = true;
1165 compareArrayToResult(this._sortedData, root);
1166 root.containerOpen = false;
1167 },
1168
1169 check_reverse: function() {
1170 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
1171 this._sortedData.reverse();
1172 this.check();
1173 }
1174 });
1175
1176 ////////////////////////////////////////////////////////////////////////////////
1177 // SORT_BY_FRECENCY_*
1178
1179 tests.push({
1180 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_ASCENDING,
1181
1182 setup: function() {
1183 LOG("Sorting test 13: SORT BY FRECENCY ");
1184
1185 var timeInMicroseconds = Date.now() * 1000;
1186 this._unsortedData = [
1187 { isVisit: true,
1188 isDetails: true,
1189 uri: "http://moz.com/",
1190 lastVisit: timeInMicroseconds++,
1191 title: "I",
1192 isInQuery: true },
1193
1194 { isVisit: true,
1195 isDetails: true,
1196 uri: "http://moz.com/",
1197 lastVisit: timeInMicroseconds++,
1198 title: "I",
1199 isInQuery: true },
1200
1201 { isVisit: true,
1202 isDetails: true,
1203 uri: "http://moz.com/",
1204 lastVisit: timeInMicroseconds++,
1205 title: "I",
1206 isInQuery: true },
1207
1208 { isVisit: true,
1209 isDetails: true,
1210 uri: "http://is.com/",
1211 lastVisit: timeInMicroseconds++,
1212 title: "love",
1213 isInQuery: true },
1214
1215 { isVisit: true,
1216 isDetails: true,
1217 uri: "http://best.com/",
1218 lastVisit: timeInMicroseconds++,
1219 title: "moz",
1220 isInQuery: true },
1221
1222 { isVisit: true,
1223 isDetails: true,
1224 uri: "http://best.com/",
1225 lastVisit: timeInMicroseconds++,
1226 title: "moz",
1227 isInQuery: true },
1228 ];
1229
1230 this._sortedData = [
1231 this._unsortedData[3],
1232 this._unsortedData[5],
1233 this._unsortedData[2],
1234 ];
1235
1236 // This function in head_queries.js creates our database with the above data
1237 yield task_populateDB(this._unsortedData);
1238 },
1239
1240 check: function() {
1241 var query = PlacesUtils.history.getNewQuery();
1242 var options = PlacesUtils.history.getNewQueryOptions();
1243 options.sortingMode = this._sortingMode;
1244
1245 var root = PlacesUtils.history.executeQuery(query, options).root;
1246 root.containerOpen = true;
1247 compareArrayToResult(this._sortedData, root);
1248 root.containerOpen = false;
1249 },
1250
1251 check_reverse: function() {
1252 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_DESCENDING;
1253 this._sortedData.reverse();
1254 this.check();
1255 }
1256 });
1257
1258 ////////////////////////////////////////////////////////////////////////////////
1259
1260 function run_test()
1261 {
1262 run_next_test();
1263 }
1264
1265 add_task(function test_sorting()
1266 {
1267 for (let [, test] in Iterator(tests)) {
1268 yield test.setup();
1269 yield promiseAsyncUpdates();
1270 test.check();
1271 // sorting reversed, usually SORT_BY have ASC and DESC
1272 test.check_reverse();
1273 // Execute cleanup tasks
1274 remove_all_bookmarks();
1275 yield promiseClearHistory();
1276 }
1277 });

mercurial