Bug 1281005 - Move the nsPlacesAutocomplete component to Suite (mozilla-central part) r=mak77

This commit is contained in:
Philip Chee 2016-09-27 16:48:14 +08:00
Родитель 17db78f2b5
Коммит 2cdba405f7
25 изменённых файлов: 0 добавлений и 2820 удалений

Просмотреть файл

@ -85,12 +85,6 @@ if CONFIG['MOZ_PLACES']:
'UnifiedComplete.js',
]
if CONFIG['MOZ_SUITE']:
EXTRA_COMPONENTS += [
'nsPlacesAutoComplete.js',
'nsPlacesAutoComplete.manifest',
]
FINAL_LIBRARY = 'xul'
include('/ipc/chromium/chromium-config.mozbuild')

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,3 +0,0 @@
component {d0272978-beab-4adc-a3d4-04b76acfa4e7} nsPlacesAutoComplete.js
contract @mozilla.org/autocomplete/search;1?name=history {d0272978-beab-4adc-a3d4-04b76acfa4e7}

Просмотреть файл

@ -1,5 +0,0 @@
{
"extends": [
"../../../../../testing/xpcshell/xpcshell.eslintrc"
]
}

Просмотреть файл

@ -1,314 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var Ci = Components.interfaces;
var Cc = Components.classes;
var Cr = Components.results;
var Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
// Import common head.
{
let commonFile = do_get_file("../head_common.js", false);
let uri = Services.io.newFileURI(commonFile);
Services.scriptloader.loadSubScript(uri.spec, this);
}
// Put any other stuff relative to this test folder below.
/**
* Header file for autocomplete testcases that create a set of pages with uris,
* titles, tags and tests that a given search term matches certain pages.
*/
var current_test = 0;
function AutoCompleteInput(aSearches) {
this.searches = aSearches;
}
AutoCompleteInput.prototype = {
timeout: 10,
textValue: "",
searches: null,
searchParam: "",
popupOpen: false,
minResultsForPopup: 0,
invalidate: function() {},
disableAutoComplete: false,
completeDefaultIndex: false,
get popup() { return this; },
onSearchBegin: function() {},
onSearchComplete: function() {},
setSelectedIndex: function() {},
get searchCount() { return this.searches.length; },
getSearchAt: function(aIndex) { return this.searches[aIndex]; },
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIAutoCompleteInput,
Ci.nsIAutoCompletePopup,
])
};
function toURI(aSpec) {
return uri(aSpec);
}
var appendTags = true;
// Helper to turn off tag matching in results
function ignoreTags()
{
print("Ignoring tags from results");
appendTags = false;
}
function ensure_results(aSearch, aExpected)
{
let controller = Cc["@mozilla.org/autocomplete/controller;1"].
getService(Ci.nsIAutoCompleteController);
// Make an AutoCompleteInput that uses our searches
// and confirms results on search complete
let input = new AutoCompleteInput(["history"]);
controller.input = input;
if (typeof kSearchParam == "string")
input.searchParam = kSearchParam;
let numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
input.onSearchComplete = function() {
do_check_eq(numSearchesStarted, 1);
aExpected = aExpected.slice();
// Check to see the expected uris and titles match up (in any order)
for (let i = 0; i < controller.matchCount; i++) {
let value = controller.getValueAt(i);
let comment = controller.getCommentAt(i);
print("Looking for '" + value + "', '" + comment + "' in expected results...");
let j;
for (j = 0; j < aExpected.length; j++) {
// Skip processed expected results
if (aExpected[j] == undefined)
continue;
let [uri, title, tags] = gPages[aExpected[j]];
// Load the real uri and titles and tags if necessary
uri = toURI(kURIs[uri]).spec;
title = kTitles[title];
if (tags && appendTags)
title += " \u2013 " + tags.map(aTag => kTitles[aTag]);
print("Checking against expected '" + uri + "', '" + title + "'...");
// Got a match on both uri and title?
if (uri == value && title == comment) {
print("Got it at index " + j + "!!");
// Make it undefined so we don't process it again
aExpected[j] = undefined;
break;
}
}
// We didn't hit the break, so we must have not found it
if (j == aExpected.length)
do_throw("Didn't find the current result ('" + value + "', '" + comment + "') in expected: " + aExpected);
}
// Make sure we have the right number of results
print("Expecting " + aExpected.length + " results; got " +
controller.matchCount + " results");
do_check_eq(controller.matchCount, aExpected.length);
// If we expect results, make sure we got matches
do_check_eq(controller.searchStatus, aExpected.length ?
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH :
Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH);
// Fetch the next test if we have more
if (++current_test < gTests.length)
run_test();
do_test_finished();
};
print("Searching for.. '" + aSearch + "'");
controller.startSearch(aSearch);
}
// Get history services
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var bhist = histsvc.QueryInterface(Ci.nsIBrowserHistory);
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var tagsvc = Cc["@mozilla.org/browser/tagging-service;1"].
getService(Ci.nsITaggingService);
var iosvc = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
// Some date not too long ago
var gDate = new Date(Date.now() - 1000 * 60 * 60) * 1000;
// Store the page info for each uri
var gPages = [];
// Initialization tasks to be run before the next test
var gNextTestSetupTasks = [];
/**
* Adds a page, and creates various properties for it depending on the
* parameters passed in. This function will also add one visit, unless
* aNoVisit is true.
*
* @param aURI
* An index into kURIs that holds the string for the URI we are to add a
* page for.
* @param aTitle
* An index into kTitles that holds the string for the title we are to
* associate with the specified URI.
* @param aBook [optional]
* An index into kTitles that holds the string for the title we are to
* associate with the bookmark. If this is undefined, no bookmark is
* created.
* @param aTags [optional]
* An array of indexes into kTitles that hold the strings for the tags we
* are to associate with the URI. If this is undefined (or aBook is), no
* tags are added.
* @param aKey [optional]
* A string to associate as the keyword for this bookmark. aBook must be
* a valid index into kTitles for this to be checked and used.
* @param aTransitionType [optional]
* The transition type to use when adding the visit. The default is
* nsINavHistoryService::TRANSITION_LINK.
* @param aNoVisit [optional]
* If true, no visit is added for the URI. If false or undefined, a
* visit is added.
*/
function addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit)
{
gNextTestSetupTasks.push([task_addPageBook, arguments]);
}
function* task_addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit)
{
// Add a page entry for the current uri
gPages[aURI] = [aURI, aBook != undefined ? aBook : aTitle, aTags];
let uri = toURI(kURIs[aURI]);
let title = kTitles[aTitle];
let out = [aURI, aTitle, aBook, aTags, aKey];
out.push("\nuri=" + kURIs[aURI]);
out.push("\ntitle=" + title);
// Add the page and a visit if we need to
if (!aNoVisit) {
yield PlacesTestUtils.addVisits({
uri: uri,
transition: aTransitionType || TRANSITION_LINK,
visitDate: gDate,
title: title
});
out.push("\nwith visit");
}
// Add a bookmark if we need to
if (aBook != undefined) {
let book = kTitles[aBook];
let bmid = bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder, uri,
bmsvc.DEFAULT_INDEX, book);
out.push("\nbook=" + book);
// Add a keyword to the bookmark if we need to
if (aKey != undefined)
yield PlacesUtils.keywords.insert({url: uri.spec, keyword: aKey});
// Add tags if we need to
if (aTags != undefined && aTags.length > 0) {
// Convert each tag index into the title
let tags = aTags.map(aTag => kTitles[aTag]);
tagsvc.tagURI(uri, tags);
out.push("\ntags=" + tags);
}
}
print("\nAdding page/book/tag: " + out.join(", "));
}
function run_test() {
print("\n");
// always search in history + bookmarks, no matter what the default is
prefs.setBoolPref("browser.urlbar.suggest.history", true);
prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
prefs.setBoolPref("browser.urlbar.suggest.openpage", true);
prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", false);
// Search is asynchronous, so don't let the test finish immediately
do_test_pending();
// Load the test and print a description then run the test
let [description, search, expected, func] = gTests[current_test];
print(description);
// By default assume we want to match tags
appendTags = true;
// Do an extra function if necessary
if (func)
func();
Task.spawn(function* () {
// Iterate over all tasks and execute them
for (let [fn, args] of gNextTestSetupTasks) {
yield fn.apply(this, args);
}
// Clean up to allow tests to register more functions.
gNextTestSetupTasks = [];
// At this point frecency could still be updating due to latest pages
// updates. This is not a problem in real life, but autocomplete tests
// should return reliable resultsets, thus we have to wait.
yield PlacesTestUtils.promiseAsyncUpdates();
}).then(() => ensure_results(search, expected),
do_report_unexpected_exception);
}
// Utility function to remove history pages
function removePages(aURIs)
{
gNextTestSetupTasks.push([do_removePages, arguments]);
}
function do_removePages(aURIs)
{
for (let uri of aURIs)
histsvc.removePage(toURI(kURIs[uri]));
}
// Utility function to mark pages as typed
function markTyped(aURIs, aTitle)
{
gNextTestSetupTasks.push([task_markTyped, arguments]);
}
function* task_markTyped(aURIs, aTitle)
{
for (let uri of aURIs) {
yield PlacesTestUtils.addVisits({
uri: toURI(kURIs[uri]),
transition: TRANSITION_TYPED,
title: kTitles[aTitle]
});
}
}

