From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/tests/unit/test_Fetch.js | 318 +++++++++++++++++++++ dom/tests/unit/test_PromiseDebugging.js | 20 ++ dom/tests/unit/test_bug319968.js | 19 ++ dom/tests/unit/test_bug465752.js | 28 ++ .../unit/test_geolocation_position_unavailable.js | 36 +++ .../test_geolocation_position_unavailable_wrap.js | 13 + dom/tests/unit/test_geolocation_provider.js | 92 ++++++ .../unit/test_geolocation_provider_timeout.js | 49 ++++ dom/tests/unit/test_geolocation_reset_accuracy.js | 112 ++++++++ .../unit/test_geolocation_reset_accuracy_wrap.js | 71 +++++ dom/tests/unit/test_geolocation_timeout.js | 67 +++++ dom/tests/unit/test_geolocation_timeout_wrap.js | 19 ++ dom/tests/unit/test_xhr_init.js | 16 ++ dom/tests/unit/xpcshell.ini | 28 ++ 14 files changed, 888 insertions(+) create mode 100644 dom/tests/unit/test_Fetch.js create mode 100644 dom/tests/unit/test_PromiseDebugging.js create mode 100644 dom/tests/unit/test_bug319968.js create mode 100644 dom/tests/unit/test_bug465752.js create mode 100644 dom/tests/unit/test_geolocation_position_unavailable.js create mode 100644 dom/tests/unit/test_geolocation_position_unavailable_wrap.js create mode 100644 dom/tests/unit/test_geolocation_provider.js create mode 100644 dom/tests/unit/test_geolocation_provider_timeout.js create mode 100644 dom/tests/unit/test_geolocation_reset_accuracy.js create mode 100644 dom/tests/unit/test_geolocation_reset_accuracy_wrap.js create mode 100644 dom/tests/unit/test_geolocation_timeout.js create mode 100644 dom/tests/unit/test_geolocation_timeout_wrap.js create mode 100644 dom/tests/unit/test_xhr_init.js create mode 100644 dom/tests/unit/xpcshell.ini (limited to 'dom/tests/unit') diff --git a/dom/tests/unit/test_Fetch.js b/dom/tests/unit/test_Fetch.js new file mode 100644 index 000000000..e87eb7180 --- /dev/null +++ b/dom/tests/unit/test_Fetch.js @@ -0,0 +1,318 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const {utils: Cu} = Components; + +Cu.importGlobalProperties(['fetch']); +Cu.import("resource://testing-common/httpd.js"); + +const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1", + "nsIBinaryInputStream", "setInputStream"); + +var server; + +function getBaseUrl () { + return "http://localhost:" + server.identity.primaryPort; +} + +// a way to create some test defaults +function createTestData(testPath) { + return { + testPath: testPath, + request: { + headers: {}, + contentType: "application/json", + }, + response: { + headers: {}, + contentType: "application/json", + body: "{\"Look\": \"Success!\"}", + status: 200, + statusText: "OK" + }, + }; +} + +// read body and content type information from a request +function readDataFromRequest(aRequest) { + let requestData = {}; + if (aRequest.method == "POST" || aRequest.method == "PUT") { + if (aRequest.bodyInputStream) { + let inputStream = new BinaryInputStream(aRequest.bodyInputStream); + let bytes = []; + let available; + + while ((available = inputStream.available()) > 0) { + Array.prototype.push.apply(bytes, inputStream.readByteArray(available)); + } + + requestData.body = String.fromCharCode.apply(null, bytes); + requestData.contentType = aRequest.getHeader("Content-Type"); + } + } + return requestData; +} + +// write status information, content type information and body to a response +function writeDataToResponse(aData, aResponse) { + aResponse.setStatusLine(null, aData.status, aData.statusText); + aResponse.setHeader("Content-Type", aData.contentType); + for (let header in aData.headers) { + aResponse.setHeader(header, aData.headers[header]); + } + aResponse.write(aData.body); +} + +// test some GET functionality +add_test(function test_GetData() { + do_test_pending(); + + let testData = createTestData("/getData"); + + // set up some headers to test + let headerNames = ["x-test-header", "x-other-test-header"]; + for (let headerName of headerNames) { + testData.request.headers[headerName] = "test-value-for-" + headerName; + } + + server.registerPathHandler(testData.testPath, function(aRequest, aResponse) { + try { + // check our request headers made it OK + for (let headerName of headerNames) { + do_check_eq(testData.request.headers[headerName], + aRequest.getHeader(headerName)); + } + + // send a response + writeDataToResponse(testData.response, aResponse); + } catch (e) { + do_report_unexpected_exception(e); + } + }); + + // fetch, via GET, with some request headers set + fetch(getBaseUrl() + testData.testPath, {headers: testData.request.headers}) + .then(function(response){ + // check response looks as expected + do_check_true(response.ok); + do_check_eq(response.status, testData.response.status); + do_check_eq(response.statusText, testData.response.statusText); + + // check a response header looks OK: + do_check_eq(response.headers.get("Content-Type"), + testData.response.contentType); + + // ... and again to check header names are case insensitive + do_check_eq(response.headers.get("content-type"), + testData.response.contentType); + + // ensure response.text() returns a promise that resolves appropriately + response.text().then(function(text) { + do_check_eq(text, testData.response.body); + do_test_finished(); + run_next_test(); + }); + }).catch(function(e){ + do_report_unexpected_exception(e); + do_test_finished(); + run_next_test(); + }); +}); + +// test a GET with no init +add_test(function test_GetDataNoInit() { + do_test_pending(); + + let testData = createTestData("/getData"); + + server.registerPathHandler(testData.testPath, function(aRequest, aResponse) { + try { + // send a response + writeDataToResponse(testData.response, aResponse); + } catch (e) { + do_report_unexpected_exception(e); + } + }); + + fetch(getBaseUrl() + testData.testPath, {headers: testData.request.headers}) + .then(function(response){ + // check response looks as expected + do_check_true(response.ok); + do_check_eq(response.status, testData.response.status); + + // ensure response.text() returns a promise that resolves appropriately + response.text().then(function(text) { + do_check_eq(text, testData.response.body); + do_test_finished(); + run_next_test(); + }); + }).catch(function(e){ + do_report_unexpected_exception(e); + do_test_finished(); + run_next_test(); + }); +}); + +// test some error responses +add_test(function test_get40x() { + do_test_pending(); + + // prepare a response with some 40x error - a 404 will do + let notFoundData = createTestData("/getNotFound"); + notFoundData.response.status = 404; + notFoundData.response.statusText = "Not found"; + notFoundData.response.body = null; + + // No need to register a path handler - httpd will return 404 anyway. + // Fetch, via GET, the resource that doesn't exist + fetch(getBaseUrl() + notFoundData.testPath).then(function(response){ + do_check_eq(response.status, 404); + do_test_finished(); + run_next_test(); + }); +}); + +add_test(function test_get50x() { + do_test_pending(); + + // prepare a response with some server error - a 500 will do + let serverErrorData = createTestData("/serverError"); + serverErrorData.response.status = 500; + serverErrorData.response.statusText = "The server broke"; + serverErrorData.response.body = null; + + server.registerPathHandler(serverErrorData.testPath, + function(aRequest, aResponse) { + try { + // send the error response + writeDataToResponse(serverErrorData.response, aResponse); + } catch (e) { + do_report_unexpected_exception(e); + } + }); + + // fetch, via GET, the resource that creates a server error + fetch(getBaseUrl() + serverErrorData.testPath).then(function(response){ + do_check_eq(response.status, 500); + do_test_finished(); + run_next_test(); + }); +}); + +// test a failure to connect +add_test(function test_getTestFailedConnect() { + do_test_pending(); + // try a server that's not there + fetch("http://localhost:4/should/fail").then(response => { + do_throw("Request should not succeed"); + }).catch(err => { + do_check_eq(true, err instanceof TypeError); + do_test_finished(); + run_next_test(); + }); +}); + +// test POSTing some JSON data +add_test(function test_PostJSONData() { + do_test_pending(); + + let testData = createTestData("/postJSONData"); + testData.request.body = "{\"foo\": \"bar\"}"; + + server.registerPathHandler(testData.testPath, function(aRequest, aResponse) { + try { + let requestData = readDataFromRequest(aRequest); + + // Check the request body is OK + do_check_eq(requestData.body, testData.request.body); + + // Check the content type is as expected + do_check_eq(requestData.contentType, testData.request.contentType); + + writeDataToResponse(testData.response, aResponse); + } catch (e) { + do_check_true(false); + } + }); + + fetch(getBaseUrl() + testData.testPath, { + method: "POST", + body: testData.request.body, + headers: { + 'Content-Type': 'application/json' + } + }).then(function(aResponse) { + do_check_true(aResponse.ok); + do_check_eq(aResponse.status, testData.response.status); + do_check_eq(aResponse.statusText, testData.response.statusText); + + do_test_finished(); + run_next_test(); + }).catch(function(e) { + do_report_unexpected_exception(e); + do_test_finished(); + run_next_test(); + }); +}); + +// test POSTing some text +add_test(function test_PostTextData() { + do_test_pending(); + + let testData = createTestData("/postTextData"); + testData.request.body = "A plain text body"; + testData.request.contentType = "text/plain"; + let responseHeaderName = "some-response-header"; + testData.response.headers[responseHeaderName] = "some header value"; + + server.registerPathHandler(testData.testPath, function(aRequest, aResponse) { + try { + let requestData = readDataFromRequest(aRequest); + + // Check the request body is OK + do_check_eq(requestData.body, testData.request.body); + + // Check the content type is as expected + do_check_eq(requestData.contentType, testData.request.contentType); + + writeDataToResponse(testData.response, aResponse); + } catch (e) { + do_check_true(false); + } + }); + + fetch(getBaseUrl() + testData.testPath, { + method: "POST", + body: testData.request.body, + headers: { + 'Content-Type': testData.request.contentType + } + }).then(function(aResponse) { + do_check_true(aResponse.ok); + do_check_eq(aResponse.status, testData.response.status); + do_check_eq(aResponse.statusText, testData.response.statusText); + + // check the response header is set OK + do_check_eq(aResponse.headers.get(responseHeaderName), + testData.response.headers[responseHeaderName]); + + do_test_finished(); + run_next_test(); + }).catch(function(e) { + do_report_unexpected_exception(e); + do_test_finished(); + run_next_test(); + }); +}); + +function run_test() { + // Set up an HTTP Server + server = new HttpServer(); + server.start(-1); + + run_next_test(); + + do_register_cleanup(function() { + server.stop(function() { }); + }); +} diff --git a/dom/tests/unit/test_PromiseDebugging.js b/dom/tests/unit/test_PromiseDebugging.js new file mode 100644 index 000000000..d6c8d4306 --- /dev/null +++ b/dom/tests/unit/test_PromiseDebugging.js @@ -0,0 +1,20 @@ +function run_test() +{ + // Hack around Promise.jsm being stuck on my global + do_check_false(PromiseDebugging === undefined); + var res; + var p = new Promise(function(resolve, reject) { res = resolve }); + var state = PromiseDebugging.getState(p); + do_check_eq(state.state, "pending"); + + do_test_pending(); + + p.then(function() { + var state = PromiseDebugging.getState(p); + do_check_eq(state.state, "fulfilled"); + do_check_eq(state.value, 5); + do_test_finished(); + }); + + res(5); +} diff --git a/dom/tests/unit/test_bug319968.js b/dom/tests/unit/test_bug319968.js new file mode 100644 index 000000000..d45fa1705 --- /dev/null +++ b/dom/tests/unit/test_bug319968.js @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +function run_test() +{ + var domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"] + .createInstance(Components.interfaces.nsIDOMParser); + var aDom = domParser.parseFromString("", + "application/xml"); + var feedList = aDom.getElementsByTagName("feed"); + do_check_neq(feedList, null); + do_check_eq(feedList.length, 1); + do_check_neq(feedList[0], null); + do_check_eq(feedList[0].tagName, "feed"); + var entry = feedList[0].getElementsByTagName("entry"); + do_check_neq(entry, null); +} diff --git a/dom/tests/unit/test_bug465752.js b/dom/tests/unit/test_bug465752.js new file mode 100644 index 000000000..e698a1f4f --- /dev/null +++ b/dom/tests/unit/test_bug465752.js @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +function run_test() +{ + const ios = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + const str = "javascript:10"; + var uri = ios.newURI(str, null, null); + var uri2 = ios.newURI(str, null, null); + const str2 = "http://example.org"; + var uri3 = ios.newURI(str2, null, null); + do_check_true(uri.equals(uri)); + do_check_true(uri.equals(uri2)); + do_check_true(uri2.equals(uri)); + do_check_true(uri2.equals(uri2)); + do_check_false(uri3.equals(uri2)); + do_check_false(uri2.equals(uri3)); + + var simple = Components.classes["@mozilla.org/network/simple-uri;1"] + .createInstance(Components.interfaces.nsIURI); + simple.spec = str; + do_check_eq(simple.spec, uri.spec); + do_check_false(simple.equals(uri)); + do_check_false(uri.equals(simple)); +} diff --git a/dom/tests/unit/test_geolocation_position_unavailable.js b/dom/tests/unit/test_geolocation_position_unavailable.js new file mode 100644 index 000000000..4a09d9798 --- /dev/null +++ b/dom/tests/unit/test_geolocation_position_unavailable.js @@ -0,0 +1,36 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; + + +function successCallback() { + do_check_true(false); + do_test_finished(); +} + +function errorCallback(err) { + do_check_eq(Ci.nsIDOMGeoPositionError.POSITION_UNAVAILABLE, err.code); + do_test_finished(); +} + +function run_test() +{ + do_test_pending(); + + if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) + .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) { + // XPCShell does not get a profile by default. The geolocation service + // depends on the settings service which uses IndexedDB and IndexedDB + // needs a place where it can store databases. + do_get_profile(); + + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); + prefs.setBoolPref("geo.wifi.scan", false); + prefs.setCharPref("geo.wifi.uri", "UrlNotUsedHere:"); + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); + } + + geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports); + geolocation.getCurrentPosition(successCallback, errorCallback); +} diff --git a/dom/tests/unit/test_geolocation_position_unavailable_wrap.js b/dom/tests/unit/test_geolocation_position_unavailable_wrap.js new file mode 100644 index 000000000..6bd5cc48c --- /dev/null +++ b/dom/tests/unit/test_geolocation_position_unavailable_wrap.js @@ -0,0 +1,13 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; + + +function run_test() { + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); + prefs.setBoolPref("geo.wifi.scan", false); + + prefs.setCharPref("geo.wifi.uri", "UrlNotUsedHere"); + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); + run_test_in_child("./test_geolocation_position_unavailable.js"); +} diff --git a/dom/tests/unit/test_geolocation_provider.js b/dom/tests/unit/test_geolocation_provider.js new file mode 100644 index 000000000..06451b6b9 --- /dev/null +++ b/dom/tests/unit/test_geolocation_provider.js @@ -0,0 +1,92 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; + +Cu.import("resource://testing-common/httpd.js"); + +var httpserver = null; +var geolocation = null; +var success = false; +var watchId = -1; + +function terminate(succ) { + success = succ; + geolocation.clearWatch(watchID); + } + +function successCallback(pos){ terminate(true); } +function errorCallback(pos) { terminate(false); } + +var observer = { + QueryInterface: function(iid) { + if (iid.equals(Ci.nsISupports) || + iid.equals(Ci.nsIObserver)) + return this; + throw Cr.NS_ERROR_NO_INTERFACE; + }, + + observe: function(subject, topic, data) { + if (data == "shutdown") { + do_check_true(1); + this._numProviders--; + if (!this._numProviders) { + httpserver.stop(function() { + do_check_true(success); + do_test_finished(); + }); + } + } + else if (data == "starting") { + do_check_true(1); + this._numProviders++; + } + }, + + _numProviders: 0, +}; + +function geoHandler(metadata, response) +{ + var georesponse = { + status: "OK", + location: { + lat: 42, + lng: 42, + }, + accuracy: 42, + }; + var position = JSON.stringify(georesponse); + response.setStatusLine("1.0", 200, "OK"); + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "aplication/x-javascript", false); + response.write(position); +} + +function run_test() +{ + // XPCShell does not get a profile by default. The geolocation service + // depends on the settings service which uses IndexedDB and IndexedDB + // needs a place where it can store databases. + do_get_profile(); + + // only kill this test when shutdown is called on the provider. + do_test_pending(); + + httpserver = new HttpServer(); + httpserver.registerPathHandler("/geo", geoHandler); + httpserver.start(-1); + + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); + prefs.setCharPref("geo.wifi.uri", "http://localhost:" + + httpserver.identity.primaryPort + "/geo"); + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); + prefs.setBoolPref("geo.wifi.scan", false); + + var obs = Cc["@mozilla.org/observer-service;1"].getService(); + obs = obs.QueryInterface(Ci.nsIObserverService); + obs.addObserver(observer, "geolocation-device-events", false); + + geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports); + watchID = geolocation.watchPosition(successCallback, errorCallback); +} diff --git a/dom/tests/unit/test_geolocation_provider_timeout.js b/dom/tests/unit/test_geolocation_provider_timeout.js new file mode 100644 index 000000000..d9078e538 --- /dev/null +++ b/dom/tests/unit/test_geolocation_provider_timeout.js @@ -0,0 +1,49 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; + +Cu.import("resource://testing-common/httpd.js"); + +var httpserver = null; +var geolocation = null; + +function geoHandler(metadata, response) +{ + response.processAsync(); +} + +function successCallback() { + // The call shouldn't be sucessful. + do_check_true(false); + do_test_finished(); +} + +function errorCallback() { + do_check_true(true); + do_test_finished(); +} + +function run_test() +{ + do_test_pending(); + + // XPCShell does not get a profile by default. The geolocation service + // depends on the settings service which uses IndexedDB and IndexedDB + // needs a place where it can store databases. + do_get_profile(); + + httpserver = new HttpServer(); + httpserver.registerPathHandler("/geo", geoHandler); + httpserver.start(-1); + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); + prefs.setCharPref("geo.wifi.uri", "http://localhost:" + + httpserver.identity.primaryPort + "/geo"); + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); + prefs.setBoolPref("geo.wifi.scan", false); + + // Setting timeout to a very low value to ensure time out will happen. + prefs.setIntPref("geo.wifi.xhr.timeout", 5); + + geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports); + geolocation.getCurrentPosition(successCallback, errorCallback); +} diff --git a/dom/tests/unit/test_geolocation_reset_accuracy.js b/dom/tests/unit/test_geolocation_reset_accuracy.js new file mode 100644 index 000000000..5d71b5930 --- /dev/null +++ b/dom/tests/unit/test_geolocation_reset_accuracy.js @@ -0,0 +1,112 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; + +const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}"); +const providerContract = "@mozilla.org/geolocation/provider;1"; + +const categoryName = "geolocation-provider"; + +var provider = { + QueryInterface: function eventsink_qi(iid) { + if (iid.equals(Components.interfaces.nsISupports) || + iid.equals(Components.interfaces.nsIFactory) || + iid.equals(Components.interfaces.nsIGeolocationProvider)) + return this; + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + createInstance: function eventsink_ci(outer, iid) { + if (outer) + throw Components.results.NS_ERROR_NO_AGGREGATION; + return this.QueryInterface(iid); + }, + lockFactory: function eventsink_lockf(lock) { + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; + }, + startup: function() { + }, + watch: function() { + }, + shutdown: function() { + }, + setHighAccuracy: function(enable) { + this._isHigh = enable; + if (enable) { + this._seenHigh = true; + do_execute_soon(stop_high_accuracy_watch); + } + }, + _isHigh: false, + _seenHigh: false +}; + +var runningInParent = true; +try { + runningInParent = Components.classes["@mozilla.org/xre/runtime;1"]. + getService(Components.interfaces.nsIXULRuntime).processType + == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT; +} +catch (e) { } + +function successCallback() +{ + do_check_true(false); + do_test_finished(); +} + +function errorCallback() +{ + do_check_true(false); + do_test_finished(); +} + +var geolocation; +var watchID2; + +function run_test() +{ + if (runningInParent) { + // XPCShell does not get a profile by default. The geolocation service + // depends on the settings service which uses IndexedDB and IndexedDB + // needs a place where it can store databases. + do_get_profile(); + + Components.manager.nsIComponentRegistrar.registerFactory(providerCID, + "Unit test geo provider", providerContract, provider); + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test", + providerContract, false, true); + + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); + prefs.setBoolPref("geo.wifi.scan", false); + } + + do_test_pending(); + + geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports); + let watchID1 = geolocation.watchPosition(successCallback, errorCallback); + watchID2 = geolocation.watchPosition(successCallback, errorCallback, + {enableHighAccuracy: true}); + + if (!runningInParent) { + do_await_remote_message('high_acc_enabled', stop_high_accuracy_watch); + } +} + +function stop_high_accuracy_watch() { + geolocation.clearWatch(watchID2); + check_results(); + do_test_finished(); +} + +function check_results() +{ + if (runningInParent) { + // check the provider was set to high accuracy during the test + do_check_true(provider._seenHigh); + // check the provider is not currently set to high accuracy + do_check_false(provider._isHigh); + } + do_test_finished(); +} diff --git a/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js b/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js new file mode 100644 index 000000000..b44a97e79 --- /dev/null +++ b/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js @@ -0,0 +1,71 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; + +const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}"); +const providerContract = "@mozilla.org/geolocation/provider;1"; + +const categoryName = "geolocation-provider"; + +var provider = { + QueryInterface: function eventsink_qi(iid) { + if (iid.equals(Components.interfaces.nsISupports) || + iid.equals(Components.interfaces.nsIFactory) || + iid.equals(Components.interfaces.nsIGeolocationProvider)) + return this; + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + createInstance: function eventsink_ci(outer, iid) { + if (outer) + throw Components.results.NS_ERROR_NO_AGGREGATION; + return this.QueryInterface(iid); + }, + lockFactory: function eventsink_lockf(lock) { + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; + }, + startup: function() { + }, + watch: function() { + }, + shutdown: function() { + }, + setHighAccuracy: function(enable) { + this._isHigh = enable; + if (enable) { + this._seenHigh = true; + do_send_remote_message('high_acc_enabled'); + } + }, + _isHigh: false, + _seenHigh: false +}; + +function run_test() +{ + // XPCShell does not get a profile by default. The geolocation service + // depends on the settings service which uses IndexedDB and IndexedDB + // needs a place where it can store databases. + do_get_profile(); + + Components.manager.nsIComponentRegistrar.registerFactory(providerCID, + "Unit test geo provider", providerContract, provider); + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test", + providerContract, false, true); + + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); + prefs.setBoolPref("geo.wifi.scan", false); + + run_test_in_child("test_geolocation_reset_accuracy.js", check_results); +} + +function check_results() +{ + // check the provider was set to high accuracy during the test + do_check_true(provider._seenHigh); + // check the provider is not currently set to high accuracy + do_check_false(provider._isHigh); + + do_test_finished(); +} diff --git a/dom/tests/unit/test_geolocation_timeout.js b/dom/tests/unit/test_geolocation_timeout.js new file mode 100644 index 000000000..cfe0ba737 --- /dev/null +++ b/dom/tests/unit/test_geolocation_timeout.js @@ -0,0 +1,67 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; + +Cu.import("resource://testing-common/httpd.js"); + +var httpserver = null; +var geolocation = null; +var success = false; +var watchId = -1; + +function geoHandler(metadata, response) +{ + var georesponse = { + status: "OK", + location: { + lat: 42, + lng: 42, + }, + accuracy: 42, + }; + var position = JSON.stringify(georesponse); + response.processAsync(); + response.setStatusLine("1.0", 200, "OK"); + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "aplication/x-javascript", false); + do_timeout(5000, function() { + response.write(position); + response.finish(); + }); +} + +function successCallback() { + do_check_true(false); + do_test_finished(); +} + +function errorCallback() { + do_check_true(true); + do_test_finished(); +} + +function run_test() +{ + do_test_pending(); + + if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) + .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) { + // XPCShell does not get a profile by default. The geolocation service + // depends on the settings service which uses IndexedDB and IndexedDB + // needs a place where it can store databases. + do_get_profile(); + + httpserver = new HttpServer(); + httpserver.registerPathHandler("/geo", geoHandler); + httpserver.start(-1); + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); + prefs.setBoolPref("geo.wifi.scan", false); + prefs.setCharPref("geo.wifi.uri", "http://localhost:" + + httpserver.identity.primaryPort + "/geo"); + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); + } + + geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports); + geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 2000}); +} diff --git a/dom/tests/unit/test_geolocation_timeout_wrap.js b/dom/tests/unit/test_geolocation_timeout_wrap.js new file mode 100644 index 000000000..1f87bec7e --- /dev/null +++ b/dom/tests/unit/test_geolocation_timeout_wrap.js @@ -0,0 +1,19 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; + +Cu.import("resource://testing-common/httpd.js"); + +var httpserver = null; + +function run_test() { + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); + prefs.setBoolPref("geo.wifi.scan", false); + + httpserver = new HttpServer(); + httpserver.start(-1); + prefs.setCharPref("geo.wifi.uri", "http://localhost:" + + httpserver.identity.primaryPort + "/geo"); + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); + run_test_in_child("./test_geolocation_timeout.js"); +} diff --git a/dom/tests/unit/test_xhr_init.js b/dom/tests/unit/test_xhr_init.js new file mode 100644 index 000000000..e3f860bdf --- /dev/null +++ b/dom/tests/unit/test_xhr_init.js @@ -0,0 +1,16 @@ +function run_test() +{ + Components.utils.importGlobalProperties(["XMLHttpRequest"]); + + var x = new XMLHttpRequest({mozAnon: true, mozSystem: false}); + do_check_true(x.mozAnon); + do_check_true(x.mozSystem); // Because we're system principal + + x = new XMLHttpRequest({mozAnon: true}); + do_check_true(x.mozAnon); + do_check_true(x.mozSystem); + + x = new XMLHttpRequest(); + do_check_false(x.mozAnon); + do_check_true(x.mozSystem); +} diff --git a/dom/tests/unit/xpcshell.ini b/dom/tests/unit/xpcshell.ini new file mode 100644 index 000000000..a7f192e87 --- /dev/null +++ b/dom/tests/unit/xpcshell.ini @@ -0,0 +1,28 @@ +[DEFAULT] +head = +tail = + +[test_bug319968.js] +[test_bug465752.js] +[test_Fetch.js] +[test_geolocation_provider.js] +# Bug 684962: test hangs consistently on Android +skip-if = os == "android" +[test_geolocation_timeout.js] +# Bug 919946: test hangs consistently on Android +skip-if = os == "android" +[test_geolocation_timeout_wrap.js] +skip-if = os == "mac" || os == "android" +[test_geolocation_reset_accuracy.js] +# Bug 919946: test hangs consistently on Android +skip-if = os == "android" +[test_geolocation_reset_accuracy_wrap.js] +skip-if = os == "mac" || os == "android" +[test_geolocation_position_unavailable.js] +skip-if = os == "android" +[test_geolocation_position_unavailable_wrap.js] +skip-if = os == "mac" || os == "android" +[test_PromiseDebugging.js] +[test_xhr_init.js] +[test_geolocation_provider_timeout.js] +skip-if = os == "android" -- cgit v1.2.3