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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 places = [];
    17   for (let i = 0; i < TOTAL_SITES; i++) {
    18     for (let j = 0; j <= i; j++) {
    19       places.push({ uri: uri("http://www.test-" + i + ".com/"),
    20                     transition: TRANSITION_TYPED });
    21         // because these are embedded visits, they should not show up on our
    22         // query results.  If they do, we have a problem.
    23       places.push({ uri: uri("http://www.hidden.com/hidden.gif"),
    24                     transition: TRANSITION_EMBED });
    25       places.push({ uri: uri("http://www.alsohidden.com/hidden.gif"),
    26                     transition: TRANSITION_FRAMED_LINK });
    27     }
    28   }
    29   yield promiseAddVisits(places);
    31   // test our optimized query for the "Most Visited" item
    32   // in the "Smart Bookmarks" folder
    33   // place:queryType=0&sort=8&maxResults=10
    34   // verify our visits AS_URI, ordered by visit count descending
    35   // we should get 10 visits:
    36   // http://www.test-19.com/
    37   // ...
    38   // http://www.test-10.com/
    39   let options = PlacesUtils.history.getNewQueryOptions();
    40   options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
    41   options.maxResults = 10;
    42   options.resultType = options.RESULTS_AS_URI;
    43   let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(),
    44                                               options).root;
    45   root.containerOpen = true;
    46   let cc = root.childCount;
    47   do_check_eq(cc, options.maxResults);
    48   for (let i = 0; i < cc; i++) {
    49     let node = root.getChild(i);
    50     let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/";
    51     do_check_eq(node.uri, site);
    52     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
    53   }
    54   root.containerOpen = false;
    56   // test without a maxResults, which executes a different query
    57   // but the first 10 results should be the same.
    58   // verify our visits AS_URI, ordered by visit count descending
    59   // we should get 20 visits, but the first 10 should be
    60   // http://www.test-19.com/
    61   // ...
    62   // http://www.test-10.com/
    63   let options = PlacesUtils.history.getNewQueryOptions();
    64   options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
    65   options.resultType = options.RESULTS_AS_URI;
    66   let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(),
    67                                               options).root;
    68   root.containerOpen = true;
    69   let cc = root.childCount;
    70   do_check_eq(cc, TOTAL_SITES);
    71   for (let i = 0; i < 10; i++) {
    72     let node = root.getChild(i);
    73     let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/";
    74     do_check_eq(node.uri, site);
    75     do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
    76   }
    77   root.containerOpen = false;
    78 });

mercurial