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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/queries/test_sorting.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1277 @@
     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 +var tests = [];
    1.11 +
    1.12 +////////////////////////////////////////////////////////////////////////////////
    1.13 +
    1.14 +tests.push({
    1.15 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_NONE,
    1.16 +
    1.17 +  setup: function() {
    1.18 +    LOG("Sorting test 1: SORT BY NONE");
    1.19 +
    1.20 +    this._unsortedData = [
    1.21 +      { isBookmark: true,
    1.22 +        uri: "http://example.com/b",
    1.23 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
    1.24 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.25 +        title: "y",
    1.26 +        keyword: "b",
    1.27 +        isInQuery: true },
    1.28 +
    1.29 +      { isBookmark: true,
    1.30 +        uri: "http://example.com/a",
    1.31 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
    1.32 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.33 +        title: "z",
    1.34 +        keyword: "a",
    1.35 +        isInQuery: true },
    1.36 +
    1.37 +      { isBookmark: true,
    1.38 +        uri: "http://example.com/c",
    1.39 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
    1.40 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.41 +        title: "x",
    1.42 +        keyword: "c",
    1.43 +        isInQuery: true },
    1.44 +    ];
    1.45 +
    1.46 +    this._sortedData = this._unsortedData;
    1.47 +
    1.48 +    // This function in head_queries.js creates our database with the above data
    1.49 +    yield task_populateDB(this._unsortedData);
    1.50 +  },
    1.51 +
    1.52 +  check: function() {
    1.53 +    // Query
    1.54 +    var query = PlacesUtils.history.getNewQuery();
    1.55 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
    1.56 +    query.onlyBookmarked = true;
    1.57 +
    1.58 +    // query options
    1.59 +    var options = PlacesUtils.history.getNewQueryOptions();
    1.60 +    options.sortingMode = this._sortingMode;
    1.61 +
    1.62 +    // Results - this gets the result set and opens it for reading and modification.
    1.63 +    var result = PlacesUtils.history.executeQuery(query, options);
    1.64 +    var root = result.root;
    1.65 +    root.containerOpen = true;
    1.66 +    compareArrayToResult(this._sortedData, root);
    1.67 +    root.containerOpen = false;
    1.68 +  },
    1.69 +
    1.70 +  check_reverse: function() {
    1.71 +    // no reverse sorting for SORT BY NONE
    1.72 +  }
    1.73 +});
    1.74 +
    1.75 +////////////////////////////////////////////////////////////////////////////////
    1.76 +
    1.77 +tests.push({
    1.78 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_ASCENDING,
    1.79 +
    1.80 +  setup: function() {
    1.81 +    LOG("Sorting test 2: SORT BY TITLE");
    1.82 +
    1.83 +    this._unsortedData = [
    1.84 +      { isBookmark: true,
    1.85 +        uri: "http://example.com/b1",
    1.86 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
    1.87 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.88 +        title: "y",
    1.89 +        isInQuery: true },
    1.90 +
    1.91 +      { isBookmark: true,
    1.92 +        uri: "http://example.com/a",
    1.93 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
    1.94 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.95 +        title: "z",
    1.96 +        isInQuery: true },
    1.97 +
    1.98 +      { isBookmark: true,
    1.99 +        uri: "http://example.com/c",
   1.100 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.101 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.102 +        title: "x",
   1.103 +        isInQuery: true },
   1.104 +
   1.105 +      // if titles are equal, should fall back to URI
   1.106 +      { isBookmark: true,
   1.107 +        uri: "http://example.com/b2",
   1.108 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.109 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.110 +        title: "y",
   1.111 +        isInQuery: true },
   1.112 +    ];
   1.113 +
   1.114 +    this._sortedData = [
   1.115 +      this._unsortedData[2],
   1.116 +      this._unsortedData[0],
   1.117 +      this._unsortedData[3],
   1.118 +      this._unsortedData[1],
   1.119 +    ];
   1.120 +
   1.121 +    // This function in head_queries.js creates our database with the above data
   1.122 +    yield task_populateDB(this._unsortedData);
   1.123 +  },
   1.124 +
   1.125 +  check: function() {
   1.126 +    // Query
   1.127 +    var query = PlacesUtils.history.getNewQuery();
   1.128 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
   1.129 +    query.onlyBookmarked = true;
   1.130 +
   1.131 +    // query options
   1.132 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.133 +    options.sortingMode = this._sortingMode;
   1.134 +
   1.135 +    // Results - this gets the result set and opens it for reading and modification.
   1.136 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.137 +    var root = result.root;
   1.138 +    root.containerOpen = true;
   1.139 +    compareArrayToResult(this._sortedData, root);
   1.140 +    root.containerOpen = false;
   1.141 +  },
   1.142 +
   1.143 +  check_reverse: function() {
   1.144 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_DESCENDING;
   1.145 +    this._sortedData.reverse();
   1.146 +    this.check();
   1.147 +  }
   1.148 +});
   1.149 +
   1.150 +////////////////////////////////////////////////////////////////////////////////
   1.151 +
   1.152 +tests.push({
   1.153 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_ASCENDING,
   1.154 +
   1.155 +  setup: function() {
   1.156 +    LOG("Sorting test 3: SORT BY DATE");
   1.157 +
   1.158 +    var timeInMicroseconds = Date.now() * 1000;
   1.159 +    this._unsortedData = [
   1.160 +      { isVisit: true,
   1.161 +        isDetails: true,
   1.162 +        isBookmark: true,
   1.163 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.164 +        index: 0,
   1.165 +        uri: "http://example.com/c1",
   1.166 +        lastVisit: timeInMicroseconds - 2,
   1.167 +        title: "x1",
   1.168 +        isInQuery: true },
   1.169 +
   1.170 +      { isVisit: true,
   1.171 +        isDetails: true,
   1.172 +        isBookmark: true,
   1.173 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.174 +        index: 1,
   1.175 +        uri: "http://example.com/a",
   1.176 +        lastVisit: timeInMicroseconds - 1,
   1.177 +        title: "z",
   1.178 +        isInQuery: true },
   1.179 +
   1.180 +      { isVisit: true,
   1.181 +        isDetails: true,
   1.182 +        isBookmark: true,
   1.183 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.184 +        index: 2,
   1.185 +        uri: "http://example.com/b",
   1.186 +        lastVisit: timeInMicroseconds - 3,
   1.187 +        title: "y",
   1.188 +        isInQuery: true },
   1.189 +
   1.190 +      // if dates are equal, should fall back to title
   1.191 +      { isVisit: true,
   1.192 +        isDetails: true,
   1.193 +        isBookmark: true,
   1.194 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.195 +        index: 3,
   1.196 +        uri: "http://example.com/c2",
   1.197 +        lastVisit: timeInMicroseconds - 2,
   1.198 +        title: "x2",
   1.199 +        isInQuery: true },
   1.200 +
   1.201 +      // if dates and title are equal, should fall back to bookmark index
   1.202 +      { isVisit: true,
   1.203 +        isDetails: true,
   1.204 +        isBookmark: true,
   1.205 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.206 +        index: 4,
   1.207 +        uri: "http://example.com/c2",
   1.208 +        lastVisit: timeInMicroseconds - 2,
   1.209 +        title: "x2",
   1.210 +        isInQuery: true },
   1.211 +    ];
   1.212 +
   1.213 +    this._sortedData = [
   1.214 +      this._unsortedData[2],
   1.215 +      this._unsortedData[0],
   1.216 +      this._unsortedData[3],
   1.217 +      this._unsortedData[4],
   1.218 +      this._unsortedData[1],
   1.219 +    ];
   1.220 +
   1.221 +    // This function in head_queries.js creates our database with the above data
   1.222 +    yield task_populateDB(this._unsortedData);
   1.223 +  },
   1.224 +
   1.225 +  check: function() {
   1.226 +    // Query
   1.227 +    var query = PlacesUtils.history.getNewQuery();
   1.228 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
   1.229 +    query.onlyBookmarked = true;
   1.230 +
   1.231 +    // query options
   1.232 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.233 +    options.sortingMode = this._sortingMode;
   1.234 +
   1.235 +    // Results - this gets the result set and opens it for reading and modification.
   1.236 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.237 +    var root = result.root;
   1.238 +    root.containerOpen = true;
   1.239 +    compareArrayToResult(this._sortedData, root);
   1.240 +    root.containerOpen = false;
   1.241 +  },
   1.242 +
   1.243 +  check_reverse: function() {
   1.244 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
   1.245 +    this._sortedData.reverse();
   1.246 +    this.check();
   1.247 +  }
   1.248 +});
   1.249 +
   1.250 +////////////////////////////////////////////////////////////////////////////////
   1.251 +
   1.252 +tests.push({
   1.253 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_URI_ASCENDING,
   1.254 +
   1.255 +  setup: function() {
   1.256 +    LOG("Sorting test 4: SORT BY URI");
   1.257 +
   1.258 +    var timeInMicroseconds = Date.now() * 1000;
   1.259 +    this._unsortedData = [
   1.260 +      { isBookmark: true,
   1.261 +        isDetails: true,
   1.262 +        lastVisit: timeInMicroseconds,
   1.263 +        uri: "http://example.com/b",
   1.264 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.265 +        index: 0,
   1.266 +        title: "y",
   1.267 +        isInQuery: true },
   1.268 +
   1.269 +      { isBookmark: true,
   1.270 +        uri: "http://example.com/c",
   1.271 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.272 +        index: 1,
   1.273 +        title: "x",
   1.274 +        isInQuery: true },
   1.275 +
   1.276 +      { isBookmark: true,
   1.277 +        uri: "http://example.com/a",
   1.278 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.279 +        index: 2,
   1.280 +        title: "z",
   1.281 +        isInQuery: true },
   1.282 +
   1.283 +      // if URIs are equal, should fall back to date
   1.284 +      { isBookmark: true,
   1.285 +        isDetails: true,
   1.286 +        lastVisit: timeInMicroseconds + 1,
   1.287 +        uri: "http://example.com/c",
   1.288 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.289 +        index: 3,
   1.290 +        title: "x",
   1.291 +        isInQuery: true },
   1.292 +
   1.293 +      // if no URI (e.g., node is a folder), should fall back to title
   1.294 +      { isFolder: true,
   1.295 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.296 +        index: 4,
   1.297 +        title: "a",
   1.298 +        isInQuery: true },
   1.299 +
   1.300 +      // if URIs and dates are equal, should fall back to bookmark index
   1.301 +      { isBookmark: true,
   1.302 +        isDetails: true,
   1.303 +        lastVisit: timeInMicroseconds + 1,
   1.304 +        uri: "http://example.com/c",
   1.305 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.306 +        index: 5,
   1.307 +        title: "x",
   1.308 +        isInQuery: true },
   1.309 +
   1.310 +      // if no URI and titles are equal, should fall back to bookmark index
   1.311 +      { isFolder: true,
   1.312 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.313 +        index: 6,
   1.314 +        title: "a",
   1.315 +        isInQuery: true },
   1.316 +    ];
   1.317 +
   1.318 +    this._sortedData = [
   1.319 +      this._unsortedData[4],
   1.320 +      this._unsortedData[6],
   1.321 +      this._unsortedData[2],
   1.322 +      this._unsortedData[0],
   1.323 +      this._unsortedData[1],
   1.324 +      this._unsortedData[3],
   1.325 +      this._unsortedData[5],
   1.326 +    ];
   1.327 +
   1.328 +    // This function in head_queries.js creates our database with the above data
   1.329 +    yield task_populateDB(this._unsortedData);
   1.330 +  },
   1.331 +
   1.332 +  check: function() {
   1.333 +    // Query
   1.334 +    var query = PlacesUtils.history.getNewQuery();
   1.335 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
   1.336 +
   1.337 +    // query options
   1.338 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.339 +    options.sortingMode = this._sortingMode;
   1.340 +
   1.341 +    // Results - this gets the result set and opens it for reading and modification.
   1.342 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.343 +    var root = result.root;
   1.344 +    root.containerOpen = true;
   1.345 +    compareArrayToResult(this._sortedData, root);
   1.346 +    root.containerOpen = false;
   1.347 +  },
   1.348 +
   1.349 +  check_reverse: function() {
   1.350 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_URI_DESCENDING;
   1.351 +    this._sortedData.reverse();
   1.352 +    this.check();
   1.353 +  }
   1.354 +});
   1.355 +
   1.356 +////////////////////////////////////////////////////////////////////////////////
   1.357 +
   1.358 +tests.push({
   1.359 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_ASCENDING,
   1.360 +
   1.361 +  setup: function() {
   1.362 +    LOG("Sorting test 5: SORT BY VISITCOUNT");
   1.363 +
   1.364 +    var timeInMicroseconds = Date.now() * 1000;
   1.365 +    this._unsortedData = [
   1.366 +      { isBookmark: true,
   1.367 +        uri: "http://example.com/a",
   1.368 +        lastVisit: timeInMicroseconds,
   1.369 +        title: "z",
   1.370 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.371 +        index: 0,
   1.372 +        isInQuery: true },
   1.373 +
   1.374 +      { isBookmark: true,
   1.375 +        uri: "http://example.com/c",
   1.376 +        lastVisit: timeInMicroseconds,
   1.377 +        title: "x",
   1.378 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.379 +        index: 1,
   1.380 +        isInQuery: true },
   1.381 +
   1.382 +      { isBookmark: true,
   1.383 +        uri: "http://example.com/b1",
   1.384 +        lastVisit: timeInMicroseconds,
   1.385 +        title: "y1",
   1.386 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.387 +        index: 2,
   1.388 +        isInQuery: true },
   1.389 +
   1.390 +      // if visitCounts are equal, should fall back to date
   1.391 +      { isBookmark: true,
   1.392 +        uri: "http://example.com/b2",
   1.393 +        lastVisit: timeInMicroseconds + 1,
   1.394 +        title: "y2a",
   1.395 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.396 +        index: 3,
   1.397 +        isInQuery: true },
   1.398 +
   1.399 +      // if visitCounts and dates are equal, should fall back to bookmark index
   1.400 +      { isBookmark: true,
   1.401 +        uri: "http://example.com/b2",
   1.402 +        lastVisit: timeInMicroseconds + 1,
   1.403 +        title: "y2b",
   1.404 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.405 +        index: 4,
   1.406 +        isInQuery: true },
   1.407 +    ];
   1.408 +
   1.409 +    this._sortedData = [
   1.410 +      this._unsortedData[0],
   1.411 +      this._unsortedData[2],
   1.412 +      this._unsortedData[3],
   1.413 +      this._unsortedData[4],
   1.414 +      this._unsortedData[1],
   1.415 +    ];
   1.416 +
   1.417 +    // This function in head_queries.js creates our database with the above data
   1.418 +    yield task_populateDB(this._unsortedData);
   1.419 +    // add visits to increase visit count
   1.420 +    yield promiseAddVisits([
   1.421 +      { uri: uri("http://example.com/a"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
   1.422 +      { uri: uri("http://example.com/b1"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
   1.423 +      { uri: uri("http://example.com/b1"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
   1.424 +      { uri: uri("http://example.com/b2"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds + 1 },
   1.425 +      { uri: uri("http://example.com/b2"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds + 1 },
   1.426 +      { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
   1.427 +      { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
   1.428 +      { uri: uri("http://example.com/c"), transition: TRANSITION_TYPED, visitDate: timeInMicroseconds },
   1.429 +    ]);
   1.430 +  },
   1.431 +
   1.432 +  check: function() {
   1.433 +    // Query
   1.434 +    var query = PlacesUtils.history.getNewQuery();
   1.435 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
   1.436 +    query.onlyBookmarked = true;
   1.437 +
   1.438 +    // query options
   1.439 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.440 +    options.sortingMode = this._sortingMode;
   1.441 +
   1.442 +    // Results - this gets the result set and opens it for reading and modification.
   1.443 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.444 +    var root = result.root;
   1.445 +    root.containerOpen = true;
   1.446 +    compareArrayToResult(this._sortedData, root);
   1.447 +    root.containerOpen = false;
   1.448 +  },
   1.449 +
   1.450 +  check_reverse: function() {
   1.451 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING;
   1.452 +    this._sortedData.reverse();
   1.453 +    this.check();
   1.454 +  }
   1.455 +});
   1.456 +
   1.457 +////////////////////////////////////////////////////////////////////////////////
   1.458 +
   1.459 +tests.push({
   1.460 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_KEYWORD_ASCENDING,
   1.461 +
   1.462 +  setup: function() {
   1.463 +    LOG("Sorting test 6: SORT BY KEYWORD");
   1.464 +
   1.465 +    this._unsortedData = [
   1.466 +      { isBookmark: true,
   1.467 +        uri: "http://example.com/a",
   1.468 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.469 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.470 +        title: "z",
   1.471 +        keyword: "a",
   1.472 +        isInQuery: true },
   1.473 +
   1.474 +      { isBookmark: true,
   1.475 +        uri: "http://example.com/c",
   1.476 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.477 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.478 +        title: "x",
   1.479 +        keyword: "c",
   1.480 +        isInQuery: true },
   1.481 +
   1.482 +      { isBookmark: true,
   1.483 +        uri: "http://example.com/b1",
   1.484 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.485 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.486 +        title: "y9",
   1.487 +        keyword: "b",
   1.488 +        isInQuery: true },
   1.489 +
   1.490 +      // without a keyword, should fall back to title
   1.491 +      { isBookmark: true,
   1.492 +        uri: "http://example.com/null2",
   1.493 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.494 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.495 +        title: "null8",
   1.496 +        keyword: null,
   1.497 +        isInQuery: true },
   1.498 +
   1.499 +      // without a keyword, should fall back to title
   1.500 +      { isBookmark: true,
   1.501 +        uri: "http://example.com/null1",
   1.502 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.503 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.504 +        title: "null9",
   1.505 +        keyword: null,
   1.506 +        isInQuery: true },
   1.507 +
   1.508 +      // if keywords are equal, should fall back to title
   1.509 +      { isBookmark: true,
   1.510 +        uri: "http://example.com/b2",
   1.511 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.512 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.513 +        title: "y8",
   1.514 +        keyword: "b",
   1.515 +        isInQuery: true },
   1.516 +    ];
   1.517 +
   1.518 +    this._sortedData = [
   1.519 +      this._unsortedData[3],
   1.520 +      this._unsortedData[4],
   1.521 +      this._unsortedData[0],
   1.522 +      this._unsortedData[5],
   1.523 +      this._unsortedData[2],
   1.524 +      this._unsortedData[1],
   1.525 +    ];
   1.526 +
   1.527 +    // This function in head_queries.js creates our database with the above data
   1.528 +    yield task_populateDB(this._unsortedData);
   1.529 +  },
   1.530 +
   1.531 +  check: function() {
   1.532 +    // Query
   1.533 +    var query = PlacesUtils.history.getNewQuery();
   1.534 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
   1.535 +    query.onlyBookmarked = true;
   1.536 +
   1.537 +    // query options
   1.538 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.539 +    options.sortingMode = this._sortingMode;
   1.540 +
   1.541 +    // Results - this gets the result set and opens it for reading and modification.
   1.542 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.543 +    var root = result.root;
   1.544 +    root.containerOpen = true;
   1.545 +    compareArrayToResult(this._sortedData, root);
   1.546 +    root.containerOpen = false;
   1.547 +  },
   1.548 +
   1.549 +  check_reverse: function() {
   1.550 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_KEYWORD_DESCENDING;
   1.551 +    this._sortedData.reverse();
   1.552 +    this.check();
   1.553 +  }
   1.554 +});
   1.555 +
   1.556 +////////////////////////////////////////////////////////////////////////////////
   1.557 +
   1.558 +tests.push({
   1.559 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_ASCENDING,
   1.560 +
   1.561 +  setup: function() {
   1.562 +    LOG("Sorting test 7: SORT BY DATEADDED");
   1.563 +
   1.564 +    var timeInMicroseconds = Date.now() * 1000;
   1.565 +    this._unsortedData = [
   1.566 +      { isBookmark: true,
   1.567 +        uri: "http://example.com/b1",
   1.568 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.569 +        index: 0,
   1.570 +        title: "y1",
   1.571 +        dateAdded: timeInMicroseconds -1,
   1.572 +        isInQuery: true },
   1.573 +
   1.574 +      { isBookmark: true,
   1.575 +        uri: "http://example.com/a",
   1.576 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.577 +        index: 1,
   1.578 +        title: "z",
   1.579 +        dateAdded: timeInMicroseconds - 2,
   1.580 +        isInQuery: true },
   1.581 +
   1.582 +      { isBookmark: true,
   1.583 +        uri: "http://example.com/c",
   1.584 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.585 +        index: 2,
   1.586 +        title: "x",
   1.587 +        dateAdded: timeInMicroseconds,
   1.588 +        isInQuery: true },
   1.589 +
   1.590 +      // if dateAddeds are equal, should fall back to title
   1.591 +      { isBookmark: true,
   1.592 +        uri: "http://example.com/b2",
   1.593 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.594 +        index: 3,
   1.595 +        title: "y2",
   1.596 +        dateAdded: timeInMicroseconds - 1,
   1.597 +        isInQuery: true },
   1.598 +
   1.599 +      // if dateAddeds and titles are equal, should fall back to bookmark index
   1.600 +      { isBookmark: true,
   1.601 +        uri: "http://example.com/b3",
   1.602 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.603 +        index: 4,
   1.604 +        title: "y3",
   1.605 +        dateAdded: timeInMicroseconds - 1,
   1.606 +        isInQuery: true },
   1.607 +    ];
   1.608 +
   1.609 +    this._sortedData = [
   1.610 +      this._unsortedData[1],
   1.611 +      this._unsortedData[0],
   1.612 +      this._unsortedData[3],
   1.613 +      this._unsortedData[4],
   1.614 +      this._unsortedData[2],
   1.615 +    ];
   1.616 +
   1.617 +    // This function in head_queries.js creates our database with the above data
   1.618 +    yield task_populateDB(this._unsortedData);
   1.619 +  },
   1.620 +
   1.621 +  check: function() {
   1.622 +    // Query
   1.623 +    var query = PlacesUtils.history.getNewQuery();
   1.624 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
   1.625 +    query.onlyBookmarked = true;
   1.626 +
   1.627 +    // query options
   1.628 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.629 +    options.sortingMode = this._sortingMode;
   1.630 +
   1.631 +    // Results - this gets the result set and opens it for reading and modification.
   1.632 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.633 +    var root = result.root;
   1.634 +    root.containerOpen = true;
   1.635 +    compareArrayToResult(this._sortedData, root);
   1.636 +    root.containerOpen = false;
   1.637 +  },
   1.638 +
   1.639 +  check_reverse: function() {
   1.640 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING;
   1.641 +    this._sortedData.reverse();
   1.642 +    this.check();
   1.643 +  }
   1.644 +});
   1.645 +
   1.646 +////////////////////////////////////////////////////////////////////////////////
   1.647 +
   1.648 +tests.push({
   1.649 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_ASCENDING,
   1.650 +
   1.651 +  setup: function() {
   1.652 +    LOG("Sorting test 8: SORT BY LASTMODIFIED");
   1.653 +
   1.654 +    var timeInMicroseconds = Date.now() * 1000;
   1.655 +    this._unsortedData = [
   1.656 +      { isBookmark: true,
   1.657 +        uri: "http://example.com/b1",
   1.658 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.659 +        index: 0,
   1.660 +        title: "y1",
   1.661 +        lastModified: timeInMicroseconds -1,
   1.662 +        isInQuery: true },
   1.663 +
   1.664 +      { isBookmark: true,
   1.665 +        uri: "http://example.com/a",
   1.666 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.667 +        index: 1,
   1.668 +        title: "z",
   1.669 +        lastModified: timeInMicroseconds - 2,
   1.670 +        isInQuery: true },
   1.671 +
   1.672 +      { isBookmark: true,
   1.673 +        uri: "http://example.com/c",
   1.674 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.675 +        index: 2,
   1.676 +        title: "x",
   1.677 +        lastModified: timeInMicroseconds,
   1.678 +        isInQuery: true },
   1.679 +
   1.680 +      // if lastModifieds are equal, should fall back to title
   1.681 +      { isBookmark: true,
   1.682 +        uri: "http://example.com/b2",
   1.683 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.684 +        index: 3,
   1.685 +        title: "y2",
   1.686 +        lastModified: timeInMicroseconds - 1,
   1.687 +        isInQuery: true },
   1.688 +
   1.689 +      // if lastModifieds and titles are equal, should fall back to bookmark
   1.690 +      // index
   1.691 +      { isBookmark: true,
   1.692 +        uri: "http://example.com/b3",
   1.693 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.694 +        index: 4,
   1.695 +        title: "y3",
   1.696 +        lastModified: timeInMicroseconds - 1,
   1.697 +        isInQuery: true },
   1.698 +    ];
   1.699 +
   1.700 +    this._sortedData = [
   1.701 +      this._unsortedData[1],
   1.702 +      this._unsortedData[0],
   1.703 +      this._unsortedData[3],
   1.704 +      this._unsortedData[4],
   1.705 +      this._unsortedData[2],
   1.706 +    ];
   1.707 +
   1.708 +    // This function in head_queries.js creates our database with the above data
   1.709 +    yield task_populateDB(this._unsortedData);
   1.710 +  },
   1.711 +
   1.712 +  check: function() {
   1.713 +    // Query
   1.714 +    var query = PlacesUtils.history.getNewQuery();
   1.715 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
   1.716 +    query.onlyBookmarked = true;
   1.717 +
   1.718 +    // query options
   1.719 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.720 +    options.sortingMode = this._sortingMode;
   1.721 +
   1.722 +    // Results - this gets the result set and opens it for reading and modification.
   1.723 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.724 +    var root = result.root;
   1.725 +    root.containerOpen = true;
   1.726 +    compareArrayToResult(this._sortedData, root);
   1.727 +    root.containerOpen = false;
   1.728 +  },
   1.729 +
   1.730 +  check_reverse: function() {
   1.731 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_DESCENDING;
   1.732 +    this._sortedData.reverse();
   1.733 +    this.check();
   1.734 +  }
   1.735 +});
   1.736 +
   1.737 +////////////////////////////////////////////////////////////////////////////////
   1.738 +
   1.739 +tests.push({
   1.740 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_ASCENDING,
   1.741 +
   1.742 +  setup: function() {
   1.743 +    LOG("Sorting test 9: SORT BY TAGS");
   1.744 +
   1.745 +    this._unsortedData = [
   1.746 +      { isBookmark: true,
   1.747 +        uri: "http://url2.com/",
   1.748 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.749 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.750 +        title: "title x",
   1.751 +        isTag: true,
   1.752 +        tagArray: ["x", "y", "z"],
   1.753 +        isInQuery: true },
   1.754 +
   1.755 +      { isBookmark: true,
   1.756 +        uri: "http://url1a.com/",
   1.757 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.758 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.759 +        title: "title y1",
   1.760 +        isTag: true,
   1.761 +        tagArray: ["a", "b"],
   1.762 +        isInQuery: true },
   1.763 +
   1.764 +      { isBookmark: true,
   1.765 +        uri: "http://url3a.com/",
   1.766 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.767 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.768 +        title: "title w1",
   1.769 +        isInQuery: true },
   1.770 +
   1.771 +      { isBookmark: true,
   1.772 +        uri: "http://url0.com/",
   1.773 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.774 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.775 +        title: "title z",
   1.776 +        isTag: true,
   1.777 +        tagArray: ["a", "y", "z"],
   1.778 +        isInQuery: true },
   1.779 +
   1.780 +      // if tags are equal, should fall back to title
   1.781 +      { isBookmark: true,
   1.782 +        uri: "http://url1b.com/",
   1.783 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.784 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.785 +        title: "title y2",
   1.786 +        isTag: true,
   1.787 +        tagArray: ["b", "a"],
   1.788 +        isInQuery: true },
   1.789 +
   1.790 +      // if tags are equal, should fall back to title
   1.791 +      { isBookmark: true,
   1.792 +        uri: "http://url3b.com/",
   1.793 +        parentFolder: PlacesUtils.bookmarks.toolbarFolder,
   1.794 +        index: PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.795 +        title: "title w2",
   1.796 +        isInQuery: true },
   1.797 +    ];
   1.798 +
   1.799 +    this._sortedData = [
   1.800 +      this._unsortedData[2],
   1.801 +      this._unsortedData[5],
   1.802 +      this._unsortedData[1],
   1.803 +      this._unsortedData[4],
   1.804 +      this._unsortedData[3],
   1.805 +      this._unsortedData[0],
   1.806 +    ];
   1.807 +
   1.808 +    // This function in head_queries.js creates our database with the above data
   1.809 +    yield task_populateDB(this._unsortedData);
   1.810 +  },
   1.811 +
   1.812 +  check: function() {
   1.813 +    // Query
   1.814 +    var query = PlacesUtils.history.getNewQuery();
   1.815 +    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
   1.816 +    query.onlyBookmarked = true;
   1.817 +
   1.818 +    // query options
   1.819 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.820 +    options.sortingMode = this._sortingMode;
   1.821 +
   1.822 +    // Results - this gets the result set and opens it for reading and modification.
   1.823 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.824 +    var root = result.root;
   1.825 +    root.containerOpen = true;
   1.826 +    compareArrayToResult(this._sortedData, root);
   1.827 +    root.containerOpen = false;
   1.828 +  },
   1.829 +
   1.830 +  check_reverse: function() {
   1.831 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_DESCENDING;
   1.832 +    this._sortedData.reverse();
   1.833 +    this.check();
   1.834 +  }
   1.835 +});
   1.836 +
   1.837 +////////////////////////////////////////////////////////////////////////////////
   1.838 +// SORT_BY_ANNOTATION_* (int32)
   1.839 +
   1.840 +tests.push({
   1.841 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
   1.842 +
   1.843 +  setup: function() {
   1.844 +    LOG("Sorting test 10: SORT BY ANNOTATION (int32)");
   1.845 +
   1.846 +    var timeInMicroseconds = Date.now() * 1000;
   1.847 +    this._unsortedData = [
   1.848 +      { isVisit: true,
   1.849 +        isDetails: true,
   1.850 +        lastVisit: timeInMicroseconds,
   1.851 +        uri: "http://example.com/b1",
   1.852 +        title: "y1",
   1.853 +        isPageAnnotation: true,
   1.854 +        annoName: "sorting",
   1.855 +        annoVal: 2,
   1.856 +        annoFlags: 0,
   1.857 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
   1.858 +        isInQuery: true },
   1.859 +
   1.860 +      { isVisit: true,
   1.861 +        isDetails: true,
   1.862 +        lastVisit: timeInMicroseconds,
   1.863 +        uri: "http://example.com/a",
   1.864 +        title: "z",
   1.865 +        isPageAnnotation: true,
   1.866 +        annoName: "sorting",
   1.867 +        annoVal: 1,
   1.868 +        annoFlags: 0,
   1.869 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
   1.870 +        isInQuery: true },
   1.871 +
   1.872 +      { isVisit: true,
   1.873 +        isDetails: true,
   1.874 +        lastVisit: timeInMicroseconds,
   1.875 +        uri: "http://example.com/c",
   1.876 +        title: "x",
   1.877 +        isPageAnnotation: true,
   1.878 +        annoName: "sorting",
   1.879 +        annoVal: 3,
   1.880 +        annoFlags: 0,
   1.881 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
   1.882 +        isInQuery: true },
   1.883 +
   1.884 +      // if annotations are equal, should fall back to title
   1.885 +      { isVisit: true,
   1.886 +        isDetails: true,
   1.887 +        lastVisit: timeInMicroseconds,
   1.888 +        uri: "http://example.com/b2",
   1.889 +        title: "y2",
   1.890 +        isPageAnnotation: true,
   1.891 +        annoName: "sorting",
   1.892 +        annoVal: 2,
   1.893 +        annoFlags: 0,
   1.894 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
   1.895 +        isInQuery: true },
   1.896 +    ];
   1.897 +
   1.898 +    this._sortedData = [
   1.899 +      this._unsortedData[1],
   1.900 +      this._unsortedData[0],
   1.901 +      this._unsortedData[3],
   1.902 +      this._unsortedData[2],
   1.903 +    ];
   1.904 +
   1.905 +    // This function in head_queries.js creates our database with the above data
   1.906 +    yield task_populateDB(this._unsortedData);
   1.907 +  },
   1.908 +
   1.909 +  check: function() {
   1.910 +    // Query
   1.911 +    var query = PlacesUtils.history.getNewQuery();
   1.912 +
   1.913 +    // query options
   1.914 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.915 +    options.sortingAnnotation = "sorting";
   1.916 +    options.sortingMode = this._sortingMode;
   1.917 +
   1.918 +    // Results - this gets the result set and opens it for reading and modification.
   1.919 +    var result = PlacesUtils.history.executeQuery(query, options);
   1.920 +    var root = result.root;
   1.921 +    root.containerOpen = true;
   1.922 +    compareArrayToResult(this._sortedData, root);
   1.923 +    root.containerOpen = false;
   1.924 +  },
   1.925 +
   1.926 +  check_reverse: function() {
   1.927 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
   1.928 +    this._sortedData.reverse();
   1.929 +    this.check();
   1.930 +  }
   1.931 +});
   1.932 +
   1.933 +////////////////////////////////////////////////////////////////////////////////
   1.934 +// SORT_BY_ANNOTATION_* (int64)
   1.935 +
   1.936 +tests.push({
   1.937 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
   1.938 +
   1.939 +  setup: function() {
   1.940 +    LOG("Sorting test 11: SORT BY ANNOTATION (int64)");
   1.941 +
   1.942 +    var timeInMicroseconds = Date.now() * 1000;
   1.943 +    this._unsortedData = [
   1.944 +      { isVisit: true,
   1.945 +        isDetails: true,
   1.946 +        uri: "http://moz.com/",
   1.947 +        lastVisit: timeInMicroseconds,
   1.948 +        title: "I",
   1.949 +        isPageAnnotation: true,
   1.950 +        annoName: "sorting",
   1.951 +        annoVal: 0xffffffff1,
   1.952 +        annoFlags: 0,
   1.953 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
   1.954 +        isInQuery: true },
   1.955 +
   1.956 +      { isVisit: true,
   1.957 +        isDetails: true,
   1.958 +        uri: "http://is.com/",
   1.959 +        lastVisit: timeInMicroseconds,
   1.960 +        title: "love",
   1.961 +        isPageAnnotation: true,
   1.962 +        annoName: "sorting",
   1.963 +        annoVal: 0xffffffff0,
   1.964 +        annoFlags: 0,
   1.965 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
   1.966 +        isInQuery: true },
   1.967 +
   1.968 +      { isVisit: true,
   1.969 +        isDetails: true,
   1.970 +        uri: "http://best.com/",
   1.971 +        lastVisit: timeInMicroseconds,
   1.972 +        title: "moz",
   1.973 +        isPageAnnotation: true,
   1.974 +        annoName: "sorting",
   1.975 +        annoVal: 0xffffffff2,
   1.976 +        annoFlags: 0,
   1.977 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
   1.978 +        isInQuery: true },
   1.979 +    ];
   1.980 +
   1.981 +    this._sortedData = [
   1.982 +      this._unsortedData[1],
   1.983 +      this._unsortedData[0],
   1.984 +      this._unsortedData[2],
   1.985 +    ];
   1.986 +
   1.987 +    // This function in head_queries.js creates our database with the above data
   1.988 +    yield task_populateDB(this._unsortedData);
   1.989 +  },
   1.990 +
   1.991 +  check: function() {
   1.992 +    // Query
   1.993 +    var query = PlacesUtils.history.getNewQuery();
   1.994 +
   1.995 +    // query options
   1.996 +    var options = PlacesUtils.history.getNewQueryOptions();
   1.997 +    options.sortingAnnotation = "sorting";
   1.998 +    options.sortingMode = this._sortingMode;
   1.999 +
  1.1000 +    // Results - this gets the result set and opens it for reading and modification.
  1.1001 +    var result = PlacesUtils.history.executeQuery(query, options);
  1.1002 +    var root = result.root;
  1.1003 +    root.containerOpen = true;
  1.1004 +    compareArrayToResult(this._sortedData, root);
  1.1005 +    root.containerOpen = false;
  1.1006 +  },
  1.1007 +
  1.1008 +  check_reverse: function() {
  1.1009 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
  1.1010 +    this._sortedData.reverse();
  1.1011 +    this.check();
  1.1012 +  }
  1.1013 +});
  1.1014 +
  1.1015 +////////////////////////////////////////////////////////////////////////////////
  1.1016 +// SORT_BY_ANNOTATION_* (string)
  1.1017 +
  1.1018 +tests.push({
  1.1019 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
  1.1020 +
  1.1021 +  setup: function() {
  1.1022 +    LOG("Sorting test 12: SORT BY ANNOTATION (string)");
  1.1023 +
  1.1024 +    var timeInMicroseconds = Date.now() * 1000;
  1.1025 +    this._unsortedData = [
  1.1026 +      { isVisit: true,
  1.1027 +        isDetails: true,
  1.1028 +        uri: "http://moz.com/",
  1.1029 +        lastVisit: timeInMicroseconds,
  1.1030 +        title: "I",
  1.1031 +        isPageAnnotation: true,
  1.1032 +        annoName: "sorting",
  1.1033 +        annoVal: "a",
  1.1034 +        annoFlags: 0,
  1.1035 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
  1.1036 +        isInQuery: true },
  1.1037 +
  1.1038 +      { isVisit: true,
  1.1039 +        isDetails: true,
  1.1040 +        uri: "http://is.com/",
  1.1041 +        lastVisit: timeInMicroseconds,
  1.1042 +        title: "love",
  1.1043 +        isPageAnnotation: true,
  1.1044 +        annoName: "sorting",
  1.1045 +        annoVal: "",
  1.1046 +        annoFlags: 0,
  1.1047 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
  1.1048 +        isInQuery: true },
  1.1049 +
  1.1050 +      { isVisit: true,
  1.1051 +        isDetails: true,
  1.1052 +        uri: "http://best.com/",
  1.1053 +        lastVisit: timeInMicroseconds,
  1.1054 +        title: "moz",
  1.1055 +        isPageAnnotation: true,
  1.1056 +        annoName: "sorting",
  1.1057 +        annoVal: "z",
  1.1058 +        annoFlags: 0,
  1.1059 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
  1.1060 +        isInQuery: true },
  1.1061 +    ];
  1.1062 +
  1.1063 +    this._sortedData = [
  1.1064 +      this._unsortedData[1],
  1.1065 +      this._unsortedData[0],
  1.1066 +      this._unsortedData[2],
  1.1067 +    ];
  1.1068 +
  1.1069 +    // This function in head_queries.js creates our database with the above data
  1.1070 +    yield task_populateDB(this._unsortedData);
  1.1071 +  },
  1.1072 +
  1.1073 +  check: function() {
  1.1074 +    // Query
  1.1075 +    var query = PlacesUtils.history.getNewQuery();
  1.1076 +
  1.1077 +    // query options
  1.1078 +    var options = PlacesUtils.history.getNewQueryOptions();
  1.1079 +    options.sortingAnnotation = "sorting";
  1.1080 +    options.sortingMode = this._sortingMode;
  1.1081 +
  1.1082 +    // Results - this gets the result set and opens it for reading and modification.
  1.1083 +    var result = PlacesUtils.history.executeQuery(query, options);
  1.1084 +    var root = result.root;
  1.1085 +    root.containerOpen = true;
  1.1086 +    compareArrayToResult(this._sortedData, root);
  1.1087 +    root.containerOpen = false;
  1.1088 +  },
  1.1089 +
  1.1090 +  check_reverse: function() {
  1.1091 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
  1.1092 +    this._sortedData.reverse();
  1.1093 +    this.check();
  1.1094 +  }
  1.1095 +});
  1.1096 +
  1.1097 +////////////////////////////////////////////////////////////////////////////////
  1.1098 +// SORT_BY_ANNOTATION_* (double)
  1.1099 +
  1.1100 +tests.push({
  1.1101 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING,
  1.1102 +
  1.1103 +  setup: function() {
  1.1104 +    LOG("Sorting test 13: SORT BY ANNOTATION (double)");
  1.1105 +
  1.1106 +    var timeInMicroseconds = Date.now() * 1000;
  1.1107 +    this._unsortedData = [
  1.1108 +      { isVisit: true,
  1.1109 +        isDetails: true,
  1.1110 +        uri: "http://moz.com/",
  1.1111 +        lastVisit: timeInMicroseconds,
  1.1112 +        title: "I",
  1.1113 +        isPageAnnotation: true,
  1.1114 +        annoName: "sorting",
  1.1115 +        annoVal: 1.2,
  1.1116 +        annoFlags: 0,
  1.1117 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
  1.1118 +        isInQuery: true },
  1.1119 +
  1.1120 +      { isVisit: true,
  1.1121 +        isDetails: true,
  1.1122 +        uri: "http://is.com/",
  1.1123 +        lastVisit: timeInMicroseconds,
  1.1124 +        title: "love",
  1.1125 +        isPageAnnotation: true,
  1.1126 +        annoName: "sorting",
  1.1127 +        annoVal: 1.1,
  1.1128 +        annoFlags: 0,
  1.1129 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
  1.1130 +        isInQuery: true },
  1.1131 +
  1.1132 +      { isVisit: true,
  1.1133 +        isDetails: true,
  1.1134 +        uri: "http://best.com/",
  1.1135 +        lastVisit: timeInMicroseconds,
  1.1136 +        title: "moz",
  1.1137 +        isPageAnnotation: true,
  1.1138 +        annoName: "sorting",
  1.1139 +        annoVal: 1.3,
  1.1140 +        annoFlags: 0,
  1.1141 +        annoExpiration: Ci.nsIAnnotationService.EXPIRE_NEVER,
  1.1142 +        isInQuery: true },
  1.1143 +    ];
  1.1144 +
  1.1145 +    this._sortedData = [
  1.1146 +      this._unsortedData[1],
  1.1147 +      this._unsortedData[0],
  1.1148 +      this._unsortedData[2],
  1.1149 +    ];
  1.1150 +
  1.1151 +    // This function in head_queries.js creates our database with the above data
  1.1152 +    yield task_populateDB(this._unsortedData);
  1.1153 +  },
  1.1154 +
  1.1155 +  check: function() {
  1.1156 +    // Query
  1.1157 +    var query = PlacesUtils.history.getNewQuery();
  1.1158 +
  1.1159 +    // query options
  1.1160 +    var options = PlacesUtils.history.getNewQueryOptions();
  1.1161 +    options.sortingAnnotation = "sorting";
  1.1162 +    options.sortingMode = this._sortingMode;
  1.1163 +
  1.1164 +    // Results - this gets the result set and opens it for reading and modification.
  1.1165 +    var result = PlacesUtils.history.executeQuery(query, options);
  1.1166 +    var root = result.root;
  1.1167 +    root.containerOpen = true;
  1.1168 +    compareArrayToResult(this._sortedData, root);
  1.1169 +    root.containerOpen = false;
  1.1170 +  },
  1.1171 +
  1.1172 +  check_reverse: function() {
  1.1173 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING;
  1.1174 +    this._sortedData.reverse();
  1.1175 +    this.check();
  1.1176 +  }
  1.1177 +});
  1.1178 +
  1.1179 +////////////////////////////////////////////////////////////////////////////////
  1.1180 +// SORT_BY_FRECENCY_*
  1.1181 +
  1.1182 +tests.push({
  1.1183 +  _sortingMode: Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_ASCENDING,
  1.1184 +
  1.1185 +  setup: function() {
  1.1186 +    LOG("Sorting test 13: SORT BY FRECENCY ");
  1.1187 +
  1.1188 +    var timeInMicroseconds = Date.now() * 1000;
  1.1189 +    this._unsortedData = [
  1.1190 +      { isVisit: true,
  1.1191 +        isDetails: true,
  1.1192 +        uri: "http://moz.com/",
  1.1193 +        lastVisit: timeInMicroseconds++,
  1.1194 +        title: "I",
  1.1195 +        isInQuery: true },
  1.1196 +
  1.1197 +      { isVisit: true,
  1.1198 +        isDetails: true,
  1.1199 +        uri: "http://moz.com/",
  1.1200 +        lastVisit: timeInMicroseconds++,
  1.1201 +        title: "I",
  1.1202 +        isInQuery: true },
  1.1203 +
  1.1204 +      { isVisit: true,
  1.1205 +        isDetails: true,
  1.1206 +        uri: "http://moz.com/",
  1.1207 +        lastVisit: timeInMicroseconds++,
  1.1208 +        title: "I",
  1.1209 +        isInQuery: true },
  1.1210 +
  1.1211 +      { isVisit: true,
  1.1212 +        isDetails: true,
  1.1213 +        uri: "http://is.com/",
  1.1214 +        lastVisit: timeInMicroseconds++,
  1.1215 +        title: "love",
  1.1216 +        isInQuery: true },
  1.1217 +
  1.1218 +      { isVisit: true,
  1.1219 +        isDetails: true,
  1.1220 +        uri: "http://best.com/",
  1.1221 +        lastVisit: timeInMicroseconds++,
  1.1222 +        title: "moz",
  1.1223 +        isInQuery: true },
  1.1224 +
  1.1225 +      { isVisit: true,
  1.1226 +        isDetails: true,
  1.1227 +        uri: "http://best.com/",
  1.1228 +        lastVisit: timeInMicroseconds++,
  1.1229 +        title: "moz",
  1.1230 +        isInQuery: true },
  1.1231 +    ];
  1.1232 +
  1.1233 +    this._sortedData = [
  1.1234 +      this._unsortedData[3],
  1.1235 +      this._unsortedData[5],
  1.1236 +      this._unsortedData[2],
  1.1237 +    ];
  1.1238 +
  1.1239 +    // This function in head_queries.js creates our database with the above data
  1.1240 +    yield task_populateDB(this._unsortedData);
  1.1241 +  },
  1.1242 +
  1.1243 +  check: function() {
  1.1244 +    var query = PlacesUtils.history.getNewQuery();
  1.1245 +    var options = PlacesUtils.history.getNewQueryOptions();
  1.1246 +    options.sortingMode = this._sortingMode;
  1.1247 +
  1.1248 +    var root = PlacesUtils.history.executeQuery(query, options).root;
  1.1249 +    root.containerOpen = true;
  1.1250 +    compareArrayToResult(this._sortedData, root);
  1.1251 +    root.containerOpen = false;
  1.1252 +  },
  1.1253 +
  1.1254 +  check_reverse: function() {
  1.1255 +    this._sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_DESCENDING;
  1.1256 +    this._sortedData.reverse();
  1.1257 +    this.check();
  1.1258 +  }
  1.1259 +});
  1.1260 +
  1.1261 +////////////////////////////////////////////////////////////////////////////////
  1.1262 +
  1.1263 +function run_test()
  1.1264 +{
  1.1265 +  run_next_test();
  1.1266 +}
  1.1267 +
  1.1268 +add_task(function test_sorting()
  1.1269 +{
  1.1270 +  for (let [, test] in Iterator(tests)) {
  1.1271 +    yield test.setup();
  1.1272 +    yield promiseAsyncUpdates();
  1.1273 +    test.check();
  1.1274 +    // sorting reversed, usually SORT_BY have ASC and DESC
  1.1275 +    test.check_reverse();
  1.1276 +    // Execute cleanup tasks
  1.1277 +    remove_all_bookmarks();
  1.1278 +    yield promiseClearHistory();
  1.1279 +  }
  1.1280 +});
  1.1281 \ No newline at end of file

mercurial