Backed out changeset 127374ca4f92 due to test failures.
authorJonas Sicking <jonas@sicking.cc>
Fri, 02 Dec 2011 19:29:35 -0800
changeset 82011 253c364458c7d14fd1ff7bddd9263a1901f7d40e
parent 82010 127374ca4f92a21a88159e43717ad9e7937947c1
child 82012 d7a9e843e573035b0e6f42d68423c85cd9851126
push idunknown
push userunknown
push dateunknown
milestone11.0a1
backs out127374ca4f92a21a88159e43717ad9e7937947c1
Backed out changeset 127374ca4f92 due to test failures.
content/base/public/nsIEventSource.idl
content/base/src/nsEventSource.cpp
content/base/src/nsEventSource.h
content/base/test/Makefile.in
content/base/test/accesscontrol.resource^headers^
content/base/test/file_restrictedEventSource.sjs
content/base/test/test_bug338583.html
--- a/content/base/public/nsIEventSource.idl
+++ b/content/base/public/nsIEventSource.idl
@@ -46,32 +46,27 @@
 
 #include "nsISupports.idl"
 
 interface nsIDOMEventListener;
 interface nsIPrincipal;
 interface nsIScriptContext;
 interface nsPIDOMWindow;
 
-[scriptable, uuid(a3d3181e-47c1-4f2e-b2c7-94775a86f5c5)]
+[scriptable, uuid(755e2d2d-a836-4539-83f4-16b51156341f)]
 interface nsIEventSource : nsISupports
 {
   readonly attribute DOMString url;
 
   // ready state
   const unsigned short CONNECTING = 0;
   const unsigned short OPEN = 1;
   const unsigned short CLOSED = 2;
   readonly attribute long readyState;
 
-  // if true then cross-site Access-Control requests are made using credentials
-  // such as cookies and authorization headers. Never affects same-site
-  // requests.
-  readonly attribute boolean withCredentials;
-
   // event handler attributes
   attribute nsIDOMEventListener onopen;
   attribute nsIDOMEventListener onmessage;
   attribute nsIDOMEventListener onerror;
 
   /**
    * Close the connection, if any, and set the readyState attribute to CLOSED.
    * If the connection is already closed, the method does nothing.
@@ -83,19 +78,14 @@ interface nsIEventSource : nsISupports
    * context, and owner window that should be used.
    *
    * @param principal The principal to use for the request. This must not be
    *                  null.
    * @param scriptContext The script context to use for the request. May be
    *                      null.
    * @param ownerWindow The associated window for the request. May be null.
    * @param url The EventSource's url. This must not be empty.
-   * @param withCredentials When set to true attempts to make cross-site
-   *                        Access-Control requests with credentials such as
-   *                        cookies and authorization headers. Never affects
-   *                        same-site requests.
    */
   [noscript] void init(in nsIPrincipal principal,
                        in nsIScriptContext scriptContext,
                        in nsPIDOMWindow ownerWindow,
-                       in DOMString url,
-                       in boolean withCredentials);
+                       in DOMString url);
 };
--- a/content/base/src/nsEventSource.cpp
+++ b/content/base/src/nsEventSource.cpp
@@ -57,17 +57,16 @@
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsIScriptError.h"
 #include "nsICharsetConverterManager.h"
 #include "nsIChannelPolicy.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsContentUtils.h"
 #include "mozilla/Preferences.h"
 #include "xpcpublic.h"
-#include "nsCrossSiteListenerProxy.h"
 
 using namespace mozilla;
 
 #define REPLACEMENT_CHAR     (PRUnichar)0xFFFD
 #define BOM_CHAR             (PRUnichar)0xFEFF
 #define SPACE_CHAR           (PRUnichar)0x0020
 #define CR_CHAR              (PRUnichar)0x000D
 #define LF_CHAR              (PRUnichar)0x000A
@@ -81,17 +80,16 @@ using namespace mozilla;
 #define DEFAULT_RECONNECTION_TIME_VALUE   5000
 #define MAX_RECONNECTION_TIME_VALUE       PR_IntervalToMilliseconds(DELAY_INTERVAL_LIMIT)
 
 nsEventSource::nsEventSource() :
   mStatus(PARSE_STATE_OFF),
   mFrozen(false),
   mErrorLoadOnRedirect(false),
   mGoingToDispatchAllMessages(false),
-  mWithCredentials(false),
   mLastConvertionResult(NS_OK),
   mReadyState(nsIEventSource::CONNECTING),
   mScriptLine(0),
   mInnerWindowID(0)
 {
 }
 
 nsEventSource::~nsEventSource()
