browser/base/content/test/general/browser_keywordSearch.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial