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