michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // This is a test for asyncExecuteLegacyQueries API. michael@0: michael@0: let tests = [ michael@0: michael@0: function test_history_query() { michael@0: let uri = NetUtil.newURI("http://test.visit.mozilla.com/"); michael@0: let title = "Test visit"; michael@0: promiseAddVisits({ uri: uri, title: title }).then(function () { michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING; michael@0: let query = PlacesUtils.history.getNewQuery(); michael@0: michael@0: PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase) michael@0: .asyncExecuteLegacyQueries([query], 1, options, { michael@0: handleResult: function (aResultSet) { michael@0: for (let row; (row = aResultSet.getNextRow());) { michael@0: try { michael@0: do_check_eq(row.getResultByIndex(1), uri.spec); michael@0: do_check_eq(row.getResultByIndex(2), title); michael@0: } catch (e) { michael@0: do_throw("Error while fetching page data."); michael@0: } michael@0: } michael@0: }, michael@0: handleError: function (aError) { michael@0: do_throw("Async execution error (" + aError.result + "): " + aError.message); michael@0: }, michael@0: handleCompletion: function (aReason) { michael@0: run_next_test(); michael@0: }, michael@0: }); michael@0: }); michael@0: }, michael@0: michael@0: function test_bookmarks_query() { michael@0: let uri = NetUtil.newURI("http://test.bookmark.mozilla.com/"); michael@0: let title = "Test bookmark"; michael@0: bookmark(uri, title); michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_LASMODIFIED_DESCENDING; michael@0: options.queryType = options.QUERY_TYPE_BOOKMARKS; michael@0: let query = PlacesUtils.history.getNewQuery(); michael@0: michael@0: PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase) michael@0: .asyncExecuteLegacyQueries([query], 1, options, { michael@0: handleResult: function (aResultSet) { michael@0: for (let row; (row = aResultSet.getNextRow());) { michael@0: try { michael@0: do_check_eq(row.getResultByIndex(1), uri.spec); michael@0: do_check_eq(row.getResultByIndex(2), title); michael@0: } catch (e) { michael@0: do_throw("Error while fetching page data."); michael@0: } michael@0: } michael@0: }, michael@0: handleError: function (aError) { michael@0: do_throw("Async execution error (" + aError.result + "): " + aError.message); michael@0: }, michael@0: handleCompletion: function (aReason) { michael@0: run_next_test(); michael@0: }, michael@0: }); michael@0: }, michael@0: michael@0: ]; michael@0: michael@0: function bookmark(aURI, aTitle) michael@0: { michael@0: PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: aURI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: aTitle); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: do_test_pending(); michael@0: run_next_test(); michael@0: } michael@0: michael@0: function run_next_test() { michael@0: if (tests.length == 0) { michael@0: do_test_finished(); michael@0: return; michael@0: } michael@0: michael@0: let test = tests.shift(); michael@0: promiseClearHistory().then(function() { michael@0: remove_all_bookmarks(); michael@0: do_execute_soon(test); michael@0: }); michael@0: }