toolkit/components/places/tests/queries/test_sorting.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 var tests = [];
michael@0 8
michael@0 9 ////////////////////////////////////////////////////////////////////////////////
michael@0 10
michael@0 11 tests.push({
michael@0 12 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_NONE,
michael@0 13
michael@0 14 setup: function() {
michael@0 15 LOG("Sorting test 1: SORT BY NONE");
michael@0 16
michael@0 17 this._unsortedData = [
michael@0 18 { isBookmark: true,
michael@0 19 uri: "http://example.com/b",
michael@0 20 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 21 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 22 title: "y",
michael@0 23 keyword: "b",
michael@0 24 isInQuery: true },
michael@0 25
michael@0 26 { isBookmark: true,
michael@0 27 uri: "http://example.com/a",
michael@0 28 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 29 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 30 title: "z",
michael@0 31 keyword: "a",
michael@0 32 isInQuery: true },
michael@0 33
michael@0 34 { isBookmark: true,
michael@0 35 uri: "http://example.com/c",
michael@0 36 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 37 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 38 title: "x",
michael@0 39 keyword: "c",
michael@0 40 isInQuery: true },
michael@0 41 ];
michael@0 42
michael@0 43 this._sortedData = this._unsortedData;
michael@0 44
michael@0 45 // This function in head_queries.js creates our database with the above data
michael@0 46 yield task_populateDB(this._unsortedData);
michael@0 47 },
michael@0 48
michael@0 49 check: function() {
michael@0 50 // Query
michael@0 51 var query = PlacesUtils.history.getNewQuery();
michael@0 52 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 53 query.onlyBookmarked = true;
michael@0 54
michael@0 55 // query options
michael@0 56 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 57 options.sortingMode = this._sortingMode;
michael@0 58
michael@0 59 // Results - this gets the result set and opens it for reading and modification.
michael@0 60 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 61 var root = result.root;
michael@0 62 root.containerOpen = true;
michael@0 63 compareArrayToResult(this._sortedData, root);
michael@0 64 root.containerOpen = false;
michael@0 65 },
michael@0 66
michael@0 67 check_reverse: function() {
michael@0 68 // no reverse sorting for SORT BY NONE
michael@0 69 }
michael@0 70 });
michael@0 71
michael@0 72 ////////////////////////////////////////////////////////////////////////////////
michael@0 73
michael@0 74 tests.push({
michael@0 75 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_ASCENDING,
michael@0 76
michael@0 77 setup: function() {
michael@0 78 LOG("Sorting test 2: SORT BY TITLE");
michael@0 79
michael@0 80 this._unsortedData = [
michael@0 81 { isBookmark: true,
michael@0 82 uri: "http://example.com/b1",
michael@0 83 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 84 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 85 title: "y",
michael@0 86 isInQuery: true },
michael@0 87
michael@0 88 { isBookmark: true,
michael@0 89 uri: "http://example.com/a",
michael@0 90 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 91 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 92 title: "z",
michael@0 93 isInQuery: true },
michael@0 94
michael@0 95 { isBookmark: true,
michael@0 96 uri: "http://example.com/c",
michael@0 97 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 98 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 99 title: "x",
michael@0 100 isInQuery: true },
michael@0 101
michael@0 102 // if titles are equal, should fall back to URI
michael@0 103 { isBookmark: true,
michael@0 104 uri: "http://example.com/b2",
michael@0 105 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 106 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 107 title: "y",
michael@0 108 isInQuery: true },
michael@0 109 ];
michael@0 110
michael@0 111 this._sortedData = [
michael@0 112 this._unsortedData[2],
michael@0 113 this._unsortedData[0],
michael@0 114 this._unsortedData[3],
michael@0 115 this._unsortedData[1],
michael@0 116 ];
michael@0 117
michael@0 118 // This function in head_queries.js creates our database with the above data
michael@0 119 yield task_populateDB(this._unsortedData);
michael@0 120 },
michael@0 121
michael@0 122 check: function() {
michael@0 123 // Query
michael@0 124 var query = PlacesUtils.history.getNewQuery();
michael@0 125 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 126 query.onlyBookmarked = true;
michael@0 127
michael@0 128 // query options
michael@0 129 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 130 options.sortingMode = this._sortingMode;
michael@0 131
michael@0 132 // Results - this gets the result set and opens it for reading and modification.
michael@0 133 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 134 var root = result.root;
michael@0 135 root.containerOpen = true;
michael@0 136 compareArrayToResult(this._sortedData, root);
michael@0 137 root.containerOpen = false;
michael@0 138 },
michael@0 139
michael@0 140 check_reverse: function() {
michael@0 141 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_DESCENDING;
michael@0 142 this._sortedData.reverse();
michael@0 143 this.check();
michael@0 144 }
michael@0 145 });
michael@0 146
michael@0 147 ////////////////////////////////////////////////////////////////////////////////
michael@0 148
michael@0 149 tests.push({
michael@0 150 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_ASCENDING,
michael@0 151
michael@0 152 setup: function() {
michael@0 153 LOG("Sorting test 3: SORT BY DATE");
michael@0 154
michael@0 155 var timeInMicroseconds = Date.now() * 1000;
michael@0 156 this._unsortedData = [
michael@0 157 { isVisit: true,
michael@0 158 isDetails: true,
michael@0 159 isBookmark: true,
michael@0 160 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 161 index: 0,
michael@0 162 uri: "http://example.com/c1",
michael@0 163 lastVisit: timeInMicroseconds - 2,
michael@0 164 title: "x1",
michael@0 165 isInQuery: true },
michael@0 166
michael@0 167 { isVisit: true,
michael@0 168 isDetails: true,
michael@0 169 isBookmark: true,
michael@0 170 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 171 index: 1,
michael@0 172 uri: "http://example.com/a",
michael@0 173 lastVisit: timeInMicroseconds - 1,
michael@0 174 title: "z",
michael@0 175 isInQuery: true },
michael@0 176
michael@0 177 { isVisit: true,
michael@0 178 isDetails: true,
michael@0 179 isBookmark: true,
michael@0 180 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 181 index: 2,
michael@0 182 uri: "http://example.com/b",
michael@0 183 lastVisit: timeInMicroseconds - 3,
michael@0 184 title: "y",
michael@0 185 isInQuery: true },
michael@0 186
michael@0 187 // if dates are equal, should fall back to title
michael@0 188 { isVisit: true,
michael@0 189 isDetails: true,
michael@0 190 isBookmark: true,
michael@0 191 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 192 index: 3,
michael@0 193 uri: "http://example.com/c2",
michael@0 194 lastVisit: timeInMicroseconds - 2,
michael@0 195 title: "x2",
michael@0 196 isInQuery: true },
michael@0 197
michael@0 198 // if dates and title are equal, should fall back to bookmark index
michael@0 199 { isVisit: true,
michael@0 200 isDetails: true,
michael@0 201 isBookmark: true,
michael@0 202 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 203 index: 4,
michael@0 204 uri: "http://example.com/c2",
michael@0 205 lastVisit: timeInMicroseconds - 2,
michael@0 206 title: "x2",
michael@0 207 isInQuery: true },
michael@0 208 ];
michael@0 209
michael@0 210 this._sortedData = [
michael@0 211 this._unsortedData[2],
michael@0 212 this._unsortedData[0],
michael@0 213 this._unsortedData[3],
michael@0 214 this._unsortedData[4],
michael@0 215 this._unsortedData[1],
michael@0 216 ];
michael@0 217
michael@0 218 // This function in head_queries.js creates our database with the above data
michael@0 219 yield task_populateDB(this._unsortedData);
michael@0 220 },
michael@0 221
michael@0 222 check: function() {
michael@0 223 // Query
michael@0 224 var query = PlacesUtils.history.getNewQuery();
michael@0 225 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 226 query.onlyBookmarked = true;
michael@0 227
michael@0 228 // query options
michael@0 229 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 230 options.sortingMode = this._sortingMode;
michael@0 231
michael@0 232 // Results - this gets the result set and opens it for reading and modification.
michael@0 233 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 234 var root = result.root;
michael@0 235 root.containerOpen = true;
michael@0 236 compareArrayToResult(this._sortedData, root);
michael@0 237 root.containerOpen = false;
michael@0 238 },
michael@0 239
michael@0 240 check_reverse: function() {
michael@0 241 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
michael@0 242 this._sortedData.reverse();
michael@0 243 this.check();
michael@0 244 }
michael@0 245 });
michael@0 246
michael@0 247 ////////////////////////////////////////////////////////////////////////////////
michael@0 248
michael@0 249 tests.push({
michael@0 250 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_URI_ASCENDING,
michael@0 251
michael@0 252 setup: function() {
michael@0 253 LOG("Sorting test 4: SORT BY URI");
michael@0 254
michael@0 255 var timeInMicroseconds = Date.now() * 1000;
michael@0 256 this._unsortedData = [
michael@0 257 { isBookmark: true,
michael@0 258 isDetails: true,
michael@0 259 lastVisit: timeInMicroseconds,
michael@0 260 uri: "http://example.com/b",
michael@0 261 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 262 index: 0,
michael@0 263 title: "y",
michael@0 264 isInQuery: true },
michael@0 265
michael@0 266 { isBookmark: true,
michael@0 267 uri: "http://example.com/c",
michael@0 268 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 269 index: 1,
michael@0 270 title: "x",
michael@0 271 isInQuery: true },
michael@0 272
michael@0 273 { isBookmark: true,
michael@0 274 uri: "http://example.com/a",
michael@0 275 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 276 index: 2,
michael@0 277 title: "z",
michael@0 278 isInQuery: true },
michael@0 279
michael@0 280 // if URIs are equal, should fall back to date
michael@0 281 { isBookmark: true,
michael@0 282 isDetails: true,
michael@0 283 lastVisit: timeInMicroseconds + 1,
michael@0 284 uri: "http://example.com/c",
michael@0 285 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 286 index: 3,
michael@0 287 title: "x",
michael@0 288 isInQuery: true },
michael@0 289
michael@0 290 // if no URI (e.g., node is a folder), should fall back to title
michael@0 291 { isFolder: true,
michael@0 292 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 293 index: 4,
michael@0 294 title: "a",
michael@0 295 isInQuery: true },
michael@0 296
michael@0 297 // if URIs and dates are equal, should fall back to bookmark index
michael@0 298 { isBookmark: true,
michael@0 299 isDetails: true,
michael@0 300 lastVisit: timeInMicroseconds + 1,
michael@0 301 uri: "http://example.com/c",
michael@0 302 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 303 index: 5,
michael@0 304 title: "x",
michael@0 305 isInQuery: true },
michael@0 306
michael@0 307 // if no URI and titles are equal, should fall back to bookmark index
michael@0 308 { isFolder: true,
michael@0 309 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 310 index: 6,
michael@0 311 title: "a",
michael@0 312 isInQuery: true },
michael@0 313 ];
michael@0 314
michael@0 315 this._sortedData = [
michael@0 316 this._unsortedData[4],
michael@0 317 this._unsortedData[6],
michael@0 318 this._unsortedData[2],
michael@0 319 this._unsortedData[0],
michael@0 320 this._unsortedData[1],
michael@0 321 this._unsortedData[3],
michael@0 322 this._unsortedData[5],
michael@0 323 ];
michael@0 324
michael@0 325 // This function in head_queries.js creates our database with the above data
michael@0 326 yield task_populateDB(this._unsortedData);
michael@0 327 },
michael@0 328
michael@0 329 check: function() {
michael@0 330 // Query
michael@0 331 var query = PlacesUtils.history.getNewQuery();
michael@0 332 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 333
michael@0 334 // query options
michael@0 335 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 336 options.sortingMode = this._sortingMode;
michael@0 337
michael@0 338 // Results - this gets the result set and opens it for reading and modification.
michael@0 339 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 340 var root = result.root;
michael@0 341 root.containerOpen = true;
michael@0 342 compareArrayToResult(this._sortedData, root);
michael@0 343 root.containerOpen = false;
michael@0 344 },
michael@0 345
michael@0 346 check_reverse: function() {
michael@0 347 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_URI_DESCENDING;
michael@0 348 this._sortedData.reverse();
michael@0 349 this.check();
michael@0 350 }
michael@0 351 });
michael@0 352
michael@0 353 ////////////////////////////////////////////////////////////////////////////////
michael@0 354
michael@0 355 tests.push({
michael@0 356 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_ASCENDING,
michael@0 357
michael@0 358 setup: function() {
michael@0 359 LOG("Sorting test 5: SORT BY VISITCOUNT");
michael@0 360
michael@0 361 var timeInMicroseconds = Date.now() * 1000;
michael@0 362 this._unsortedData = [
michael@0 363 { isBookmark: true,
michael@0 364 uri: "http://example.com/a",
michael@0 365 lastVisit: timeInMicroseconds,
michael@0 366 title: "z",
michael@0 367 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 368 index: 0,
michael@0 369 isInQuery: true },
michael@0 370
michael@0 371 { isBookmark: true,
michael@0 372 uri: "http://example.com/c",
michael@0 373 lastVisit: timeInMicroseconds,
michael@0 374 title: "x",
michael@0 375 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 376 index: 1,
michael@0 377 isInQuery: true },
michael@0 378
michael@0 379 { isBookmark: true,
michael@0 380 uri: "http://example.com/b1",
michael@0 381 lastVisit: timeInMicroseconds,
michael@0 382 title: "y1",
michael@0 383 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 384 index: 2,
michael@0 385 isInQuery: true },
michael@0 386
michael@0 387 // if visitCounts are equal, should fall back to date
michael@0 388 { isBookmark: true,
michael@0 389 uri: "http://example.com/b2",
michael@0 390 lastVisit: timeInMicroseconds + 1,
michael@0 391 title: "y2a",
michael@0 392 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 393 index: 3,
michael@0 394 isInQuery: true },
michael@0 395
michael@0 396 // if visitCounts and dates are equal, should fall back to bookmark index
michael@0 397 { isBookmark: true,
michael@0 398 uri: "http://example.com/b2",
michael@0 399 lastVisit: timeInMicroseconds + 1,
michael@0 400 title: "y2b",
michael@0 401 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 402 index: 4,
michael@0 403 isInQuery: true },
michael@0 404 ];
michael@0 405
michael@0 406 this._sortedData = [
michael@0 407 this._unsortedData[0],
michael@0 408 this._unsortedData[2],
michael@0 409 this._unsortedData[3],
michael@0 410 this._unsortedData[4],
michael@0 411 this._unsortedData[1],
michael@0 412 ];
michael@0 413
michael@0 414 // This function in head_queries.js creates our database with the above data
michael@0 415 yield task_populateDB(this._unsortedData);
michael@0 416 // add visits to increase visit count
michael@0 417 yield promiseAddVisits([
michael@0 418 { uri: uri("http://example.com/a"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
michael@0 419 { uri: uri("http://example.com/b1"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
michael@0 420 { uri: uri("http://example.com/b1"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
michael@0 421 { uri: uri("http://example.com/b2"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds + 1 },
michael@0 422 { uri: uri("http://example.com/b2"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds + 1 },
michael@0 423 { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
michael@0 424 { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
michael@0 425 { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
michael@0 426 ]);
michael@0 427 },
michael@0 428
michael@0 429 check: function() {
michael@0 430 // Query
michael@0 431 var query = PlacesUtils.history.getNewQuery();
michael@0 432 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 433 query.onlyBookmarked = true;
michael@0 434
michael@0 435 // query options
michael@0 436 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 437 options.sortingMode = this._sortingMode;
michael@0 438
michael@0 439 // Results - this gets the result set and opens it for reading and modification.
michael@0 440 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 441 var root = result.root;
michael@0 442 root.containerOpen = true;
michael@0 443 compareArrayToResult(this._sortedData, root);
michael@0 444 root.containerOpen = false;
michael@0 445 },
michael@0 446
michael@0 447 check_reverse: function() {
michael@0 448 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING;
michael@0 449 this._sortedData.reverse();
michael@0 450 this.check();
michael@0 451 }
michael@0 452 });
michael@0 453
michael@0 454 ////////////////////////////////////////////////////////////////////////////////
michael@0 455
michael@0 456 tests.push({
michael@0 457 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_KEYWORD_ASCENDING,
michael@0 458
michael@0 459 setup: function() {
michael@0 460 LOG("Sorting test 6: SORT BY KEYWORD");
michael@0 461
michael@0 462 this._unsortedData = [
michael@0 463 { isBookmark: true,
michael@0 464 uri: "http://example.com/a",
michael@0 465 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 466 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 467 title: "z",
michael@0 468 keyword: "a",
michael@0 469 isInQuery: true },
michael@0 470
michael@0 471 { isBookmark: true,
michael@0 472 uri: "http://example.com/c",
michael@0 473 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 474 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 475 title: "x",
michael@0 476 keyword: "c",
michael@0 477 isInQuery: true },
michael@0 478
michael@0 479 { isBookmark: true,
michael@0 480 uri: "http://example.com/b1",
michael@0 481 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 482 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 483 title: "y9",
michael@0 484 keyword: "b",
michael@0 485 isInQuery: true },
michael@0 486
michael@0 487 // without a keyword, should fall back to title
michael@0 488 { isBookmark: true,
michael@0 489 uri: "http://example.com/null2",
michael@0 490 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 491 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 492 title: "null8",
michael@0 493 keyword: null,
michael@0 494 isInQuery: true },
michael@0 495
michael@0 496 // without a keyword, should fall back to title
michael@0 497 { isBookmark: true,
michael@0 498 uri: "http://example.com/null1",
michael@0 499 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 500 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 501 title: "null9",
michael@0 502 keyword: null,
michael@0 503 isInQuery: true },
michael@0 504
michael@0 505 // if keywords are equal, should fall back to title
michael@0 506 { isBookmark: true,
michael@0 507 uri: "http://example.com/b2",
michael@0 508 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 509 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 510 title: "y8",
michael@0 511 keyword: "b",
michael@0 512 isInQuery: true },
michael@0 513 ];
michael@0 514
michael@0 515 this._sortedData = [
michael@0 516 this._unsortedData[3],
michael@0 517 this._unsortedData[4],
michael@0 518 this._unsortedData[0],
michael@0 519 this._unsortedData[5],
michael@0 520 this._unsortedData[2],
michael@0 521 this._unsortedData[1],
michael@0 522 ];
michael@0 523
michael@0 524 // This function in head_queries.js creates our database with the above data
michael@0 525 yield task_populateDB(this._unsortedData);
michael@0 526 },
michael@0 527
michael@0 528 check: function() {
michael@0 529 // Query
michael@0 530 var query = PlacesUtils.history.getNewQuery();
michael@0 531 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 532 query.onlyBookmarked = true;
michael@0 533
michael@0 534 // query options
michael@0 535 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 536 options.sortingMode = this._sortingMode;
michael@0 537
michael@0 538 // Results - this gets the result set and opens it for reading and modification.
michael@0 539 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 540 var root = result.root;
michael@0 541 root.containerOpen = true;
michael@0 542 compareArrayToResult(this._sortedData, root);
michael@0 543 root.containerOpen = false;
michael@0 544 },
michael@0 545
michael@0 546 check_reverse: function() {
michael@0 547 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_KEYWORD_DESCENDING;
michael@0 548 this._sortedData.reverse();
michael@0 549 this.check();
michael@0 550 }
michael@0 551 });
michael@0 552
michael@0 553 ////////////////////////////////////////////////////////////////////////////////
michael@0 554
michael@0 555 tests.push({
michael@0 556 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_ASCENDING,
michael@0 557
michael@0 558 setup: function() {
michael@0 559 LOG("Sorting test 7: SORT BY DATEADDED");
michael@0 560
michael@0 561 var timeInMicroseconds = Date.now() * 1000;
michael@0 562 this._unsortedData = [
michael@0 563 { isBookmark: true,
michael@0 564 uri: "http://example.com/b1",
michael@0 565 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 566 index: 0,
michael@0 567 title: "y1",
michael@0 568 dateAdded: timeInMicroseconds -1,
michael@0 569 isInQuery: true },
michael@0 570
michael@0 571 { isBookmark: true,
michael@0 572 uri: "http://example.com/a",
michael@0 573 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 574 index: 1,
michael@0 575 title: "z",
michael@0 576 dateAdded: timeInMicroseconds - 2,
michael@0 577 isInQuery: true },
michael@0 578
michael@0 579 { isBookmark: true,
michael@0 580 uri: "http://example.com/c",
michael@0 581 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 582 index: 2,
michael@0 583 title: "x",
michael@0 584 dateAdded: timeInMicroseconds,
michael@0 585 isInQuery: true },
michael@0 586
michael@0 587 // if dateAddeds are equal, should fall back to title
michael@0 588 { isBookmark: true,
michael@0 589 uri: "http://example.com/b2",
michael@0 590 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 591 index: 3,
michael@0 592 title: "y2",
michael@0 593 dateAdded: timeInMicroseconds - 1,
michael@0 594 isInQuery: true },
michael@0 595
michael@0 596 // if dateAddeds and titles are equal, should fall back to bookmark index
michael@0 597 { isBookmark: true,
michael@0 598 uri: "http://example.com/b3",
michael@0 599 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 600 index: 4,
michael@0 601 title: "y3",
michael@0 602 dateAdded: timeInMicroseconds - 1,
michael@0 603 isInQuery: true },
michael@0 604 ];
michael@0 605
michael@0 606 this._sortedData = [
michael@0 607 this._unsortedData[1],
michael@0 608 this._unsortedData[0],
michael@0 609 this._unsortedData[3],
michael@0 610 this._unsortedData[4],
michael@0 611 this._unsortedData[2],
michael@0 612 ];
michael@0 613
michael@0 614 // This function in head_queries.js creates our database with the above data
michael@0 615 yield task_populateDB(this._unsortedData);
michael@0 616 },
michael@0 617
michael@0 618 check: function() {
michael@0 619 // Query
michael@0 620 var query = PlacesUtils.history.getNewQuery();
michael@0 621 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 622 query.onlyBookmarked = true;
michael@0 623
michael@0 624 // query options
michael@0 625 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 626 options.sortingMode = this._sortingMode;
michael@0 627
michael@0 628 // Results - this gets the result set and opens it for reading and modification.
michael@0 629 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 630 var root = result.root;
michael@0 631 root.containerOpen = true;
michael@0 632 compareArrayToResult(this._sortedData, root);
michael@0 633 root.containerOpen = false;
michael@0 634 },
michael@0 635
michael@0 636 check_reverse: function() {
michael@0 637 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING;
michael@0 638 this._sortedData.reverse();
michael@0 639 this.check();
michael@0 640 }
michael@0 641 });
michael@0 642
michael@0 643 ////////////////////////////////////////////////////////////////////////////////
michael@0 644
michael@0 645 tests.push({
michael@0 646 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_ASCENDING,
michael@0 647
michael@0 648 setup: function() {
michael@0 649 LOG("Sorting test 8: SORT BY LASTMODIFIED");
michael@0 650
michael@0 651 var timeInMicroseconds = Date.now() * 1000;
michael@0 652 this._unsortedData = [
michael@0 653 { isBookmark: true,
michael@0 654 uri: "http://example.com/b1",
michael@0 655 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 656 index: 0,
michael@0 657 title: "y1",
michael@0 658 lastModified: timeInMicroseconds -1,
michael@0 659 isInQuery: true },
michael@0 660
michael@0 661 { isBookmark: true,
michael@0 662 uri: "http://example.com/a",
michael@0 663 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 664 index: 1,
michael@0 665 title: "z",
michael@0 666 lastModified: timeInMicroseconds - 2,
michael@0 667 isInQuery: true },
michael@0 668
michael@0 669 { isBookmark: true,
michael@0 670 uri: "http://example.com/c",
michael@0 671 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 672 index: 2,
michael@0 673 title: "x",
michael@0 674 lastModified: timeInMicroseconds,
michael@0 675 isInQuery: true },
michael@0 676
michael@0 677 // if lastModifieds are equal, should fall back to title
michael@0 678 { isBookmark: true,
michael@0 679 uri: "http://example.com/b2",
michael@0 680 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 681 index: 3,
michael@0 682 title: "y2",
michael@0 683 lastModified: timeInMicroseconds - 1,
michael@0 684 isInQuery: true },
michael@0 685
michael@0 686 // if lastModifieds and titles are equal, should fall back to bookmark
michael@0 687 // index
michael@0 688 { isBookmark: true,
michael@0 689 uri: "http://example.com/b3",
michael@0 690 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 691 index: 4,
michael@0 692 title: "y3",
michael@0 693 lastModified: timeInMicroseconds - 1,
michael@0 694 isInQuery: true },
michael@0 695 ];
michael@0 696
michael@0 697 this._sortedData = [
michael@0 698 this._unsortedData[1],
michael@0 699 this._unsortedData[0],
michael@0 700 this._unsortedData[3],
michael@0 701 this._unsortedData[4],
michael@0 702 this._unsortedData[2],
michael@0 703 ];
michael@0 704
michael@0 705 // This function in head_queries.js creates our database with the above data
michael@0 706 yield task_populateDB(this._unsortedData);
michael@0 707 },
michael@0 708
michael@0 709 check: function() {
michael@0 710 // Query
michael@0 711 var query = PlacesUtils.history.getNewQuery();
michael@0 712 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 713 query.onlyBookmarked = true;
michael@0 714
michael@0 715 // query options
michael@0 716 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 717 options.sortingMode = this._sortingMode;
michael@0 718
michael@0 719 // Results - this gets the result set and opens it for reading and modification.
michael@0 720 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 721 var root = result.root;
michael@0 722 root.containerOpen = true;
michael@0 723 compareArrayToResult(this._sortedData, root);
michael@0 724 root.containerOpen = false;
michael@0 725 },
michael@0 726
michael@0 727 check_reverse: function() {
michael@0 728 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_DESCENDING;
michael@0 729 this._sortedData.reverse();
michael@0 730 this.check();
michael@0 731 }
michael@0 732 });
michael@0 733
michael@0 734 ////////////////////////////////////////////////////////////////////////////////
michael@0 735
michael@0 736 tests.push({
michael@0 737 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_ASCENDING,
michael@0 738
michael@0 739 setup: function() {
michael@0 740 LOG("Sorting test 9: SORT BY TAGS");
michael@0 741
michael@0 742 this._unsortedData = [
michael@0 743 { isBookmark: true,
michael@0 744 uri: "http://url2.com/",
michael@0 745 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 746 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 747 title: "title x",
michael@0 748 isTag: true,
michael@0 749 tagArray: ["x", "y", "z"],
michael@0 750 isInQuery: true },
michael@0 751
michael@0 752 { isBookmark: true,
michael@0 753 uri: "http://url1a.com/",
michael@0 754 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 755 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 756 title: "title y1",
michael@0 757 isTag: true,
michael@0 758 tagArray: ["a", "b"],
michael@0 759 isInQuery: true },
michael@0 760
michael@0 761 { isBookmark: true,
michael@0 762 uri: "http://url3a.com/",
michael@0 763 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 764 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 765 title: "title w1",
michael@0 766 isInQuery: true },
michael@0 767
michael@0 768 { isBookmark: true,
michael@0 769 uri: "http://url0.com/",
michael@0 770 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 771 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 772 title: "title z",
michael@0 773 isTag: true,
michael@0 774 tagArray: ["a", "y", "z"],
michael@0 775 isInQuery: true },
michael@0 776
michael@0 777 // if tags are equal, should fall back to title
michael@0 778 { isBookmark: true,
michael@0 779 uri: "http://url1b.com/",
michael@0 780 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 781 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 782 title: "title y2",
michael@0 783 isTag: true,
michael@0 784 tagArray: ["b", "a"],
michael@0 785 isInQuery: true },
michael@0 786
michael@0 787 // if tags are equal, should fall back to title
michael@0 788 { isBookmark: true,
michael@0 789 uri: "http://url3b.com/",
michael@0 790 parentFolder: PlacesUtils.bookmarks.toolbarFolder,
michael@0 791 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 792 title: "title w2",
michael@0 793 isInQuery: true },
michael@0 794 ];
michael@0 795
michael@0 796 this._sortedData = [
michael@0 797 this._unsortedData[2],
michael@0 798 this._unsortedData[5],
michael@0 799 this._unsortedData[1],
michael@0 800 this._unsortedData[4],
michael@0 801 this._unsortedData[3],
michael@0 802 this._unsortedData[0],
michael@0 803 ];
michael@0 804
michael@0 805 // This function in head_queries.js creates our database with the above data
michael@0 806 yield task_populateDB(this._unsortedData);
michael@0 807 },
michael@0 808
michael@0 809 check: function() {
michael@0 810 // Query
michael@0 811 var query = PlacesUtils.history.getNewQuery();
michael@0 812 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
michael@0 813 query.onlyBookmarked = true;
michael@0 814
michael@0 815 // query options
michael@0 816 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 817 options.sortingMode = this._sortingMode;
michael@0 818
michael@0 819 // Results - this gets the result set and opens it for reading and modification.
michael@0 820 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 821 var root = result.root;
michael@0 822 root.containerOpen = true;
michael@0 823 compareArrayToResult(this._sortedData, root);
michael@0 824 root.containerOpen = false;
michael@0 825 },
michael@0 826
michael@0 827 check_reverse: function() {
michael@0 828 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_DESCENDING;
michael@0 829 this._sortedData.reverse();
michael@0 830 this.check();
michael@0 831 }
michael@0 832 });
michael@0 833
michael@0 834 ////////////////////////////////////////////////////////////////////////////////
michael@0 835 // SORT_BY_ANNOTATION_* (int32)
michael@0 836
michael@0 837 tests.push({
michael@0 838 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
michael@0 839
michael@0 840 setup: function() {
michael@0 841 LOG("Sorting test 10: SORT BY ANNOTATION (int32)");
michael@0 842
michael@0 843 var timeInMicroseconds = Date.now() * 1000;
michael@0 844 this._unsortedData = [
michael@0 845 { isVisit: true,
michael@0 846 isDetails: true,
michael@0 847 lastVisit: timeInMicroseconds,
michael@0 848 uri: "http://example.com/b1",
michael@0 849 title: "y1",
michael@0 850 isPageAnnotation: true,
michael@0 851 annoName: "sorting",
michael@0 852 annoVal: 2,
michael@0 853 annoFlags: 0,
michael@0 854 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 855 isInQuery: true },
michael@0 856
michael@0 857 { isVisit: true,
michael@0 858 isDetails: true,
michael@0 859 lastVisit: timeInMicroseconds,
michael@0 860 uri: "http://example.com/a",
michael@0 861 title: "z",
michael@0 862 isPageAnnotation: true,
michael@0 863 annoName: "sorting",
michael@0 864 annoVal: 1,
michael@0 865 annoFlags: 0,
michael@0 866 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 867 isInQuery: true },
michael@0 868
michael@0 869 { isVisit: true,
michael@0 870 isDetails: true,
michael@0 871 lastVisit: timeInMicroseconds,
michael@0 872 uri: "http://example.com/c",
michael@0 873 title: "x",
michael@0 874 isPageAnnotation: true,
michael@0 875 annoName: "sorting",
michael@0 876 annoVal: 3,
michael@0 877 annoFlags: 0,
michael@0 878 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 879 isInQuery: true },
michael@0 880
michael@0 881 // if annotations are equal, should fall back to title
michael@0 882 { isVisit: true,
michael@0 883 isDetails: true,
michael@0 884 lastVisit: timeInMicroseconds,
michael@0 885 uri: "http://example.com/b2",
michael@0 886 title: "y2",
michael@0 887 isPageAnnotation: true,
michael@0 888 annoName: "sorting",
michael@0 889 annoVal: 2,
michael@0 890 annoFlags: 0,
michael@0 891 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 892 isInQuery: true },
michael@0 893 ];
michael@0 894
michael@0 895 this._sortedData = [
michael@0 896 this._unsortedData[1],
michael@0 897 this._unsortedData[0],
michael@0 898 this._unsortedData[3],
michael@0 899 this._unsortedData[2],
michael@0 900 ];
michael@0 901
michael@0 902 // This function in head_queries.js creates our database with the above data
michael@0 903 yield task_populateDB(this._unsortedData);
michael@0 904 },
michael@0 905
michael@0 906 check: function() {
michael@0 907 // Query
michael@0 908 var query = PlacesUtils.history.getNewQuery();
michael@0 909
michael@0 910 // query options
michael@0 911 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 912 options.sortingAnnotation = "sorting";
michael@0 913 options.sortingMode = this._sortingMode;
michael@0 914
michael@0 915 // Results - this gets the result set and opens it for reading and modification.
michael@0 916 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 917 var root = result.root;
michael@0 918 root.containerOpen = true;
michael@0 919 compareArrayToResult(this._sortedData, root);
michael@0 920 root.containerOpen = false;
michael@0 921 },
michael@0 922
michael@0 923 check_reverse: function() {
michael@0 924 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
michael@0 925 this._sortedData.reverse();
michael@0 926 this.check();
michael@0 927 }
michael@0 928 });
michael@0 929
michael@0 930 ////////////////////////////////////////////////////////////////////////////////
michael@0 931 // SORT_BY_ANNOTATION_* (int64)
michael@0 932
michael@0 933 tests.push({
michael@0 934 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
michael@0 935
michael@0 936 setup: function() {
michael@0 937 LOG("Sorting test 11: SORT BY ANNOTATION (int64)");
michael@0 938
michael@0 939 var timeInMicroseconds = Date.now() * 1000;
michael@0 940 this._unsortedData = [
michael@0 941 { isVisit: true,
michael@0 942 isDetails: true,
michael@0 943 uri: "http://moz.com/",
michael@0 944 lastVisit: timeInMicroseconds,
michael@0 945 title: "I",
michael@0 946 isPageAnnotation: true,
michael@0 947 annoName: "sorting",
michael@0 948 annoVal: 0xffffffff1,
michael@0 949 annoFlags: 0,
michael@0 950 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 951 isInQuery: true },
michael@0 952
michael@0 953 { isVisit: true,
michael@0 954 isDetails: true,
michael@0 955 uri: "http://is.com/",
michael@0 956 lastVisit: timeInMicroseconds,
michael@0 957 title: "love",
michael@0 958 isPageAnnotation: true,
michael@0 959 annoName: "sorting",
michael@0 960 annoVal: 0xffffffff0,
michael@0 961 annoFlags: 0,
michael@0 962 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 963 isInQuery: true },
michael@0 964
michael@0 965 { isVisit: true,
michael@0 966 isDetails: true,
michael@0 967 uri: "http://best.com/",
michael@0 968 lastVisit: timeInMicroseconds,
michael@0 969 title: "moz",
michael@0 970 isPageAnnotation: true,
michael@0 971 annoName: "sorting",
michael@0 972 annoVal: 0xffffffff2,
michael@0 973 annoFlags: 0,
michael@0 974 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 975 isInQuery: true },
michael@0 976 ];
michael@0 977
michael@0 978 this._sortedData = [
michael@0 979 this._unsortedData[1],
michael@0 980 this._unsortedData[0],
michael@0 981 this._unsortedData[2],
michael@0 982 ];
michael@0 983
michael@0 984 // This function in head_queries.js creates our database with the above data
michael@0 985 yield task_populateDB(this._unsortedData);
michael@0 986 },
michael@0 987
michael@0 988 check: function() {
michael@0 989 // Query
michael@0 990 var query = PlacesUtils.history.getNewQuery();
michael@0 991
michael@0 992 // query options
michael@0 993 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 994 options.sortingAnnotation = "sorting";
michael@0 995 options.sortingMode = this._sortingMode;
michael@0 996
michael@0 997 // Results - this gets the result set and opens it for reading and modification.
michael@0 998 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 999 var root = result.root;
michael@0 1000 root.containerOpen = true;
michael@0 1001 compareArrayToResult(this._sortedData, root);
michael@0 1002 root.containerOpen = false;
michael@0 1003 },
michael@0 1004
michael@0 1005 check_reverse: function() {
michael@0 1006 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
michael@0 1007 this._sortedData.reverse();
michael@0 1008 this.check();
michael@0 1009 }
michael@0 1010 });
michael@0 1011
michael@0 1012 ////////////////////////////////////////////////////////////////////////////////
michael@0 1013 // SORT_BY_ANNOTATION_* (string)
michael@0 1014
michael@0 1015 tests.push({
michael@0 1016 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
michael@0 1017
michael@0 1018 setup: function() {
michael@0 1019 LOG("Sorting test 12: SORT BY ANNOTATION (string)");
michael@0 1020
michael@0 1021 var timeInMicroseconds = Date.now() * 1000;
michael@0 1022 this._unsortedData = [
michael@0 1023 { isVisit: true,
michael@0 1024 isDetails: true,
michael@0 1025 uri: "http://moz.com/",
michael@0 1026 lastVisit: timeInMicroseconds,
michael@0 1027 title: "I",
michael@0 1028 isPageAnnotation: true,
michael@0 1029 annoName: "sorting",
michael@0 1030 annoVal: "a",
michael@0 1031 annoFlags: 0,
michael@0 1032 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 1033 isInQuery: true },
michael@0 1034
michael@0 1035 { isVisit: true,
michael@0 1036 isDetails: true,
michael@0 1037 uri: "http://is.com/",
michael@0 1038 lastVisit: timeInMicroseconds,
michael@0 1039 title: "love",
michael@0 1040 isPageAnnotation: true,
michael@0 1041 annoName: "sorting",
michael@0 1042 annoVal: "",
michael@0 1043 annoFlags: 0,
michael@0 1044 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 1045 isInQuery: true },
michael@0 1046
michael@0 1047 { isVisit: true,
michael@0 1048 isDetails: true,
michael@0 1049 uri: "http://best.com/",
michael@0 1050 lastVisit: timeInMicroseconds,
michael@0 1051 title: "moz",
michael@0 1052 isPageAnnotation: true,
michael@0 1053 annoName: "sorting",
michael@0 1054 annoVal: "z",
michael@0 1055 annoFlags: 0,
michael@0 1056 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 1057 isInQuery: true },
michael@0 1058 ];
michael@0 1059
michael@0 1060 this._sortedData = [
michael@0 1061 this._unsortedData[1],
michael@0 1062 this._unsortedData[0],
michael@0 1063 this._unsortedData[2],
michael@0 1064 ];
michael@0 1065
michael@0 1066 // This function in head_queries.js creates our database with the above data
michael@0 1067 yield task_populateDB(this._unsortedData);
michael@0 1068 },
michael@0 1069
michael@0 1070 check: function() {
michael@0 1071 // Query
michael@0 1072 var query = PlacesUtils.history.getNewQuery();
michael@0 1073
michael@0 1074 // query options
michael@0 1075 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 1076 options.sortingAnnotation = "sorting";
michael@0 1077 options.sortingMode = this._sortingMode;
michael@0 1078
michael@0 1079 // Results - this gets the result set and opens it for reading and modification.
michael@0 1080 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 1081 var root = result.root;
michael@0 1082 root.containerOpen = true;
michael@0 1083 compareArrayToResult(this._sortedData, root);
michael@0 1084 root.containerOpen = false;
michael@0 1085 },
michael@0 1086
michael@0 1087 check_reverse: function() {
michael@0 1088 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
michael@0 1089 this._sortedData.reverse();
michael@0 1090 this.check();
michael@0 1091 }
michael@0 1092 });
michael@0 1093
michael@0 1094 ////////////////////////////////////////////////////////////////////////////////
michael@0 1095 // SORT_BY_ANNOTATION_* (double)
michael@0 1096
michael@0 1097 tests.push({
michael@0 1098 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
michael@0 1099
michael@0 1100 setup: function() {
michael@0 1101 LOG("Sorting test 13: SORT BY ANNOTATION (double)");
michael@0 1102
michael@0 1103 var timeInMicroseconds = Date.now() * 1000;
michael@0 1104 this._unsortedData = [
michael@0 1105 { isVisit: true,
michael@0 1106 isDetails: true,
michael@0 1107 uri: "http://moz.com/",
michael@0 1108 lastVisit: timeInMicroseconds,
michael@0 1109 title: "I",
michael@0 1110 isPageAnnotation: true,
michael@0 1111 annoName: "sorting",
michael@0 1112 annoVal: 1.2,
michael@0 1113 annoFlags: 0,
michael@0 1114 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 1115 isInQuery: true },
michael@0 1116
michael@0 1117 { isVisit: true,
michael@0 1118 isDetails: true,
michael@0 1119 uri: "http://is.com/",
michael@0 1120 lastVisit: timeInMicroseconds,
michael@0 1121 title: "love",
michael@0 1122 isPageAnnotation: true,
michael@0 1123 annoName: "sorting",
michael@0 1124 annoVal: 1.1,
michael@0 1125 annoFlags: 0,
michael@0 1126 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 1127 isInQuery: true },
michael@0 1128
michael@0 1129 { isVisit: true,
michael@0 1130 isDetails: true,
michael@0 1131 uri: "http://best.com/",
michael@0 1132 lastVisit: timeInMicroseconds,
michael@0 1133 title: "moz",
michael@0 1134 isPageAnnotation: true,
michael@0 1135 annoName: "sorting",
michael@0 1136 annoVal: 1.3,
michael@0 1137 annoFlags: 0,
michael@0 1138 annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
michael@0 1139 isInQuery: true },
michael@0 1140 ];
michael@0 1141
michael@0 1142 this._sortedData = [
michael@0 1143 this._unsortedData[1],
michael@0 1144 this._unsortedData[0],
michael@0 1145 this._unsortedData[2],
michael@0 1146 ];
michael@0 1147
michael@0 1148 // This function in head_queries.js creates our database with the above data
michael@0 1149 yield task_populateDB(this._unsortedData);
michael@0 1150 },
michael@0 1151
michael@0 1152 check: function() {
michael@0 1153 // Query
michael@0 1154 var query = PlacesUtils.history.getNewQuery();
michael@0 1155
michael@0 1156 // query options
michael@0 1157 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 1158 options.sortingAnnotation = "sorting";
michael@0 1159 options.sortingMode = this._sortingMode;
michael@0 1160
michael@0 1161 // Results - this gets the result set and opens it for reading and modification.
michael@0 1162 var result = PlacesUtils.history.executeQuery(query, options);
michael@0 1163 var root = result.root;
michael@0 1164 root.containerOpen = true;
michael@0 1165 compareArrayToResult(this._sortedData, root);
michael@0 1166 root.containerOpen = false;
michael@0 1167 },
michael@0 1168
michael@0 1169 check_reverse: function() {
michael@0 1170 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
michael@0 1171 this._sortedData.reverse();
michael@0 1172 this.check();
michael@0 1173 }
michael@0 1174 });
michael@0 1175
michael@0 1176 ////////////////////////////////////////////////////////////////////////////////
michael@0 1177 // SORT_BY_FRECENCY_*
michael@0 1178
michael@0 1179 tests.push({
michael@0 1180 _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_ASCENDING,
michael@0 1181
michael@0 1182 setup: function() {
michael@0 1183 LOG("Sorting test 13: SORT BY FRECENCY ");
michael@0 1184
michael@0 1185 var timeInMicroseconds = Date.now() * 1000;
michael@0 1186 this._unsortedData = [
michael@0 1187 { isVisit: true,
michael@0 1188 isDetails: true,
michael@0 1189 uri: "http://moz.com/",
michael@0 1190 lastVisit: timeInMicroseconds++,
michael@0 1191 title: "I",
michael@0 1192 isInQuery: true },
michael@0 1193
michael@0 1194 { isVisit: true,
michael@0 1195 isDetails: true,
michael@0 1196 uri: "http://moz.com/",
michael@0 1197 lastVisit: timeInMicroseconds++,
michael@0 1198 title: "I",
michael@0 1199 isInQuery: true },
michael@0 1200
michael@0 1201 { isVisit: true,
michael@0 1202 isDetails: true,
michael@0 1203 uri: "http://moz.com/",
michael@0 1204 lastVisit: timeInMicroseconds++,
michael@0 1205 title: "I",
michael@0 1206 isInQuery: true },
michael@0 1207
michael@0 1208 { isVisit: true,
michael@0 1209 isDetails: true,
michael@0 1210 uri: "http://is.com/",
michael@0 1211 lastVisit: timeInMicroseconds++,
michael@0 1212 title: "love",
michael@0 1213 isInQuery: true },
michael@0 1214
michael@0 1215 { isVisit: true,
michael@0 1216 isDetails: true,
michael@0 1217 uri: "http://best.com/",
michael@0 1218 lastVisit: timeInMicroseconds++,
michael@0 1219 title: "moz",
michael@0 1220 isInQuery: true },
michael@0 1221
michael@0 1222 { isVisit: true,
michael@0 1223 isDetails: true,
michael@0 1224 uri: "http://best.com/",
michael@0 1225 lastVisit: timeInMicroseconds++,
michael@0 1226 title: "moz",
michael@0 1227 isInQuery: true },
michael@0 1228 ];
michael@0 1229
michael@0 1230 this._sortedData = [
michael@0 1231 this._unsortedData[3],
michael@0 1232 this._unsortedData[5],
michael@0 1233 this._unsortedData[2],
michael@0 1234 ];
michael@0 1235
michael@0 1236 // This function in head_queries.js creates our database with the above data
michael@0 1237 yield task_populateDB(this._unsortedData);
michael@0 1238 },
michael@0 1239
michael@0 1240 check: function() {
michael@0 1241 var query = PlacesUtils.history.getNewQuery();
michael@0 1242 var options = PlacesUtils.history.getNewQueryOptions();
michael@0 1243 options.sortingMode = this._sortingMode;
michael@0 1244
michael@0 1245 var root = PlacesUtils.history.executeQuery(query, options).root;
michael@0 1246 root.containerOpen = true;
michael@0 1247 compareArrayToResult(this._sortedData, root);
michael@0 1248 root.containerOpen = false;
michael@0 1249 },
michael@0 1250
michael@0 1251 check_reverse: function() {
michael@0 1252 this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_DESCENDING;
michael@0 1253 this._sortedData.reverse();
michael@0 1254 this.check();
michael@0 1255 }
michael@0 1256 });
michael@0 1257
michael@0 1258 ////////////////////////////////////////////////////////////////////////////////
michael@0 1259
michael@0 1260 function run_test()
michael@0 1261 {
michael@0 1262 run_next_test();
michael@0 1263 }
michael@0 1264
michael@0 1265 add_task(function test_sorting()
michael@0 1266 {
michael@0 1267 for (let [, test] in Iterator(tests)) {
michael@0 1268 yield test.setup();
michael@0 1269 yield promiseAsyncUpdates();
michael@0 1270 test.check();
michael@0 1271 // sorting reversed, usually SORT_BY have ASC and DESC
michael@0 1272 test.check_reverse();
michael@0 1273 // Execute cleanup tasks
michael@0 1274 remove_all_bookmarks();
michael@0 1275 yield promiseClearHistory();
michael@0 1276 }
michael@0 1277 });

mercurial