toolkit/components/places/tests/unit/test_454977.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 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 // Cache actual visit_count value, filled by add_visit, used by check_results
     8 let visit_count = 0;
    10 // Returns the Place ID corresponding to an added visit.
    11 function task_add_visit(aURI, aVisitType)
    12 {
    13   // Add the visit asynchronously, and save its visit ID.
    14   let deferUpdatePlaces = Promise.defer();
    15   PlacesUtils.asyncHistory.updatePlaces({
    16     uri: aURI,
    17     visits: [{ transitionType: aVisitType, visitDate: Date.now() * 1000 }]
    18   }, {
    19     handleError: function TAV_handleError() {
    20       deferUpdatePlaces.reject(new Error("Unexpected error in adding visit."));
    21     },
    22     handleResult: function (aPlaceInfo) {
    23       this.visitId = aPlaceInfo.visits[0].visitId;
    24     },
    25     handleCompletion: function TAV_handleCompletion() {
    26       deferUpdatePlaces.resolve(this.visitId);
    27     }
    28   });
    29   let visitId = yield deferUpdatePlaces.promise;
    31   // Increase visit_count if applicable
    32   if (aVisitType != 0 &&
    33       aVisitType != TRANSITION_EMBED &&
    34       aVisitType != TRANSITION_FRAMED_LINK &&
    35       aVisitType != TRANSITION_DOWNLOAD) {
    36     visit_count ++;
    37   }
    39   // Get the place id
    40   if (visitId > 0) {
    41     let sql = "SELECT place_id FROM moz_historyvisits WHERE id = ?1";
    42     let stmt = DBConn().createStatement(sql);
    43     stmt.bindByIndex(0, visitId);
    44     do_check_true(stmt.executeStep());
    45     let placeId = stmt.getInt64(0);
    46     stmt.finalize();
    47     do_check_true(placeId > 0);
    48     throw new Task.Result(placeId);
    49   }
    50   throw new Task.Result(0);
    51 }
    53 /**
    54  * Checks for results consistency, using visit_count as constraint
    55  * @param   aExpectedCount
    56  *          Number of history results we are expecting (excluded hidden ones)
    57  * @param   aExpectedCountWithHidden
    58  *          Number of history results we are expecting (included hidden ones)
    59  */
    60 function check_results(aExpectedCount, aExpectedCountWithHidden)
    61 {
    62   let query = PlacesUtils.history.getNewQuery();
    63   // used to check visit_count
    64   query.minVisits = visit_count;
    65   query.maxVisits = visit_count;
    66   let options = PlacesUtils.history.getNewQueryOptions();
    67   options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY;
    68   let root = PlacesUtils.history.executeQuery(query, options).root;
    69   root.containerOpen = true;
    70   // Children without hidden ones
    71   do_check_eq(root.childCount, aExpectedCount);
    72   root.containerOpen = false;
    74   // Execute again with includeHidden = true
    75   // This will ensure visit_count is correct
    76   options.includeHidden = true;
    77   root = PlacesUtils.history.executeQuery(query, options).root;
    78   root.containerOpen = true;
    79   // Children with hidden ones
    80   do_check_eq(root.childCount, aExpectedCountWithHidden);
    81   root.containerOpen = false;
    82 }
    84 // main
    85 function run_test()
    86 {
    87   run_next_test();
    88 }
    90 add_task(function test_execute()
    91 {
    92   const TEST_URI = uri("http://test.mozilla.org/");
    94   // Add a visit that force hidden
    95   yield task_add_visit(TEST_URI, TRANSITION_EMBED);
    96   check_results(0, 0);
    98   let placeId = yield task_add_visit(TEST_URI, TRANSITION_FRAMED_LINK);
    99   check_results(0, 1);
   101   // Add a visit that force unhide and check the place id.
   102   // - We expect that the place gets hidden = 0 while retaining the same
   103   //   place id and a correct visit_count.
   104   do_check_eq((yield task_add_visit(TEST_URI, TRANSITION_TYPED)), placeId);
   105   check_results(1, 1);
   107   // Add a visit, check that hidden is not overwritten
   108   // - We expect that the place has still hidden = 0, while retaining
   109   //   correct visit_count.
   110   yield task_add_visit(TEST_URI, TRANSITION_EMBED);
   111   check_results(1, 1);
   112 });

mercurial