1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/queries/test_abstime-annotation-uri.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,208 @@ 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 + 1.54 + // Test flat domain with annotation 1.55 + {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true, 1.56 + uri: "http://foo.com/", annoName: goodAnnoName, annoVal: val, 1.57 + lastVisit: jan14_2130, title: "moz"}, 1.58 + 1.59 + // Test begin edge of time 1.60 + {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla", 1.61 + uri: "http://foo.com/begin.html", lastVisit: beginTime}, 1.62 + 1.63 + // Test end edge of time 1.64 + {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla", 1.65 + uri: "http://foo.com/end.html", lastVisit: endTime}, 1.66 + 1.67 + // Test uri included with isRedirect=true, different transtype 1.68 + {isInQuery: true, isVisit: true, isDetails: true, title: "moz", 1.69 + isRedirect: true, uri: "http://foo.com/redirect", lastVisit: jan11_800, 1.70 + transType: PlacesUtils.history.TRANSITION_LINK}, 1.71 + 1.72 + // Test leading time edge with tag string is included 1.73 + {isInQuery: true, isVisit: true, isDetails: true, title: "taggariffic", 1.74 + uri: "http://foo.com/tagging/test.html", lastVisit: beginTime, isTag: true, 1.75 + tagArray: ["moz"] }, 1.76 + 1.77 + // Begin the invalid queries: 1.78 + // Test www. style URI is not included, with an annotation 1.79 + {isInQuery: false, isVisit: true, isDetails: true, isPageAnnotation: true, 1.80 + uri: "http://www.foo.com/yiihah", annoName: goodAnnoName, annoVal: val, 1.81 + lastVisit: jan7_800, title: "moz"}, 1.82 + 1.83 + // Test subdomain not inclued at the leading time edge 1.84 + {isInQuery: false, isVisit: true, isDetails: true, 1.85 + uri: "http://mail.foo.com/yiihah", title: "moz", lastVisit: jan6_815}, 1.86 + 1.87 + // Test https protocol 1.88 + {isInQuery: false, isVisit: true, isDetails: true, title: "moz", 1.89 + uri: "https://foo.com/", lastVisit: jan15_2045}, 1.90 + 1.91 + // Test ftp protocol 1.92 + {isInQuery: false, isVisit: true, isDetails: true, 1.93 + uri: "ftp://foo.com/ftp", lastVisit: jan12_1730, 1.94 + title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"}, 1.95 + 1.96 + // Test too early 1.97 + {isInQuery: false, isVisit:true, isDetails: true, title: "moz", 1.98 + uri: "http://foo.com/tooearly.php", lastVisit: jan6_700}, 1.99 + 1.100 + // Test Bad Annotation 1.101 + {isInQuery: false, isVisit:true, isDetails: true, isPageAnnotation: true, 1.102 + title: "moz", uri: "http://foo.com/badanno.htm", lastVisit: jan12_1730, 1.103 + annoName: badAnnoName, annoVal: val}, 1.104 + 1.105 + // Test afterward, one to update 1.106 + {isInQuery: false, isVisit:true, isDetails: true, title: "changeme", 1.107 + uri: "http://foo.com/changeme1.htm", lastVisit: jan12_1730}, 1.108 + 1.109 + // Test invalid title 1.110 + {isInQuery: false, isVisit:true, isDetails: true, title: "changeme2", 1.111 + uri: "http://foo.com/changeme2.htm", lastVisit: jan7_800}, 1.112 + 1.113 + // Test changing the lastVisit 1.114 + {isInQuery: false, isVisit:true, isDetails: true, title: "moz", 1.115 + uri: "http://foo.com/changeme3.htm", lastVisit: dec27_800}]; 1.116 + 1.117 +/** 1.118 + * This test will test a Query using several terms and do a bit of negative 1.119 + * testing for items that should be ignored while querying over history. 1.120 + * The Query:WHERE absoluteTime(matches) AND searchTerms AND URI 1.121 + * AND annotationIsNot(match) GROUP BY Domain, Day SORT BY uri,ascending 1.122 + * excludeITems(should be ignored) 1.123 + */ 1.124 +function run_test() 1.125 +{ 1.126 + run_next_test(); 1.127 +} 1.128 + 1.129 +add_task(function test_abstime_annotation_uri() 1.130 +{ 1.131 + //Initialize database 1.132 + yield task_populateDB(testData); 1.133 + 1.134 + // Query 1.135 + var query = PlacesUtils.history.getNewQuery(); 1.136 + query.beginTime = beginTime; 1.137 + query.endTime = endTime; 1.138 + query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH; 1.139 + query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH; 1.140 + query.searchTerms = "moz"; 1.141 + query.uri = uri("http://foo.com"); 1.142 + query.uriIsPrefix = true; 1.143 + query.annotation = "text/foo"; 1.144 + query.annotationIsNot = true; 1.145 + 1.146 + // Options 1.147 + var options = PlacesUtils.history.getNewQueryOptions(); 1.148 + options.sortingMode = options.SORT_BY_URI_ASCENDING; 1.149 + options.resultType = options.RESULTS_AS_URI; 1.150 + // The next two options should be ignored 1.151 + // can't use this one, breaks test - bug 419779 1.152 + // options.excludeItems = true; 1.153 + 1.154 + // Results 1.155 + var result = PlacesUtils.history.executeQuery(query, options); 1.156 + var root = result.root; 1.157 + root.containerOpen = true; 1.158 + 1.159 + // Ensure the result set is correct 1.160 + compareArrayToResult(testData, root); 1.161 + 1.162 + // Make some changes to the result set 1.163 + // Let's add something first 1.164 + var addItem = [{isInQuery: true, isVisit: true, isDetails: true, title: "moz", 1.165 + uri: "http://foo.com/i-am-added.html", lastVisit: jan11_800}]; 1.166 + yield task_populateDB(addItem); 1.167 + LOG("Adding item foo.com/i-am-added.html"); 1.168 + do_check_eq(isInResult(addItem, root), true); 1.169 + 1.170 + // Let's update something by title 1.171 + var change1 = [{isDetails: true, uri: "http://foo.com/changeme1", 1.172 + lastVisit: jan12_1730, title: "moz moz mozzie"}]; 1.173 + yield task_populateDB(change1); 1.174 + LOG("LiveUpdate by changing title"); 1.175 + do_check_eq(isInResult(change1, root), true); 1.176 + 1.177 + // Let's update something by annotation 1.178 + // Updating a page by removing an annotation does not cause it to join this 1.179 + // query set. I tend to think that it should cause that page to join this 1.180 + // query set, because this visit fits all theother specified criteria once the 1.181 + // annotation is removed. Uncommenting this will fail the test. 1.182 + // This is bug 424050 - appears to happen for both domain and URI queries 1.183 + /*var change2 = [{isPageAnnotation: true, uri: "http://foo.com/badannotaion.html", 1.184 + annoName: "text/mozilla", annoVal: "test"}]; 1.185 + yield task_populateDB(change2); 1.186 + LOG("LiveUpdate by removing annotation"); 1.187 + do_check_eq(isInResult(change2, root), true);*/ 1.188 + 1.189 + // Let's update by adding a visit in the time range for an existing URI 1.190 + var change3 = [{isDetails: true, uri: "http://foo.com/changeme3.htm", 1.191 + title: "moz", lastVisit: jan15_2045}]; 1.192 + yield task_populateDB(change3); 1.193 + LOG("LiveUpdate by adding visit within timerange"); 1.194 + do_check_eq(isInResult(change3, root), true); 1.195 + 1.196 + // And delete something from the result set - using annotation 1.197 + // Once more, bug 424050 1.198 + /*var change4 = [{isPageAnnotation: true, uri: "http://foo.com/", 1.199 + annoVal: "test", annoName: badAnnoName}]; 1.200 + yield task_populateDB(change4); 1.201 + LOG("LiveUpdate by deleting item from set by adding annotation"); 1.202 + do_check_eq(isInResult(change4, root), false);*/ 1.203 + 1.204 + // Delete something by changing the title 1.205 + var change5 = [{isDetails: true, uri: "http://foo.com/end.html", title: "deleted"}]; 1.206 + yield task_populateDB(change5); 1.207 + LOG("LiveUpdate by deleting item by changing title"); 1.208 + do_check_eq(isInResult(change5, root), false); 1.209 + 1.210 + root.containerOpen = false; 1.211 +});