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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // This is a test for asyncExecuteLegacyQueries API.
     7 let tests = [
     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();
    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 },
    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();
    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 },
    69 ];
    71 function bookmark(aURI, aTitle)
    72 {
    73   PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    74                                        aURI,
    75                                        PlacesUtils.bookmarks.DEFAULT_INDEX,
    76                                        aTitle);
    77 }
    79 function run_test()
    80 {
    81   do_test_pending();
    82   run_next_test();
    83 }
    85 function run_next_test() {
    86   if (tests.length == 0) {
    87     do_test_finished();
    88     return;
    89   }
    91   let test = tests.shift();
    92   promiseClearHistory().then(function() {
    93     remove_all_bookmarks();
    94     do_execute_soon(test);
    95   });
    96 }

mercurial