Bug 687332: Fix up update tests.
authorKyle Huey <khuey@kylehuey.com>
Thu, 29 Sep 2011 12:06:36 -0400
changeset 77818 acffd2f7d6658534587beeae35fd25a33f40cdf4
parent 77817 1f8c38d6e4bf5519fc6e0a33452d8c813da64b63
child 77819 6d59d323116d6f2541c341d7224f933af0cecc14
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
bugs687332
milestone10.0a1
Bug 687332: Fix up update tests.
content/base/test/unit/test_bug553888.js
content/base/test/unit/test_error_codes.js
netwerk/test/unit/test_xmlhttprequest.js
toolkit/mozapps/update/test/unit/head_update.js.in
toolkit/mozapps/update/test/unit/test_0020_general.js
toolkit/mozapps/update/test/unit/test_0030_general.js
toolkit/mozapps/update/test/unit/test_0040_general.js
toolkit/mozapps/update/test/unit/test_0050_general.js
--- a/content/base/test/unit/test_bug553888.js
+++ b/content/base/test/unit/test_bug553888.js
@@ -74,21 +74,21 @@ function run_test() {
   server.registerPathHandler(headerCheckPath, headerCheckHandler);
   server.start(SERVER_PORT);
 
   do_test_pending();
   var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
                 .createInstance(Components.interfaces.nsIXMLHttpRequest);
   request.open("GET", redirectURL, true);
   request.setRequestHeader("X-Custom-Header", "present");
-  request.onreadystatechange = function() {
+  request.addEventListener("readystatechange", function() {
     if (request.readyState == 4) {
       do_check_eq(request.status, 200);
       server.stop(do_test_finished);
     }
-  };
+  }, false);
   request.send();
   try {
     request.setRequestHeader("X-Unwanted-Header", "present");
     do_throw("Shouldn't be able to set a header after send");
   } catch (x) {
   }    
 }
--- a/content/base/test/unit/test_error_codes.js
+++ b/content/base/test/unit/test_error_codes.js
@@ -41,17 +41,17 @@ var gNextTestFunc   = null;
 
 var asyncXHR = {
   load: function() {
     var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
                             .createInstance(Components.interfaces.nsIXMLHttpRequest);
     request.open("GET", "http://localhost:4444/test_error_code.xml", true);
 
     var self = this;
-    request.onerror = function(event) { self.onError(event); };
+    request.addEventListener("error", function(event) { self.onError(event); }, false);
     request.send(null);
   },
   onError: function doAsyncRequest_onError(event) {
     var request = event.target.channel.QueryInterface(Components.interfaces.nsIRequest);
     do_check_eq(request.status, gExpectedStatus);
     gNextTestFunc();
   }
 }
--- a/netwerk/test/unit/test_xmlhttprequest.js
+++ b/netwerk/test/unit/test_xmlhttprequest.js
@@ -33,20 +33,20 @@ function run_test()
 
   // Test sync XHR sending
   var sync = createXHR(false);
   sync.send(null);
   checkResults(sync);
 
   // Test async XHR sending
   let async = createXHR(true);
-  async.onreadystatechange = function(event) {
+  async.addEventListener("readystatechange", function(event) {
     if (checkResults(async))
       httpserver.stop(do_test_finished);
-  };
+  }, false);
   async.send(null);
   do_test_pending();
 }
 
 function serverHandler(metadata, response)
 {
   response.setHeader("Content-Type", "text/xml", false);
   response.bodyOutputStream.write(httpbody, httpbody.length);
--- a/toolkit/mozapps/update/test/unit/head_update.js.in
+++ b/toolkit/mozapps/update/test/unit/head_update.js.in
@@ -1002,16 +1002,19 @@ xhr.prototype = {
   set onprogress(val) { gXHR._onprogress = makeHandler(val); },
   get onprogress() { return gXHR._onprogress; },
   _onerror: null,
   set onerror(val) { gXHR._onerror = makeHandler(val); },
   get onerror() { return gXHR._onerror; },
   _onload: null,
   set onload(val) { gXHR._onload = makeHandler(val); },
   get onload() { return gXHR._onload; },
+  addEventListener: function(event, val, capturing) {
+    eval("gXHR._on" + event + " = val");
+  },
   flags: AUS_Ci.nsIClassInfo.SINGLETON,
   implementationLanguage: AUS_Ci.nsIProgrammingLanguage.JAVASCRIPT,
   getHelperForLanguage: function(language) null,
   getInterfaces: function(count) {
     var interfaces = [AUS_Ci.nsISupports];
     count.value = interfaces.length;
     return interfaces;
   },
--- a/toolkit/mozapps/update/test/unit/test_0020_general.js
+++ b/toolkit/mozapps/update/test/unit/test_0020_general.js
@@ -82,17 +82,17 @@ function callHandleEvent() {
     var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"].
                  createInstance(AUS_Ci.nsIDOMParser);
     gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml");
   }
   catch(e) {
     gXHR.responseXML = null;
   }
   var e = { target: gXHR };
-  gXHR.onload.handleEvent(e);
+  gXHR.onload(e);
 }
 
 // update xml not found
 function run_test_pt01() {
   run_test_helper_pt1("testing update xml not available",
                       null, run_test_pt02);
 }
 
--- a/toolkit/mozapps/update/test/unit/test_0030_general.js
+++ b/toolkit/mozapps/update/test/unit/test_0030_general.js
@@ -72,17 +72,17 @@ function callHandleEvent() {
   try {
     var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"].
                  createInstance(AUS_Ci.nsIDOMParser);
     gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml");
   }
   catch(e) {
   }
   var e = { target: gXHR };
-  gXHR.onload.handleEvent(e);
+  gXHR.onload(e);
 }
 
 // Helper function for testing mar downloads that have the correct size
 // specified in the update xml.
 function run_test_helper_pt1(aMsg, aExpectedStatusResult, aNextRunFunc) {
   gUpdates = null;
   gUpdateCount = null;
   gStatusResult = null;
--- a/toolkit/mozapps/update/test/unit/test_0040_general.js
+++ b/toolkit/mozapps/update/test/unit/test_0040_general.js
@@ -58,17 +58,17 @@ function run_test() {
 function end_test() {
   cleanUp();
 }
 
 // Callback function used by the custom XMLHttpRequest implementation to
 // call the nsIDOMEventListener's handleEvent method for onload.
 function callHandleEvent() {
   var e = { target: gXHR };
-  gXHR.onload.handleEvent(e);
+  gXHR.onload(e);
 }
 
 // Helper function for parsing the result from the contructed url
 function getResult(url) {
   return url.substr(URL_PREFIX.length).split("/")[0];
 }
 
 // url constructed with %PRODUCT%
--- a/toolkit/mozapps/update/test/unit/test_0050_general.js
+++ b/toolkit/mozapps/update/test/unit/test_0050_general.js
@@ -63,17 +63,17 @@ function end_test() {
   cleanUp();
 }
 
 // Callback function used by the custom XMLHttpRequest implementation to
 // call the nsIDOMEventListener's handleEvent method for onload.
 function callHandleEvent() {
   gXHR.status = gExpectedStatusCode;
   var e = { target: gXHR };
-  gXHR.onload.handleEvent(e);
+  gXHR.onload(e);
 }
 
 // Helper functions for testing nsIUpdateCheckListener statusText
 function run_test_helper(aNextRunFunc, aExpectedStatusCode, aMsg) {
   gStatusCode = null;
   gStatusText = null;
   gCheckFunc = check_test_helper;
   gNextRunFunc = aNextRunFunc;