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: /** michael@0: * Test for bug 395161 that allows special searches that restrict results to michael@0: * history/bookmark/tagged items and title/url matches. michael@0: * michael@0: * Test 485122 by making sure results don't have tags when restricting result michael@0: * to just history either by default behavior or dynamic query restrict. michael@0: */ michael@0: michael@0: // Define some shared uris and titles (each page needs its own uri) michael@0: let kURIs = [ michael@0: "http://url/", michael@0: "http://url/2", michael@0: "http://foo.bar/", michael@0: "http://foo.bar/2", michael@0: "http://url/star", michael@0: "http://url/star/2", michael@0: "http://foo.bar/star", michael@0: "http://foo.bar/star/2", michael@0: "http://url/tag", michael@0: "http://url/tag/2", michael@0: "http://foo.bar/tag", michael@0: "http://foo.bar/tag/2", michael@0: ]; michael@0: let kTitles = [ michael@0: "title", michael@0: "foo.bar", michael@0: ]; michael@0: michael@0: // Plain page visits michael@0: addPageBook(0, 0); // plain page michael@0: addPageBook(1, 1); // title michael@0: addPageBook(2, 0); // url michael@0: addPageBook(3, 1); // title and url michael@0: michael@0: // Bookmarked pages (no tag) michael@0: addPageBook(4, 0, 0); // bookmarked page michael@0: addPageBook(5, 1, 1); // title michael@0: addPageBook(6, 0, 0); // url michael@0: addPageBook(7, 1, 1); // title and url michael@0: michael@0: // Tagged pages michael@0: addPageBook(8, 0, 0, [1]); // tagged page michael@0: addPageBook(9, 1, 1, [1]); // title michael@0: addPageBook(10, 0, 0, [1]); // url michael@0: addPageBook(11, 1, 1, [1]); // title and url michael@0: michael@0: // Remove pages from history to treat them as unvisited, so pages that do have michael@0: // visits are 0,1,2,3,5,10 michael@0: removePages([4,6,7,8,9,11]); michael@0: // Set some pages as typed michael@0: markTyped([0,10], 0); michael@0: markTyped([3], 1); michael@0: michael@0: // Provide for each test: description; search terms; array of gPages indices of michael@0: // pages that should match; optional function to be run before the test michael@0: let gTests = [ michael@0: // Test restricting searches michael@0: ["0: History restrict", michael@0: "^", [0,1,2,3,5,10], ignoreTags], michael@0: ["1: Star restrict", michael@0: "*", [4,5,6,7,8,9,10,11]], michael@0: ["2: Tag restrict", michael@0: "+", [8,9,10,11]], michael@0: michael@0: // Test specials as any word position michael@0: ["3: Special as first word", michael@0: "^ foo bar", [1,2,3,5,10], ignoreTags], michael@0: ["4: Special as middle word", michael@0: "foo ^ bar", [1,2,3,5,10], ignoreTags], michael@0: ["5: Special as last word", michael@0: "foo bar ^", [1,2,3,5,10], ignoreTags], michael@0: michael@0: // Test restricting and matching searches with a term michael@0: ["6.1: foo ^ -> history", michael@0: "foo ^", [1,2,3,5,10], ignoreTags], michael@0: ["6.2: foo | -> history (change pref)", michael@0: "foo |", [1,2,3,5,10], function() {ignoreTags(); changeRestrict("history", "|"); }], michael@0: ["7.1: foo * -> is star", michael@0: "foo *", [5,6,7,8,9,10,11], function() resetRestrict("history")], michael@0: ["7.2: foo | -> is star (change pref)", michael@0: "foo |", [5,6,7,8,9,10,11], function() changeRestrict("bookmark", "|")], michael@0: ["8.1: foo # -> in title", michael@0: "foo #", [1,3,5,7,8,9,10,11], function() resetRestrict("bookmark")], michael@0: ["8.2: foo | -> in title (change pref)", michael@0: "foo |", [1,3,5,7,8,9,10,11], function() changeRestrict("title", "|")], michael@0: ["9.1: foo @ -> in url", michael@0: "foo @", [2,3,6,7,10,11], function() resetRestrict("title")], michael@0: ["9.2: foo | -> in url (change pref)", michael@0: "foo |", [2,3,6,7,10,11], function() changeRestrict("url", "|")], michael@0: ["10: foo + -> is tag", michael@0: "foo +", [8,9,10,11], function() resetRestrict("url")], michael@0: ["10.2: foo | -> is tag (change pref)", michael@0: "foo |", [8,9,10,11], function() changeRestrict("tag", "|")], michael@0: ["10.3: foo ~ -> is typed", michael@0: "foo ~", [3,10], function() resetRestrict("tag")], michael@0: ["10.4: foo | -> is typed (change pref)", michael@0: "foo |", [3,10], function() changeRestrict("typed", "|")], michael@0: michael@0: // Test various pairs of special searches michael@0: ["11: foo ^ * -> history, is star", michael@0: "foo ^ *", [5,10], function() resetRestrict("typed")], michael@0: ["12: foo ^ # -> history, in title", michael@0: "foo ^ #", [1,3,5,10], ignoreTags], michael@0: ["13: foo ^ @ -> history, in url", michael@0: "foo ^ @", [2,3,10], ignoreTags], michael@0: ["14: foo ^ + -> history, is tag", michael@0: "foo ^ +", [10]], michael@0: ["14.1: foo ^ ~ -> history, is typed", michael@0: "foo ^ ~", [3,10], ignoreTags], michael@0: ["15: foo * # -> is star, in title", michael@0: "foo * #", [5,7,8,9,10,11]], michael@0: ["16: foo * @ -> is star, in url", michael@0: "foo * @", [6,7,10,11]], michael@0: ["17: foo * + -> same as +", michael@0: "foo * +", [8,9,10,11]], michael@0: ["17.1: foo * ~ -> is star, is typed", michael@0: "foo * ~", [10]], michael@0: ["18: foo # @ -> in title, in url", michael@0: "foo # @", [3,7,10,11]], michael@0: ["19: foo # + -> in title, is tag", michael@0: "foo # +", [8,9,10,11]], michael@0: ["19.1: foo # ~ -> in title, is typed", michael@0: "foo # ~", [3,10]], michael@0: ["20: foo @ + -> in url, is tag", michael@0: "foo @ +", [10,11]], michael@0: ["20.1: foo @ ~ -> in url, is typed", michael@0: "foo @ ~", [3,10]], michael@0: ["20.2: foo + ~ -> is tag, is typed", michael@0: "foo + ~", [10]], michael@0: michael@0: // Test default usage by setting certain bits of default.behavior to 1 michael@0: ["21: foo -> default history", michael@0: "foo", [1,2,3,5,10], function() makeDefault(1)], michael@0: ["22: foo -> default history, is star", michael@0: "foo", [5,10], function() makeDefault(3)], michael@0: ["22.1: foo -> default history, is star, is typed", michael@0: "foo", [10], function() makeDefault(35)], michael@0: ["23: foo -> default history, is star, in url", michael@0: "foo", [10], function() makeDefault(19)], michael@0: michael@0: // Change the default to be less restrictive to make sure we find more michael@0: ["24: foo -> default is star, in url", michael@0: "foo", [6,7,10,11], function() makeDefault(18)], michael@0: ["25: foo -> default in url", michael@0: "foo", [2,3,6,7,10,11], function() makeDefault(16)], michael@0: ]; michael@0: michael@0: function makeDefault(aDefault) { michael@0: // We want to ignore tags if we're restricting to history unless we're showing michael@0: if ((aDefault & 1) && !((aDefault & 2) || (aDefault & 4))) michael@0: ignoreTags(); michael@0: michael@0: prefs.setIntPref("browser.urlbar.default.behavior", aDefault); michael@0: } michael@0: michael@0: function changeRestrict(aType, aChar) michael@0: { michael@0: let branch = "browser.urlbar."; michael@0: // "title" and "url" are different from everything else, so special case them. michael@0: if (aType == "title" || aType == "url") michael@0: branch += "match."; michael@0: else michael@0: branch += "restrict."; michael@0: michael@0: print("changing restrict for " + aType + " to '" + aChar + "'"); michael@0: prefs.setCharPref(branch + aType, aChar); michael@0: } michael@0: michael@0: function resetRestrict(aType) michael@0: { michael@0: let branch = "browser.urlbar."; michael@0: // "title" and "url" are different from everything else, so special case them. michael@0: if (aType == "title" || aType == "url") michael@0: branch += "match."; michael@0: else michael@0: branch += "restrict."; michael@0: michael@0: if (prefs.prefHasUserValue(branch + aType)) michael@0: prefs.clearUserPref(branch + aType); michael@0: }