michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Tests the interaction of includeHidden and searchTerms search options. michael@0: michael@0: let timeInMicroseconds = Date.now() * 1000; michael@0: michael@0: const VISITS = [ michael@0: { isVisit: true, michael@0: transType: TRANSITION_TYPED, michael@0: uri: "http://redirect.example.com/", michael@0: title: "example", michael@0: isRedirect: true, michael@0: lastVisit: timeInMicroseconds-- michael@0: }, michael@0: { isVisit: true, michael@0: transType: TRANSITION_TYPED, michael@0: uri: "http://target.example.com/", michael@0: title: "example", michael@0: lastVisit: timeInMicroseconds-- michael@0: } michael@0: ]; michael@0: michael@0: const HIDDEN_VISITS = [ michael@0: { isVisit: true, michael@0: transType: TRANSITION_FRAMED_LINK, michael@0: uri: "http://hidden.example.com/", michael@0: title: "red", michael@0: lastVisit: timeInMicroseconds-- michael@0: }, michael@0: ]; michael@0: michael@0: const TEST_DATA = [ michael@0: { searchTerms: "example", michael@0: includeHidden: true, michael@0: expectedResults: 2 michael@0: }, michael@0: { searchTerms: "example", michael@0: includeHidden: false, michael@0: expectedResults: 1 michael@0: }, michael@0: { searchTerms: "red", michael@0: includeHidden: true, michael@0: expectedResults: 1 michael@0: } michael@0: ]; michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_initalize() michael@0: { michael@0: yield task_populateDB(VISITS); michael@0: }); michael@0: michael@0: add_task(function test_searchTerms_includeHidden() michael@0: { michael@0: for (let data of TEST_DATA) { michael@0: let query = PlacesUtils.history.getNewQuery(); michael@0: query.searchTerms = data.searchTerms; michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.includeHidden = data.includeHidden; michael@0: michael@0: let root = PlacesUtils.history.executeQuery(query, options).root; michael@0: root.containerOpen = true; michael@0: michael@0: let cc = root.childCount; michael@0: // Live update with hidden visits. michael@0: yield task_populateDB(HIDDEN_VISITS); michael@0: let cc_update = root.childCount; michael@0: michael@0: root.containerOpen = false; michael@0: michael@0: do_check_eq(cc, data.expectedResults); michael@0: do_check_eq(cc_update, data.expectedResults + (data.includeHidden ? 1 : 0)); michael@0: michael@0: PlacesUtils.bhistory.removePage(uri("http://hidden.example.com/")); michael@0: } michael@0: });