Просмотреть файл

@ -1,30 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* Test bug 416211 to make sure results that match the tag show the bookmark
* title instead of the page title.
*/
var theTag = "superTag";
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://theuri/",
];
var kTitles = [
"Page title",
"Bookmark title",
theTag,
];
// Add page with a title, bookmark, and [tags]
addPageBook(0, 0, 1, [2]);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Make sure the tag match gives the bookmark title",
theTag, [0]],
];

Просмотреть файл

@ -1,38 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* Test autocomplete for non-English URLs that match the tag bug 416214. Also
* test bug 417441 by making sure escaped ascii characters like "+" remain
* escaped.
*
* - add a visit for a page with a non-English URL
* - add a tag for the page
* - search for the tag
* - test number of matches (should be exactly one)
* - make sure the url is decoded
*/
var theTag = "superTag";
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://escaped/ユニコード",
"http://asciiescaped/blocking-firefox3%2B",
];
var kTitles = [
"title",
theTag,
];
// Add pages that match the tag
addPageBook(0, 0, 0, [1]);
addPageBook(1, 0, 0, [1]);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Make sure tag matches return the right url as well as '+' remain escaped",
theTag, [0, 1]],
];

Просмотреть файл

@ -1,36 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test for bug 417798 to make sure javascript: URIs don't show up unless the
* user searches for javascript: explicitly.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://abc/def",
"javascript:5",
];
var kTitles = [
"Title with javascript:",
];
addPageBook(0, 0); // regular url
// javascript: uri as bookmark (no visit)
addPageBook(1, 0, 0, undefined, undefined, undefined, true);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Match non-javascript: with plain search",
"a", [0]],
["1: Match non-javascript: with almost javascript:",
"javascript", [0]],
["2: Match javascript:",
"javascript:", [0, 1]],
["3: Match nothing with non-first javascript:",
"5 javascript:", []],
["4: Match javascript: with multi-word search",
"javascript: 5", [1]],
];

