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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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 const DAY_MSEC = 86400000;
     8 const MIN_MSEC = 60000;
     9 const HOUR_MSEC = 3600000;
    10 // Jan 6 2008 at 8am is our begin edge of the query
    11 var beginTimeDate = new Date(2008, 0, 6, 8, 0, 0, 0);
    12 // Jan 15 2008 at 9:30pm is our ending edge of the query
    13 var endTimeDate = new Date(2008, 0, 15, 21, 30, 0, 0);
    15 // These as millisecond values
    16 var beginTime = beginTimeDate.getTime();
    17 var endTime = endTimeDate.getTime();
    19 // Some range dates inside our query - mult by 1000 to convert to PRTIME
    20 var jan7_800 = (beginTime + DAY_MSEC) * 1000;
    21 var jan6_815 = (beginTime + (MIN_MSEC * 15)) * 1000;
    22 var jan11_800 = (beginTime + (DAY_MSEC * 5)) * 1000;
    23 var jan14_2130 = (endTime - DAY_MSEC) * 1000;
    24 var jan15_2045 = (endTime - (MIN_MSEC * 45)) * 1000;
    25 var jan12_1730 = (endTime - (DAY_MSEC * 3) - (HOUR_MSEC*4)) * 1000;
    27 // Dates outside our query - mult by 1000 to convert to PRTIME
    28 var jan6_700 = (beginTime - HOUR_MSEC) * 1000;
    29 var jan5_800 = (beginTime - DAY_MSEC) * 1000;
    30 var dec27_800 = (beginTime - (DAY_MSEC * 10)) * 1000;
    31 var jan15_2145 = (endTime + (MIN_MSEC * 15)) * 1000;
    32 var jan16_2130 = (endTime + (DAY_MSEC)) * 1000;
    33 var jan25_2130 = (endTime + (DAY_MSEC * 10)) * 1000;
    35 // So that we can easily use these too, convert them to PRTIME
    36 beginTime *= 1000;
    37 endTime *= 1000;
    39 /**
    40  * Array of objects to build our test database
    41  */
    42 var goodAnnoName = "moz-test-places/testing123";
    43 var val = "test";
    44 var badAnnoName = "text/foo";
    46 // The test data for our database, note that the ordering of the results that
    47 // will be returned by the query (the isInQuery: true objects) is IMPORTANT.
    48 // see compareArrayToResult in head_queries.js for more info.
    49 var testData = [
    50   // Test ftp protocol - vary the title length
    51   {isInQuery: true, isVisit: true, isDetails: true,
    52    uri: "ftp://foo.com/ftp", lastVisit: jan12_1730,
    53    title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"},
    55   // Test flat domain with annotation
    56   {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
    57    uri: "http://foo.com/", annoName: goodAnnoName, annoVal: val,
    58    lastVisit: jan14_2130, title: "moz"},
    60   // Test subdomain included with isRedirect=true, different transtype
    61   {isInQuery: true, isVisit: true, isDetails: true, title: "moz",
    62    isRedirect: true, uri: "http://mail.foo.com/redirect", lastVisit: jan11_800,
    63    transType: PlacesUtils.history.TRANSITION_LINK},
    65   // Test subdomain inclued at the leading time edge 
    66   {isInQuery: true, isVisit: true, isDetails: true,
    67    uri: "http://mail.foo.com/yiihah", title: "moz", lastVisit: jan6_815},
    69   // Test www. style URI is included, with an annotation
    70   {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
    71    uri: "http://www.foo.com/yiihah", annoName: goodAnnoName, annoVal: val,
    72    lastVisit: jan7_800, title: "moz"},
    74   // Test https protocol
    75   {isInQuery: true, isVisit: true, isDetails: true, title: "moz",
    76    uri: "https://foo.com/", lastVisit: jan15_2045},
    78   // Test begin edge of time
    79   {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla",
    80    uri: "https://foo.com/begin.html", lastVisit: beginTime},
    82   //Test end edge of time
    83   {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla",
    84    uri: "https://foo.com/end.html", lastVisit: endTime},
    86   // Test an image link, with annotations
    87   {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
    88    title: "mozzie the dino", uri: "https://foo.com/mozzie.png",
    89    annoName: goodAnnoName, annoVal: val, lastVisit: jan14_2130},
    91   // Begin the invalid queries: Test too early
    92   {isInQuery: false, isVisit:true, isDetails: true, title: "moz",
    93    uri: "http://foo.com/tooearly.php", lastVisit: jan6_700},
    95   // Test Bad Annotation
    96   {isInQuery: false, isVisit:true, isDetails: true, isPageAnnotation: true,
    97    title: "moz", uri: "http://foo.com/badanno.htm", lastVisit: jan12_1730,
    98    annoName: badAnnoName, annoVal: val},
   100   // Test bad URI
   101   {isInQuery: false, isVisit:true, isDetails: true, title: "moz",
   102    uri: "http://somefoo.com/justwrong.htm", lastVisit: jan11_800},
   104   // Test afterward, one to update
   105   {isInQuery: false, isVisit:true, isDetails: true, title: "changeme",
   106    uri: "http://foo.com/changeme1.htm", lastVisit: jan12_1730},
   108   // Test invalid title
   109   {isInQuery: false, isVisit:true, isDetails: true, title: "changeme2",
   110    uri: "http://foo.com/changeme2.htm", lastVisit: jan7_800},
   112   // Test changing the lastVisit
   113   {isInQuery: false, isVisit:true, isDetails: true, title: "moz",
   114    uri: "http://foo.com/changeme3.htm", lastVisit: dec27_800}];
   116 /**
   117  * This test will test a Query using several terms and do a bit of negative
   118  * testing for items that should be ignored while querying over history.
   119  * The Query:WHERE absoluteTime(matches) AND searchTerms AND URI
   120  *                 AND annotationIsNot(match) GROUP BY Domain, Day SORT BY uri,ascending
   121  *                 excludeITems(should be ignored)
   122  */
   123 function run_test()
   124 {
   125   run_next_test();
   126 }
   128 add_task(function test_abstime_annotation_domain()
   129 {
   130   //Initialize database
   131   yield task_populateDB(testData);
   133   // Query
   134   var query = PlacesUtils.history.getNewQuery();
   135   query.beginTime = beginTime;
   136   query.endTime = endTime;
   137   query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
   138   query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
   139   query.searchTerms = "moz";
   140   query.domain = "foo.com";
   141   query.domainIsHost = false;
   142   query.annotation = "text/foo";
   143   query.annotationIsNot = true;
   145   // Options
   146   var options = PlacesUtils.history.getNewQueryOptions();
   147   options.sortingMode = options.SORT_BY_URI_ASCENDING;
   148   options.resultType = options.RESULTS_AS_URI;
   149   // The next two options should be ignored
   150   // can't use this one, breaks test - bug 419779
   151   // options.excludeItems = true;
   153   // Results
   154   var result = PlacesUtils.history.executeQuery(query, options);
   155   var root = result.root;
   156   root.containerOpen = true;
   158   // Ensure the result set is correct
   159   compareArrayToResult(testData, root);
   161   // Make some changes to the result set
   162   // Let's add something first
   163   var addItem = [{isInQuery: true, isVisit: true, isDetails: true, title: "moz",
   164                  uri: "http://www.foo.com/i-am-added.html", lastVisit: jan11_800}];
   165   yield task_populateDB(addItem);
   166   LOG("Adding item foo.com/i-am-added.html");
   167   do_check_eq(isInResult(addItem, root), true);
   169   // Let's update something by title
   170   var change1 = [{isDetails: true, uri: "http://foo.com/changeme1",
   171                   lastVisit: jan12_1730, title: "moz moz mozzie"}];
   172   yield task_populateDB(change1);
   173   LOG("LiveUpdate by changing title");
   174   do_check_eq(isInResult(change1, root), true);
   176   // Let's update something by annotation
   177   // Updating a page by removing an annotation does not cause it to join this
   178   // query set.  I tend to think that it should cause that page to join this
   179   // query set, because this visit fits all theother specified criteria once the
   180   // annotation is removed. Uncommenting this will fail the test.
   181   // Bug 424050
   182   /*var change2 = [{isPageAnnotation: true, uri: "http://foo.com/badannotaion.html",
   183                   annoName: "text/mozilla", annoVal: "test"}];
   184   yield task_populateDB(change2);
   185   LOG("LiveUpdate by removing annotation");
   186   do_check_eq(isInResult(change2, root), true);*/
   188   // Let's update by adding a visit in the time range for an existing URI
   189   var change3 = [{isDetails: true, uri: "http://foo.com/changeme3.htm",
   190                   title: "moz", lastVisit: jan15_2045}];
   191   yield task_populateDB(change3);
   192   LOG("LiveUpdate by adding visit within timerange");
   193   do_check_eq(isInResult(change3, root), true);
   195   // And delete something from the result set - using annotation
   196   // Once again, bug 424050 prevents this from passing
   197   /*var change4 = [{isPageAnnotation: true, uri: "ftp://foo.com/ftp",
   198                   annoVal: "test", annoName: badAnnoName}];
   199   yield task_populateDB(change4);
   200   LOG("LiveUpdate by deleting item from set by adding annotation");
   201   do_check_eq(isInResult(change4, root), false);*/
   203   // Delete something by changing the title
   204   var change5 = [{isDetails: true, uri: "http://foo.com/end.html", title: "deleted"}];
   205   yield task_populateDB(change5);
   206   LOG("LiveUpdate by deleting item by changing title");
   207   do_check_eq(isInResult(change5, root), false);
   209   root.containerOpen = false;
   210 });

mercurial