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