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

mercurial