1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/queries/test_415716.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 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 +function modHistoryTypes(val){ 1.11 + switch(val % 8) { 1.12 + case 0: 1.13 + case 1: 1.14 + return TRANSITION_LINK; 1.15 + case 2: 1.16 + return TRANSITION_TYPED; 1.17 + case 3: 1.18 + return TRANSITION_BOOKMARK; 1.19 + case 4: 1.20 + return TRANSITION_EMBED; 1.21 + case 5: 1.22 + return TRANSITION_REDIRECT_PERMANENT; 1.23 + case 6: 1.24 + return TRANSITION_REDIRECT_TEMPORARY; 1.25 + case 7: 1.26 + return TRANSITION_DOWNLOAD; 1.27 + case 8: 1.28 + return TRANSITION_FRAMED_LINK; 1.29 + } 1.30 + return TRANSITION_TYPED; 1.31 +} 1.32 + 1.33 +function run_test() 1.34 +{ 1.35 + run_next_test(); 1.36 +} 1.37 + 1.38 +/** 1.39 + * Builds a test database by hand using various times, annotations and 1.40 + * visit numbers for this test 1.41 + */ 1.42 +add_task(function test_buildTestDatabase() 1.43 +{ 1.44 + // This is the set of visits that we will match - our min visit is 2 so that's 1.45 + // why we add more visits to the same URIs. 1.46 + let testURI = uri("http://www.foo.com"); 1.47 + let places = []; 1.48 + 1.49 + for (let i = 0; i < 12; ++i) { 1.50 + places.push({ 1.51 + uri: testURI, 1.52 + transition: modHistoryTypes(i), 1.53 + visitDate: today 1.54 + }); 1.55 + } 1.56 + 1.57 + testURI = uri("http://foo.com/youdontseeme.html"); 1.58 + let testAnnoName = "moz-test-places/testing123"; 1.59 + let testAnnoVal = "test"; 1.60 + for (let i = 0; i < 12; ++i) { 1.61 + places.push({ 1.62 + uri: testURI, 1.63 + transition: modHistoryTypes(i), 1.64 + visitDate: today 1.65 + }); 1.66 + } 1.67 + 1.68 + yield promiseAddVisits(places); 1.69 + 1.70 + PlacesUtils.annotations.setPageAnnotation(testURI, testAnnoName, 1.71 + testAnnoVal, 0, 0); 1.72 +}); 1.73 + 1.74 +/** 1.75 + * This test will test Queries that use relative Time Range, minVists, maxVisits, 1.76 + * annotation. 1.77 + * The Query: 1.78 + * Annotation == "moz-test-places/testing123" && 1.79 + * TimeRange == "now() - 2d" && 1.80 + * minVisits == 2 && 1.81 + * maxVisits == 10 1.82 + */ 1.83 +add_task(function test_execute() 1.84 +{ 1.85 + let query = PlacesUtils.history.getNewQuery(); 1.86 + query.annotation = "moz-test-places/testing123"; 1.87 + query.beginTime = daybefore * 1000; 1.88 + query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_NOW; 1.89 + query.endTime = today * 1000; 1.90 + query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_NOW; 1.91 + query.minVisits = 2; 1.92 + query.maxVisits = 10; 1.93 + 1.94 + // Options 1.95 + let options = PlacesUtils.history.getNewQueryOptions(); 1.96 + options.sortingMode = options.SORT_BY_DATE_DESCENDING; 1.97 + options.resultType = options.RESULTS_AS_VISIT; 1.98 + 1.99 + // Results 1.100 + let root = PlacesUtils.history.executeQuery(query, options).root; 1.101 + root.containerOpen = true; 1.102 + let cc = root.childCount; 1.103 + dump("----> cc is: " + cc + "\n"); 1.104 + for(let i = 0; i < root.childCount; ++i) { 1.105 + let resultNode = root.getChild(i); 1.106 + let accesstime = Date(resultNode.time / 1000); 1.107 + dump("----> result: " + resultNode.uri + " Date: " + accesstime.toLocaleString() + "\n"); 1.108 + } 1.109 + do_check_eq(cc,0); 1.110 + root.containerOpen = false; 1.111 +});