toolkit/components/places/tests/queries/test_415716.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 function modHistoryTypes(val){
     8   switch(val % 8) {
     9     case 0:
    10     case 1:
    11       return TRANSITION_LINK;
    12     case 2:
    13       return TRANSITION_TYPED;
    14     case 3:
    15       return TRANSITION_BOOKMARK;
    16     case 4:
    17       return TRANSITION_EMBED;
    18     case 5:
    19       return TRANSITION_REDIRECT_PERMANENT;
    20     case 6:
    21       return TRANSITION_REDIRECT_TEMPORARY;
    22     case 7:
    23       return TRANSITION_DOWNLOAD;
    24     case 8:
    25       return TRANSITION_FRAMED_LINK;
    26   }
    27   return TRANSITION_TYPED;
    28 }
    30 function run_test()
    31 {
    32   run_next_test();
    33 }
    35 /**
    36  * Builds a test database by hand using various times, annotations and
    37  * visit numbers for this test
    38  */
    39 add_task(function test_buildTestDatabase()
    40 {
    41   // This is the set of visits that we will match - our min visit is 2 so that's
    42   // why we add more visits to the same URIs.
    43   let testURI = uri("http://www.foo.com");
    44   let places = [];
    46   for (let i = 0; i < 12; ++i) {
    47     places.push({
    48       uri: testURI,
    49       transition: modHistoryTypes(i),
    50       visitDate: today
    51     });
    52   }
    54   testURI = uri("http://foo.com/youdontseeme.html");
    55   let testAnnoName = "moz-test-places/testing123";
    56   let testAnnoVal = "test";
    57   for (let i = 0; i < 12; ++i) {
    58     places.push({
    59       uri: testURI,
    60       transition: modHistoryTypes(i),
    61       visitDate: today
    62     });
    63   }
    65   yield promiseAddVisits(places);
    67   PlacesUtils.annotations.setPageAnnotation(testURI, testAnnoName,
    68                                             testAnnoVal, 0, 0);
    69 });
    71 /**
    72  * This test will test Queries that use relative Time Range, minVists, maxVisits,
    73  * annotation.
    74  * The Query:
    75  * Annotation == "moz-test-places/testing123" &&
    76  * TimeRange == "now() - 2d" &&
    77  * minVisits == 2 &&
    78  * maxVisits == 10 
    79  */
    80 add_task(function test_execute()
    81 {
    82   let query = PlacesUtils.history.getNewQuery();
    83   query.annotation = "moz-test-places/testing123";
    84   query.beginTime = daybefore * 1000;
    85   query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_NOW;
    86   query.endTime = today * 1000;
    87   query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_NOW;
    88   query.minVisits = 2;
    89   query.maxVisits = 10;
    91   // Options
    92   let options = PlacesUtils.history.getNewQueryOptions();
    93   options.sortingMode = options.SORT_BY_DATE_DESCENDING;
    94   options.resultType = options.RESULTS_AS_VISIT;
    96   // Results
    97   let root = PlacesUtils.history.executeQuery(query, options).root;
    98   root.containerOpen = true;
    99   let cc = root.childCount;
   100   dump("----> cc is: " + cc + "\n");
   101   for(let i = 0; i < root.childCount; ++i) {
   102     let resultNode = root.getChild(i);
   103     let accesstime = Date(resultNode.time / 1000);
   104     dump("----> result: " + resultNode.uri + "   Date: " + accesstime.toLocaleString() + "\n");
   105   }
   106   do_check_eq(cc,0);
   107   root.containerOpen = false;
   108 });

mercurial