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 | const TOTAL_SITES = 20; |
michael@0 | 8 | |
michael@0 | 9 | function run_test() |
michael@0 | 10 | { |
michael@0 | 11 | run_next_test(); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | add_task(function test_execute() |
michael@0 | 15 | { |
michael@0 | 16 | let now = Date.now() * 1000; |
michael@0 | 17 | |
michael@0 | 18 | for (let i = 0; i < TOTAL_SITES; i++) { |
michael@0 | 19 | let site = "http://www.test-" + i + ".com/"; |
michael@0 | 20 | let testURI = uri(site); |
michael@0 | 21 | let testImageURI = uri(site + "blank.gif"); |
michael@0 | 22 | let when = now + (i * TOTAL_SITES); |
michael@0 | 23 | yield promiseAddVisits([ |
michael@0 | 24 | { uri: testURI, visitDate: when, transition: TRANSITION_TYPED }, |
michael@0 | 25 | { uri: testImageURI, visitDate: ++when, transition: TRANSITION_EMBED }, |
michael@0 | 26 | { uri: testImageURI, visitDate: ++when, transition: TRANSITION_FRAMED_LINK }, |
michael@0 | 27 | { uri: testURI, visitDate: ++when, transition: TRANSITION_LINK }, |
michael@0 | 28 | ]); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | // verify our visits AS_VISIT, ordered by date descending |
michael@0 | 32 | // including hidden |
michael@0 | 33 | // we should get 80 visits: |
michael@0 | 34 | // http://www.test-19.com/ |
michael@0 | 35 | // http://www.test-19.com/blank.gif |
michael@0 | 36 | // http://www.test-19.com/ |
michael@0 | 37 | // http://www.test-19.com/ |
michael@0 | 38 | // ... |
michael@0 | 39 | // http://www.test-0.com/ |
michael@0 | 40 | // http://www.test-0.com/blank.gif |
michael@0 | 41 | // http://www.test-0.com/ |
michael@0 | 42 | // http://www.test-0.com/ |
michael@0 | 43 | let options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 44 | options.sortingMode = options.SORT_BY_DATE_DESCENDING; |
michael@0 | 45 | options.resultType = options.RESULTS_AS_VISIT; |
michael@0 | 46 | options.includeHidden = true; |
michael@0 | 47 | let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), |
michael@0 | 48 | options).root; |
michael@0 | 49 | root.containerOpen = true; |
michael@0 | 50 | let cc = root.childCount; |
michael@0 | 51 | // Embed visits are not added to the database, thus they won't appear. |
michael@0 | 52 | do_check_eq(cc, 3 * TOTAL_SITES); |
michael@0 | 53 | for (let i = 0; i < TOTAL_SITES; i++) { |
michael@0 | 54 | let index = i * 3; |
michael@0 | 55 | let node = root.getChild(index); |
michael@0 | 56 | let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; |
michael@0 | 57 | do_check_eq(node.uri, site); |
michael@0 | 58 | do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); |
michael@0 | 59 | node = root.getChild(++index); |
michael@0 | 60 | do_check_eq(node.uri, site + "blank.gif"); |
michael@0 | 61 | do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); |
michael@0 | 62 | node = root.getChild(++index); |
michael@0 | 63 | do_check_eq(node.uri, site); |
michael@0 | 64 | do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); |
michael@0 | 65 | } |
michael@0 | 66 | root.containerOpen = false; |
michael@0 | 67 | |
michael@0 | 68 | // verify our visits AS_VISIT, ordered by date descending |
michael@0 | 69 | // we should get 40 visits: |
michael@0 | 70 | // http://www.test-19.com/ |
michael@0 | 71 | // http://www.test-19.com/ |
michael@0 | 72 | // ... |
michael@0 | 73 | // http://www.test-0.com/ |
michael@0 | 74 | // http://www.test-0.com/ |
michael@0 | 75 | let options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 76 | options.sortingMode = options.SORT_BY_DATE_DESCENDING; |
michael@0 | 77 | options.resultType = options.RESULTS_AS_VISIT; |
michael@0 | 78 | let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), |
michael@0 | 79 | options).root; |
michael@0 | 80 | root.containerOpen = true; |
michael@0 | 81 | let cc = root.childCount; |
michael@0 | 82 | // 2 * TOTAL_SITES because we count the TYPED and LINK, but not EMBED or FRAMED |
michael@0 | 83 | do_check_eq(cc, 2 * TOTAL_SITES); |
michael@0 | 84 | for (let i=0; i < TOTAL_SITES; i++) { |
michael@0 | 85 | let index = i * 2; |
michael@0 | 86 | let node = root.getChild(index); |
michael@0 | 87 | let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; |
michael@0 | 88 | do_check_eq(node.uri, site); |
michael@0 | 89 | do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); |
michael@0 | 90 | node = root.getChild(++index); |
michael@0 | 91 | do_check_eq(node.uri, site); |
michael@0 | 92 | do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); |
michael@0 | 93 | } |
michael@0 | 94 | root.containerOpen = false; |
michael@0 | 95 | |
michael@0 | 96 | // test our optimized query for the places menu |
michael@0 | 97 | // place:type=0&sort=4&maxResults=10 |
michael@0 | 98 | // verify our visits AS_URI, ordered by date descending |
michael@0 | 99 | // we should get 10 visits: |
michael@0 | 100 | // http://www.test-19.com/ |
michael@0 | 101 | // ... |
michael@0 | 102 | // http://www.test-10.com/ |
michael@0 | 103 | let options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 104 | options.sortingMode = options.SORT_BY_DATE_DESCENDING; |
michael@0 | 105 | options.maxResults = 10; |
michael@0 | 106 | options.resultType = options.RESULTS_AS_URI; |
michael@0 | 107 | let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), |
michael@0 | 108 | options).root; |
michael@0 | 109 | root.containerOpen = true; |
michael@0 | 110 | let cc = root.childCount; |
michael@0 | 111 | do_check_eq(cc, options.maxResults); |
michael@0 | 112 | for (let i=0; i < cc; i++) { |
michael@0 | 113 | let node = root.getChild(i); |
michael@0 | 114 | let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; |
michael@0 | 115 | do_check_eq(node.uri, site); |
michael@0 | 116 | do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); |
michael@0 | 117 | } |
michael@0 | 118 | root.containerOpen = false; |
michael@0 | 119 | |
michael@0 | 120 | // test without a maxResults, which executes a different query |
michael@0 | 121 | // but the first 10 results should be the same. |
michael@0 | 122 | // verify our visits AS_URI, ordered by date descending |
michael@0 | 123 | // we should get 20 visits, but the first 10 should be |
michael@0 | 124 | // http://www.test-19.com/ |
michael@0 | 125 | // ... |
michael@0 | 126 | // http://www.test-10.com/ |
michael@0 | 127 | let options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 128 | options.sortingMode = options.SORT_BY_DATE_DESCENDING; |
michael@0 | 129 | options.resultType = options.RESULTS_AS_URI; |
michael@0 | 130 | let root = PlacesUtils.history.executeQuery(PlacesUtils.history.getNewQuery(), |
michael@0 | 131 | options).root; |
michael@0 | 132 | root.containerOpen = true; |
michael@0 | 133 | let cc = root.childCount; |
michael@0 | 134 | do_check_eq(cc, TOTAL_SITES); |
michael@0 | 135 | for (let i=0; i < 10; i++) { |
michael@0 | 136 | let node = root.getChild(i); |
michael@0 | 137 | let site = "http://www.test-" + (TOTAL_SITES - 1 - i) + ".com/"; |
michael@0 | 138 | do_check_eq(node.uri, site); |
michael@0 | 139 | do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI); |
michael@0 | 140 | } |
michael@0 | 141 | root.containerOpen = false; |
michael@0 | 142 | }); |