toolkit/components/places/tests/queries/test_sort-date-site-grouping.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

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 /* ***** BEGIN LICENSE BLOCK *****
michael@0 4 Any copyright is dedicated to the Public Domain.
michael@0 5 http://creativecommons.org/publicdomain/zero/1.0/
michael@0 6 * ***** END LICENSE BLOCK ***** */
michael@0 7
michael@0 8 // This test ensures that the date and site type of |place:| query maintains
michael@0 9 // its quantifications correctly. Namely, it ensures that the date part of the
michael@0 10 // query is not lost when the domain queries are made.
michael@0 11
michael@0 12 // We specifically craft these entries so that if a by Date and Site sorting is
michael@0 13 // applied, we find one domain in the today range, and two domains in the older
michael@0 14 // than six months range.
michael@0 15 // The correspondence between item in |testData| and date range is stored in
michael@0 16 // leveledTestData.
michael@0 17 let testData = [
michael@0 18 {
michael@0 19 isVisit: true,
michael@0 20 uri: "file:///directory/1",
michael@0 21 lastVisit: today,
michael@0 22 title: "test visit",
michael@0 23 isInQuery: true
michael@0 24 },
michael@0 25 {
michael@0 26 isVisit: true,
michael@0 27 uri: "http://example.com/1",
michael@0 28 lastVisit: today,
michael@0 29 title: "test visit",
michael@0 30 isInQuery: true
michael@0 31 },
michael@0 32 {
michael@0 33 isVisit: true,
michael@0 34 uri: "http://example.com/2",
michael@0 35 lastVisit: today,
michael@0 36 title: "test visit",
michael@0 37 isInQuery: true
michael@0 38 },
michael@0 39 {
michael@0 40 isVisit: true,
michael@0 41 uri: "file:///directory/2",
michael@0 42 lastVisit: olderthansixmonths,
michael@0 43 title: "test visit",
michael@0 44 isInQuery: true
michael@0 45 },
michael@0 46 {
michael@0 47 isVisit: true,
michael@0 48 uri: "http://example.com/3",
michael@0 49 lastVisit: olderthansixmonths,
michael@0 50 title: "test visit",
michael@0 51 isInQuery: true
michael@0 52 },
michael@0 53 {
michael@0 54 isVisit: true,
michael@0 55 uri: "http://example.com/4",
michael@0 56 lastVisit: olderthansixmonths,
michael@0 57 title: "test visit",
michael@0 58 isInQuery: true
michael@0 59 },
michael@0 60 {
michael@0 61 isVisit: true,
michael@0 62 uri: "http://example.net/1",
michael@0 63 lastVisit: olderthansixmonths + 1,
michael@0 64 title: "test visit",
michael@0 65 isInQuery: true
michael@0 66 }
michael@0 67 ];
michael@0 68 let domainsInRange = [2, 3];
michael@0 69 let leveledTestData = [// Today
michael@0 70 [[0], // Today, local files
michael@0 71 [1,2]], // Today, example.com
michael@0 72 // Older than six months
michael@0 73 [[3], // Older than six months, local files
michael@0 74 [4,5], // Older than six months, example.com
michael@0 75 [6] // Older than six months, example.net
michael@0 76 ]];
michael@0 77
michael@0 78 // This test data is meant for live updating. The |levels| property indicates
michael@0 79 // date range index and then domain index.
michael@0 80 let testDataAddedLater = [
michael@0 81 {
michael@0 82 isVisit: true,
michael@0 83 uri: "http://example.com/5",
michael@0 84 lastVisit: olderthansixmonths,
michael@0 85 title: "test visit",
michael@0 86 isInQuery: true,
michael@0 87 levels: [1,1]
michael@0 88 },
michael@0 89 {
michael@0 90 isVisit: true,
michael@0 91 uri: "http://example.com/6",
michael@0 92 lastVisit: olderthansixmonths,
michael@0 93 title: "test visit",
michael@0 94 isInQuery: true,
michael@0 95 levels: [1,1]
michael@0 96 },
michael@0 97 {
michael@0 98 isVisit: true,
michael@0 99 uri: "http://example.com/7",
michael@0 100 lastVisit: today,
michael@0 101 title: "test visit",
michael@0 102 isInQuery: true,
michael@0 103 levels: [0,1]
michael@0 104 },
michael@0 105 {
michael@0 106 isVisit: true,
michael@0 107 uri: "file:///directory/3",
michael@0 108 lastVisit: today,
michael@0 109 title: "test visit",
michael@0 110 isInQuery: true,
michael@0 111 levels: [0,0]
michael@0 112 }
michael@0 113 ];
michael@0 114
michael@0 115 function run_test()
michael@0 116 {
michael@0 117 run_next_test();
michael@0 118 }
michael@0 119
michael@0 120 add_task(function test_sort_date_site_grouping()
michael@0 121 {
michael@0 122 yield task_populateDB(testData);
michael@0 123
michael@0 124 // On Linux, the (local files) folder is shown after sites unlike Mac/Windows.
michael@0 125 // Thus, we avoid running this test on Linux but this should be re-enabled
michael@0 126 // after bug 624024 is resolved.
michael@0 127 let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Components.classes);
michael@0 128 if (isLinux)
michael@0 129 return;
michael@0 130
michael@0 131 // In this test, there are three levels of results:
michael@0 132 // 1st: Date queries. e.g., today, last week, or older than 6 months.
michael@0 133 // 2nd: Domain queries restricted to a date. e.g. mozilla.com today.
michael@0 134 // 3rd: Actual visits. e.g. mozilla.com/index.html today.
michael@0 135 //
michael@0 136 // We store all the third level result roots so that we can easily close all
michael@0 137 // containers and test live updating into specific results.
michael@0 138 let roots = [];
michael@0 139
michael@0 140 let query = PlacesUtils.history.getNewQuery();
michael@0 141 let options = PlacesUtils.history.getNewQueryOptions();
michael@0 142 options.resultType = Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_SITE_QUERY;
michael@0 143
michael@0 144 let root = PlacesUtils.history.executeQuery(query, options).root;
michael@0 145 root.containerOpen = true;
michael@0 146
michael@0 147 // This corresponds to the number of date ranges.
michael@0 148 do_check_eq(root.childCount, leveledTestData.length);
michael@0 149
michael@0 150 // We pass off to |checkFirstLevel| to check the first level of results.
michael@0 151 for (let index = 0; index < leveledTestData.length; index++) {
michael@0 152 let node = root.getChild(index);
michael@0 153 checkFirstLevel(index, node, roots);
michael@0 154 }
michael@0 155
michael@0 156 // Test live updating.
michael@0 157 testDataAddedLater.forEach(function(visit) {
michael@0 158 yield task_populateDB([visit]);
michael@0 159 let oldLength = testData.length;
michael@0 160 let i = visit.levels[0];
michael@0 161 let j = visit.levels[1];
michael@0 162 testData.push(visit);
michael@0 163 leveledTestData[i][j].push(oldLength);
michael@0 164 compareArrayToResult(leveledTestData[i][j].
michael@0 165 map(function(x) testData[x]), roots[i][j]);
michael@0 166 });
michael@0 167
michael@0 168 for (let i = 0; i < roots.length; i++) {
michael@0 169 for (let j = 0; j < roots[i].length; j++)
michael@0 170 roots[i][j].containerOpen = false;
michael@0 171 }
michael@0 172
michael@0 173 root.containerOpen = false;
michael@0 174 });
michael@0 175
michael@0 176 function checkFirstLevel(index, node, roots) {
michael@0 177 PlacesUtils.asContainer(node).containerOpen = true;
michael@0 178
michael@0 179 do_check_true(PlacesUtils.nodeIsDay(node));
michael@0 180 PlacesUtils.asQuery(node);
michael@0 181 let queries = node.getQueries();
michael@0 182 let options = node.queryOptions;
michael@0 183
michael@0 184 do_check_eq(queries.length, 1);
michael@0 185 let query = queries[0];
michael@0 186
michael@0 187 do_check_true(query.hasBeginTime && query.hasEndTime);
michael@0 188
michael@0 189 // Here we check the second level of results.
michael@0 190 let root = PlacesUtils.history.executeQuery(query, options).root;
michael@0 191 roots.push([]);
michael@0 192 root.containerOpen = true;
michael@0 193
michael@0 194 do_check_eq(root.childCount, leveledTestData[index].length);
michael@0 195 for (var secondIndex = 0; secondIndex < root.childCount; secondIndex++) {
michael@0 196 let child = PlacesUtils.asQuery(root.getChild(secondIndex));
michael@0 197 checkSecondLevel(index, secondIndex, child, roots);
michael@0 198 }
michael@0 199 root.containerOpen = false;
michael@0 200 node.containerOpen = false;
michael@0 201 }
michael@0 202
michael@0 203 function checkSecondLevel(index, secondIndex, child, roots) {
michael@0 204 let queries = child.getQueries();
michael@0 205 let options = child.queryOptions;
michael@0 206
michael@0 207 do_check_eq(queries.length, 1);
michael@0 208 let query = queries[0];
michael@0 209
michael@0 210 do_check_true(query.hasDomain);
michael@0 211 do_check_true(query.hasBeginTime && query.hasEndTime);
michael@0 212
michael@0 213 let root = PlacesUtils.history.executeQuery(query, options).root;
michael@0 214 // We should now have that roots[index][secondIndex] is set to the second
michael@0 215 // level's results root.
michael@0 216 roots[index].push(root);
michael@0 217
michael@0 218 // We pass off to compareArrayToResult to check the third level of
michael@0 219 // results.
michael@0 220 root.containerOpen = true;
michael@0 221 compareArrayToResult(leveledTestData[index][secondIndex].
michael@0 222 map(function(x) testData[x]), root);
michael@0 223 // We close |root|'s container later so that we can test live
michael@0 224 // updates into it.
michael@0 225 }

mercurial