michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const TOTAL_SITES = 20; michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_execute() michael@0: { michael@0: let places = []; michael@0: for (let i = 0; i < TOTAL_SITES; i++) { michael@0: for (let j = 0; j <= i; j++) { michael@0: places.push({ uri: uri("http://www.test-" + i + ".com/"), michael@0: transition: TRANSITION_TYPED }); michael@0: // because these are embedded visits, they should not show up on our michael@0: // query results. If they do, we have a problem. michael@0: places.push({ uri: uri("http://www.hidden.com/hidden.gif"), michael@0: transition: TRANSITION_EMBED }); michael@0: places.push({ uri: uri("http://www.alsohidden.com/hidden.gif"), michael@0: transition: TRANSITION_FRAMED_LINK }); michael@0: } michael@0: } michael@0: yield promiseAddVisits(places); michael@0: michael@0: // test our optimized query for the "Most Visited" item michael@0: // in the "Smart Bookmarks" folder michael@0: // place:queryType=0&sort=8&maxResults=10 michael@0: // verify our visits AS_URI, ordered by visit count descending michael@0: // we should get 10 visits: michael@0: // http://www.test-19.com/ michael@0: // ... michael@0: // http://www.test-10.com/ michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING; michael@0: options.maxResults = 10; michael@0: options.resultType = options.RESULTS_AS_URI; michael@0: let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), michael@0: options).root; michael@0: root.containerOpen = true; michael@0: let cc = root.childCount; michael@0: do_check_eq(cc, options.maxResults); michael@0: for (let i = 0; i < cc; i++) { michael@0: let node = root.getChild(i); michael@0: let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; michael@0: do_check_eq(node.uri, site); michael@0: do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); michael@0: } michael@0: root.containerOpen = false; michael@0: michael@0: // test without a maxResults, which executes a different query michael@0: // but the first 10 results should be the same. michael@0: // verify our visits AS_URI, ordered by visit count descending michael@0: // we should get 20 visits, but the first 10 should be michael@0: // http://www.test-19.com/ michael@0: // ... michael@0: // http://www.test-10.com/ michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING; michael@0: options.resultType = options.RESULTS_AS_URI; michael@0: let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), michael@0: options).root; michael@0: root.containerOpen = true; michael@0: let cc = root.childCount; michael@0: do_check_eq(cc, TOTAL_SITES); michael@0: for (let i = 0; i < 10; i++) { michael@0: let node = root.getChild(i); michael@0: let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; michael@0: do_check_eq(node.uri, site); michael@0: do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); michael@0: } michael@0: root.containerOpen = false; michael@0: });