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.

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

mercurial