Просмотреть файл

@ -1,43 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test bug 418257 by making sure tags are returned with the title as part of
* the "comment" if there are tags even if we didn't match in the tags. They
* are separated from the title by a endash.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://page1",
"http://page2",
"http://page3",
"http://page4",
];
var kTitles = [
"tag1",
"tag2",
"tag3",
];
// Add pages with varying number of tags
addPageBook(0, 0, 0, [0]);
addPageBook(1, 0, 0, [0, 1]);
addPageBook(2, 0, 0, [0, 2]);
addPageBook(3, 0, 0, [0, 1, 2]);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Make sure tags come back in the title when matching tags",
"page1 tag", [0]],
["1: Check tags in title for page2",
"page2 tag", [1]],
["2: Make sure tags appear even when not matching the tag",
"page3", [2]],
["3: Multiple tags come in commas for page4",
"page4", [3]],
["4: Extra test just to make sure we match the title",
"tag2", [1, 3]],
];

Просмотреть файл

@ -1,25 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test bug 422277 to make sure bad escaped uris don't get escaped. This makes
* sure we don't hit an assertion for "not a UTF8 string".
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://site/%EAid",
];
var kTitles = [
"title",
];
addPageBook(0, 0);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Bad escaped uri stays escaped",
"site", [0]],
];

Просмотреть файл

@ -1,54 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* Need to test that removing a page from autocomplete actually removes a page
* Description From Shawn Wilsher :sdwilsh 2009-02-18 11:29:06 PST
* We don't test the code path of onValueRemoved
* for the autocomplete implementation
* Bug 479089
*/
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
function run_test()
{
run_next_test();
}
add_task(function* test_autocomplete_on_value_removed()
{
// QI to nsIAutoCompleteSimpleResultListener
var listener = Cc["@mozilla.org/autocomplete/search;1?name=history"].
getService(Components.interfaces.nsIAutoCompleteSimpleResultListener);
// add history visit
var testUri = uri("http://foo.mozilla.com/");
yield PlacesTestUtils.addVisits({
uri: testUri,
referrer: uri("http://mozilla.com/")
});
// create a query object
var query = histsvc.getNewQuery();
// create the options object we will never use
var options = histsvc.getNewQueryOptions();
// look for this uri only
query.uri = testUri;
// execute
var queryRes = histsvc.executeQuery(query, options);
// open the result container
queryRes.root.containerOpen = true;
// debug queries
// dump_table("moz_places");
do_check_eq(queryRes.root.childCount, 1);
// call the untested code path
listener.onValueRemoved(null, testUri.spec, true);
// make sure it is GONE from the DB
do_check_eq(queryRes.root.childCount, 0);
// close the container
queryRes.root.containerOpen = false;
});

Просмотреть файл

@ -1,53 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
* vim:set ts=2 sw=2 sts=2 et:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Tests bug 449406 to ensure that TRANSITION_DOWNLOAD, TRANSITION_EMBED and
* TRANSITION_FRAMED_LINK bookmarked uri's show up in the location bar.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://download/bookmarked",
"http://embed/bookmarked",
"http://framed/bookmarked",
"http://download",
"http://embed",
"http://framed",
];
var kTitles = [
"download-bookmark",
"embed-bookmark",
"framed-bookmark",
"download2",
"embed2",
"framed2",
];
// Add download and embed uris
addPageBook(0, 0, 0, undefined, undefined, TRANSITION_DOWNLOAD);
addPageBook(1, 1, 1, undefined, undefined, TRANSITION_EMBED);
addPageBook(2, 2, 2, undefined, undefined, TRANSITION_FRAMED_LINK);
addPageBook(3, 3, undefined, undefined, undefined, TRANSITION_DOWNLOAD);
addPageBook(4, 4, undefined, undefined, undefined, TRANSITION_EMBED);
addPageBook(5, 5, undefined, undefined, undefined, TRANSITION_FRAMED_LINK);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Searching for bookmarked download uri matches",
kTitles[0], [0]],
["1: Searching for bookmarked embed uri matches",
kTitles[1], [1]],
["2: Searching for bookmarked framed uri matches",
kTitles[2], [2]],
["3: Searching for download uri does not match",
kTitles[3], []],
["4: Searching for embed uri does not match",
kTitles[4], []],
["5: Searching for framed uri does not match",
kTitles[5], []],
];

