Wed, 31 Dec 2014 06:09:35 +0100
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 | // The test data for our database, note that the ordering of the results that |
michael@0 | 8 | // will be returned by the query (the isInQuery: true objects) is IMPORTANT. |
michael@0 | 9 | // see compareArrayToResult in head_queries.js for more info. |
michael@0 | 10 | var testData = [ |
michael@0 | 11 | // Test ftp protocol - vary the title length, embed search term |
michael@0 | 12 | {isInQuery: true, isVisit: true, isDetails: true, |
michael@0 | 13 | uri: "ftp://foo.com/ftp", lastVisit: lastweek, |
michael@0 | 14 | title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"}, |
michael@0 | 15 | |
michael@0 | 16 | // Test flat domain with annotation, search term in sentence |
michael@0 | 17 | {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true, |
michael@0 | 18 | uri: "http://foo.com/", annoName: "moz/test", annoVal: "val", |
michael@0 | 19 | lastVisit: lastweek, title: "you know, moz is cool"}, |
michael@0 | 20 | |
michael@0 | 21 | // Test subdomain included with isRedirect=true, different transtype |
michael@0 | 22 | {isInQuery: true, isVisit: true, isDetails: true, title: "amozzie", |
michael@0 | 23 | isRedirect: true, uri: "http://mail.foo.com/redirect", lastVisit: old, |
michael@0 | 24 | referrer: "http://myreferrer.com", transType: PlacesUtils.history.TRANSITION_LINK}, |
michael@0 | 25 | |
michael@0 | 26 | // Test subdomain inclued, search term at end |
michael@0 | 27 | {isInQuery: true, isVisit: true, isDetails: true, |
michael@0 | 28 | uri: "http://mail.foo.com/yiihah", title: "blahmoz", lastVisit: daybefore}, |
michael@0 | 29 | |
michael@0 | 30 | // Test www. style URI is included, with a tag |
michael@0 | 31 | {isInQuery: true, isVisit: true, isDetails: true, isTag: true, |
michael@0 | 32 | uri: "http://www.foo.com/yiihah", tagArray: ["moz"], |
michael@0 | 33 | lastVisit: yesterday, title: "foo"}, |
michael@0 | 34 | |
michael@0 | 35 | // Test https protocol |
michael@0 | 36 | {isInQuery: true, isVisit: true, isDetails: true, title: "moz", |
michael@0 | 37 | uri: "https://foo.com/", lastVisit: today}, |
michael@0 | 38 | |
michael@0 | 39 | // Begin the invalid queries: wrong search term |
michael@0 | 40 | {isInQuery: false, isVisit:true, isDetails: true, title: "m o z", |
michael@0 | 41 | uri: "http://foo.com/tooearly.php", lastVisit: today}, |
michael@0 | 42 | |
michael@0 | 43 | // Test bad URI |
michael@0 | 44 | {isInQuery: false, isVisit:true, isDetails: true, title: "moz", |
michael@0 | 45 | uri: "http://sffoo.com/justwrong.htm", lastVisit: tomorrow}, |
michael@0 | 46 | |
michael@0 | 47 | // Test what we do with escaping in titles |
michael@0 | 48 | {isInQuery: false, isVisit:true, isDetails: true, title: "m%0o%0z", |
michael@0 | 49 | uri: "http://foo.com/changeme1.htm", lastVisit: yesterday}, |
michael@0 | 50 | |
michael@0 | 51 | // Test another invalid title - for updating later |
michael@0 | 52 | {isInQuery: false, isVisit:true, isDetails: true, title: "m,oz", |
michael@0 | 53 | uri: "http://foo.com/changeme2.htm", lastVisit: tomorrow}]; |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * This test will test Queries that use relative search terms and domain options |
michael@0 | 57 | */ |
michael@0 | 58 | function run_test() |
michael@0 | 59 | { |
michael@0 | 60 | run_next_test(); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | add_task(function test_searchterms_domain() |
michael@0 | 64 | { |
michael@0 | 65 | yield task_populateDB(testData); |
michael@0 | 66 | var query = PlacesUtils.history.getNewQuery(); |
michael@0 | 67 | query.searchTerms = "moz"; |
michael@0 | 68 | query.domain = "foo.com"; |
michael@0 | 69 | query.domainIsHost = false; |
michael@0 | 70 | |
michael@0 | 71 | // Options |
michael@0 | 72 | var options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 73 | options.sortingMode = options.SORT_BY_DATE_ASCENDING; |
michael@0 | 74 | options.resultType = options.RESULTS_AS_URI; |
michael@0 | 75 | |
michael@0 | 76 | // Results |
michael@0 | 77 | var result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 78 | var root = result.root; |
michael@0 | 79 | root.containerOpen = true; |
michael@0 | 80 | |
michael@0 | 81 | LOG("Number of items in result set: " + root.childCount); |
michael@0 | 82 | for(var i=0; i < root.childCount; ++i) { |
michael@0 | 83 | LOG("result: " + root.getChild(i).uri + " Title: " + root.getChild(i).title); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | // Check our inital result set |
michael@0 | 87 | compareArrayToResult(testData, root); |
michael@0 | 88 | |
michael@0 | 89 | // If that passes, check liveupdate |
michael@0 | 90 | // Add to the query set |
michael@0 | 91 | LOG("Adding item to query") |
michael@0 | 92 | var change1 = [{isVisit: true, isDetails: true, uri: "http://foo.com/added.htm", |
michael@0 | 93 | title: "moz", transType: PlacesUtils.history.TRANSITION_LINK}]; |
michael@0 | 94 | yield task_populateDB(change1); |
michael@0 | 95 | do_check_true(isInResult(change1, root)); |
michael@0 | 96 | |
michael@0 | 97 | // Update an existing URI |
michael@0 | 98 | LOG("Updating Item"); |
michael@0 | 99 | var change2 = [{isDetails: true, uri: "http://foo.com/changeme1.htm", |
michael@0 | 100 | title: "moz" }]; |
michael@0 | 101 | yield task_populateDB(change2); |
michael@0 | 102 | do_check_true(isInResult(change2, root)); |
michael@0 | 103 | |
michael@0 | 104 | // Add one and take one out of query set, and simply change one so that it |
michael@0 | 105 | // still applies to the query. |
michael@0 | 106 | LOG("Updating More Items"); |
michael@0 | 107 | var change3 = [{isDetails: true, uri:"http://foo.com/changeme2.htm", |
michael@0 | 108 | title: "moz"}, |
michael@0 | 109 | {isDetails: true, uri: "http://mail.foo.com/yiihah", |
michael@0 | 110 | title: "moz now updated"}, |
michael@0 | 111 | {isDetails: true, uri: "ftp://foo.com/ftp", title: "gone"}]; |
michael@0 | 112 | yield task_populateDB(change3); |
michael@0 | 113 | do_check_true(isInResult({uri: "http://foo.com/changeme2.htm"}, root)); |
michael@0 | 114 | do_check_true(isInResult({uri: "http://mail.foo.com/yiihah"}, root)); |
michael@0 | 115 | do_check_false(isInResult({uri: "ftp://foo.com/ftp"}, root)); |
michael@0 | 116 | |
michael@0 | 117 | // And now, delete one |
michael@0 | 118 | LOG("Deleting items"); |
michael@0 | 119 | var change4 = [{isDetails: true, uri: "https://foo.com/", |
michael@0 | 120 | title: "mo,z"}]; |
michael@0 | 121 | yield task_populateDB(change4); |
michael@0 | 122 | do_check_false(isInResult(change4, root)); |
michael@0 | 123 | |
michael@0 | 124 | root.containerOpen = false; |
michael@0 | 125 | }); |