toolkit/components/search/tests/xpcshell/test_purpose.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /*
michael@0 5 * Test that a search purpose can be specified and that query parameters for
michael@0 6 * that purpose are included in the search URL.
michael@0 7 */
michael@0 8
michael@0 9 "use strict";
michael@0 10
michael@0 11 const Ci = Components.interfaces;
michael@0 12
michael@0 13 Components.utils.import("resource://testing-common/httpd.js");
michael@0 14
michael@0 15 function search_observer(aSubject, aTopic, aData) {
michael@0 16 let engine = aSubject.QueryInterface(Ci.nsISearchEngine);
michael@0 17 do_print("Observer: " + aData + " for " + engine.name);
michael@0 18
michael@0 19 if (aData != "engine-added")
michael@0 20 return;
michael@0 21
michael@0 22 if (engine.name != "Test search engine")
michael@0 23 return;
michael@0 24
michael@0 25 function check_submission(aExpected, aSearchTerm, aType, aPurpose) {
michael@0 26 do_check_eq(engine.getSubmission(aSearchTerm, aType, aPurpose).uri.spec,
michael@0 27 base + aExpected);
michael@0 28 }
michael@0 29
michael@0 30 let base = "http://www.google.com/search?q=foo&ie=utf-8&oe=utf-8&aq=t&client=firefox";
michael@0 31 check_submission("", "foo");
michael@0 32 check_submission("", "foo", null);
michael@0 33 check_submission("", "foo", "text/html");
michael@0 34 check_submission("&channel=rcs", "foo", null, "contextmenu");
michael@0 35 check_submission("&channel=rcs", "foo", "text/html", "contextmenu");
michael@0 36 check_submission("&channel=fflb", "foo", null, "keyword");
michael@0 37 check_submission("&channel=fflb", "foo", "text/html", "keyword");
michael@0 38 check_submission("", "foo", "text/html", "invalid");
michael@0 39
michael@0 40 // Tests for a param that varies with a purpose but has a default value.
michael@0 41 base = "http://www.google.com/search?q=foo&client=firefox";
michael@0 42 check_submission("&channel=none", "foo", "application/x-moz-default-purpose");
michael@0 43 check_submission("&channel=none", "foo", "application/x-moz-default-purpose", null);
michael@0 44 check_submission("&channel=none", "foo", "application/x-moz-default-purpose", "");
michael@0 45 check_submission("&channel=rcs", "foo", "application/x-moz-default-purpose", "contextmenu");
michael@0 46 check_submission("&channel=fflb", "foo", "application/x-moz-default-purpose", "keyword");
michael@0 47 check_submission("", "foo", "application/x-moz-default-purpose", "invalid");
michael@0 48
michael@0 49 do_test_finished();
michael@0 50 };
michael@0 51
michael@0 52 function run_test() {
michael@0 53 removeMetadata();
michael@0 54 updateAppInfo();
michael@0 55 do_load_manifest("data/chrome.manifest");
michael@0 56
michael@0 57 let httpServer = new HttpServer();
michael@0 58 httpServer.start(-1);
michael@0 59 httpServer.registerDirectory("/", do_get_cwd());
michael@0 60
michael@0 61 do_register_cleanup(function cleanup() {
michael@0 62 httpServer.stop(function() {});
michael@0 63 Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
michael@0 64 });
michael@0 65
michael@0 66 do_test_pending();
michael@0 67 Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
michael@0 68
michael@0 69 Services.search.addEngine("http://localhost:" +
michael@0 70 httpServer.identity.primaryPort +
michael@0 71 "/data/engine.xml",
michael@0 72 Ci.nsISearchEngine.DATA_XML,
michael@0 73 null, false);
michael@0 74 }

mercurial