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: function modHistoryTypes(val){ michael@0: switch(val % 8) { michael@0: case 0: michael@0: case 1: michael@0: return TRANSITION_LINK; michael@0: case 2: michael@0: return TRANSITION_TYPED; michael@0: case 3: michael@0: return TRANSITION_BOOKMARK; michael@0: case 4: michael@0: return TRANSITION_EMBED; michael@0: case 5: michael@0: return TRANSITION_REDIRECT_PERMANENT; michael@0: case 6: michael@0: return TRANSITION_REDIRECT_TEMPORARY; michael@0: case 7: michael@0: return TRANSITION_DOWNLOAD; michael@0: case 8: michael@0: return TRANSITION_FRAMED_LINK; michael@0: } michael@0: return TRANSITION_TYPED; michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: /** michael@0: * Builds a test database by hand using various times, annotations and michael@0: * visit numbers for this test michael@0: */ michael@0: add_task(function test_buildTestDatabase() michael@0: { michael@0: // This is the set of visits that we will match - our min visit is 2 so that's michael@0: // why we add more visits to the same URIs. michael@0: let testURI = uri("http://www.foo.com"); michael@0: let places = []; michael@0: michael@0: for (let i = 0; i < 12; ++i) { michael@0: places.push({ michael@0: uri: testURI, michael@0: transition: modHistoryTypes(i), michael@0: visitDate: today michael@0: }); michael@0: } michael@0: michael@0: testURI = uri("http://foo.com/youdontseeme.html"); michael@0: let testAnnoName = "moz-test-places/testing123"; michael@0: let testAnnoVal = "test"; michael@0: for (let i = 0; i < 12; ++i) { michael@0: places.push({ michael@0: uri: testURI, michael@0: transition: modHistoryTypes(i), michael@0: visitDate: today michael@0: }); michael@0: } michael@0: michael@0: yield promiseAddVisits(places); michael@0: michael@0: PlacesUtils.annotations.setPageAnnotation(testURI, testAnnoName, michael@0: testAnnoVal, 0, 0); michael@0: }); michael@0: michael@0: /** michael@0: * This test will test Queries that use relative Time Range, minVists, maxVisits, michael@0: * annotation. michael@0: * The Query: michael@0: * Annotation == "moz-test-places/testing123" && michael@0: * TimeRange == "now() - 2d" && michael@0: * minVisits == 2 && michael@0: * maxVisits == 10 michael@0: */ michael@0: add_task(function test_execute() michael@0: { michael@0: let query = PlacesUtils.history.getNewQuery(); michael@0: query.annotation = "moz-test-places/testing123"; michael@0: query.beginTime = daybefore * 1000; michael@0: query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_NOW; michael@0: query.endTime = today * 1000; michael@0: query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_NOW; michael@0: query.minVisits = 2; michael@0: query.maxVisits = 10; michael@0: michael@0: // Options 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: michael@0: // Results michael@0: let root = PlacesUtils.history.executeQuery(query, options).root; michael@0: root.containerOpen = true; michael@0: let cc = root.childCount; michael@0: dump("----> cc is: " + cc + "\n"); michael@0: for(let i = 0; i < root.childCount; ++i) { michael@0: let resultNode = root.getChild(i); michael@0: let accesstime = Date(resultNode.time / 1000); michael@0: dump("----> result: " + resultNode.uri + " Date: " + accesstime.toLocaleString() + "\n"); michael@0: } michael@0: do_check_eq(cc,0); michael@0: root.containerOpen = false; michael@0: });