dom/tests/unit/test_geolocation_timeout.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 const Cc = Components.classes;
     2 const Ci = Components.interfaces;
     3 const Cu = Components.utils;
     4 const Cr = Components.results;
     6 Cu.import("resource://testing-common/httpd.js");
     8 var httpserver = null;
     9 var geolocation = null;
    10 var success = false;
    11 var watchId = -1;
    13 function geoHandler(metadata, response)
    14 {
    15     var georesponse = {
    16         status: "OK",
    17         location: {
    18             lat: 42,
    19             lng: 42,
    20         },
    21         accuracy: 42,
    22     };
    23   var position = JSON.stringify(georesponse);
    24   response.processAsync();
    25   response.setStatusLine("1.0", 200, "OK");
    26   response.setHeader("Cache-Control", "no-cache", false);
    27   response.setHeader("Content-Type", "aplication/x-javascript", false);
    28   do_timeout(5000, function() {
    29     response.write(position);
    30     response.finish();
    31   });
    32 }
    34 function successCallback() {
    35   do_check_true(false);
    36   do_test_finished();
    37 }
    39 function errorCallback() {
    40   do_check_true(true);
    41   do_test_finished();
    42 }
    44 function run_test()
    45 {
    46   do_test_pending();
    48   if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
    49         .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
    50     // XPCShell does not get a profile by default. The geolocation service
    51     // depends on the settings service which uses IndexedDB and IndexedDB
    52     // needs a place where it can store databases.
    53     do_get_profile();
    55     httpserver = new HttpServer();
    56     httpserver.registerPathHandler("/geo", geoHandler);
    57     httpserver.start(-1);
    58     var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
    59     prefs.setBoolPref("geo.wifi.scan", false);
    60     prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
    61                       httpserver.identity.primaryPort + "/geo");
    62     prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
    63   }
    65   geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
    66   geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 2000});
    67 }

mercurial