Просмотреть файл

@ -1,69 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test for bug 426864 that makes sure the empty search (drop down list) only
* shows typed pages from history.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://foo/0",
"http://foo/1",
"http://foo/2",
"http://foo/3",
"http://foo/4",
"http://foo/5",
];
var kTitles = [
"title",
];
// Visited (in history)
addPageBook(0, 0); // history
addPageBook(1, 0, 0); // bookmark
addPageBook(2, 0); // history typed
addPageBook(3, 0, 0); // bookmark typed
// Unvisited bookmark
addPageBook(4, 0, 0); // bookmark
addPageBook(5, 0, 0); // bookmark typed
// Set some pages as typed
markTyped([2, 3, 5], 0);
// Remove pages from history to treat them as unvisited
removePages([4, 5]);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Match everything",
"foo", [0, 1, 2, 3, 4, 5]],
["1: Match only typed history",
"foo ^ ~", [2, 3]],
["2: Drop-down empty search matches only typed history",
"", [2, 3]],
["3: Drop-down empty search matches only bookmarks",
"", [2, 3], matchBookmarks],
["4: Drop-down empty search matches only typed",
"", [2, 3], matchTyped],
];
function matchBookmarks() {
prefs.setBoolPref("browser.urlbar.suggest.history", false);
prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
clearPrefs();
}
function matchTyped() {
prefs.setBoolPref("browser.urlbar.suggest.history", true);
prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", true);
clearPrefs();
}
function clearPrefs() {
prefs.clearUserPref("browser.urlbar.suggest.history");
prefs.clearUserPref("browser.urlbar.suggest.bookmark");
prefs.clearUserPref("browser.urlbar.suggest.history.onlyTyped");
}

Просмотреть файл

@ -1,69 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test for bug 471903 to make sure searching in autocomplete can be turned on
* and off. Also test bug 463535 for pref changing search.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://url/0",
];
var kTitles = [
"title",
];
addPageBook(0, 0); // visited page
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["1: plain search",
"url", [0]],
["2: search disabled",
"url", [], () => setSearch(0)],
["3: resume normal search",
"url", [0], () => setSearch(1)],
];
function setSearch(aSearch) {
prefs.setBoolPref("browser.urlbar.autocomplete.enabled", !!aSearch);
}
add_task(function* test_sync_enabled() {
// Initialize autocomplete component.
Cc["@mozilla.org/autocomplete/search;1?name=history"]
.getService(Ci.mozIPlacesAutoComplete);
let types = [ "history", "bookmark", "openpage" ];
// Test the service keeps browser.urlbar.autocomplete.enabled synchronized
// with browser.urlbar.suggest prefs.
for (let type of types) {
Services.prefs.setBoolPref("browser.urlbar.suggest." + type, true);
}
Assert.equal(Services.prefs.getBoolPref("browser.urlbar.autocomplete.enabled"), true);
// Disable autocomplete and check all the suggest prefs are set to false.
Services.prefs.setBoolPref("browser.urlbar.autocomplete.enabled", false);
for (let type of types) {
Assert.equal(Services.prefs.getBoolPref("browser.urlbar.suggest." + type), false);
}
// Setting even a single suggest pref to true should enable autocomplete.
Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
for (let type of types.filter(t => t != "history")) {
Assert.equal(Services.prefs.getBoolPref("browser.urlbar.suggest." + type), false);
}
Assert.equal(Services.prefs.getBoolPref("browser.urlbar.autocomplete.enabled"), true);
// Disable autocoplete again, then re-enable it and check suggest prefs
// have been reset.
Services.prefs.setBoolPref("browser.urlbar.autocomplete.enabled", false);
Services.prefs.setBoolPref("browser.urlbar.autocomplete.enabled", true);
for (let type of types.filter(t => t != "history")) {
Assert.equal(Services.prefs.getBoolPref("browser.urlbar.suggest." + type), true);
}
});

Просмотреть файл

@ -1,30 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test bug 422698 to make sure searches with urls from the location bar
* correctly match itself when it contains escaped characters.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://unescapeduri/",
"http://escapeduri/%40/",
];
var kTitles = [
"title",
];
// Add unescaped and escaped uris
addPageBook(0, 0);
addPageBook(1, 0);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Unescaped location matches itself",
kURIs[0], [0]],
["1: Escaped location matches itself",
kURIs[1], [1]],
];

Просмотреть файл

