1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/queries/test_searchTerms_includeHidden.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 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 +// Tests the interaction of includeHidden and searchTerms search options. 1.11 + 1.12 +let timeInMicroseconds = Date.now() * 1000; 1.13 + 1.14 +const VISITS = [ 1.15 + { isVisit: true, 1.16 + transType: TRANSITION_TYPED, 1.17 + uri: "http://redirect.example.com/", 1.18 + title: "example", 1.19 + isRedirect: true, 1.20 + lastVisit: timeInMicroseconds-- 1.21 + }, 1.22 + { isVisit: true, 1.23 + transType: TRANSITION_TYPED, 1.24 + uri: "http://target.example.com/", 1.25 + title: "example", 1.26 + lastVisit: timeInMicroseconds-- 1.27 + } 1.28 +]; 1.29 + 1.30 +const HIDDEN_VISITS = [ 1.31 + { isVisit: true, 1.32 + transType: TRANSITION_FRAMED_LINK, 1.33 + uri: "http://hidden.example.com/", 1.34 + title: "red", 1.35 + lastVisit: timeInMicroseconds-- 1.36 + }, 1.37 +]; 1.38 + 1.39 +const TEST_DATA = [ 1.40 + { searchTerms: "example", 1.41 + includeHidden: true, 1.42 + expectedResults: 2 1.43 + }, 1.44 + { searchTerms: "example", 1.45 + includeHidden: false, 1.46 + expectedResults: 1 1.47 + }, 1.48 + { searchTerms: "red", 1.49 + includeHidden: true, 1.50 + expectedResults: 1 1.51 + } 1.52 +]; 1.53 + 1.54 +function run_test() 1.55 +{ 1.56 + run_next_test(); 1.57 +} 1.58 + 1.59 +add_task(function test_initalize() 1.60 +{ 1.61 + yield task_populateDB(VISITS); 1.62 +}); 1.63 + 1.64 +add_task(function test_searchTerms_includeHidden() 1.65 +{ 1.66 + for (let data of TEST_DATA) { 1.67 + let query = PlacesUtils.history.getNewQuery(); 1.68 + query.searchTerms = data.searchTerms; 1.69 + let options = PlacesUtils.history.getNewQueryOptions(); 1.70 + options.includeHidden = data.includeHidden; 1.71 + 1.72 + let root = PlacesUtils.history.executeQuery(query, options).root; 1.73 + root.containerOpen = true; 1.74 + 1.75 + let cc = root.childCount; 1.76 + // Live update with hidden visits. 1.77 + yield task_populateDB(HIDDEN_VISITS); 1.78 + let cc_update = root.childCount; 1.79 + 1.80 + root.containerOpen = false; 1.81 + 1.82 + do_check_eq(cc, data.expectedResults); 1.83 + do_check_eq(cc_update, data.expectedResults + (data.includeHidden ? 1 : 0)); 1.84 + 1.85 + PlacesUtils.bhistory.removePage(uri("http://hidden.example.com/")); 1.86 + } 1.87 +});