Wed, 31 Dec 2014 06:09:35 +0100
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 | expectText: "test+search" |
michael@0 | 11 | }, |
michael@0 | 12 | { |
michael@0 | 13 | name: "?-prefixed search (search service)", |
michael@0 | 14 | testText: "? foo ", |
michael@0 | 15 | expectText: "foo" |
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 tab = gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 23 | |
michael@0 | 24 | let searchObserver = function search_observer(aSubject, aTopic, aData) { |
michael@0 | 25 | let engine = aSubject.QueryInterface(Ci.nsISearchEngine); |
michael@0 | 26 | info("Observer: " + aData + " for " + engine.name); |
michael@0 | 27 | |
michael@0 | 28 | if (aData != "engine-added") |
michael@0 | 29 | return; |
michael@0 | 30 | |
michael@0 | 31 | if (engine.name != "POST Search") |
michael@0 | 32 | return; |
michael@0 | 33 | |
michael@0 | 34 | Services.search.defaultEngine = engine; |
michael@0 | 35 | |
michael@0 | 36 | registerCleanupFunction(function () { |
michael@0 | 37 | Services.search.removeEngine(engine); |
michael@0 | 38 | }); |
michael@0 | 39 | |
michael@0 | 40 | // ready to execute the tests! |
michael@0 | 41 | executeSoon(nextTest); |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | Services.obs.addObserver(searchObserver, "browser-search-engine-modified", false); |
michael@0 | 45 | |
michael@0 | 46 | registerCleanupFunction(function () { |
michael@0 | 47 | gBrowser.removeTab(tab); |
michael@0 | 48 | |
michael@0 | 49 | Services.obs.removeObserver(searchObserver, "browser-search-engine-modified"); |
michael@0 | 50 | }); |
michael@0 | 51 | |
michael@0 | 52 | Services.search.addEngine("http://test:80/browser/browser/base/content/test/general/POSTSearchEngine.xml", |
michael@0 | 53 | Ci.nsISearchEngine.DATA_XML, null, false); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | var gCurrTest; |
michael@0 | 57 | function nextTest() { |
michael@0 | 58 | if (gTests.length) { |
michael@0 | 59 | gCurrTest = gTests.shift(); |
michael@0 | 60 | doTest(); |
michael@0 | 61 | } else { |
michael@0 | 62 | finish(); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function doTest() { |
michael@0 | 67 | info("Running test: " + gCurrTest.name); |
michael@0 | 68 | |
michael@0 | 69 | waitForLoad(function () { |
michael@0 | 70 | let loadedText = gBrowser.contentDocument.body.textContent; |
michael@0 | 71 | ok(loadedText, "search page loaded"); |
michael@0 | 72 | let needle = "searchterms=" + gCurrTest.expectText; |
michael@0 | 73 | is(loadedText, needle, "The query POST data should be returned in the response"); |
michael@0 | 74 | nextTest(); |
michael@0 | 75 | }); |
michael@0 | 76 | |
michael@0 | 77 | // Simulate a user entering search terms |
michael@0 | 78 | gURLBar.value = gCurrTest.testText; |
michael@0 | 79 | gURLBar.focus(); |
michael@0 | 80 | EventUtils.synthesizeKey("VK_RETURN", {}); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | |
michael@0 | 84 | function waitForLoad(cb) { |
michael@0 | 85 | let browser = gBrowser.selectedBrowser; |
michael@0 | 86 | browser.addEventListener("load", function listener() { |
michael@0 | 87 | if (browser.currentURI.spec == "about:blank") |
michael@0 | 88 | return; |
michael@0 | 89 | info("Page loaded: " + browser.currentURI.spec); |
michael@0 | 90 | browser.removeEventListener("load", listener, true); |
michael@0 | 91 | |
michael@0 | 92 | cb(); |
michael@0 | 93 | }, true); |
michael@0 | 94 | } |