mobile/android/base/tests/testDeviceSearchEngine.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 7
michael@0 8 var Cc = Components.classes;
michael@0 9 var Ci = Components.interfaces;
michael@0 10
michael@0 11 function search_observer(aSubject, aTopic, aData) {
michael@0 12 let engine = aSubject.QueryInterface(Ci.nsISearchEngine);
michael@0 13 do_print("Observer: " + aData + " for " + engine.name);
michael@0 14
michael@0 15 if (aData != "engine-added")
michael@0 16 return;
michael@0 17
michael@0 18 if (engine.name != "Test search engine")
michael@0 19 return;
michael@0 20
michael@0 21 function check_submission(aExpected, aSearchTerm, aType) {
michael@0 22 do_check_eq(engine.getSubmission(aSearchTerm, aType).uri.spec, "http://example.com/search" + aExpected);
michael@0 23 }
michael@0 24
michael@0 25 // Force the type and check for the expected URL
michael@0 26 check_submission("?q=foo", "foo", "text/html");
michael@0 27 check_submission("/tablet?q=foo", "foo", "application/x-moz-tabletsearch");
michael@0 28 check_submission("/phone?q=foo", "foo", "application/x-moz-phonesearch");
michael@0 29
michael@0 30 // Let the service pick the appropriate type based on the device
michael@0 31 // and check for expected URL
michael@0 32 let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
michael@0 33 if (sysInfo.get("tablet")) {
michael@0 34 do_print("Device: tablet");
michael@0 35 check_submission("/tablet?q=foo", "foo", null);
michael@0 36 } else {
michael@0 37 do_print("Device: phone");
michael@0 38 check_submission("/phone?q=foo", "foo", null);
michael@0 39 }
michael@0 40
michael@0 41 run_next_test();
michael@0 42 };
michael@0 43
michael@0 44 add_test(function test_default() {
michael@0 45 do_register_cleanup(function cleanup() {
michael@0 46 Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
michael@0 47 });
michael@0 48
michael@0 49 Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
michael@0 50
michael@0 51 do_print("Loading search engine");
michael@0 52 Services.search.addEngine("http://mochi.test:8888/tests/robocop/devicesearch.xml", Ci.nsISearchEngine.DATA_XML, null, false);
michael@0 53 });
michael@0 54
michael@0 55 run_next_test();

mercurial