@ -1,27 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test bug 424509 to make sure searching for "h" doesn't match "http" of urls.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://site/",
"http://happytimes/",
];
var kTitles = [
"title",
];
// Add site without "h" and with "h"
addPageBook(0, 0);
addPageBook(1, 0);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Searching for h matches site and not http://",
"h", [1]],
];

Просмотреть файл

@ -1,73 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test for bug 392143 that puts keyword results into the autocomplete. Makes
* sure that multiple parameter queries get spaces converted to +, + converted
* to %2B, non-ascii become escaped, and pages in history that match the
* keyword uses the page's title.
*
* Also test for bug 249468 by making sure multiple keyword bookmarks with the
* same keyword appear in the list.
*/
// Details for the keyword bookmark
var keyBase = "http://abc/?search=";
var keyKey = "key";
// A second keyword bookmark with the same keyword
var otherBase = "http://xyz/?foo=";
var unescaped = "ユニコード";
var pageInHistory = "ThisPageIsInHistory";
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
keyBase + "%s",
keyBase + "term",
keyBase + "multi+word",
keyBase + "blocking%2B",
keyBase + unescaped,
keyBase + pageInHistory,
keyBase,
otherBase + "%s",
keyBase + "twoKey",
otherBase + "twoKey"
];
var kTitles = [
"Generic page title",
"Keyword title",
"abc",
"xyz"
];
// Add the keyword bookmark
addPageBook(0, 0, 1, [], keyKey);
// Add in the "fake pages" for keyword searches
gPages[1] = [1, 2];
gPages[2] = [2, 2];
gPages[3] = [3, 2];
gPages[4] = [4, 2];
// Add a page into history
addPageBook(5, 2);
gPages[6] = [6, 2];
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Plain keyword query",
keyKey + " term", [1]],
["1: Multi-word keyword query",
keyKey + " multi word", [2]],
["2: Keyword query with +",
keyKey + " blocking+", [3]],
["3: Unescaped term in query",
keyKey + " " + unescaped, [4]],
["4: Keyword that happens to match a page",
keyKey + " " + pageInHistory, [5]],
["5: Keyword without query (without space)",
keyKey, [6]],
["6: Keyword without query (with space)",
keyKey + " ", [6]],
];

Просмотреть файл

@ -1,45 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test bug 451760 which allows matching only at the beginning of urls or
* titles to simulate Firefox 2 functionality.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://x.com/y",
"https://y.com/x",
];
var kTitles = [
"a b",
"b a",
];
addPageBook(0, 0);
addPageBook(1, 1);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
// Tests after this one will match at the beginning
["0: Match at the beginning of titles",
"a", [0],
() => setBehavior(3)],
["1: Match at the beginning of titles",
"b", [1]],
["2: Match at the beginning of urls",
"x", [0]],
["3: Match at the beginning of urls",
"y", [1]],
// Tests after this one will match against word boundaries and anywhere
["4: Sanity check that matching anywhere finds more",
"a", [0, 1],
() => setBehavior(1)],
];
function setBehavior(aType) {
prefs.setIntPref("browser.urlbar.matchBehavior", aType);
}

Просмотреть файл

@ -1,49 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test for bug 401869 to allow multiple words separated by spaces to match in
* the page title, page url, or bookmark title to be considered a match. All
* terms must match but not all terms need to be in the title, etc.
*
* Test bug 424216 by making sure bookmark titles are always shown if one is
* available. Also bug 425056 makes sure matches aren't found partially in the
* page title and partially in the bookmark.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://a.b.c/d-e_f/h/t/p",
"http://d.e.f/g-h_i/h/t/p",
"http://g.h.i/j-k_l/h/t/p",
"http://j.k.l/m-n_o/h/t/p",
];
var kTitles = [
"f(o)o b<a>r",
"b(a)r b<a>z",
];
// Regular pages
addPageBook(0, 0);
addPageBook(1, 1);
// Bookmarked pages
addPageBook(2, 0, 0);
addPageBook(3, 0, 1);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: Match 2 terms all in url",
"c d", [0]],
["1: Match 1 term in url and 1 term in title",
"b e", [0, 1]],
["2: Match 3 terms all in title; display bookmark title if matched",
"b a z", [1, 3]],
["3: Match 2 terms in url and 1 in title; make sure bookmark title is used for search",
"k f t", [2]],
["4: Match 3 terms in url and 1 in title",
"d i g z", [1]],
["5: Match nothing",
"m o z i", []],
];

Просмотреть файл

