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