Bug 489817 - migrate existing geolocation tests from mochitest to browser-chrome; r=(ctalbert + doug.turner)
authorJoel Maher <jmaher@mozilla.com>
Tue, 09 Jun 2009 01:18:02 +0200
changeset 25915 6aca7b6b2ca83c03bdc46b4fd19059980c87873f
parent 25914 db8c7dd92ece010dfaa56575ba1dbfb060cab6c7
child 25916 2626fd551f31d5ae77eee734a17a5280b0453d40
push id1668
push usersgautherie.bz@free.fr
push dateMon, 08 Jun 2009 23:20:45 +0000
bugs489817
milestone1.9.1pre
Bug 489817 - migrate existing geolocation tests from mochitest to browser-chrome; r=(ctalbert + doug.turner)
build/automation.py.in
dom/src/geolocation/Makefile.in
dom/src/geolocation/test/Makefile.in
dom/src/geolocation/test/TestGeolocationProvider.js
dom/tests/mochitest/geolocation/Makefile.in
dom/tests/mochitest/geolocation/geolocation_common.js
dom/tests/mochitest/geolocation/network_geolocation.sjs
dom/tests/mochitest/geolocation/test_allowCurrent.html
dom/tests/mochitest/geolocation/test_allowWatch.html
dom/tests/mochitest/geolocation/test_cancelCurrent.html
dom/tests/mochitest/geolocation/test_cancelWatch.html
dom/tests/mochitest/geolocation/test_clearWatch.html
dom/tests/mochitest/geolocation/test_optional_api_params.html
dom/tests/mochitest/geolocation/test_timeoutWatch.html
testing/mochitest/Makefile.in
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -244,16 +244,17 @@ user_pref("javascript.options.showInCons
 user_pref("layout.debug.enable_data_xbl", true);
 user_pref("browser.EULA.override", true);
 user_pref("javascript.options.jit.content", true);
 user_pref("gfx.color_management.force_srgb", true);
 user_pref("security.default_personal_cert", "Select Automatically"); // Need to client auth test be w/o any dialogs
 user_pref("network.http.prompt-temp-redirect", false);
 user_pref("media.cache_size", 100);
 
+user_pref("geo.wifi.uri", "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
 user_pref("camino.warn_when_closing", false); // Camino-only, harmless to others
 """
   prefs.append(part)
 
   locations = readLocations()
 
   # Grant God-power to all the privileged servers on which tests run.
   privileged = filter(lambda loc: "privileged" in loc.options, locations)
--- a/dom/src/geolocation/Makefile.in
+++ b/dom/src/geolocation/Makefile.in
@@ -80,17 +80,13 @@ ifdef NS_MAEMO_LOCATION
 CPPSRCS		+= MaemoLocationProvider.cpp
 LOCAL_INCLUDES	+= $(MOZ_LOCATION_CFLAGS)
 endif
 
 ifdef WINCE
 CPPSRCS         += WinMobileLocationProvider.cpp
 endif
 
-ifdef ENABLE_TESTS
-DIRS += test
-endif
-
 EXTRA_COMPONENTS = \
                  NetworkGeolocationProvider.js \
                  $(NULL)
 
 include $(topsrcdir)/config/rules.mk
deleted file mode 100644
--- a/dom/src/geolocation/test/Makefile.in
+++ /dev/null
@@ -1,50 +0,0 @@
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is mozilla.org build system.
-#
-# The Initial Developer of the Original Code is Mozilla Corporation
-# Portions created by the Initial Developer are Copyright (C) 2008
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#  Doug Turner <dougt@meer.net>
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either the GNU General Public License Version 2 or later (the "GPL"), or
-# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH		= ../../../..
-topsrcdir	= @top_srcdir@
-srcdir		= @srcdir@
-VPATH		= @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE         = dom_geolocation_test
-
-ifdef ENABLE_TESTS
-EXTRA_COMPONENTS = TestGeolocationProvider.js
-endif
-
-include $(topsrcdir)/config/rules.mk
deleted file mode 100644
--- a/dom/src/geolocation/test/TestGeolocationProvider.js
+++ /dev/null
@@ -1,137 +0,0 @@
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-
-function GeoPositionCoordsObject() {
-};
-
-GeoPositionCoordsObject.prototype = {
-
-    QueryInterface:   XPCOMUtils.generateQI([Ci.nsIDOMGeoPositionCoords, Ci.nsIClassInfo]),
-
-    // Class Info is required to be able to pass objects back into the DOM.
-    getInterfaces: function(countRef) {
-        var interfaces = [Ci.nsIDOMGeoPositionCoords, Ci.nsIClassInfo, Ci.nsISupports];
-        countRef.value = interfaces.length;
-        return interfaces;
-    },
-
-    getHelperForLanguage: function(language) null,
-    contractID: "",
-    classDescription: "testing geolocation coords object",
-    classID: null,
-    implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
-    flags: Ci.nsIClassInfo.DOM_OBJECT,
-
-    latitude: 37.41857,
-    longitude: -122.08769,
-    
-    // some numbers that we can test against
-    altitude: 42,
-    accuracy: 42,
-    altitudeAccuracy: 42,
-    heading: 42,
-    speed: 42,
-};
-
-function GeoPositionObject() {
-};
-
-GeoPositionObject.prototype = {
-
-    QueryInterface:   XPCOMUtils.generateQI([Ci.nsIDOMGeoPosition, Ci.nsIClassInfo]),
-
-    // Class Info is required to be able to pass objects back into the DOM.
-    getInterfaces: function(countRef) {
-        var interfaces = [Ci.nsIDOMGeoPosition, Ci.nsIClassInfo, Ci.nsISupports];
-        countRef.value = interfaces.length;
-        return interfaces;
-    },
-
-    getHelperForLanguage: function(language) null,
-    contractID: "",
-    classDescription: "test geolocation object",
-    classID: null,
-    implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
-    flags: Ci.nsIClassInfo.DOM_OBJECT,
-
-    coords: new GeoPositionCoordsObject(),
-    timestamp: Date.now(),
-
-};
-
-function MyLocation() {};
-MyLocation.prototype = {
-    classDescription: "A component that returns a geolocation",
-    classID:          Components.ID("{10F622A4-6D7F-43A1-A938-5FFCBE2B1D1D}"),
-    contractID:       "@mozilla.org/geolocation/provider;1",
-    QueryInterface:   XPCOMUtils.generateQI([Ci.nsIGeolocationProvider]),
-  
-    geolocation:     null,
-    timer:           null,
-    timerInterval:   500,
-
-    startup:         function() { 
-
-        var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-        observerService.addObserver(this, "geolocation-test-control", false);
-    
-    },
-    
-    isReady:         function() {return true},
-  
-    watch:           function(c) {
-
-                        var watchCallback = 
-                        {
-                            notify: function(timer) { this.parent.currentLocation.timestamp = Date.now();
-                                                      c.update(this.parent.currentLocation); }
-                        };
-
-                        watchCallback.parent = this;
-
-                        if(!this.timer) 
-                           this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-
-                        this.timer.initWithCallback(watchCallback,
-                                                    this.timerInterval, 
-                                                    Ci.nsITimer.TYPE_REPEATING_SLACK);
-    },
-
-    currentLocation: new GeoPositionObject(),
-    shutdown:        function() { 
-                       if(this.timer)
-                           this.timer.cancel();
-
-                       var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-                       observerService.removeObserver(this, "geolocation-test-control");
-
-    },
-
-    observe: function (subject, topic, data) {
-
-        if (topic == "geolocation-test-control") {
-            if (data == "stop-responding")
-            {
-                if(this.timer) 
-                    this.timer.cancel();
-            }
-            else if (data == "start-responding")
-            {
-
-                if(!this.timer) 
-                    this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-
-                this.timer.initWithCallback(watchCallback,
-                                            this.timerInterval, 
-                                            Ci.nsITimer.TYPE_REPEATING_SLACK);
-            }
-        }
-    },
-};
-
-var components = [MyLocation];
-function NSGetModule(compMgr, fileSpec) {
-  return XPCOMUtils.generateModule(components);
-}
--- a/dom/tests/mochitest/geolocation/Makefile.in
+++ b/dom/tests/mochitest/geolocation/Makefile.in
@@ -51,14 +51,15 @@ include $(topsrcdir)/config/rules.mk
 		test_cancelCurrent.html \
 		test_cancelWatch.html \
 		test_clearWatch.html \
 		test_clearWatch_invalid.html \
 		test_timeoutWatch.html \
 		geolocation_common.js  \
 		geolocation.html \
 		test_optional_api_params.html \
+                network_geolocation.sjs \
 		$(NULL)
 
 
 libs:: 	$(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 
--- a/dom/tests/mochitest/geolocation/geolocation_common.js
+++ b/dom/tests/mochitest/geolocation/geolocation_common.js
@@ -1,24 +1,10 @@
 
 
-function ensure_geolocationProvider()
-{
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-    
-    const testing_provider_cid = Components.ID("{10F622A4-6D7F-43A1-A938-5FFCBE2B1D1D}");
-    
-    var testing_factory = Components.manager.getClassObject(testing_provider_cid, Components.interfaces.nsIFactory);
-    
-    Components.manager.nsIComponentRegistrar.registerFactory(testing_provider_cid,
-                                                             "Test Geolocation Provider",
-                                                             "@mozilla.org/geolocation/provider;1",
-                                                             testing_factory);
-}
-
 function stop_geolocationProvider()
 {
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
   observerService.notifyObservers(null, "geolocation-test-control", "stop-responding");
 }
 
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/network_geolocation.sjs
@@ -0,0 +1,24 @@
+
+function handleRequest(request, response)
+{
+
+  var coords = {
+    latitude: 37.41857,
+    longitude: -122.08769,
+
+    altitude: 42,
+    accuracy: 42,
+    altitudeAccuracy: 42,
+    heading: 42,
+    speed: 42,
+  };
+
+  var geoposition = {
+    location: coords,
+  };
+
+  response.setStatusLine("1.0", 200, "OK");
+  response.setHeader("Content-Type", "aplication/x-javascript", false);
+  response.write(JSON.stringify(geoposition));
+}
+
--- a/dom/tests/mochitest/geolocation/test_allowCurrent.html
+++ b/dom/tests/mochitest/geolocation/test_allowCurrent.html
@@ -28,17 +28,16 @@ function successCallback(position) {
   SimpleTest.finish();
 }
 
 function accept() {
   hasAccepted = true;
   clickNotificationButton(kAcceptButton);
 }
 
-ensure_geolocationProvider();
 SimpleTest.waitForExplicitFinish();
 
 // one-shot position requests
 navigator.geolocation.getCurrentPosition(successCallback, null, null);
 
 setTimeout(accept, 50);
 
 </script>
--- a/dom/tests/mochitest/geolocation/test_allowWatch.html
+++ b/dom/tests/mochitest/geolocation/test_allowWatch.html
@@ -34,17 +34,16 @@ function successCallback(position) {
 
 function accept() {
   hasAccepted = true;
   clickNotificationButton(kAcceptButton);
 }
 
 /** Test for Bug  **/
 
-ensure_geolocationProvider();
 SimpleTest.waitForExplicitFinish();
 
 watchID = navigator.geolocation.watchPosition(successCallback, null, null);
 
 setTimeout(accept, 50);
 
 </script>
 </pre>
--- a/dom/tests/mochitest/geolocation/test_cancelCurrent.html
+++ b/dom/tests/mochitest/geolocation/test_cancelCurrent.html
@@ -27,17 +27,16 @@ function failureCallback(error) {
 
 function successCallback(position){
   ok(0, "Success was called when it shouldn't have been.  major problem");
   SimpleTest.finish();
 }
 
 /** Test for Bug  **/
 
-ensure_geolocationProvider();
 SimpleTest.waitForExplicitFinish();
 
 navigator.geolocation.getCurrentPosition(successCallback, failureCallback, null);
 
 // click deny
 setTimeout(clickNotificationButton, 50, kDenyButton);
 
 </script>
--- a/dom/tests/mochitest/geolocation/test_cancelWatch.html
+++ b/dom/tests/mochitest/geolocation/test_cancelWatch.html
@@ -29,17 +29,16 @@ function failureCallback(error) {
 
 function successCallback(position){
   ok(0, "Success was called when it shouldn't have been.  major problem");
   SimpleTest.finish();
 }
 
 /** Test for Bug  **/
 
-ensure_geolocationProvider();
 SimpleTest.waitForExplicitFinish();
 
 watchID = navigator.geolocation.getCurrentPosition(successCallback, failureCallback, null);
 
 // click deny
 setTimeout(clickNotificationButton, 50, kDenyButton);
 
 </script>
--- a/dom/tests/mochitest/geolocation/test_clearWatch.html
+++ b/dom/tests/mochitest/geolocation/test_clearWatch.html
@@ -41,17 +41,16 @@ function clearWatch() {
 
 function testAccepted() {
   SimpleTest.finish();
 }
 
 
 /** Test for Bug  **/
 
-ensure_geolocationProvider();
 SimpleTest.waitForExplicitFinish();
 
 watchID = navigator.geolocation.watchPosition(successCallback, failureCallback, null);
 
 setTimeout(clickNotificationButton, 10, kAcceptButton);
 
 setTimeout(clearWatch, 50);
 
--- a/dom/tests/mochitest/geolocation/test_optional_api_params.html
+++ b/dom/tests/mochitest/geolocation/test_optional_api_params.html
@@ -18,17 +18,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 452566 **/
 
 const NOT_ENOUGH_ARGS = 2153185281;
 
-ensure_geolocationProvider();
 ok(navigator.geolocation, "Should have geolocation");
 
 var exception = null;
 try {
   navigator.geolocation.getCurrentPosition();
 } catch(ex) {
   if (ex.result == NOT_ENOUGH_ARGS) {
     exception = ex;
--- a/dom/tests/mochitest/geolocation/test_timeoutWatch.html
+++ b/dom/tests/mochitest/geolocation/test_timeoutWatch.html
@@ -16,17 +16,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 <p id="display"></p>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 /** Test for Bug  **/
 
-ensure_geolocationProvider();
 SimpleTest.waitForExplicitFinish();
 
 stop_geolocationProvider();
 
 function successCallback(pos){
   ok(false, "success should have never been called.");
   resume_geolocationProvider();
   SimpleTest.finish();
--- a/testing/mochitest/Makefile.in
+++ b/testing/mochitest/Makefile.in
@@ -96,17 +96,16 @@ TEST_HARNESS_BINS := \
   certutil$(BIN_SUFFIX) \
   pk12util$(BIN_SUFFIX) \
   $(NULL)
 
 # Components / typelibs that don't get packaged with
 # the build, but that we need for the test harness.
 TEST_HARNESS_COMPONENTS := \
   test_necko.xpt \
-  TestGeolocationProvider.js \
   $(NULL)
 
 # We need the test plugin as some tests rely on it
 ifeq (Darwin,$(OS_TARGET))
 TEST_HARNESS_PLUGINS := \
   Test.plugin/
 else
 TEST_HARNESS_PLUGINS := \