1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
**/
var gTests = [
{
name: "normal search (search service)",
testText: "test search",
searchURL: Services.search.defaultEngine.getSubmission("test search", null, "keyword").uri.spec
},
{
name: "?-prefixed search (search service)",
testText: "? foo ",
searchURL: Services.search.defaultEngine.getSubmission("foo", null, "keyword").uri.spec
}
];
function test() {
waitForExplicitFinish();
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);
let tab = gBrowser.selectedTab = gBrowser.addTab();
let listener = {
onStateChange: function onLocationChange(webProgress, req, flags, status) {
// Only care about document starts
let docStart = Ci.nsIWebProgressListener.STATE_IS_DOCUMENT |
Ci.nsIWebProgressListener.STATE_START;
if (!(flags & docStart))
return;
info("received document start");
ok(req instanceof Ci.nsIChannel, "req is a channel");
is(req.originalURI.spec, gCurrTest.searchURL, "search URL was loaded");
info("Actual URI: " + req.URI.spec);
req.cancel(Components.results.NS_ERROR_FAILURE);
executeSoon(nextTest);
}
};
gBrowser.addProgressListener(listener);
registerCleanupFunction(function () {
Services.ww.unregisterNotification(windowObserver);
gBrowser.removeProgressListener(listener);
gBrowser.removeTab(tab);
});
nextTest();
}
var gCurrTest;
function nextTest() {
if (gTests.length) {
gCurrTest = gTests.shift();
doTest();
} else {
finish();
}
}
function doTest() {
info("Running test: " + gCurrTest.name);
// Simulate a user entering search terms
gURLBar.value = gCurrTest.testText;
gURLBar.focus();
EventUtils.synthesizeKey("VK_RETURN", {});
}
|