2010-09-11 11:41:13 -07:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
**/
|
|
|
|
|
2010-10-31 13:01:28 -07:00
|
|
|
var gTests = [
|
|
|
|
{
|
|
|
|
name: "normal search (search service)",
|
|
|
|
testText: "test search",
|
|
|
|
searchURL: Services.search.originalDefaultEngine.getSubmission("test search").uri.spec
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "?-prefixed search (search service)",
|
|
|
|
testText: "? foo ",
|
|
|
|
searchURL: Services.search.originalDefaultEngine.getSubmission("foo").uri.spec
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "normal search (keyword.url)",
|
|
|
|
testText: "test search",
|
|
|
|
keywordURLPref: "http://example.com/?q=",
|
|
|
|
searchURL: "http://example.com/?q=test+search"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "?-prefixed search (keyword.url)",
|
|
|
|
testText: "? foo ",
|
|
|
|
keywordURLPref: "http://example.com/?q=",
|
|
|
|
searchURL: "http://example.com/?q=foo"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "encoding test (keyword.url)",
|
|
|
|
testText: "test encoded+%/",
|
|
|
|
keywordURLPref: "http://example.com/?q=",
|
|
|
|
searchURL: "http://example.com/?q=test+encoded%2B%25%2F"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2010-09-11 11:41:13 -07:00
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
2010-10-31 13:01:28 -07:00
|
|
|
let windowObserver = {
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic == "domwindowopened") {
|
|
|
|
ok(false, "Alert window opened");
|
|
|
|
let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
|
|
|
|
win.addEventListener("load", function() {
|
|
|
|
win.removeEventListener("load", arguments.callee, false);
|
|
|
|
win.close();
|
|
|
|
}, false);
|
|
|
|
executeSoon(finish);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Services.ww.registerNotification(windowObserver);
|
|
|
|
|
2010-09-11 11:41:13 -07:00
|
|
|
let tab = gBrowser.selectedTab = gBrowser.addTab();
|
|
|
|
|
|
|
|
let listener = {
|
|
|
|
onStateChange: function onLocationChange(webProgress, req, flags, status) {
|
2010-10-31 13:01:28 -07:00
|
|
|
// Only care about document starts
|
|
|
|
let docStart = Ci.nsIWebProgressListener.STATE_IS_DOCUMENT |
|
|
|
|
Ci.nsIWebProgressListener.STATE_START;
|
|
|
|
if (!(flags & docStart))
|
2010-09-11 11:41:13 -07:00
|
|
|
return;
|
|
|
|
|
2010-10-31 13:01:28 -07:00
|
|
|
info("received document start");
|
2010-09-11 11:41:13 -07:00
|
|
|
|
2010-10-31 13:01:28 -07:00
|
|
|
ok(req instanceof Ci.nsIChannel, "req is a channel");
|
|
|
|
is(req.originalURI.spec, gCurrTest.searchURL, "search URL was loaded");
|
2010-09-11 11:41:13 -07:00
|
|
|
info("Actual URI: " + req.URI.spec);
|
|
|
|
|
2010-10-31 13:01:28 -07:00
|
|
|
executeSoon(nextTest);
|
2010-09-11 11:41:13 -07:00
|
|
|
}
|
|
|
|
}
|
2010-10-31 13:01:28 -07:00
|
|
|
gBrowser.addProgressListener(listener);
|
2010-09-11 11:41:13 -07:00
|
|
|
|
2010-10-31 13:01:28 -07:00
|
|
|
registerCleanupFunction(function () {
|
|
|
|
Services.ww.unregisterNotification(windowObserver);
|
|
|
|
|
|
|
|
gBrowser.removeProgressListener(listener);
|
|
|
|
gBrowser.removeTab(tab);
|
|
|
|
});
|
|
|
|
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
var gCurrTest;
|
|
|
|
function nextTest() {
|
|
|
|
// Clear the pref before every test (and after the last)
|
|
|
|
try {
|
|
|
|
Services.prefs.clearUserPref("keyword.URL");
|
|
|
|
} catch(ex) {}
|
|
|
|
|
|
|
|
if (gTests.length) {
|
|
|
|
gCurrTest = gTests.shift();
|
|
|
|
doTest();
|
|
|
|
} else {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function doTest() {
|
|
|
|
info("Running test: " + gCurrTest.name);
|
|
|
|
|
|
|
|
if (gCurrTest.keywordURLPref)
|
|
|
|
Services.prefs.setCharPref("keyword.URL", gCurrTest.keywordURLPref);
|
2010-09-11 11:41:13 -07:00
|
|
|
|
|
|
|
// Simulate a user entering search terms
|
2010-10-31 13:01:28 -07:00
|
|
|
gURLBar.value = gCurrTest.testText;
|
2010-09-11 11:41:13 -07:00
|
|
|
gURLBar.focus();
|
|
|
|
EventUtils.synthesizeKey("VK_RETURN", {});
|
|
|
|
}
|