1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/autocomplete/test_empty_search.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/** 1.9 + * Test for bug 426864 that makes sure the empty search (drop down list) only 1.10 + * shows typed pages from history. 1.11 + */ 1.12 + 1.13 +// Define some shared uris and titles (each page needs its own uri) 1.14 +let kURIs = [ 1.15 + "http://foo/0", 1.16 + "http://foo/1", 1.17 + "http://foo/2", 1.18 + "http://foo/3", 1.19 + "http://foo/4", 1.20 + "http://foo/5", 1.21 +]; 1.22 +let kTitles = [ 1.23 + "title", 1.24 +]; 1.25 + 1.26 +// Visited (in history) 1.27 +addPageBook(0, 0); // history 1.28 +addPageBook(1, 0, 0); // bookmark 1.29 +addPageBook(2, 0); // history typed 1.30 +addPageBook(3, 0, 0); // bookmark typed 1.31 + 1.32 +// Unvisited bookmark 1.33 +addPageBook(4, 0, 0); // bookmark 1.34 +addPageBook(5, 0, 0); // bookmark typed 1.35 + 1.36 +// Set some pages as typed 1.37 +markTyped([2,3,5], 0); 1.38 +// Remove pages from history to treat them as unvisited 1.39 +removePages([4,5]); 1.40 + 1.41 +// Provide for each test: description; search terms; array of gPages indices of 1.42 +// pages that should match; optional function to be run before the test 1.43 +let gTests = [ 1.44 + ["0: Match everything", 1.45 + "foo", [0,1,2,3,4,5]], 1.46 + ["1: Match only typed history", 1.47 + "foo ^ ~", [2,3]], 1.48 + ["2: Drop-down empty search matches only typed history", 1.49 + "", [2,3]], 1.50 + ["3: Drop-down empty search matches everything", 1.51 + "", [0,1,2,3,4,5], function () setEmptyPref(0)], 1.52 + ["4: Drop-down empty search matches only typed", 1.53 + "", [2,3,5], function () setEmptyPref(32)], 1.54 + ["5: Drop-down empty search matches only typed history", 1.55 + "", [2,3], clearEmptyPref], 1.56 +]; 1.57 + 1.58 +function setEmptyPref(aValue) 1.59 + prefs.setIntPref("browser.urlbar.default.behavior.emptyRestriction", aValue); 1.60 + 1.61 +function clearEmptyPref() 1.62 +{ 1.63 + if (prefs.prefHasUserValue("browser.urlbar.default.behavior.emptyRestriction")) 1.64 + prefs.clearUserPref("browser.urlbar.default.behavior.emptyRestriction"); 1.65 +} 1.66 +