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 now = Date.now() * 1000; michael@0: michael@0: for (let i = 0; i < TOTAL_SITES; i++) { michael@0: let site = "http://www.test-" + i + ".com/"; michael@0: let testURI = uri(site); michael@0: let testImageURI = uri(site + "blank.gif"); michael@0: let when = now + (i * TOTAL_SITES); michael@0: yield promiseAddVisits([ michael@0: { uri: testURI, visitDate: when, transition: TRANSITION_TYPED }, michael@0: { uri: testImageURI, visitDate: ++when, transition: TRANSITION_EMBED }, michael@0: { uri: testImageURI, visitDate: ++when, transition: TRANSITION_FRAMED_LINK }, michael@0: { uri: testURI, visitDate: ++when, transition: TRANSITION_LINK }, michael@0: ]); michael@0: } michael@0: michael@0: // verify our visits AS_VISIT, ordered by date descending michael@0: // including hidden michael@0: // we should get 80 visits: michael@0: // http://www.test-19.com/ michael@0: // http://www.test-19.com/blank.gif michael@0: // http://www.test-19.com/ michael@0: // http://www.test-19.com/ michael@0: // ... michael@0: // http://www.test-0.com/ michael@0: // http://www.test-0.com/blank.gif michael@0: // http://www.test-0.com/ michael@0: // http://www.test-0.com/ michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.sortingMode = options.SORT_BY_DATE_DESCENDING; michael@0: options.resultType = options.RESULTS_AS_VISIT; michael@0: options.includeHidden = true; 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: // Embed visits are not added to the database, thus they won't appear. michael@0: do_check_eq(cc, 3 * TOTAL_SITES); michael@0: for (let i = 0; i < TOTAL_SITES; i++) { michael@0: let index = i * 3; michael@0: let node = root.getChild(index); 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: node = root.getChild(++index); michael@0: do_check_eq(node.uri, site + "blank.gif"); michael@0: do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); michael@0: node = root.getChild(++index); 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: // verify our visits AS_VISIT, ordered by date descending michael@0: // we should get 40 visits: michael@0: // http://www.test-19.com/ michael@0: // http://www.test-19.com/ michael@0: // ... michael@0: // http://www.test-0.com/ michael@0: // http://www.test-0.com/ michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.sortingMode = options.SORT_BY_DATE_DESCENDING; michael@0: options.resultType = options.RESULTS_AS_VISIT; 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: // 2 * TOTAL_SITES because we count the TYPED and LINK, but not EMBED or FRAMED michael@0: do_check_eq(cc, 2 * TOTAL_SITES); michael@0: for (let i=0; i < TOTAL_SITES; i++) { michael@0: let index = i * 2; michael@0: let node = root.getChild(index); 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: node = root.getChild(++index); 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 our optimized query for the places menu michael@0: // place:type=0&sort=4&maxResults=10 michael@0: // verify our visits AS_URI, ordered by date 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_DATE_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 date 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_DATE_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: });