@ -1,183 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test for bug 395161 that allows special searches that restrict results to
* history/bookmark/tagged items and title/url matches.
*
* Test 485122 by making sure results don't have tags when restricting result
* to just history either by default behavior or dynamic query restrict.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://url/",
"http://url/2",
"http://foo.bar/",
"http://foo.bar/2",
"http://url/star",
"http://url/star/2",
"http://foo.bar/star",
"http://foo.bar/star/2",
"http://url/tag",
"http://url/tag/2",
"http://foo.bar/tag",
"http://foo.bar/tag/2",
];
var kTitles = [
"title",
"foo.bar",
];
// Plain page visits
addPageBook(0, 0); // plain page
addPageBook(1, 1); // title
addPageBook(2, 0); // url
addPageBook(3, 1); // title and url
// Bookmarked pages (no tag)
addPageBook(4, 0, 0); // bookmarked page
addPageBook(5, 1, 1); // title
addPageBook(6, 0, 0); // url
addPageBook(7, 1, 1); // title and url
// Tagged pages
addPageBook(8, 0, 0, [1]); // tagged page
addPageBook(9, 1, 1, [1]); // title
addPageBook(10, 0, 0, [1]); // url
addPageBook(11, 1, 1, [1]); // title and url
// Remove pages from history to treat them as unvisited, so pages that do have
// visits are 0,1,2,3,5,10
removePages([4, 6, 7, 8, 9, 11]);
// Set some pages as typed
markTyped([0, 10], 0);
markTyped([3], 1);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
// Test restricting searches
["0: History restrict",
"^", [0, 1, 2, 3, 5, 10]],
["1: Star restrict",
"*", [4, 5, 6, 7, 8, 9, 10, 11]],
["2: Tag restrict",
"+", [8, 9, 10, 11]],
// Test specials as any word position
["3: Special as first word",
"^ foo bar", [1, 2, 3, 5, 10]],
["4: Special as middle word",
"foo ^ bar", [1, 2, 3, 5, 10]],
["5: Special as last word",
"foo bar ^", [1, 2, 3, 5, 10]],
// Test restricting and matching searches with a term
["6.1: foo ^ -> history",
"foo ^", [1, 2, 3, 5, 10]],
["6.2: foo | -> history (change pref)",
"foo |", [1, 2, 3, 5, 10], () => changeRestrict("history", "|")],
["7.1: foo * -> is star",
"foo *", [5, 6, 7, 8, 9, 10, 11], () => resetRestrict("history")],
["7.2: foo | -> is star (change pref)",
"foo |", [5, 6, 7, 8, 9, 10, 11], () => changeRestrict("bookmark", "|")],
["8.1: foo # -> in title",
"foo #", [1, 3, 5, 7, 8, 9, 10, 11], () => resetRestrict("bookmark")],
["8.2: foo | -> in title (change pref)",
"foo |", [1, 3, 5, 7, 8, 9, 10, 11], () => changeRestrict("title", "|")],
["9.1: foo @ -> in url",
"foo @", [2, 3, 6, 7, 10, 11], () => resetRestrict("title")],
["9.2: foo | -> in url (change pref)",
"foo |", [2, 3, 6, 7, 10, 11], () => changeRestrict("url", "|")],
["10: foo + -> is tag",
"foo +", [8, 9, 10, 11], () => resetRestrict("url")],
["10.2: foo | -> is tag (change pref)",
"foo |", [8, 9, 10, 11], () => changeRestrict("tag", "|")],
["10.3: foo ~ -> is typed",
"foo ~", [3, 10], () => resetRestrict("tag")],
["10.4: foo | -> is typed (change pref)",
"foo |", [3, 10], () => changeRestrict("typed", "|")],
// Test various pairs of special searches
["11: foo ^ * -> history, is star",
"foo ^ *", [5, 10], () => resetRestrict("typed")],
["12: foo ^ # -> history, in title",
"foo ^ #", [1, 3, 5, 10]],
["13: foo ^ @ -> history, in url",
"foo ^ @", [2, 3, 10]],
["14: foo ^ + -> history, is tag",
"foo ^ +", [10]],
["14.1: foo ^ ~ -> history, is typed",
"foo ^ ~", [3, 10]],
["15: foo * # -> is star, in title",
"foo * #", [5, 7, 8, 9, 10, 11]],
["16: foo * @ -> is star, in url",
"foo * @", [6, 7, 10, 11]],
["17: foo * + -> same as +",
"foo * +", [8, 9, 10, 11]],
["17.1: foo * ~ -> is star, is typed",
"foo * ~", [10]],
["18: foo # @ -> in title, in url",
"foo # @", [3, 7, 10, 11]],
["19: foo # + -> in title, is tag",
"foo # +", [8, 9, 10, 11]],
["19.1: foo # ~ -> in title, is typed",
"foo # ~", [3, 10]],
["20: foo @ + -> in url, is tag",
"foo @ +", [10, 11]],
["20.1: foo @ ~ -> in url, is typed",
"foo @ ~", [3, 10]],
["20.2: foo + ~ -> is tag, is typed",
"foo + ~", [10]],
// Test default usage by setting certain bits of default.behavior to 1
["21: foo -> default history",
"foo", [1, 2, 3, 5, 10], function () { setPref({ history: true }); }],
["22: foo -> default history or is star",
"foo", [1, 2, 3, 5, 6, 7, 8, 9, 10, 11], () => setPref({ history: true, bookmark: true })],
["22.1: foo -> default history or is star, is typed",
"foo", [3, 10], () => setPref({ history: true, bookmark: true, "history.onlyTyped": true })],
];
function setPref(aTypes) {
clearSuggestPrefs();
for (let type in aTypes) {
prefs.setBoolPref("browser.urlbar.suggest." + type, aTypes[type]);
}
}
function clearSuggestPrefs() {
prefs.setBoolPref("browser.urlbar.suggest.history", false);
prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", false);
prefs.setBoolPref("browser.urlbar.suggest.openpage", false);
}
function changeRestrict(aType, aChar)
{
let branch = "browser.urlbar.";
// "title" and "url" are different from everything else, so special case them.
if (aType == "title" || aType == "url")
branch += "match.";
else
branch += "restrict.";
print("changing restrict for " + aType + " to '" + aChar + "'");
prefs.setCharPref(branch + aType, aChar);
}
function resetRestrict(aType)
{
let branch = "browser.urlbar.";
// "title" and "url" are different from everything else, so special case them.
if (aType == "title" || aType == "url")
branch += "match.";
else
branch += "restrict.";
if (prefs.prefHasUserValue(branch + aType))
prefs.clearUserPref(branch + aType);
}

