toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:18f132050c3a
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5 // This is a test for asyncExecuteLegacyQueries API.
6
7 let tests = [
8
9 function test_history_query() {
10 let uri = NetUtil.newURI("http://test.visit.mozilla.com/");
11 let title = "Test visit";
12 promiseAddVisits({ uri: uri, title: title }).then(function () {
13 let options = PlacesUtils.history.getNewQueryOptions();
14 options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
15 let query = PlacesUtils.history.getNewQuery();
16
17 PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
18 .asyncExecuteLegacyQueries([query], 1, options, {
19 handleResult: function (aResultSet) {
20 for (let row; (row = aResultSet.getNextRow());) {
21 try {
22 do_check_eq(row.getResultByIndex(1), uri.spec);
23 do_check_eq(row.getResultByIndex(2), title);
24 } catch (e) {
25 do_throw("Error while fetching page data.");
26 }
27 }
28 },
29 handleError: function (aError) {
30 do_throw("Async execution error (" + aError.result + "): " + aError.message);
31 },
32 handleCompletion: function (aReason) {
33 run_next_test();
34 },
35 });
36 });
37 },
38
39 function test_bookmarks_query() {
40 let uri = NetUtil.newURI("http://test.bookmark.mozilla.com/");
41 let title = "Test bookmark";
42 bookmark(uri, title);
43 let options = PlacesUtils.history.getNewQueryOptions();
44 options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_LASMODIFIED_DESCENDING;
45 options.queryType = options.QUERY_TYPE_BOOKMARKS;
46 let query = PlacesUtils.history.getNewQuery();
47
48 PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
49 .asyncExecuteLegacyQueries([query], 1, options, {
50 handleResult: function (aResultSet) {
51 for (let row; (row = aResultSet.getNextRow());) {
52 try {
53 do_check_eq(row.getResultByIndex(1), uri.spec);
54 do_check_eq(row.getResultByIndex(2), title);
55 } catch (e) {
56 do_throw("Error while fetching page data.");
57 }
58 }
59 },
60 handleError: function (aError) {
61 do_throw("Async execution error (" + aError.result + "): " + aError.message);
62 },
63 handleCompletion: function (aReason) {
64 run_next_test();
65 },
66 });
67 },
68
69 ];
70
71 function bookmark(aURI, aTitle)
72 {
73 PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
74 aURI,
75 PlacesUtils.bookmarks.DEFAULT_INDEX,
76 aTitle);
77 }
78
79 function run_test()
80 {
81 do_test_pending();
82 run_next_test();
83 }
84
85 function run_next_test() {
86 if (tests.length == 0) {
87 do_test_finished();
88 return;
89 }
90
91 let test = tests.shift();
92 promiseClearHistory().then(function() {
93 remove_all_bookmarks();
94 do_execute_soon(test);
95 });
96 }

mercurial