1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// This is a test for asyncExecuteLegacyQueries API. 1.9 + 1.10 +let tests = [ 1.11 + 1.12 +function test_history_query() { 1.13 + let uri = NetUtil.newURI("http://test.visit.mozilla.com/"); 1.14 + let title = "Test visit"; 1.15 + promiseAddVisits({ uri: uri, title: title }).then(function () { 1.16 + let options = PlacesUtils.history.getNewQueryOptions(); 1.17 + options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING; 1.18 + let query = PlacesUtils.history.getNewQuery(); 1.19 + 1.20 + PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase) 1.21 + .asyncExecuteLegacyQueries([query], 1, options, { 1.22 + handleResult: function (aResultSet) { 1.23 + for (let row; (row = aResultSet.getNextRow());) { 1.24 + try { 1.25 + do_check_eq(row.getResultByIndex(1), uri.spec); 1.26 + do_check_eq(row.getResultByIndex(2), title); 1.27 + } catch (e) { 1.28 + do_throw("Error while fetching page data."); 1.29 + } 1.30 + } 1.31 + }, 1.32 + handleError: function (aError) { 1.33 + do_throw("Async execution error (" + aError.result + "): " + aError.message); 1.34 + }, 1.35 + handleCompletion: function (aReason) { 1.36 + run_next_test(); 1.37 + }, 1.38 + }); 1.39 + }); 1.40 +}, 1.41 + 1.42 +function test_bookmarks_query() { 1.43 + let uri = NetUtil.newURI("http://test.bookmark.mozilla.com/"); 1.44 + let title = "Test bookmark"; 1.45 + bookmark(uri, title); 1.46 + let options = PlacesUtils.history.getNewQueryOptions(); 1.47 + options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_LASMODIFIED_DESCENDING; 1.48 + options.queryType = options.QUERY_TYPE_BOOKMARKS; 1.49 + let query = PlacesUtils.history.getNewQuery(); 1.50 + 1.51 + PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase) 1.52 + .asyncExecuteLegacyQueries([query], 1, options, { 1.53 + handleResult: function (aResultSet) { 1.54 + for (let row; (row = aResultSet.getNextRow());) { 1.55 + try { 1.56 + do_check_eq(row.getResultByIndex(1), uri.spec); 1.57 + do_check_eq(row.getResultByIndex(2), title); 1.58 + } catch (e) { 1.59 + do_throw("Error while fetching page data."); 1.60 + } 1.61 + } 1.62 + }, 1.63 + handleError: function (aError) { 1.64 + do_throw("Async execution error (" + aError.result + "): " + aError.message); 1.65 + }, 1.66 + handleCompletion: function (aReason) { 1.67 + run_next_test(); 1.68 + }, 1.69 + }); 1.70 +}, 1.71 + 1.72 +]; 1.73 + 1.74 +function bookmark(aURI, aTitle) 1.75 +{ 1.76 + PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.77 + aURI, 1.78 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.79 + aTitle); 1.80 +} 1.81 + 1.82 +function run_test() 1.83 +{ 1.84 + do_test_pending(); 1.85 + run_next_test(); 1.86 +} 1.87 + 1.88 +function run_next_test() { 1.89 + if (tests.length == 0) { 1.90 + do_test_finished(); 1.91 + return; 1.92 + } 1.93 + 1.94 + let test = tests.shift(); 1.95 + promiseClearHistory().then(function() { 1.96 + remove_all_bookmarks(); 1.97 + do_execute_soon(test); 1.98 + }); 1.99 +}