Просмотреть файл

@ -1,63 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test bug 424717 to make sure searching with an existing location like
* http://site/ also matches https://site/ or ftp://site/. Same thing for
* ftp://site/ and https://site/.
*
* Test bug 461483 to make sure a search for "w" doesn't match the "www." from
* site subdomains.
*/
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://www.site/",
"http://site/",
"ftp://ftp.site/",
"ftp://site/",
"https://www.site/",
"https://site/",
"http://woohoo/",
"http://wwwwwwacko/",
];
var kTitles = [
"title",
];
// Add various protocols of site
addPageBook(0, 0);
addPageBook(1, 0);
addPageBook(2, 0);
addPageBook(3, 0);
addPageBook(4, 0);
addPageBook(5, 0);
addPageBook(6, 0);
addPageBook(7, 0);
var allSite = [0, 1, 2, 3, 4, 5];
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
["0: http://www.site matches all site", "http://www.site", allSite],
["1: http://site matches all site", "http://site", allSite],
["2: ftp://ftp.site matches itself", "ftp://ftp.site", [2]],
["3: ftp://site matches all site", "ftp://site", allSite],
["4: https://www.site matches all site", "https://www.site", allSite],
["5: https://site matches all site", "https://site", allSite],
["6: www.site matches all site", "www.site", allSite],
["7: w matches none of www.", "w", [6, 7]],
["8: http://w matches none of www.", "w", [6, 7]],
["9: http://www.w matches none of www.", "w", [6, 7]],
["10: ww matches none of www.", "ww", [7]],
["11: http://ww matches none of www.", "http://ww", [7]],
["12: http://www.ww matches none of www.", "http://www.ww", [7]],
["13: www matches none of www.", "www", [7]],
["14: http://www matches none of www.", "http://www", [7]],
["15: http://www.www matches none of www.", "http://www.www", [7]],
];

Просмотреть файл

@ -1,97 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
* vim:set ts=2 sw=2 sts=2 et:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var gTabRestrictChar = "%";
prefs.setCharPref("browser.urlbar.restrict.openpage", gTabRestrictChar);
do_register_cleanup(() => {
prefs.clearUserPref("browser.urlbar.restrict.openpage");
});
var kSearchParam = "enable-actions";
var kURIs = [
"http://abc.com/",
"moz-action:switchtab,http://abc.com/",
"http://xyz.net/",
"moz-action:switchtab,http://xyz.net/",
"about:mozilla",
"moz-action:switchtab,about:mozilla",
"data:text/html,test",
"moz-action:switchtab,data:text/html,test"
];
var kTitles = [
"ABC rocks",
"xyz.net - we're better than ABC",
"about:mozilla",
"data:text/html,test"
];
addPageBook(0, 0);
gPages[1] = [1, 0];
addPageBook(2, 1);
gPages[3] = [3, 1];
addOpenPages(0, 1);
// PAges that cannot be registered in history.
addOpenPages(4, 1);
gPages[5] = [5, 2];
addOpenPages(6, 1);
gPages[7] = [7, 3];
var gTests = [
["0: single result, that is also a tab match",
"abc.com", [1]],
["1: two results, one tab match",
"abc", [1, 2]],
["2: two results, both tab matches",
"abc", [1, 3],
function() {
addOpenPages(2, 1);
}],
["3: two results, both tab matches, one has multiple tabs",
"abc", [1, 3],
function() {
addOpenPages(2, 5);
}],
["4: two results, no tab matches",
"abc", [0, 2],
function() {
removeOpenPages(0, 1);
removeOpenPages(2, 6);
}],
["5: tab match search with restriction character",
gTabRestrictChar + " abc", [1],
function() {
addOpenPages(0, 1);
}],
["6: tab match with not-addable pages",
"mozilla", [5]],
["7: tab match with not-addable pages and restriction character",
gTabRestrictChar + " mozilla", [5]],
["8: tab match with not-addable pages and only restriction character",
gTabRestrictChar, [1, 5, 7]],
];
function addOpenPages(aUri, aCount) {
let num = aCount || 1;
let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"].
getService(Ci.mozIPlacesAutoComplete);
for (let i = 0; i < num; i++) {
acprovider.registerOpenPage(toURI(kURIs[aUri]));
}
}
function removeOpenPages(aUri, aCount) {
let num = aCount || 1;
let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"].
getService(Ci.mozIPlacesAutoComplete);
for (let i = 0; i < num; i++) {
acprovider.unregisterOpenPage(toURI(kURIs[aUri]));
}
}

