toolkit/components/places/tests/unit/test_385397.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 const TOTAL_SITES = 20;
     9 function run_test()
    10 {
    11   run_next_test();
    12 }
    14 add_task(function test_execute()
    15 {
    16   let now = Date.now() * 1000;
    18   for (let i = 0; i < TOTAL_SITES; i++) {
    19     let site = "http://www.test-" + i + ".com/";
    20     let testURI = uri(site);
    21     let testImageURI = uri(site + "blank.gif");
    22     let when = now + (i * TOTAL_SITES);
    23     yield promiseAddVisits([
    24       { uri: testURI, visitDate: when, transition: TRANSITION_TYPED },
    25       { uri: testImageURI, visitDate: ++when, transition: TRANSITION_EMBED },
    26       { uri: testImageURI, visitDate: ++when, transition: TRANSITION_FRAMED_LINK },
    27       { uri: testURI, visitDate: ++when, transition: TRANSITION_LINK },
    28     ]);
    29   }
    31   // verify our visits AS_VISIT, ordered by date descending
    32   // including hidden
    33   // we should get 80 visits:
    34   // http://www.test-19.com/
    35   // http://www.test-19.com/blank.gif
    36   // http://www.test-19.com/
    37   // http://www.test-19.com/
    38   // ...
    39   // http://www.test-0.com/
    40   // http://www.test-0.com/blank.gif
    41   // http://www.test-0.com/
    42   // http://www.test-0.com/
    43   let options = PlacesUtils.history.getNewQueryOptions();
    44   options.sortingMode = options.SORT_BY_DATE_DESCENDING;
    45   options.resultType = options.RESULTS_AS_VISIT;
    46   options.includeHidden = true;
    47   let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(),
    48                                               options).root;
    49   root.containerOpen = true;
    50   let cc = root.childCount;
    51   // Embed visits are not added to the database, thus they won't appear.
    52   do_check_eq(cc, 3 * TOTAL_SITES);
    53   for (let i = 0; i < TOTAL_SITES; i++) {
    54     let index = i * 3;
    55     let node = root.getChild(index);
    56     let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/";
    57     do_check_eq(node.uri, site);
    58     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
    59     node = root.getChild(++index);
    60     do_check_eq(node.uri, site + "blank.gif");
    61     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
    62     node = root.getChild(++index);
    63     do_check_eq(node.uri, site);
    64     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
    65   }
    66   root.containerOpen = false;
    68   // verify our visits AS_VISIT, ordered by date descending
    69   // we should get 40 visits:
    70   // http://www.test-19.com/
    71   // http://www.test-19.com/
    72   // ...
    73   // http://www.test-0.com/
    74   // http://www.test-0.com/
    75   let options = PlacesUtils.history.getNewQueryOptions();
    76   options.sortingMode = options.SORT_BY_DATE_DESCENDING;
    77   options.resultType = options.RESULTS_AS_VISIT;
    78   let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(),
    79                                               options).root;
    80   root.containerOpen = true;
    81   let cc = root.childCount;
    82   // 2 * TOTAL_SITES because we count the TYPED and LINK, but not EMBED or FRAMED
    83   do_check_eq(cc, 2 * TOTAL_SITES); 
    84   for (let i=0; i < TOTAL_SITES; i++) {
    85     let index = i * 2;
    86     let node = root.getChild(index);
    87     let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/";
    88     do_check_eq(node.uri, site);
    89     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
    90     node = root.getChild(++index);
    91     do_check_eq(node.uri, site);
    92     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
    93   }
    94   root.containerOpen = false;
    96   // test our optimized query for the places menu
    97   // place:type=0&sort=4&maxResults=10
    98   // verify our visits AS_URI, ordered by date descending
    99   // we should get 10 visits:
   100   // http://www.test-19.com/
   101   // ...
   102   // http://www.test-10.com/
   103   let options = PlacesUtils.history.getNewQueryOptions();
   104   options.sortingMode = options.SORT_BY_DATE_DESCENDING;
   105   options.maxResults = 10;
   106   options.resultType = options.RESULTS_AS_URI;
   107   let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(),
   108                                               options).root;
   109   root.containerOpen = true;
   110   let cc = root.childCount;
   111   do_check_eq(cc, options.maxResults);
   112   for (let i=0; i < cc; i++) {
   113     let node = root.getChild(i);
   114     let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/";
   115     do_check_eq(node.uri, site);
   116     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
   117   }
   118   root.containerOpen = false;
   120   // test without a maxResults, which executes a different query
   121   // but the first 10 results should be the same.
   122   // verify our visits AS_URI, ordered by date descending
   123   // we should get 20 visits, but the first 10 should be
   124   // http://www.test-19.com/
   125   // ...
   126   // http://www.test-10.com/
   127   let options = PlacesUtils.history.getNewQueryOptions();
   128   options.sortingMode = options.SORT_BY_DATE_DESCENDING;
   129   options.resultType = options.RESULTS_AS_URI;
   130   let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(),
   131                                               options).root;
   132   root.containerOpen = true;
   133   let cc = root.childCount;
   134   do_check_eq(cc, TOTAL_SITES);
   135   for (let i=0; i < 10; i++) {
   136     let node = root.getChild(i);
   137     let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/";
   138     do_check_eq(node.uri, site);
   139     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
   140   }
   141   root.containerOpen = false;
   142 });

mercurial