1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_399266.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +const TOTAL_SITES = 20; 1.11 + 1.12 +function run_test() 1.13 +{ 1.14 + run_next_test(); 1.15 +} 1.16 + 1.17 +add_task(function test_execute() 1.18 +{ 1.19 + let places = []; 1.20 + for (let i = 0; i < TOTAL_SITES; i++) { 1.21 + for (let j = 0; j <= i; j++) { 1.22 + places.push({ uri: uri("http://www.test-" + i + ".com/"), 1.23 + transition: TRANSITION_TYPED }); 1.24 + // because these are embedded visits, they should not show up on our 1.25 + // query results. If they do, we have a problem. 1.26 + places.push({ uri: uri("http://www.hidden.com/hidden.gif"), 1.27 + transition: TRANSITION_EMBED }); 1.28 + places.push({ uri: uri("http://www.alsohidden.com/hidden.gif"), 1.29 + transition: TRANSITION_FRAMED_LINK }); 1.30 + } 1.31 + } 1.32 + yield promiseAddVisits(places); 1.33 + 1.34 + // test our optimized query for the "Most Visited" item 1.35 + // in the "Smart Bookmarks" folder 1.36 + // place:queryType=0&sort=8&maxResults=10 1.37 + // verify our visits AS_URI, ordered by visit count descending 1.38 + // we should get 10 visits: 1.39 + // http://www.test-19.com/ 1.40 + // ... 1.41 + // http://www.test-10.com/ 1.42 + let options = PlacesUtils.history.getNewQueryOptions(); 1.43 + options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING; 1.44 + options.maxResults = 10; 1.45 + options.resultType = options.RESULTS_AS_URI; 1.46 + let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), 1.47 + options).root; 1.48 + root.containerOpen = true; 1.49 + let cc = root.childCount; 1.50 + do_check_eq(cc, options.maxResults); 1.51 + for (let i = 0; i < cc; i++) { 1.52 + let node = root.getChild(i); 1.53 + let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; 1.54 + do_check_eq(node.uri, site); 1.55 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.56 + } 1.57 + root.containerOpen = false; 1.58 + 1.59 + // test without a maxResults, which executes a different query 1.60 + // but the first 10 results should be the same. 1.61 + // verify our visits AS_URI, ordered by visit count descending 1.62 + // we should get 20 visits, but the first 10 should be 1.63 + // http://www.test-19.com/ 1.64 + // ... 1.65 + // http://www.test-10.com/ 1.66 + let options = PlacesUtils.history.getNewQueryOptions(); 1.67 + options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING; 1.68 + options.resultType = options.RESULTS_AS_URI; 1.69 + let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), 1.70 + options).root; 1.71 + root.containerOpen = true; 1.72 + let cc = root.childCount; 1.73 + do_check_eq(cc, TOTAL_SITES); 1.74 + for (let i = 0; i < 10; i++) { 1.75 + let node = root.getChild(i); 1.76 + let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; 1.77 + do_check_eq(node.uri, site); 1.78 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.79 + } 1.80 + root.containerOpen = false; 1.81 +});