Просмотреть файл

@ -1,105 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test bug 393678 to make sure matches against the url, title, tags are only
* made on word boundaries instead of in the middle of words.
*
* Make sure we don't try matching one after a CamelCase because the upper-case
* isn't really a word boundary. (bug 429498)
*
* Bug 429531 provides switching between "must match on word boundary" and "can
* match," so leverage "must match" pref for checking word boundary logic and
* make sure "can match" matches anywhere.
*/
var katakana = ["\u30a8", "\u30c9"]; // E, Do
var ideograph = ["\u4efb", "\u5929", "\u5802"]; // Nin Ten Do
// Define some shared uris and titles (each page needs its own uri)
var kURIs = [
"http://matchme/",
"http://dontmatchme/",
"http://title/1",
"http://title/2",
"http://tag/1",
"http://tag/2",
"http://crazytitle/",
"http://katakana/",
"http://ideograph/",
"http://camel/pleaseMatchMe/",
];
var kTitles = [
"title1",
"matchme2",
"dontmatchme3",
"!@#$%^&*()_+{}|:<>?word",
katakana.join(""),
ideograph.join(""),
];
// Boundaries on the url
addPageBook(0, 0);
addPageBook(1, 0);
// Boundaries on the title
addPageBook(2, 1);
addPageBook(3, 2);
// Boundaries on the tag
addPageBook(4, 0, 0, [1]);
addPageBook(5, 0, 0, [2]);
// Lots of word boundaries before a word
addPageBook(6, 3);
// Katakana
addPageBook(7, 4);
// Ideograph
addPageBook(8, 5);
// CamelCase
addPageBook(9, 0);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test
var gTests = [
// Tests after this one will match only on word boundaries
["0: Match 'match' at the beginning or after / or on a CamelCase",
"match", [0, 2, 4, 9],
() => setBehavior(2)],
["1: Match 'dont' at the beginning or after /",
"dont", [1, 3, 5]],
["2: Match '2' after the slash and after a word (in tags too)",
"2", [2, 3, 4, 5]],
["3: Match 't' at the beginning or after /",
"t", [0, 1, 2, 3, 4, 5, 9]],
["4: Match 'word' after many consecutive word boundaries",
"word", [6]],
["5: Match a word boundary '/' for everything",
"/", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]],
["6: Match word boundaries '()_+' that are among word boundaries",
"()_+", [6]],
["7: Katakana characters form a string, so match the beginning",
katakana[0], [7]],
/*["8: Middle of a katakana word shouldn't be matched",
katakana[1], []],*/
["9: Ideographs are treated as words so 'nin' is one word",
ideograph[0], [8]],
["10: Ideographs are treated as words so 'ten' is another word",
ideograph[1], [8]],
["11: Ideographs are treated as words so 'do' is yet another",
ideograph[2], [8]],
["12: Extra negative assert that we don't match in the middle",
"ch", []],
["13: Don't match one character after a camel-case word boundary (bug 429498)",
"atch", []],
// Tests after this one will match against word boundaries and anywhere
["14: Match on word boundaries as well as anywhere (bug 429531)",
"tch", [0, 1, 2, 3, 4, 5, 9],
() => setBehavior(1)],
];
function setBehavior(aType) {
prefs.setIntPref("browser.urlbar.matchBehavior", aType);
}

Просмотреть файл

@ -1,29 +0,0 @@
[DEFAULT]
head = head_autocomplete.js
tail =
skip-if = toolkit == 'android' || toolkit == 'gonk'
[test_416211.js]
[test_416214.js]
[test_417798.js]
[test_418257.js]
[test_422277.js]
[test_autocomplete_on_value_removed_479089.js]
# Bug 676989: test fails consistently on Android
fail-if = os == "android"
[test_download_embed_bookmarks.js]
# Bug 676989: test fails consistently on Android
fail-if = os == "android"
[test_empty_search.js]
# Bug 676989: test fails consistently on Android
fail-if = os == "android"
[test_enabled.js]
[test_escape_self.js]
[test_ignore_protocol.js]
[test_keyword_search.js]
[test_match_beginning.js]
[test_multi_word_search.js]
[test_special_search.js]
[test_swap_protocol.js]
[test_tabmatches.js]
[test_word_boundary_search.js]

Просмотреть файл

@ -22,11 +22,6 @@ XPCSHELL_TESTS_MANIFESTS += [
'unit/xpcshell.ini',
]
if CONFIG['MOZ_SUITE']:
XPCSHELL_TESTS_MANIFESTS += [
'autocomplete/xpcshell.ini',
]
BROWSER_CHROME_MANIFESTS += ['browser/browser.ini']
MOCHITEST_CHROME_MANIFESTS += [
'chrome/chrome.ini',