@@ -162,24 +160,16 @@ nsEventSource::GetUrl(nsAString& aURL)
 NS_IMETHODIMP
 nsEventSource::GetReadyState(PRInt32 *aReadyState)
 {
   NS_ENSURE_ARG_POINTER(aReadyState);
   *aReadyState = mReadyState;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsEventSource::GetWithCredentials(bool *aWithCredentials)
-{
-  NS_ENSURE_ARG_POINTER(aWithCredentials);
-  *aWithCredentials = mWithCredentials;
-  return NS_OK;
-}
-
 #define NS_EVENTSRC_IMPL_DOMEVENTLISTENER(_eventlistenername, _eventlistener)  \
   NS_IMETHODIMP                                                                \
   nsEventSource::GetOn##_eventlistenername(nsIDOMEventListener * *aListener)   \
   {                                                                            \
     return GetInnerEventListener(_eventlistener, aListener);                   \
   }                                                                            \
                                                                                \
   NS_IMETHODIMP                                                                \
@@ -235,28 +225,26 @@ nsEventSource::Close()
 
 /**
  * This Init method should only be called by C++ consumers.
  */
 NS_IMETHODIMP
 nsEventSource::Init(nsIPrincipal* aPrincipal,
                     nsIScriptContext* aScriptContext,
                     nsPIDOMWindow* aOwnerWindow,
-                    const nsAString& aURL,
-                    bool aWithCredentials)
+                    const nsAString& aURL)
 {
   NS_ENSURE_ARG(aPrincipal);
 
   if (mReadyState != nsIEventSource::CONNECTING || !PrefEnabled()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   mPrincipal = aPrincipal;
   mScriptContext = aScriptContext;
-  mWithCredentials = aWithCredentials;
   if (aOwnerWindow) {
     mOwner = aOwnerWindow->IsOuterWindow() ?
       aOwnerWindow->GetCurrentInnerWindow() : aOwnerWindow;
   } else {
     mOwner = nsnull;
   }
 
   nsCOMPtr<nsIJSContextStack> stack =
@@ -383,41 +371,17 @@ nsEventSource::Initialize(nsISupports* a
   NS_ENSURE_STATE(scriptContext);
 
   nsCOMPtr<nsIScriptObjectPrincipal> scriptPrincipal =
     do_QueryInterface(aOwner);
   NS_ENSURE_STATE(scriptPrincipal);
   nsCOMPtr<nsIPrincipal> principal = scriptPrincipal->GetPrincipal();
   NS_ENSURE_STATE(principal);
 
-  bool withCredentialsParam = false;
-  if (aArgc >= 2) {
-    NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(aArgv[1]), NS_ERROR_INVALID_ARG);
-
-    JSObject *obj = JSVAL_TO_OBJECT(aArgv[1]);
-    NS_ASSERTION(obj, "obj shouldn't be null!!");
-
-    JSBool hasProperty = JS_FALSE;
-    NS_ENSURE_TRUE(JS_HasProperty(aContext, obj, "withCredentials",
-                                  &hasProperty), NS_ERROR_FAILURE);
-
-    if (hasProperty) {
-      jsval withCredentialsVal;
-      NS_ENSURE_TRUE(JS_GetProperty(aContext, obj, "withCredentials",
-                                    &withCredentialsVal), NS_ERROR_FAILURE);
-
-      JSBool withCredentials = JS_FALSE;
-      NS_ENSURE_TRUE(JS_ValueToBoolean(aContext, withCredentialsVal,
-                                       &withCredentials), NS_ERROR_FAILURE);
-      withCredentialsParam = !!withCredentials;
-    }
-  }
-
-  return Init(principal, scriptContext, ownerWindow,
-              urlParam, withCredentialsParam);
+  return Init(principal, scriptContext, ownerWindow, urlParam);
 }
 
 //-----------------------------------------------------------------------------
 // nsEventSource::nsIObserver
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsEventSource::Observe(nsISupports* aSubject,
@@ -917,23 +881,18 @@ nsEventSource::InitChannelAndRequestEven
   NS_ENSURE_SUCCESS(rv, rv);
 
   mHttpChannel = do_QueryInterface(channel);
   NS_ENSURE_TRUE(mHttpChannel, NS_ERROR_NO_INTERFACE);
 
   rv = SetupHttpChannel();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIStreamListener> listener =
-    new nsCORSListenerProxy(this, mPrincipal, mHttpChannel,
-                            mWithCredentials, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   // Start reading from the channel
-  return mHttpChannel->AsyncOpen(listener, nsnull);
+  return mHttpChannel->AsyncOpen(this, nsnull);
 }
 
 void
 nsEventSource::AnnounceConnection()
 {
   if (mReadyState == nsIEventSource::CLOSED) {
     return;
   }
@@ -1209,23 +1168,26 @@ nsEventSource::FailConnection()
 
 bool
 nsEventSource::CheckCanRequestSrc(nsIURI* aSrc)
 {
   if (mReadyState == nsIEventSource::CLOSED) {
     return false;
   }
 
+  bool isSameOrigin = false;
   bool isValidURI = false;
   bool isValidContentLoadPolicy = false;
   bool isValidProtocol = false;
 
   nsCOMPtr<nsIURI> srcToTest = aSrc ? aSrc : mSrc.get();
   NS_ENSURE_TRUE(srcToTest, false);
 
+  isSameOrigin = NS_SUCCEEDED(mPrincipal->CheckMayLoad(srcToTest, false));
+
   PRUint32 aCheckURIFlags =
     nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL |
     nsIScriptSecurityManager::DISALLOW_SCRIPT;
 
   nsresult rv = nsContentUtils::GetSecurityManager()->
     CheckLoadURIWithPrincipal(mPrincipal,
                               srcToTest,
                               aCheckURIFlags);
@@ -1255,17 +1217,18 @@ nsEventSource::CheckCanRequestSrc(nsIURI
   nsCAutoString targetURIScheme;
   rv = srcToTest->GetScheme(targetURIScheme);
   if (NS_SUCCEEDED(rv)) {
     // We only have the http support for now
     isValidProtocol = targetURIScheme.EqualsLiteral("http") ||
                       targetURIScheme.EqualsLiteral("https");
   }
 
-  return isValidURI && isValidContentLoadPolicy && isValidProtocol;
+  return isSameOrigin && isValidURI && isValidContentLoadPolicy &&
+         isValidProtocol;
 }
 
 // static
 void
 nsEventSource::TimerCallback(nsITimer* aTimer, void* aClosure)
 {
   nsRefPtr<nsEventSource> thisObject = static_cast<nsEventSource*>(aClosure);
 
--- a/content/base/src/nsEventSource.h
+++ b/content/base/src/nsEventSource.h
@@ -210,17 +210,16 @@ protected:
     PARSE_STATE_FIELD_VALUE,
     PARSE_STATE_BEGIN_OF_LINE
   };
   ParserStatus mStatus;
 
   bool mFrozen;
   bool mErrorLoadOnRedirect;
   bool mGoingToDispatchAllMessages;
-  bool mWithCredentials;
 
   // used while reading the input streams
   nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder;
   nsresult mLastConvertionResult;
   nsString mLastFieldName;
   nsString mLastFieldValue;
 
   nsRefPtr<nsDOMEventListenerWrapper> mOnOpenListener;
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -489,17 +489,16 @@ include $(topsrcdir)/config/rules.mk
 		badContentType.eventsource \
 		badContentType.eventsource^headers^ \
 		badEventFieldName.eventsource \
 		badEventFieldName.eventsource^headers^ \
 		badHTTPResponseCode.eventsource \
 		badHTTPResponseCode.eventsource^headers^ \
 		badMessageEvent.eventsource \
 		badMessageEvent.eventsource^headers^ \
-		file_restrictedEventSource.sjs \
 		forRemoval.resource \
 		forRemoval.resource^headers^ \
 		accesscontrol.resource \
 		accesscontrol.resource^headers^ \
 		invalid_accesscontrol.resource \
 		invalid_accesscontrol.resource^headers^ \
 		test_xhr_progressevents.html \
 		progressserver.sjs \
--- a/content/base/test/accesscontrol.resource^headers^
+++ b/content/base/test/accesscontrol.resource^headers^
@@ -1,5 +1,4 @@
-Access-Control-Allow-Origin: http://mochi.test:8888
-Access-Control-Allow-Credentials: true
+Access-Control-Allow-Origin: http://localhost:8888
 Content-Type: text/event-stream
 Cache-Control: no-cache, must-revalidate
 
deleted file mode 100644
--- a/content/base/test/file_restrictedEventSource.sjs
+++ /dev/null
@@ -1,50 +0,0 @@
-function handleRequest(request, response)
-{
-  if ((request.queryString == "test=user1_xhr" &&
-       request.hasHeader("Authorization") &&
-       request.getHeader("Authorization") == "Basic dXNlciAxOnBhc3N3b3JkIDE=") ||
-      (request.queryString == "test=user1_evtsrc" &&
-       request.hasHeader("Authorization") &&
-       request.getHeader("Authorization") == "Basic dXNlciAxOnBhc3N3b3JkIDE=" &&
-       request.hasHeader("Cookie") &&
-       request.getHeader("Cookie") == "test=5c")) {
-    response.setStatusLine(null, 200, "OK");
-    response.setHeader("Content-Type", "text/event-stream", false);
-    response.setHeader("Access-Control-Allow-Origin", "http://mochi.test:8888", false);
-    response.setHeader("Access-Control-Allow-Credentials", "true", false);
-    response.setHeader("Cache-Control", "no-cache, must-revalidate", false);
-    if (request.queryString == "test=user1_xhr") {
-      response.setHeader("Set-Cookie", "test=5c", false);
-    }
-    response.write("event: message\ndata: 1\n\n");
-  } else if ((request.queryString == "test=user2_xhr" &&
-              request.hasHeader("Authorization") &&
-              request.getHeader("Authorization") == "Basic dXNlciAyOnBhc3N3b3JkIDI=") ||
-             (request.queryString == "test=user2_evtsrc" &&
-              request.hasHeader("Authorization") &&
-              request.getHeader("Authorization") == "Basic dXNlciAyOnBhc3N3b3JkIDI=" &&
-              request.hasHeader("Cookie") &&
-              request.getHeader("Cookie") == "test=5d")) {
-    response.setStatusLine(null, 200, "OK");
-    response.setHeader("Content-Type", "text/event-stream", false);
-    response.setHeader("Access-Control-Allow-Origin", "http://mochi.test:8888", false);
-    response.setHeader("Access-Control-Allow-Credentials", "true", false);
-    response.setHeader("Cache-Control", "no-cache, must-revalidate", false);
-    if (request.queryString == "test=user2_xhr") {
-      response.setHeader("Set-Cookie", "test=5d", false);
-    }
-    response.write("event: message\ndata: 1\n\n");
-  } else if (request.queryString == "test=user1_xhr" ||
-             request.queryString == "test=user2_xhr") {
-    response.setStatusLine(null, 401, "Unauthorized");
-    response.setHeader("WWW-Authenticate", "basic realm=\"restricted\"", false);
-    response.setHeader("Access-Control-Allow-Origin", "http://mochi.test:8888", false);
-    response.setHeader("Access-Control-Allow-Credentials", "true", false);
-    response.write("Unauthorized");
-  } else {
-    response.setStatusLine(null, 403, "Forbidden");
-    response.setHeader("Access-Control-Allow-Origin", "http://mochi.test:8888", false);
-    response.setHeader("Access-Control-Allow-Credentials", "true", false);
-    response.write("Forbidden");
-  }
-}
\ No newline at end of file
--- a/content/base/test/test_bug338583.html
+++ b/content/base/test/test_bug338583.html
@@ -27,56 +27,34 @@ https://bugzilla.mozilla.org/show_bug.cg
 //   3) possible invalid eventsources
 //   4) the close method when the object is just been used
 //   5) access-control
 //   6) the data parameter
 //   7) delayed server responses
 
 // --
 
-  var gTestsHaveFinished = [];
-
-  function setTestHasFinished(test_id)
-  {
-    if (gTestsHaveFinished[test_id]) {
-      return;
-    }
-
-    gTestsHaveFinished[test_id] = true;
-    for (var i=0; i < gTestsHaveFinished.length; ++i) {
-      if (!gTestsHaveFinished[i]) {
-        return;
-      }
-    }
-
-    SimpleTest.finish();
-  }
-
   function runAllTests() {
-    // these tests run asynchronously, and they will take 8000 ms
-    var all_tests = [
-      doTest1, doTest1_e, doTest2, doTest3, doTest3_b, doTest3_c, doTest3_d,
-      doTest3_e, doTest3_f, doTest3_g, doTest3_h, doTest4, doTest4_b,
-      doTest5, doTest5_b, doTest5_c, doTest5_e, doTest6, doTest7
-    ];
-
-    for (var test_id=0; test_id < all_tests.length; ++test_id) {
-      gTestsHaveFinished[test_id] = false;
-      var fn = all_tests[test_id];
-      fn(test_id);
-    }
-
-    setTimeout(function() {
-      for (var test_id=0; test_id < all_tests.length; ++test_id) {
-        if (!gTestsHaveFinished[test_id]) {
-          ok(false, "Test " + test_id + " took too long");
-          setTestHasFinished(test_id);
-        }
-      }
-    }, 60000 * stress_factor); // all tests together are supposed to take less than 1 minute
+    // these tests run asynchronously
+    doTest1();    // this will take 8000 ms
+    doTest2();    // this will take 5000 ms
+    doTest3();    // this will take 1500 ms
+    doTest3_b();  // this will take 1500 ms
+    doTest3_c();  // this will take 1500 ms
+    doTest3_d();  // this will take 1500 ms
+    doTest3_e();  // this will take 1500 ms
+    doTest3_f();  // this will take 1500 ms
+    doTest3_g();  // this will take 1500 ms
+    doTest3_h();  // this will take 1500 ms
+    doTest4();    // this will take 3000 ms
+    doTest4_b();  // this will take 3000 ms
+    doTest5();    // this will take 3000 ms
+    doTest5_b();  // this will take 3000 ms
+    doTest6();    // this will take 2500 ms
+    doTest7();    // this will take 8000 ms
   }
 
   function fn_onmessage(e) {
     if (e.currentTarget == e.target && e.target.hits != null)
       e.target.hits['fn_onmessage']++;
   }
 
   function fn_event_listener_message(e) {
@@ -87,26 +65,24 @@ https://bugzilla.mozilla.org/show_bug.cg
   function fn_other_event_name(e) {
     if (e.currentTarget == e.target && e.target.hits != null)
       e.target.hits['fn_other_event_name']++;
   }
 
   var domBranch;
   var oldPrefVal;
 
-  var gEventSourceObj1 = null, gEventSourceObj1_e;
+  var gEventSourceObj1 = null;
   var gEventSourceObj2 = null;
   var gEventSourceObj3_a = null, gEventSourceObj3_b = null,
       gEventSourceObj3_c = null, gEventSourceObj3_d = null,
       gEventSourceObj3_e = null, gEventSourceObj3_f = null,
       gEventSourceObj3_g = null, gEventSourceObj3_h = null;
   var gEventSourceObj4_a = null, gEventSourceObj4_b = null;
-  var gEventSourceObj5_a = null, gEventSourceObj5_b = null,
-      gEventSourceObj5_c = null, gEventSourceObj5_d = null,
-      gEventSourceObj5_e = null, gEventSourceObj5_f = null;
+  var gEventSourceObj5_a = null, gEventSourceObj5_b = null;
   var gEventSourceObj6 = null;
   var gEventSourceObj7 = null;
   var stress_factor;  // used in the setTimeouts in order to help
                       // the test when running in slow machines
 
   function hasBeenHitFor1And2(obj, min) {
     if (obj.hits['fn_onmessage'] < min ||
         obj.hits['fn_event_listener_message'] < min ||
@@ -115,227 +91,205 @@ https://bugzilla.mozilla.org/show_bug.cg
     return true;
   }
 
 // in order to test (1):
 //   a) if the EventSource constructor parameter is equal to its url attribute
 //   b) let its fn_onmessage, fn_event_listener_message, and fn_other_event_name functions listeners be hit four times each
 //   c) the close method (we expect readyState == CLOSED)
 //   d) the close method (we expect no message events anymore)
-//   e) if the ctor throws an exception when the second parameter is null
 
-  function doTest1(test_id) {
+  function doTest1() {
     gEventSourceObj1 = new EventSource("eventsource.resource");
     ok(gEventSourceObj1.url == "http://mochi.test:8888/tests/content/base/test/eventsource.resource", "Test 1.a failed.");
     ok(gEventSourceObj1.readyState == 0 || gEventSourceObj1.readyState == 1, "Test 1.a failed.");
 
-    doTest1_b(test_id);
+    doTest1_b();
   }
 
-  function doTest1_b(test_id) {
+  function doTest1_b() {
     gEventSourceObj1.hits = [];
     gEventSourceObj1.hits['fn_onmessage'] = 0;
     gEventSourceObj1.onmessage = fn_onmessage;
     gEventSourceObj1.hits['fn_event_listener_message'] = 0;
     gEventSourceObj1.addEventListener('message', fn_event_listener_message, true);
     gEventSourceObj1.hits['fn_other_event_name'] = 0;
     gEventSourceObj1.addEventListener('other_event_name', fn_other_event_name, true);
 
     // the eventsources.res always use a retry of 0.5 second, so for four hits a timeout of 6 seconds is enough
     setTimeout(function(){
       bhits = hasBeenHitFor1And2(gEventSourceObj1, 4);
       ok(bhits, "Test 1.b failed.");
 
-      doTest1_c(test_id);
+      doTest1_c();
     }, parseInt(6000*stress_factor));
   }
 
-  function doTest1_c(test_id) {
+  function doTest1_c() {
     gEventSourceObj1.close();
     ok(gEventSourceObj1.readyState == 2, "Test 1.c failed.");
 
-    doTest1_d(test_id);
+    doTest1_d();
   }
 
-  function doTest1_d(test_id) {
+  function doTest1_d() {
     gEventSourceObj1.hits['fn_onmessage'] = 0;
     gEventSourceObj1.hits['fn_event_listener_message'] = 0;
     gEventSourceObj1.hits['fn_other_event_name'] = 0;
 
     setTimeout(function(){
       bhits = hasBeenHitFor1And2(gEventSourceObj1, 1);
       ok(!bhits, "Test 1.d failed.");
       gEventSourceObj1.close();
-      setTestHasFinished(test_id);
     }, parseInt(2000*stress_factor));
   }
 
-  function doTest1_e(test_id) {
-    try {
-      gEventSourceObj1_e = new EventSource("eventsource.resource", null);
-      ok(false, "Test 1.e failed");
-      gEventSourceObj1_e.close();
-    } catch (e) {
-      ok(true, "Test 1.e failed");
-    }
-    setTestHasFinished(test_id);
-  }
-
 // in order to test (2)
 //   a) set a eventsource that give the dom events messages
 //   b) expect trusted events
 
-  function doTest2(test_id) {
+  function doTest2() {
     var func = function(e) {
       ok(e.isTrusted, "Test 2 failed");
       gEventSourceObj2.close();
     };
 
     gEventSourceObj2 = new EventSource("eventsource.resource");
     gEventSourceObj2.onmessage = func;
 
-    setTimeout(function() {  // just to clean...
+    setTimeout(function(){  // just to clean...
       gEventSourceObj2.close();
-      setTestHasFinished(test_id);
     }, parseInt(5000*stress_factor));
   }
 
 // in order to test (3)
 //   a) XSite domain error test
 //   b) protocol file:// test
 //   c) protocol javascript: test
 //   d) wrong Content-Type test
 //   e) bad http response code test
 //   f) message eventsource without a data test
 //   g) eventsource with invalid NCName char in the event field test
 //   h) DNS error
 
-  function doTest3(test_id) {
+  function doTest3() {
     gEventSourceObj3_a = new EventSource("http://example.org/tests/content/base/test/eventsource.resource");
 
     gEventSourceObj3_a.onmessage = fn_onmessage;
     gEventSourceObj3_a.hits = [];
     gEventSourceObj3_a.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
       ok(gEventSourceObj3_a.hits['fn_onmessage'] == 0, "Test 3.a failed");
       gEventSourceObj3_a.close();
-      setTestHasFinished(test_id);
     }, parseInt(1500*stress_factor));
   }
 
-  function doTest3_b(test_id) {
+  function doTest3_b() {
     var xhr = new XMLHttpRequest;
     xhr.open("GET", "/dynamic/getMyDirectory.sjs", false);
     xhr.send();
     var basePath = xhr.responseText;
 
     gEventSourceObj3_b = new EventSource("file://" + basePath + "eventsource.resource");
 
     gEventSourceObj3_b.onmessage = fn_onmessage;
     gEventSourceObj3_b.hits = [];
     gEventSourceObj3_b.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
       ok(gEventSourceObj3_b.hits['fn_onmessage'] == 0, "Test 3.b failed");
       gEventSourceObj3_b.close();
-      setTestHasFinished(test_id);
     }, parseInt(1500*stress_factor));
   }
 
   function jsEvtSource()
   {
     return "event: message\n" +
            "data: 1\n\n";
   }
 
-  function doTest3_c(test_id) {
+  function doTest3_c() {
     gEventSourceObj3_c = new EventSource("javascript: return jsEvtSource()");
 
     gEventSourceObj3_c.onmessage = fn_onmessage;
     gEventSourceObj3_c.hits = [];
     gEventSourceObj3_c.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
       ok(gEventSourceObj3_c.hits['fn_onmessage'] == 0, "Test 3.c failed");
       gEventSourceObj3_c.close();
-      setTestHasFinished(test_id);
     }, parseInt(1500*stress_factor));
   }
 
-  function doTest3_d(test_id) {
+  function doTest3_d() {
     gEventSourceObj3_d = new EventSource("badContentType.eventsource");
 
     gEventSourceObj3_d.onmessage = fn_onmessage;
     gEventSourceObj3_d.hits = [];
     gEventSourceObj3_d.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
       ok(gEventSourceObj3_d.hits['fn_onmessage'] == 0, "Test 3.d failed");
       gEventSourceObj3_d.close();
-      setTestHasFinished(test_id);
     }, parseInt(1500*stress_factor));
   }
 
-  function doTest3_e(test_id) {
+  function doTest3_e() {
     gEventSourceObj3_e = new EventSource("badHTTPResponseCode.eventsource");
 
     gEventSourceObj3_e.onmessage = fn_onmessage;
     gEventSourceObj3_e.hits = [];
     gEventSourceObj3_e.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
       ok(gEventSourceObj3_e.hits['fn_onmessage'] == 0, "Test 3.e failed");
       gEventSourceObj3_e.close();
-      setTestHasFinished(test_id);
     }, parseInt(1500*stress_factor));
   }
 
-  function doTest3_f(test_id) {
+  function doTest3_f() {
     gEventSourceObj3_f = new EventSource("badMessageEvent.eventsource");
 
     gEventSourceObj3_f.onmessage = fn_onmessage;
     gEventSourceObj3_f.hits = [];
     gEventSourceObj3_f.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
       ok(gEventSourceObj3_f.hits['fn_onmessage'] == 0, "Test 3.f failed");
       gEventSourceObj3_f.close();
-      setTestHasFinished(test_id);
     }, parseInt(1500*stress_factor));
   }
 
   function fnInvalidNCName() {
     fnInvalidNCName.hits++;
   }
 
-  function doTest3_g(test_id) {
+  function doTest3_g() {
     gEventSourceObj3_g = new EventSource("badEventFieldName.eventsource");
 
     fnInvalidNCName.hits = 0;
     gEventSourceObj3_g.addEventListener('message event', fnInvalidNCName, true);
 
     setTimeout(function() {
       ok(fnInvalidNCName.hits != 0, "Test 3.g failed");
       gEventSourceObj3_g.close();
-      setTestHasFinished(test_id);
     }, parseInt(1500*stress_factor));
   }
 
-  function doTest3_h(test_id) {
+  function doTest3_h() {
     gEventSourceObj3_h = new EventSource("http://hdfskjghsbg.jtiyoejowe.dafsgbhjab.com");
 
     gEventSourceObj3_h.onmessage = fn_onmessage;
     gEventSourceObj3_h.hits = [];
     gEventSourceObj3_h.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
       ok(gEventSourceObj3_h.hits['fn_onmessage'] == 0, "Test 3.h failed");
       gEventSourceObj3_h.close();
-      setTestHasFinished(test_id);
     }, parseInt(1500*stress_factor));
   }
 
 // in order to test (4)
 //   a) close the object when it is in use, which is being processed and that is expected
 //      to dispatch more eventlisteners
 //   b) remove an eventlistener in use
 
@@ -350,186 +304,72 @@ https://bugzilla.mozilla.org/show_bug.cg
   function fn_onmessage4_b(e)
   {
     if (e.data > gEventSourceObj4_b.lastData)
       gEventSourceObj4_b.lastData = e.data;
     if (e.data == 2)
       gEventSourceObj4_b.removeEventListener('message', fn_onmessage4_b, true);
   }
 
-  function doTest4(test_id) {
+  function doTest4() {
     gEventSourceObj4_a = new EventSource("forRemoval.resource");
     gEventSourceObj4_a.lastData = 0;
     gEventSourceObj4_a.onmessage = fn_onmessage4_a;
 
     setTimeout(function() {
       ok(gEventSourceObj4_a.lastData == 2, "Test 4.a failed");
       gEventSourceObj4_a.close();
-      setTestHasFinished(test_id);
     }, parseInt(3000*stress_factor));
   }
 
-  function doTest4_b(test_id)
+  function doTest4_b()
   {
     gEventSourceObj4_b = new EventSource("forRemoval.resource");
     gEventSourceObj4_b.lastData = 0;
     gEventSourceObj4_b.addEventListener('message', fn_onmessage4_b, true);
 
     setTimeout(function() {
       ok(gEventSourceObj4_b.lastData == 2, "Test 4.b failed");
       gEventSourceObj4_b.close();
-      setTestHasFinished(test_id);
     }, parseInt(3000*stress_factor));
   }
 
 // in order to test (5)
-//   a) valid access-control xsite request
+//   a) valid access-control xsite request (but must fail)
 //   b) invalid access-control xsite request
-//   c) valid access-control xsite request on a restricted page with credentials
-//   d) valid access-control xsite request on a restricted page without credentials
-//   e) valid access-control xsite request on a restricted page when the parameter withCredentials is a getter 
-//   f) valid access-control xsite request on a restricted page when the parameter withCredentials is missing 
 
-  function doTest5(test_id)
+  function doTest5()
   {
     gEventSourceObj5_a = new EventSource("http://example.org/tests/content/base/test/accesscontrol.resource");
 
     gEventSourceObj5_a.onmessage = fn_onmessage;
     gEventSourceObj5_a.hits = [];
     gEventSourceObj5_a.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
-      ok(gEventSourceObj5_a.hits['fn_onmessage'] != 0, "Test 5.a failed");
+      ok(gEventSourceObj5_a.hits['fn_onmessage'] == 0, "Test 5.a failed");
       gEventSourceObj5_a.close();
-      setTestHasFinished(test_id);
     }, parseInt(3000*stress_factor));
   }
 
-  function doTest5_b(test_id)
+  function doTest5_b()
   {
     gEventSourceObj5_b = new EventSource("http://example.org/tests/content/base/test/invalid_accesscontrol.resource");
 
     gEventSourceObj5_b.onmessage = fn_onmessage;
     gEventSourceObj5_b.hits = [];
     gEventSourceObj5_b.hits['fn_onmessage'] = 0;
 
     setTimeout(function() {
       ok(gEventSourceObj5_b.hits['fn_onmessage'] == 0, "Test 5.b failed");
       gEventSourceObj5_b.close();
-      setTestHasFinished(test_id);
-    }, parseInt(3000*stress_factor));
-  }
-
-  function doTest5_c(test_id)
-  {
-    // credentials using the auth cache and cookies
-    var xhr = SpecialPowers.createSystemXHR();
-    xhr.withCredentials = true;
-    // also, test mixed mode UI
-    xhr.open("GET", "https://example.com/tests/content/base/test/file_restrictedEventSource.sjs?test=user1_xhr", false, "user 1", "password 1");
-    xhr.send();
-    ok(xhr.status == 200, "Failed to set credentials in test 5.c");
-
-    gEventSourceObj5_c = new EventSource("https://example.com/tests/content/base/test/file_restrictedEventSource.sjs?test=user1_evtsrc",
-                                         { withCredentials: true } );
-    ok(gEventSourceObj5_c.withCredentials, "Wrong withCredentials in test 5.c");
-
-    gEventSourceObj5_c.onmessage = function(e) {
-      ok(e.origin == "https://example.com", "Wrong Origin in test 5.c");
-      fn_onmessage(e);
-    };
-    gEventSourceObj5_c.hits = [];
-    gEventSourceObj5_c.hits['fn_onmessage'] = 0;
-
-    setTimeout(function() {
-      ok(gEventSourceObj5_c.hits['fn_onmessage'] > 0, "Test 5.c failed");
-      gEventSourceObj5_c.close();
-      doTest5_d(test_id);
     }, parseInt(3000*stress_factor));
   }
 
-  function doTest5_d(test_id)
-  {
-    var xhr = SpecialPowers.createSystemXHR();
-    xhr.withCredentials = true;
-    xhr.open("GET", "https://example.com/tests/content/base/test/file_restrictedEventSource.sjs?test=user2_xhr", false, "user 2", "password 2");
-    xhr.send();
-    ok(xhr.status == 200, "Failed to set credentials in test 5.d");
-
-    gEventSourceObj5_d = new EventSource("https://example.com/tests/content/base/test/file_restrictedEventSource.sjs?test=user2_evtsrc");
-    ok(!gEventSourceObj5_d.withCredentials, "Wrong withCredentials in test 5.d");
-
-    gEventSourceObj5_d.onmessage = function(e) {
-      ok(e.origin == "https://example.com", "Wrong Origin in test 5.d");
-      fn_onmessage(e);
-    };
-    gEventSourceObj5_d.hits = [];
-    gEventSourceObj5_d.hits['fn_onmessage'] = 0;
-
-    setTimeout(function() {
-      ok(gEventSourceObj5_d.hits['fn_onmessage'] == 0, "Test 5.d failed");
-      gEventSourceObj5_d.close();
-      setTestHasFinished(test_id);
-    }, parseInt(3000*stress_factor));
-  }
-
-  function doTest5_e(test_id)
-  {
-    // credentials using the auth cache and cookies
-    var xhr = SpecialPowers.createSystemXHR();
-    xhr.withCredentials = true;
-    xhr.open("GET", "http://example.org/tests/content/base/test/file_restrictedEventSource.sjs?test=user1_xhr", false, "user 1", "password 1");
-    xhr.send();
-    ok(xhr.status == 200, "Failed to set credentials in test 5.e");
-
-    gEventSourceObj5_e = new EventSource("http://example.org/tests/content/base/test/file_restrictedEventSource.sjs?test=user1_evtsrc",
-                                         { get withCredentials() { return true; } } );
-    ok(gEventSourceObj5_e.withCredentials, "Wrong withCredentials in test 5.e");
-
-    gEventSourceObj5_e.onmessage = function(e) {
-      ok(e.origin == "http://example.org", "Wrong Origin in test 5.e");
-      fn_onmessage(e);
-    };
-    gEventSourceObj5_e.hits = [];
-    gEventSourceObj5_e.hits['fn_onmessage'] = 0;
-
-    setTimeout(function() {
-      ok(gEventSourceObj5_e.hits['fn_onmessage'] > 0, "Test 5.e failed");
-      gEventSourceObj5_e.close();
-      doTest5_f(test_id);
-    }, parseInt(5000*stress_factor));
-  }
-
-  function doTest5_f(test_id)
-  {
-    var xhr = SpecialPowers.createSystemXHR();
-    xhr.withCredentials = true;
-    xhr.open("GET", "http://example.org/tests/content/base/test/file_restrictedEventSource.sjs?test=user2_xhr", false, "user 2", "password 2");
-    xhr.send();
-    ok(xhr.status == 200, "Failed to set credentials in test 5.f");
-
-    gEventSourceObj5_f = new EventSource("http://example.org/tests/content/base/test/file_restrictedEventSource.sjs?test=user2_evtsrc",
-                                         { });
-    ok(!gEventSourceObj5_f.withCredentials, "Wrong withCredentials in test 5.f");
-
-    gEventSourceObj5_f.onmessage = function(e) {
-      ok(e.origin == "http://example.org", "Wrong Origin in test 5.f");
-      fn_onmessage(e);
-    };
-    gEventSourceObj5_f.hits = [];
-    gEventSourceObj5_f.hits['fn_onmessage'] = 0;
-
-    setTimeout(function() {
-      ok(gEventSourceObj5_f.hits['fn_onmessage'] == 0, "Test 5.f failed");
-      gEventSourceObj5_f.close();
-      setTestHasFinished(test_id);
-    }, parseInt(3000*stress_factor));
-  }
-
-  function doTest6(test_id)
+  function doTest6()
   {
     gEventSourceObj6 = new EventSource("somedatas.resource");
     var fn_somedata = function(e) {
       if (fn_somedata.expected == 0) {
         ok(e.data == "123456789\n123456789123456789\n123456789123456789123456789123456789\n 123456789123456789123456789123456789123456789123456789123456789123456789\nçãá\"\'@`~Ý Ḿyyyy",
           "Test 6.a failed");
       } else if (fn_somedata.expected == 1) {
         ok(e.data == " :xxabcdefghij\nçãá\"\'@`~Ý Ḿyyyy : zz",
@@ -542,21 +382,20 @@ https://bugzilla.mozilla.org/show_bug.cg
       }
       fn_somedata.expected++;
     }
     fn_somedata.expected = 0;
     gEventSourceObj6.onmessage = fn_somedata;
 
     setTimeout(function() {
       gEventSourceObj6.close();
-      setTestHasFinished(test_id);
     }, parseInt(2500*stress_factor));
   }
 
-  function doTest7(test_id)
+  function doTest7()
   {
     gEventSourceObj7 = new EventSource("delayedServerEvents.sjs");
     gEventSourceObj7.msg_received = [];
     gEventSourceObj7.onmessage = function(e)
     {
       e.target.msg_received.push(e.data);
     }
     
@@ -564,21 +403,21 @@ https://bugzilla.mozilla.org/show_bug.cg
       gEventSourceObj7.close();
       
       ok(gEventSourceObj7.msg_received[0] == "" &&
          gEventSourceObj7.msg_received[1] == "delayed1" &&
          gEventSourceObj7.msg_received[2] == "delayed2", "Test 7 failed");
 
       SpecialPowers.setBoolPref("dom.server-events.enabled", oldPrefVal);
       document.getElementById('waitSpan').innerHTML = '';
-      setTestHasFinished(test_id);
+      SimpleTest.finish();
     }, parseInt(8000*stress_factor));
   }
 
-  function doTest(test_id)
+  function doTest()
   {
     oldPrefVal = SpecialPowers.getBoolPref("dom.server-events.enabled");
     SpecialPowers.setBoolPref("dom.server-events.enabled", true);
 
     // we get a good stress_factor by testing 10 setTimeouts and some float
     // arithmetic taking my machine as stress_factor==1 (time=589)
 
     var begin_time = (new Date()).getTime();