toolkit/components/places/tests/queries/test_abstime-annotation-domain.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/queries/test_abstime-annotation-domain.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,210 @@
     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 +const DAY_MSEC = 86400000;
    1.11 +const MIN_MSEC = 60000;
    1.12 +const HOUR_MSEC = 3600000;
    1.13 +// Jan 6 2008 at 8am is our begin edge of the query
    1.14 +var beginTimeDate = new Date(2008, 0, 6, 8, 0, 0, 0);
    1.15 +// Jan 15 2008 at 9:30pm is our ending edge of the query
    1.16 +var endTimeDate = new Date(2008, 0, 15, 21, 30, 0, 0);
    1.17 +
    1.18 +// These as millisecond values
    1.19 +var beginTime = beginTimeDate.getTime();
    1.20 +var endTime = endTimeDate.getTime();
    1.21 +
    1.22 +// Some range dates inside our query - mult by 1000 to convert to PRTIME
    1.23 +var jan7_800 = (beginTime + DAY_MSEC) * 1000;
    1.24 +var jan6_815 = (beginTime + (MIN_MSEC * 15)) * 1000;
    1.25 +var jan11_800 = (beginTime + (DAY_MSEC * 5)) * 1000;
    1.26 +var jan14_2130 = (endTime - DAY_MSEC) * 1000;
    1.27 +var jan15_2045 = (endTime - (MIN_MSEC * 45)) * 1000;
    1.28 +var jan12_1730 = (endTime - (DAY_MSEC * 3) - (HOUR_MSEC*4)) * 1000;
    1.29 +
    1.30 +// Dates outside our query - mult by 1000 to convert to PRTIME
    1.31 +var jan6_700 = (beginTime - HOUR_MSEC) * 1000;
    1.32 +var jan5_800 = (beginTime - DAY_MSEC) * 1000;
    1.33 +var dec27_800 = (beginTime - (DAY_MSEC * 10)) * 1000;
    1.34 +var jan15_2145 = (endTime + (MIN_MSEC * 15)) * 1000;
    1.35 +var jan16_2130 = (endTime + (DAY_MSEC)) * 1000;
    1.36 +var jan25_2130 = (endTime + (DAY_MSEC * 10)) * 1000;
    1.37 +
    1.38 +// So that we can easily use these too, convert them to PRTIME
    1.39 +beginTime *= 1000;
    1.40 +endTime *= 1000;
    1.41 +
    1.42 +/**
    1.43 + * Array of objects to build our test database
    1.44 + */
    1.45 +var goodAnnoName = "moz-test-places/testing123";
    1.46 +var val = "test";
    1.47 +var badAnnoName = "text/foo";
    1.48 +
    1.49 +// The test data for our database, note that the ordering of the results that
    1.50 +// will be returned by the query (the isInQuery: true objects) is IMPORTANT.
    1.51 +// see compareArrayToResult in head_queries.js for more info.
    1.52 +var testData = [
    1.53 +  // Test ftp protocol - vary the title length
    1.54 +  {isInQuery: true, isVisit: true, isDetails: true,
    1.55 +   uri: "ftp://foo.com/ftp", lastVisit: jan12_1730,
    1.56 +   title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"},
    1.57 +
    1.58 +  // Test flat domain with annotation
    1.59 +  {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
    1.60 +   uri: "http://foo.com/", annoName: goodAnnoName, annoVal: val,
    1.61 +   lastVisit: jan14_2130, title: "moz"},
    1.62 +
    1.63 +  // Test subdomain included with isRedirect=true, different transtype
    1.64 +  {isInQuery: true, isVisit: true, isDetails: true, title: "moz",
    1.65 +   isRedirect: true, uri: "http://mail.foo.com/redirect", lastVisit: jan11_800,
    1.66 +   transType: PlacesUtils.history.TRANSITION_LINK},
    1.67 +
    1.68 +  // Test subdomain inclued at the leading time edge 
    1.69 +  {isInQuery: true, isVisit: true, isDetails: true,
    1.70 +   uri: "http://mail.foo.com/yiihah", title: "moz", lastVisit: jan6_815},
    1.71 +
    1.72 +  // Test www. style URI is included, with an annotation
    1.73 +  {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
    1.74 +   uri: "http://www.foo.com/yiihah", annoName: goodAnnoName, annoVal: val,
    1.75 +   lastVisit: jan7_800, title: "moz"},
    1.76 +
    1.77 +  // Test https protocol
    1.78 +  {isInQuery: true, isVisit: true, isDetails: true, title: "moz",
    1.79 +   uri: "https://foo.com/", lastVisit: jan15_2045},
    1.80 +
    1.81 +  // Test begin edge of time
    1.82 +  {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla",
    1.83 +   uri: "https://foo.com/begin.html", lastVisit: beginTime},
    1.84 +
    1.85 +  //Test end edge of time
    1.86 +  {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla",
    1.87 +   uri: "https://foo.com/end.html", lastVisit: endTime},
    1.88 +
    1.89 +  // Test an image link, with annotations
    1.90 +  {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
    1.91 +   title: "mozzie the dino", uri: "https://foo.com/mozzie.png",
    1.92 +   annoName: goodAnnoName, annoVal: val, lastVisit: jan14_2130},
    1.93 +
    1.94 +  // Begin the invalid queries: Test too early
    1.95 +  {isInQuery: false, isVisit:true, isDetails: true, title: "moz",
    1.96 +   uri: "http://foo.com/tooearly.php", lastVisit: jan6_700},
    1.97 +
    1.98 +  // Test Bad Annotation
    1.99 +  {isInQuery: false, isVisit:true, isDetails: true, isPageAnnotation: true,
   1.100 +   title: "moz", uri: "http://foo.com/badanno.htm", lastVisit: jan12_1730,
   1.101 +   annoName: badAnnoName, annoVal: val},
   1.102 +
   1.103 +  // Test bad URI
   1.104 +  {isInQuery: false, isVisit:true, isDetails: true, title: "moz",
   1.105 +   uri: "http://somefoo.com/justwrong.htm", lastVisit: jan11_800},
   1.106 +  
   1.107 +  // Test afterward, one to update
   1.108 +  {isInQuery: false, isVisit:true, isDetails: true, title: "changeme",
   1.109 +   uri: "http://foo.com/changeme1.htm", lastVisit: jan12_1730},
   1.110 +
   1.111 +  // Test invalid title
   1.112 +  {isInQuery: false, isVisit:true, isDetails: true, title: "changeme2",
   1.113 +   uri: "http://foo.com/changeme2.htm", lastVisit: jan7_800},
   1.114 +
   1.115 +  // Test changing the lastVisit
   1.116 +  {isInQuery: false, isVisit:true, isDetails: true, title: "moz",
   1.117 +   uri: "http://foo.com/changeme3.htm", lastVisit: dec27_800}];
   1.118 +
   1.119 +/**
   1.120 + * This test will test a Query using several terms and do a bit of negative
   1.121 + * testing for items that should be ignored while querying over history.
   1.122 + * The Query:WHERE absoluteTime(matches) AND searchTerms AND URI
   1.123 + *                 AND annotationIsNot(match) GROUP BY Domain, Day SORT BY uri,ascending
   1.124 + *                 excludeITems(should be ignored)
   1.125 + */
   1.126 +function run_test()
   1.127 +{
   1.128 +  run_next_test();
   1.129 +}
   1.130 +
   1.131 +add_task(function test_abstime_annotation_domain()
   1.132 +{
   1.133 +  //Initialize database
   1.134 +  yield task_populateDB(testData);
   1.135 +
   1.136 +  // Query
   1.137 +  var query = PlacesUtils.history.getNewQuery();
   1.138 +  query.beginTime = beginTime;
   1.139 +  query.endTime = endTime;
   1.140 +  query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
   1.141 +  query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
   1.142 +  query.searchTerms = "moz";
   1.143 +  query.domain = "foo.com";
   1.144 +  query.domainIsHost = false;
   1.145 +  query.annotation = "text/foo";
   1.146 +  query.annotationIsNot = true;
   1.147 +
   1.148 +  // Options
   1.149 +  var options = PlacesUtils.history.getNewQueryOptions();
   1.150 +  options.sortingMode = options.SORT_BY_URI_ASCENDING;
   1.151 +  options.resultType = options.RESULTS_AS_URI;
   1.152 +  // The next two options should be ignored
   1.153 +  // can't use this one, breaks test - bug 419779
   1.154 +  // options.excludeItems = true;
   1.155 +
   1.156 +  // Results
   1.157 +  var result = PlacesUtils.history.executeQuery(query, options);
   1.158 +  var root = result.root;
   1.159 +  root.containerOpen = true;
   1.160 +
   1.161 +  // Ensure the result set is correct
   1.162 +  compareArrayToResult(testData, root);
   1.163 +
   1.164 +  // Make some changes to the result set
   1.165 +  // Let's add something first
   1.166 +  var addItem = [{isInQuery: true, isVisit: true, isDetails: true, title: "moz",
   1.167 +                 uri: "http://www.foo.com/i-am-added.html", lastVisit: jan11_800}];
   1.168 +  yield task_populateDB(addItem);
   1.169 +  LOG("Adding item foo.com/i-am-added.html");
   1.170 +  do_check_eq(isInResult(addItem, root), true);
   1.171 +
   1.172 +  // Let's update something by title
   1.173 +  var change1 = [{isDetails: true, uri: "http://foo.com/changeme1",
   1.174 +                  lastVisit: jan12_1730, title: "moz moz mozzie"}];
   1.175 +  yield task_populateDB(change1);
   1.176 +  LOG("LiveUpdate by changing title");
   1.177 +  do_check_eq(isInResult(change1, root), true);
   1.178 +
   1.179 +  // Let's update something by annotation
   1.180 +  // Updating a page by removing an annotation does not cause it to join this
   1.181 +  // query set.  I tend to think that it should cause that page to join this
   1.182 +  // query set, because this visit fits all theother specified criteria once the
   1.183 +  // annotation is removed. Uncommenting this will fail the test.
   1.184 +  // Bug 424050
   1.185 +  /*var change2 = [{isPageAnnotation: true, uri: "http://foo.com/badannotaion.html",
   1.186 +                  annoName: "text/mozilla", annoVal: "test"}];
   1.187 +  yield task_populateDB(change2);
   1.188 +  LOG("LiveUpdate by removing annotation");
   1.189 +  do_check_eq(isInResult(change2, root), true);*/
   1.190 +
   1.191 +  // Let's update by adding a visit in the time range for an existing URI
   1.192 +  var change3 = [{isDetails: true, uri: "http://foo.com/changeme3.htm",
   1.193 +                  title: "moz", lastVisit: jan15_2045}];
   1.194 +  yield task_populateDB(change3);
   1.195 +  LOG("LiveUpdate by adding visit within timerange");
   1.196 +  do_check_eq(isInResult(change3, root), true);
   1.197 +
   1.198 +  // And delete something from the result set - using annotation
   1.199 +  // Once again, bug 424050 prevents this from passing
   1.200 +  /*var change4 = [{isPageAnnotation: true, uri: "ftp://foo.com/ftp",
   1.201 +                  annoVal: "test", annoName: badAnnoName}];
   1.202 +  yield task_populateDB(change4);
   1.203 +  LOG("LiveUpdate by deleting item from set by adding annotation");
   1.204 +  do_check_eq(isInResult(change4, root), false);*/
   1.205 +
   1.206 +  // Delete something by changing the title
   1.207 +  var change5 = [{isDetails: true, uri: "http://foo.com/end.html", title: "deleted"}];
   1.208 +  yield task_populateDB(change5);
   1.209 +  LOG("LiveUpdate by deleting item by changing title");
   1.210 +  do_check_eq(isInResult(change5, root), false);
   1.211 +
   1.212 +  root.containerOpen = false;
   1.213 +});

mercurial