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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 const TOTAL_SITES = 20;
michael@0 8
michael@0 9 function run_test()
michael@0 10 {
michael@0 11 run_next_test();
michael@0 12 }
michael@0 13
michael@0 14 add_task(function test_execute()
michael@0 15 {
michael@0 16 let places = [];
michael@0 17 for (let i = 0; i < TOTAL_SITES; i++) {
michael@0 18 for (let j = 0; j <= i; j++) {
michael@0 19 places.push({ uri: uri("http://www.test-" + i + ".com/"),
michael@0 20 transition: TRANSITION_TYPED });
michael@0 21 // because these are embedded visits, they should not show up on our
michael@0 22 // query results. If they do, we have a problem.
michael@0 23 places.push({ uri: uri("http://www.hidden.com/hidden.gif"),
michael@0 24 transition: TRANSITION_EMBED });
michael@0 25 places.push({ uri: uri("http://www.alsohidden.com/hidden.gif"),
michael@0 26 transition: TRANSITION_FRAMED_LINK });
michael@0 27 }
michael@0 28 }
michael@0 29 yield promiseAddVisits(places);
michael@0 30
michael@0 31 // test our optimized query for the "Most Visited" item
michael@0 32 // in the "Smart Bookmarks" folder
michael@0 33 // place:queryType=0&sort=8&maxResults=10
michael@0 34 // verify our visits AS_URI, ordered by visit count descending
michael@0 35 // we should get 10 visits:
michael@0 36 // http://www.test-19.com/
michael@0 37 // ...
michael@0 38 // http://www.test-10.com/
michael@0 39 let options = PlacesUtils.history.getNewQueryOptions();
michael@0 40 options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
michael@0 41 options.maxResults = 10;
michael@0 42 options.resultType = options.RESULTS_AS_URI;
michael@0 43 let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(),
michael@0 44 options).root;
michael@0 45 root.containerOpen = true;
michael@0 46 let cc = root.childCount;
michael@0 47 do_check_eq(cc, options.maxResults);
michael@0 48 for (let i = 0; i < cc; i++) {
michael@0 49 let node = root.getChild(i);
michael@0 50 let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/";
michael@0 51 do_check_eq(node.uri, site);
michael@0 52 do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
michael@0 53 }
michael@0 54 root.containerOpen = false;
michael@0 55
michael@0 56 // test without a maxResults, which executes a different query
michael@0 57 // but the first 10 results should be the same.
michael@0 58 // verify our visits AS_URI, ordered by visit count descending
michael@0 59 // we should get 20 visits, but the first 10 should be
michael@0 60 // http://www.test-19.com/
michael@0 61 // ...
michael@0 62 // http://www.test-10.com/
michael@0 63 let options = PlacesUtils.history.getNewQueryOptions();
michael@0 64 options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
michael@0 65 options.resultType = options.RESULTS_AS_URI;
michael@0 66 let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(),
michael@0 67 options).root;
michael@0 68 root.containerOpen = true;
michael@0 69 let cc = root.childCount;
michael@0 70 do_check_eq(cc, TOTAL_SITES);
michael@0 71 for (let i = 0; i < 10; i++) {
michael@0 72 let node = root.getChild(i);
michael@0 73 let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/";
michael@0 74 do_check_eq(node.uri, site);
michael@0 75 do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
michael@0 76 }
michael@0 77 root.containerOpen = false;
michael@0 78 });

mercurial