1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_385397.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,142 @@ 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 now = Date.now() * 1000; 1.20 + 1.21 + for (let i = 0; i < TOTAL_SITES; i++) { 1.22 + let site = "http://www.test-" + i + ".com/"; 1.23 + let testURI = uri(site); 1.24 + let testImageURI = uri(site + "blank.gif"); 1.25 + let when = now + (i * TOTAL_SITES); 1.26 + yield promiseAddVisits([ 1.27 + { uri: testURI, visitDate: when, transition: TRANSITION_TYPED }, 1.28 + { uri: testImageURI, visitDate: ++when, transition: TRANSITION_EMBED }, 1.29 + { uri: testImageURI, visitDate: ++when, transition: TRANSITION_FRAMED_LINK }, 1.30 + { uri: testURI, visitDate: ++when, transition: TRANSITION_LINK }, 1.31 + ]); 1.32 + } 1.33 + 1.34 + // verify our visits AS_VISIT, ordered by date descending 1.35 + // including hidden 1.36 + // we should get 80 visits: 1.37 + // http://www.test-19.com/ 1.38 + // http://www.test-19.com/blank.gif 1.39 + // http://www.test-19.com/ 1.40 + // http://www.test-19.com/ 1.41 + // ... 1.42 + // http://www.test-0.com/ 1.43 + // http://www.test-0.com/blank.gif 1.44 + // http://www.test-0.com/ 1.45 + // http://www.test-0.com/ 1.46 + let options = PlacesUtils.history.getNewQueryOptions(); 1.47 + options.sortingMode = options.SORT_BY_DATE_DESCENDING; 1.48 + options.resultType = options.RESULTS_AS_VISIT; 1.49 + options.includeHidden = true; 1.50 + let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), 1.51 + options).root; 1.52 + root.containerOpen = true; 1.53 + let cc = root.childCount; 1.54 + // Embed visits are not added to the database, thus they won't appear. 1.55 + do_check_eq(cc, 3 * TOTAL_SITES); 1.56 + for (let i = 0; i < TOTAL_SITES; i++) { 1.57 + let index = i * 3; 1.58 + let node = root.getChild(index); 1.59 + let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; 1.60 + do_check_eq(node.uri, site); 1.61 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.62 + node = root.getChild(++index); 1.63 + do_check_eq(node.uri, site + "blank.gif"); 1.64 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.65 + node = root.getChild(++index); 1.66 + do_check_eq(node.uri, site); 1.67 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.68 + } 1.69 + root.containerOpen = false; 1.70 + 1.71 + // verify our visits AS_VISIT, ordered by date descending 1.72 + // we should get 40 visits: 1.73 + // http://www.test-19.com/ 1.74 + // http://www.test-19.com/ 1.75 + // ... 1.76 + // http://www.test-0.com/ 1.77 + // http://www.test-0.com/ 1.78 + let options = PlacesUtils.history.getNewQueryOptions(); 1.79 + options.sortingMode = options.SORT_BY_DATE_DESCENDING; 1.80 + options.resultType = options.RESULTS_AS_VISIT; 1.81 + let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), 1.82 + options).root; 1.83 + root.containerOpen = true; 1.84 + let cc = root.childCount; 1.85 + // 2 * TOTAL_SITES because we count the TYPED and LINK, but not EMBED or FRAMED 1.86 + do_check_eq(cc, 2 * TOTAL_SITES); 1.87 + for (let i=0; i < TOTAL_SITES; i++) { 1.88 + let index = i * 2; 1.89 + let node = root.getChild(index); 1.90 + let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; 1.91 + do_check_eq(node.uri, site); 1.92 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.93 + node = root.getChild(++index); 1.94 + do_check_eq(node.uri, site); 1.95 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.96 + } 1.97 + root.containerOpen = false; 1.98 + 1.99 + // test our optimized query for the places menu 1.100 + // place:type=0&sort=4&maxResults=10 1.101 + // verify our visits AS_URI, ordered by date descending 1.102 + // we should get 10 visits: 1.103 + // http://www.test-19.com/ 1.104 + // ... 1.105 + // http://www.test-10.com/ 1.106 + let options = PlacesUtils.history.getNewQueryOptions(); 1.107 + options.sortingMode = options.SORT_BY_DATE_DESCENDING; 1.108 + options.maxResults = 10; 1.109 + options.resultType = options.RESULTS_AS_URI; 1.110 + let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), 1.111 + options).root; 1.112 + root.containerOpen = true; 1.113 + let cc = root.childCount; 1.114 + do_check_eq(cc, options.maxResults); 1.115 + for (let i=0; i < cc; i++) { 1.116 + let node = root.getChild(i); 1.117 + let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; 1.118 + do_check_eq(node.uri, site); 1.119 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.120 + } 1.121 + root.containerOpen = false; 1.122 + 1.123 + // test without a maxResults, which executes a different query 1.124 + // but the first 10 results should be the same. 1.125 + // verify our visits AS_URI, ordered by date descending 1.126 + // we should get 20 visits, but the first 10 should be 1.127 + // http://www.test-19.com/ 1.128 + // ... 1.129 + // http://www.test-10.com/ 1.130 + let options = PlacesUtils.history.getNewQueryOptions(); 1.131 + options.sortingMode = options.SORT_BY_DATE_DESCENDING; 1.132 + options.resultType = options.RESULTS_AS_URI; 1.133 + let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), 1.134 + options).root; 1.135 + root.containerOpen = true; 1.136 + let cc = root.childCount; 1.137 + do_check_eq(cc, TOTAL_SITES); 1.138 + for (let i=0; i < 10; i++) { 1.139 + let node = root.getChild(i); 1.140 + let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; 1.141 + do_check_eq(node.uri, site); 1.142 + do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); 1.143 + } 1.144 + root.containerOpen = false; 1.145 +});