toolkit/components/places/tests/queries/test_results-as-visit.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.

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 var testData = [];
     7 var now = Date.now() * 1000;
     8 function createTestData() {
     9   function generateVisits(aPage) {
    10     for (var i = 0; i < aPage.visitCount; i++) {
    11       testData.push({ isInQuery: aPage.inQuery,
    12                       isVisit: true,
    13                       title: aPage.title,
    14                       uri: aPage.uri,
    15                       lastVisit: now++,
    16                       isTag: aPage.tags && aPage.tags.length > 0,
    17                       tagArray: aPage.tags });
    18     }
    19   }
    21   var pages = [
    22     { uri: "http://foo.com/", title: "amo", tags: ["moz"], visitCount: 3, inQuery: true },
    23     { uri: "http://moilla.com/", title: "bMoz", tags: ["bugzilla"], visitCount: 5, inQuery: true },
    24     { uri: "http://foo.mail.com/changeme1.html", title: "c Moz", visitCount: 7, inQuery: true },
    25     { uri: "http://foo.mail.com/changeme2.html", tags: ["moz"], title: "", visitCount: 1, inQuery: false },
    26     { uri: "http://foo.mail.com/changeme3.html", title: "zydeco", visitCount: 5, inQuery: false },
    27   ];
    28   pages.forEach(generateVisits);
    29 }
    31 /**
    32  * This test will test Queries that use relative search terms and URI options
    33  */
    34 function run_test()
    35 {
    36   run_next_test();
    37 }
    39 add_task(function test_results_as_visit()
    40 {
    41    createTestData();
    42    yield task_populateDB(testData);
    43    var query = PlacesUtils.history.getNewQuery();
    44    query.searchTerms = "moz";
    45    query.minVisits = 2;
    47    // Options
    48    var options = PlacesUtils.history.getNewQueryOptions();
    49    options.sortingMode = options.SORT_BY_VISITCOUNT_ASCENDING;
    50    options.resultType = options.RESULTS_AS_VISIT;
    52    // Results
    53    var result = PlacesUtils.history.executeQuery(query, options);
    54    var root = result.root;
    55    root.containerOpen = true;
    57    LOG("Number of items in result set: " + root.childCount);
    58    for(var i=0; i < root.childCount; ++i) {
    59      LOG("result: " + root.getChild(i).uri + " Title: " + root.getChild(i).title);
    60    }
    62    // Check our inital result set
    63    compareArrayToResult(testData, root);
    65    // If that passes, check liveupdate
    66    // Add to the query set
    67    LOG("Adding item to query")
    68    var tmp = [];
    69    for (var i=0; i < 2; i++) {
    70      tmp.push({ isVisit: true,
    71                 uri: "http://foo.com/added.html",
    72                 title: "ab moz" });
    73    }
    74    yield task_populateDB(tmp);
    75    for (var i=0; i < 2; i++)
    76      do_check_eq(root.getChild(i).title, "ab moz");
    78    // Update an existing URI
    79    LOG("Updating Item");
    80    var change2 = [{ isVisit: true,
    81                     title: "moz",
    82                     uri: "http://foo.mail.com/changeme2.html" }];
    83    yield task_populateDB(change2);
    84    do_check_true(isInResult(change2, root));
    86    // Update some visits - add one and take one out of query set, and simply
    87    // change one so that it still applies to the query.
    88    LOG("Updating More Items");
    89    var change3 = [{ isVisit: true,
    90                     lastVisit: now++,
    91                     uri: "http://foo.mail.com/changeme1.html",
    92                     title: "foo"},
    93                   { isVisit: true,
    94                     lastVisit: now++,
    95                     uri: "http://foo.mail.com/changeme3.html",
    96                     title: "moz",
    97                     isTag: true,
    98                     tagArray: ["foo", "moz"] }];
    99    yield task_populateDB(change3);
   100    do_check_false(isInResult({uri: "http://foo.mail.com/changeme1.html"}, root));
   101    do_check_true(isInResult({uri: "http://foo.mail.com/changeme3.html"}, root));
   103    // And now, delete one
   104    LOG("Delete item outside of batch");
   105    var change4 = [{ isVisit: true,
   106                     lastVisit: now++,
   107                     uri: "http://moilla.com/",
   108                     title: "mo,z" }];
   109    yield task_populateDB(change4);
   110    do_check_false(isInResult(change4, root));
   112    root.containerOpen = false;
   113 });

mercurial