Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
7 var tests = [];
9 ////////////////////////////////////////////////////////////////////////////////
11 tests.push({
12 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_NONE,
14 setup: function() {
15 LOG("Sorting test 1: SORT BY NONE");
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 },
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 },
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 ];
43 this._sortedData = this._unsortedData;
45 // This function in head_queries.js creates our database with the above data
46 yield task_populateDB(this._unsortedData);
47 },
49 check: function() {
50 // Query
51 var query = PlacesUtils.history.getNewQuery();
52 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
53 query.onlyBookmarked = true;
55 // query options
56 var options = PlacesUtils.history.getNewQueryOptions();
57 options.sortingMode = this._sortingMode;
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 },
67 check_reverse: function() {
68 // no reverse sorting for SORT BY NONE
69 }
70 });
72 ////////////////////////////////////////////////////////////////////////////////
74 tests.push({
75 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_ASCENDING,
77 setup: function() {
78 LOG("Sorting test 2: SORT BY TITLE");
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 },
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 },
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 },
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 ];
111 this._sortedData = [
112 this._unsortedData[2],
113 this._unsortedData[0],
114 this._unsortedData[3],
115 this._unsortedData[1],
116 ];
118 // This function in head_queries.js creates our database with the above data
119 yield task_populateDB(this._unsortedData);
120 },
122 check: function() {
123 // Query
124 var query = PlacesUtils.history.getNewQuery();
125 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
126 query.onlyBookmarked = true;
128 // query options
129 var options = PlacesUtils.history.getNewQueryOptions();
130 options.sortingMode = this._sortingMode;
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 },
140 check_reverse: function() {
141 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_DESCENDING;
142 this._sortedData.reverse();
143 this.check();
144 }
145 });
147 ////////////////////////////////////////////////////////////////////////////////
149 tests.push({
150 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_ASCENDING,
152 setup: function() {
153 LOG("Sorting test 3: SORT BY DATE");
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 },
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 },
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 },
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 },
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 ];
210 this._sortedData = [
211 this._unsortedData[2],
212 this._unsortedData[0],
213 this._unsortedData[3],
214 this._unsortedData[4],
215 this._unsortedData[1],
216 ];
218 // This function in head_queries.js creates our database with the above data
219 yield task_populateDB(this._unsortedData);
220 },
222 check: function() {
223 // Query
224 var query = PlacesUtils.history.getNewQuery();
225 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
226 query.onlyBookmarked = true;
228 // query options
229 var options = PlacesUtils.history.getNewQueryOptions();
230 options.sortingMode = this._sortingMode;
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 },
240 check_reverse: function() {
241 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
242 this._sortedData.reverse();
243 this.check();
244 }
245 });
247 ////////////////////////////////////////////////////////////////////////////////
249 tests.push({
250 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_URI_ASCENDING,
252 setup: function() {
253 LOG("Sorting test 4: SORT BY URI");
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 },
266 { isBookmark: true,
267 uri: "http://example.com/c",
268 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
269 index: 1,
270 title: "x",
271 isInQuery: true },
273 { isBookmark: true,
274 uri: "http://example.com/a",
275 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
276 index: 2,
277 title: "z",
278 isInQuery: true },
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 },
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 },
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 },
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 ];
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 ];
325 // This function in head_queries.js creates our database with the above data
326 yield task_populateDB(this._unsortedData);
327 },
329 check: function() {
330 // Query
331 var query = PlacesUtils.history.getNewQuery();
332 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
334 // query options
335 var options = PlacesUtils.history.getNewQueryOptions();
336 options.sortingMode = this._sortingMode;
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 },
346 check_reverse: function() {
347 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_URI_DESCENDING;
348 this._sortedData.reverse();
349 this.check();
350 }
351 });
353 ////////////////////////////////////////////////////////////////////////////////
355 tests.push({
356 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_ASCENDING,
358 setup: function() {
359 LOG("Sorting test 5: SORT BY VISITCOUNT");
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 },
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 },
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 },
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 },
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 ];
406 this._sortedData = [
407 this._unsortedData[0],
408 this._unsortedData[2],
409 this._unsortedData[3],
410 this._unsortedData[4],
411 this._unsortedData[1],
412 ];
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 },
429 check: function() {
430 // Query
431 var query = PlacesUtils.history.getNewQuery();
432 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
433 query.onlyBookmarked = true;
435 // query options
436 var options = PlacesUtils.history.getNewQueryOptions();
437 options.sortingMode = this._sortingMode;
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 },
447 check_reverse: function() {
448 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING;
449 this._sortedData.reverse();
450 this.check();
451 }
452 });
454 ////////////////////////////////////////////////////////////////////////////////
456 tests.push({
457 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_KEYWORD_ASCENDING,
459 setup: function() {
460 LOG("Sorting test 6: SORT BY KEYWORD");
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 },
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 },
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 },
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 },
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 },
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 ];
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 ];
524 // This function in head_queries.js creates our database with the above data
525 yield task_populateDB(this._unsortedData);
526 },
528 check: function() {
529 // Query
530 var query = PlacesUtils.history.getNewQuery();
531 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
532 query.onlyBookmarked = true;
534 // query options
535 var options = PlacesUtils.history.getNewQueryOptions();
536 options.sortingMode = this._sortingMode;
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 },
546 check_reverse: function() {
547 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_KEYWORD_DESCENDING;
548 this._sortedData.reverse();
549 this.check();
550 }
551 });
553 ////////////////////////////////////////////////////////////////////////////////
555 tests.push({
556 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_ASCENDING,
558 setup: function() {
559 LOG("Sorting test 7: SORT BY DATEADDED");
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 },
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 },
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 },
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 },
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 ];
606 this._sortedData = [
607 this._unsortedData[1],
608 this._unsortedData[0],
609 this._unsortedData[3],
610 this._unsortedData[4],
611 this._unsortedData[2],
612 ];
614 // This function in head_queries.js creates our database with the above data
615 yield task_populateDB(this._unsortedData);
616 },
618 check: function() {
619 // Query
620 var query = PlacesUtils.history.getNewQuery();
621 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
622 query.onlyBookmarked = true;
624 // query options
625 var options = PlacesUtils.history.getNewQueryOptions();
626 options.sortingMode = this._sortingMode;
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 },
636 check_reverse: function() {
637 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING;
638 this._sortedData.reverse();
639 this.check();
640 }
641 });
643 ////////////////////////////////////////////////////////////////////////////////
645 tests.push({
646 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_ASCENDING,
648 setup: function() {
649 LOG("Sorting test 8: SORT BY LASTMODIFIED");
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 },
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 },
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 },
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 },
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 ];
697 this._sortedData = [
698 this._unsortedData[1],
699 this._unsortedData[0],
700 this._unsortedData[3],
701 this._unsortedData[4],
702 this._unsortedData[2],
703 ];
705 // This function in head_queries.js creates our database with the above data
706 yield task_populateDB(this._unsortedData);
707 },
709 check: function() {
710 // Query
711 var query = PlacesUtils.history.getNewQuery();
712 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
713 query.onlyBookmarked = true;
715 // query options
716 var options = PlacesUtils.history.getNewQueryOptions();
717 options.sortingMode = this._sortingMode;
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 },
727 check_reverse: function() {
728 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_DESCENDING;
729 this._sortedData.reverse();
730 this.check();
731 }
732 });
734 ////////////////////////////////////////////////////////////////////////////////
736 tests.push({
737 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_ASCENDING,
739 setup: function() {
740 LOG("Sorting test 9: SORT BY TAGS");
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 },
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 },
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 },
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 },
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 },
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 ];
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 ];
805 // This function in head_queries.js creates our database with the above data
806 yield task_populateDB(this._unsortedData);
807 },
809 check: function() {
810 // Query
811 var query = PlacesUtils.history.getNewQuery();
812 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
813 query.onlyBookmarked = true;
815 // query options
816 var options = PlacesUtils.history.getNewQueryOptions();
817 options.sortingMode = this._sortingMode;
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 },
827 check_reverse: function() {
828 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_DESCENDING;
829 this._sortedData.reverse();
830 this.check();
831 }
832 });
834 ////////////////////////////////////////////////////////////////////////////////
835 // SORT_BY_ANNOTATION_* (int32)
837 tests.push({
838 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
840 setup: function() {
841 LOG("Sorting test 10: SORT BY ANNOTATION (int32)");
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 },
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 },
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 },
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 ];
895 this._sortedData = [
896 this._unsortedData[1],
897 this._unsortedData[0],
898 this._unsortedData[3],
899 this._unsortedData[2],
900 ];
902 // This function in head_queries.js creates our database with the above data
903 yield task_populateDB(this._unsortedData);
904 },
906 check: function() {
907 // Query
908 var query = PlacesUtils.history.getNewQuery();
910 // query options
911 var options = PlacesUtils.history.getNewQueryOptions();
912 options.sortingAnnotation = "sorting";
913 options.sortingMode = this._sortingMode;
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 },
923 check_reverse: function() {
924 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
925 this._sortedData.reverse();
926 this.check();
927 }
928 });
930 ////////////////////////////////////////////////////////////////////////////////
931 // SORT_BY_ANNOTATION_* (int64)
933 tests.push({
934 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
936 setup: function() {
937 LOG("Sorting test 11: SORT BY ANNOTATION (int64)");
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 },
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 },
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 ];
978 this._sortedData = [
979 this._unsortedData[1],
980 this._unsortedData[0],
981 this._unsortedData[2],
982 ];
984 // This function in head_queries.js creates our database with the above data
985 yield task_populateDB(this._unsortedData);
986 },
988 check: function() {
989 // Query
990 var query = PlacesUtils.history.getNewQuery();
992 // query options
993 var options = PlacesUtils.history.getNewQueryOptions();
994 options.sortingAnnotation = "sorting";
995 options.sortingMode = this._sortingMode;
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 },
1005 check_reverse: function() {
1006 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
1007 this._sortedData.reverse();
1008 this.check();
1009 }
1010 });
1012 ////////////////////////////////////////////////////////////////////////////////
1013 // SORT_BY_ANNOTATION_* (string)
1015 tests.push({
1016 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
1018 setup: function() {
1019 LOG("Sorting test 12: SORT BY ANNOTATION (string)");
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 },
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 },
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 ];
1060 this._sortedData = [
1061 this._unsortedData[1],
1062 this._unsortedData[0],
1063 this._unsortedData[2],
1064 ];
1066 // This function in head_queries.js creates our database with the above data
1067 yield task_populateDB(this._unsortedData);
1068 },
1070 check: function() {
1071 // Query
1072 var query = PlacesUtils.history.getNewQuery();
1074 // query options
1075 var options = PlacesUtils.history.getNewQueryOptions();
1076 options.sortingAnnotation = "sorting";
1077 options.sortingMode = this._sortingMode;
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 },
1087 check_reverse: function() {
1088 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
1089 this._sortedData.reverse();
1090 this.check();
1091 }
1092 });
1094 ////////////////////////////////////////////////////////////////////////////////
1095 // SORT_BY_ANNOTATION_* (double)
1097 tests.push({
1098 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
1100 setup: function() {
1101 LOG("Sorting test 13: SORT BY ANNOTATION (double)");
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 },
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 },
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 ];
1142 this._sortedData = [
1143 this._unsortedData[1],
1144 this._unsortedData[0],
1145 this._unsortedData[2],
1146 ];
1148 // This function in head_queries.js creates our database with the above data
1149 yield task_populateDB(this._unsortedData);
1150 },
1152 check: function() {
1153 // Query
1154 var query = PlacesUtils.history.getNewQuery();
1156 // query options
1157 var options = PlacesUtils.history.getNewQueryOptions();
1158 options.sortingAnnotation = "sorting";
1159 options.sortingMode = this._sortingMode;
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 },
1169 check_reverse: function() {
1170 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
1171 this._sortedData.reverse();
1172 this.check();
1173 }
1174 });
1176 ////////////////////////////////////////////////////////////////////////////////
1177 // SORT_BY_FRECENCY_*
1179 tests.push({
1180 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_ASCENDING,
1182 setup: function() {
1183 LOG("Sorting test 13: SORT BY FRECENCY ");
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 },
1194 { isVisit: true,
1195 isDetails: true,
1196 uri: "http://moz.com/",
1197 lastVisit: timeInMicroseconds++,
1198 title: "I",
1199 isInQuery: true },
1201 { isVisit: true,
1202 isDetails: true,
1203 uri: "http://moz.com/",
1204 lastVisit: timeInMicroseconds++,
1205 title: "I",
1206 isInQuery: true },
1208 { isVisit: true,
1209 isDetails: true,
1210 uri: "http://is.com/",
1211 lastVisit: timeInMicroseconds++,
1212 title: "love",
1213 isInQuery: true },
1215 { isVisit: true,
1216 isDetails: true,
1217 uri: "http://best.com/",
1218 lastVisit: timeInMicroseconds++,
1219 title: "moz",
1220 isInQuery: true },
1222 { isVisit: true,
1223 isDetails: true,
1224 uri: "http://best.com/",
1225 lastVisit: timeInMicroseconds++,
1226 title: "moz",
1227 isInQuery: true },
1228 ];
1230 this._sortedData = [
1231 this._unsortedData[3],
1232 this._unsortedData[5],
1233 this._unsortedData[2],
1234 ];
1236 // This function in head_queries.js creates our database with the above data
1237 yield task_populateDB(this._unsortedData);
1238 },
1240 check: function() {
1241 var query = PlacesUtils.history.getNewQuery();
1242 var options = PlacesUtils.history.getNewQueryOptions();
1243 options.sortingMode = this._sortingMode;
1245 var root = PlacesUtils.history.executeQuery(query, options).root;
1246 root.containerOpen = true;
1247 compareArrayToResult(this._sortedData, root);
1248 root.containerOpen = false;
1249 },
1251 check_reverse: function() {
1252 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_DESCENDING;
1253 this._sortedData.reverse();
1254 this.check();
1255 }
1256 });
1258 ////////////////////////////////////////////////////////////////////////////////
1260 function run_test()
1261 {
1262 run_next_test();
1263 }
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 });