toolkit/components/places/tests/queries/test_searchterms-uri.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_searchterms-uri.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,122 @@
     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 +  // The test data for our database, note that the ordering of the results that
    1.11 +  // will be returned by the query (the isInQuery: true objects) is IMPORTANT.
    1.12 +  // see compareArrayToResult in head_queries.js for more info.
    1.13 +  var testData = [
    1.14 +    // Test flat domain with annotation, search term in sentence
    1.15 +    {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true,
    1.16 +     uri: "http://foo.com/", annoName: "moz/test", annoVal: "val",
    1.17 +     lastVisit: lastweek, title: "you know, moz is cool"},
    1.18 +
    1.19 +    // Test subdomain included with isRedirect=true, different transtype
    1.20 +    {isInQuery: true, isVisit: true, isDetails: true, title: "amozzie",
    1.21 +     isRedirect: true, uri: "http://foo.com/redirect", lastVisit: old,
    1.22 +     referrer: "http://myreferrer.com", transType: PlacesUtils.history.TRANSITION_LINK},
    1.23 +
    1.24 +    // Test www. style URI is included, with a tag
    1.25 +    {isInQuery: true, isVisit: true, isDetails: true, isTag: true,
    1.26 +     uri: "http://foo.com/yiihah", tagArray: ["moz"], lastVisit: yesterday,
    1.27 +     title: "foo"},
    1.28 +
    1.29 +    // Test https protocol
    1.30 +    {isInQuery: false, isVisit: true, isDetails: true, title: "moz",
    1.31 +     uri: "https://foo.com/", lastVisit: today},
    1.32 +
    1.33 +    // Begin the invalid queries: wrong search term
    1.34 +    {isInQuery: false, isVisit:true, isDetails: true, title: "m o z",
    1.35 +     uri: "http://foo.com/wrongsearch.php", lastVisit: today},
    1.36 +
    1.37 +     // Test subdomain inclued, search term at end
    1.38 +     {isInQuery: false, isVisit: true, isDetails: true,
    1.39 +      uri: "http://mail.foo.com/yiihah", title: "blahmoz", lastVisit: daybefore},
    1.40 +
    1.41 +     // Test ftp protocol - vary the title length, embed search term
    1.42 +     {isInQuery: false, isVisit: true, isDetails: true,
    1.43 +      uri: "ftp://foo.com/ftp", lastVisit: lastweek,
    1.44 +      title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"},
    1.45 +
    1.46 +    // Test what we do with escaping in titles
    1.47 +    {isInQuery: false, isVisit:true, isDetails: true, title: "m%0o%0z",
    1.48 +     uri: "http://foo.com/changeme1.htm", lastVisit: yesterday},
    1.49 +
    1.50 +    // Test another invalid title - for updating later
    1.51 +    {isInQuery: false, isVisit:true, isDetails: true, title: "m,oz",
    1.52 +     uri: "http://foo.com/changeme2.htm", lastVisit: tomorrow}];
    1.53 +
    1.54 +/**
    1.55 + * This test will test Queries that use relative search terms and URI options
    1.56 + */
    1.57 +function run_test()
    1.58 +{
    1.59 +  run_next_test();
    1.60 +}
    1.61 +
    1.62 +add_task(function test_searchterms_uri()
    1.63 +{
    1.64 +  yield task_populateDB(testData);
    1.65 +   var query = PlacesUtils.history.getNewQuery();
    1.66 +   query.searchTerms = "moz";
    1.67 +   query.uri = uri("http://foo.com");
    1.68 +   query.uriIsPrefix = true;
    1.69 +
    1.70 +   // Options
    1.71 +   var options = PlacesUtils.history.getNewQueryOptions();
    1.72 +   options.sortingMode = options.SORT_BY_DATE_ASCENDING;
    1.73 +   options.resultType = options.RESULTS_AS_URI;
    1.74 +   
    1.75 +   // Results
    1.76 +   var result = PlacesUtils.history.executeQuery(query, options);
    1.77 +   var root = result.root;
    1.78 +   root.containerOpen = true;
    1.79 +
    1.80 +   LOG("Number of items in result set: " + root.childCount);
    1.81 +   for(var i=0; i < root.childCount; ++i) {
    1.82 +     LOG("result: " + root.getChild(i).uri + " Title: " + root.getChild(i).title);
    1.83 +   }
    1.84 +
    1.85 +   // Check our inital result set
    1.86 +   compareArrayToResult(testData, root);
    1.87 +
    1.88 +   // If that passes, check liveupdate
    1.89 +   // Add to the query set
    1.90 +   LOG("Adding item to query")
    1.91 +   var change1 = [{isVisit: true, isDetails: true, uri: "http://foo.com/added.htm",
    1.92 +                   title: "moz", transType: PlacesUtils.history.TRANSITION_LINK}];
    1.93 +   yield task_populateDB(change1);
    1.94 +   do_check_true(isInResult(change1, root));
    1.95 +
    1.96 +   // Update an existing URI
    1.97 +   LOG("Updating Item");
    1.98 +   var change2 = [{isDetails: true, uri: "http://foo.com/changeme1.htm",
    1.99 +                   title: "moz" }];
   1.100 +   yield task_populateDB(change2);
   1.101 +   do_check_true(isInResult(change2, root));
   1.102 +
   1.103 +   // Add one and take one out of query set, and simply change one so that it
   1.104 +   // still applies to the query.
   1.105 +   LOG("Updating More Items");
   1.106 +   var change3 = [{isDetails: true, uri:"http://foo.com/changeme2.htm",
   1.107 +                   title: "moz"},
   1.108 +                  {isDetails: true, uri: "http://foo.com/yiihah",
   1.109 +                   title: "moz now updated"},
   1.110 +                  {isDetails: true, uri: "http://foo.com/redirect",
   1.111 +                   title: "gone"}];
   1.112 +   yield task_populateDB(change3);
   1.113 +   do_check_true(isInResult({uri: "http://foo.com/changeme2.htm"}, root));
   1.114 +   do_check_true(isInResult({uri: "http://foo.com/yiihah"}, root));
   1.115 +   do_check_false(isInResult({uri: "http://foo.com/redirect"}, root));
   1.116 +
   1.117 +   // And now, delete one
   1.118 +   LOG("Deleting items");
   1.119 +   var change4 = [{isDetails: true, uri: "http://foo.com/",
   1.120 +                   title: "mo,z"}];
   1.121 +   yield task_populateDB(change4);
   1.122 +   do_check_false(isInResult(change4, root));
   1.123 +
   1.124 +   root.containerOpen = false;
   1.125 +});

mercurial