Back out 3ad7f12bde01 (bug 664179) and 3ab7b95bfcb5 (bug 673296) for Linux debug M1 orange

This commit is contained in:
Phil Ringnalda 2011-10-29 09:52:45 -07:00
Родитель 9a02a2a1cb
Коммит 17efb78985
7 изменённых файлов: 61 добавлений и 306 удалений

Просмотреть файл

@ -51,7 +51,7 @@ interface nsIPrincipal;
interface nsIScriptContext; interface nsIScriptContext;
interface nsPIDOMWindow; interface nsPIDOMWindow;
[scriptable, uuid(83dc8c2b-376e-42b3-8bed-1ad6dea7d6d7)] [scriptable, uuid(755e2d2d-a836-4539-83f4-16b51156341f)]
interface nsIEventSource : nsISupports interface nsIEventSource : nsISupports
{ {
readonly attribute DOMString url; readonly attribute DOMString url;
@ -62,11 +62,6 @@ interface nsIEventSource : nsISupports
const unsigned short CLOSED = 2; const unsigned short CLOSED = 2;
readonly attribute long readyState; 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 mozWithCredentials;
// event handler attributes // event handler attributes
attribute nsIDOMEventListener onopen; attribute nsIDOMEventListener onopen;
attribute nsIDOMEventListener onmessage; attribute nsIDOMEventListener onmessage;
@ -88,14 +83,9 @@ interface nsIEventSource : nsISupports
* null. * null.
* @param ownerWindow The associated window 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 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, [noscript] void init(in nsIPrincipal principal,
in nsIScriptContext scriptContext, in nsIScriptContext scriptContext,
in nsPIDOMWindow ownerWindow, in nsPIDOMWindow ownerWindow,
in DOMString url, in DOMString url);
in boolean withCredentials);
}; };

Просмотреть файл

@ -62,7 +62,6 @@
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "xpcpublic.h" #include "xpcpublic.h"
#include "nsCrossSiteListenerProxy.h"
using namespace mozilla; using namespace mozilla;
@ -86,7 +85,6 @@ nsEventSource::nsEventSource() :
mFrozen(false), mFrozen(false),
mErrorLoadOnRedirect(false), mErrorLoadOnRedirect(false),
mGoingToDispatchAllMessages(false), mGoingToDispatchAllMessages(false),
mWithCredentials(false),
mLastConvertionResult(NS_OK), mLastConvertionResult(NS_OK),
mReadyState(nsIEventSource::CONNECTING), mReadyState(nsIEventSource::CONNECTING),
mScriptLine(0), mScriptLine(0),
@ -167,14 +165,6 @@ nsEventSource::GetReadyState(PRInt32 *aReadyState)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsEventSource::GetMozWithCredentials(bool *aWithCredentials)
{
NS_ENSURE_ARG_POINTER(aWithCredentials);
*aWithCredentials = mWithCredentials;
return NS_OK;
}
#define NS_EVENTSRC_IMPL_DOMEVENTLISTENER(_eventlistenername, _eventlistener) \ #define NS_EVENTSRC_IMPL_DOMEVENTLISTENER(_eventlistenername, _eventlistener) \
NS_IMETHODIMP \ NS_IMETHODIMP \
nsEventSource::GetOn##_eventlistenername(nsIDOMEventListener * *aListener) \ nsEventSource::GetOn##_eventlistenername(nsIDOMEventListener * *aListener) \
@ -240,8 +230,7 @@ NS_IMETHODIMP
nsEventSource::Init(nsIPrincipal* aPrincipal, nsEventSource::Init(nsIPrincipal* aPrincipal,
nsIScriptContext* aScriptContext, nsIScriptContext* aScriptContext,
nsPIDOMWindow* aOwnerWindow, nsPIDOMWindow* aOwnerWindow,
const nsAString& aURL, const nsAString& aURL)
bool aWithCredentials)
{ {
NS_ENSURE_ARG(aPrincipal); NS_ENSURE_ARG(aPrincipal);
@ -251,7 +240,6 @@ nsEventSource::Init(nsIPrincipal* aPrincipal,
mPrincipal = aPrincipal; mPrincipal = aPrincipal;
mScriptContext = aScriptContext; mScriptContext = aScriptContext;
mWithCredentials = aWithCredentials;
if (aOwnerWindow) { if (aOwnerWindow) {
mOwner = aOwnerWindow->IsOuterWindow() ? mOwner = aOwnerWindow->IsOuterWindow() ?
aOwnerWindow->GetCurrentInnerWindow() : aOwnerWindow; aOwnerWindow->GetCurrentInnerWindow() : aOwnerWindow;
@ -302,8 +290,8 @@ nsEventSource::Init(nsIPrincipal* aPrincipal,
rv = os->AddObserver(this, DOM_WINDOW_THAWED_TOPIC, true); rv = os->AddObserver(this, DOM_WINDOW_THAWED_TOPIC, true);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsAutoString origin; nsXPIDLCString origin;
rv = nsContentUtils::GetUTFOrigin(srcURI, origin); rv = mPrincipal->GetOrigin(getter_Copies(origin));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString spec; nsCAutoString spec;
@ -388,31 +376,7 @@ nsEventSource::Initialize(nsISupports* aOwner,
nsCOMPtr<nsIPrincipal> principal = scriptPrincipal->GetPrincipal(); nsCOMPtr<nsIPrincipal> principal = scriptPrincipal->GetPrincipal();
NS_ENSURE_STATE(principal); NS_ENSURE_STATE(principal);
bool withCredentialsParam = false; return Init(principal, scriptContext, ownerWindow, urlParam);
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, "mozWithCredentials",
&hasProperty), NS_ERROR_FAILURE);
if (hasProperty) {
jsval withCredentialsVal;
NS_ENSURE_TRUE(JS_GetProperty(aContext, obj, "mozWithCredentials",
&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);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -922,13 +886,8 @@ nsEventSource::InitChannelAndRequestEventSource()
rv = SetupHttpChannel(); rv = SetupHttpChannel();
NS_ENSURE_SUCCESS(rv, rv); 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 // Start reading from the channel
return mHttpChannel->AsyncOpen(listener, nsnull); return mHttpChannel->AsyncOpen(this, nsnull);
} }
void void
@ -1214,6 +1173,7 @@ nsEventSource::CheckCanRequestSrc(nsIURI* aSrc)
return false; return false;
} }
bool isSameOrigin = false;
bool isValidURI = false; bool isValidURI = false;
bool isValidContentLoadPolicy = false; bool isValidContentLoadPolicy = false;
bool isValidProtocol = false; bool isValidProtocol = false;
@ -1221,6 +1181,8 @@ nsEventSource::CheckCanRequestSrc(nsIURI* aSrc)
nsCOMPtr<nsIURI> srcToTest = aSrc ? aSrc : mSrc.get(); nsCOMPtr<nsIURI> srcToTest = aSrc ? aSrc : mSrc.get();
NS_ENSURE_TRUE(srcToTest, false); NS_ENSURE_TRUE(srcToTest, false);
isSameOrigin = NS_SUCCEEDED(mPrincipal->CheckMayLoad(srcToTest, false));
PRUint32 aCheckURIFlags = PRUint32 aCheckURIFlags =
nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL | nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL |
nsIScriptSecurityManager::DISALLOW_SCRIPT; nsIScriptSecurityManager::DISALLOW_SCRIPT;
@ -1260,7 +1222,8 @@ nsEventSource::CheckCanRequestSrc(nsIURI* aSrc)
targetURIScheme.EqualsLiteral("https"); targetURIScheme.EqualsLiteral("https");
} }
return isValidURI && isValidContentLoadPolicy && isValidProtocol; return isSameOrigin && isValidURI && isValidContentLoadPolicy &&
isValidProtocol;
} }
// static // static
@ -1424,7 +1387,7 @@ nsEventSource::DispatchAllMessageEvents()
rv = messageEvent->InitMessageEvent(message->mEventName, rv = messageEvent->InitMessageEvent(message->mEventName,
false, false, false, false,
jsData, jsData,
mOrigin, NS_ConvertUTF8toUTF16(mOrigin),
message->mLastEventID, nsnull); message->mLastEventID, nsnull);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("Failed to init the message event!!!"); NS_WARNING("Failed to init the message event!!!");

Просмотреть файл

@ -215,7 +215,6 @@ protected:
bool mFrozen; bool mFrozen;
bool mErrorLoadOnRedirect; bool mErrorLoadOnRedirect;
bool mGoingToDispatchAllMessages; bool mGoingToDispatchAllMessages;
bool mWithCredentials;
// used while reading the input streams // used while reading the input streams
nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder; nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder;
@ -244,7 +243,7 @@ protected:
nsString mOriginalURL; nsString mOriginalURL;
nsCOMPtr<nsIPrincipal> mPrincipal; nsCOMPtr<nsIPrincipal> mPrincipal;
nsString mOrigin; nsCString mOrigin;
PRUint32 mRedirectFlags; PRUint32 mRedirectFlags;
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback; nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;

Просмотреть файл

@ -521,7 +521,6 @@ _TEST_FILES2 = \
test_bug692434.html \ test_bug692434.html \
file_bug692434.xml \ file_bug692434.xml \
test_bug693875.html \ test_bug693875.html \
file_restrictedEventSource.sjs \
$(NULL) $(NULL)
_CHROME_FILES = \ _CHROME_FILES = \

Просмотреть файл

@ -1,5 +1,4 @@
Access-Control-Allow-Origin: http://mochi.test:8888 Access-Control-Allow-Origin: http://localhost:8888
Access-Control-Allow-Credentials: true
Content-Type: text/event-stream Content-Type: text/event-stream
Cache-Control: no-cache, must-revalidate Cache-Control: no-cache, must-revalidate

Просмотреть файл

@ -1,44 +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 {
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");
}
}

Просмотреть файл

@ -32,36 +32,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
// -- // --
var gTestsHaveFinished = [];
function setTestHasFinished(test_id)
{
gTestsHaveFinished[test_id] = true;
for (var i=0; i < gTestsHaveFinished.length; ++i) {
if (!gTestsHaveFinished[i]) {
return;
}
}
SimpleTest.finish();
}
function runAllTests() { function runAllTests() {
// these tests run asynchronously, and they will take 8000 ms // these tests run asynchronously
var all_tests = [ doTest1(); // this will take 8000 ms
doTest1, doTest1_e, doTest2, doTest3, doTest3_b, doTest3_c, doTest3_d, doTest2(); // this will take 5000 ms
doTest3_e, doTest3_f, doTest3_g, doTest3_h, doTest4, doTest4_b, doTest3(); // this will take 1500 ms
doTest5, doTest5_b, doTest5_c, doTest5_e, doTest6, doTest7 doTest3_b(); // this will take 1500 ms
]; doTest3_c(); // this will take 1500 ms
for (var test_id=0; test_id < all_tests.length; ++test_id) { doTest3_d(); // this will take 1500 ms
gTestsHaveFinished[test_id] = false; doTest3_e(); // this will take 1500 ms
var fn = all_tests[test_id]; doTest3_f(); // this will take 1500 ms
fn(test_id); doTest3_g(); // this will take 1500 ms
setTimeout(new Function( doTest3_h(); // this will take 1500 ms
"if (!gTestsHaveFinished[" + test_id + "]) { " + doTest4(); // this will take 3000 ms
"ok(false, 'Test " + test_id + " took too long'); " + doTest4_b(); // this will take 3000 ms
"setTestHasFinished(" + test_id + "); " + doTest5(); // this will take 3000 ms
"}"), 15000); doTest5_b(); // this will take 3000 ms
} doTest6(); // this will take 2500 ms
doTest7(); // this will take 8000 ms
} }
function fn_onmessage(e) { function fn_onmessage(e) {
@ -82,16 +70,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
var domBranch; var domBranch;
var oldPrefVal; var oldPrefVal;
var gEventSourceObj1 = null, gEventSourceObj1_e; var gEventSourceObj1 = null;
var gEventSourceObj2 = null; var gEventSourceObj2 = null;
var gEventSourceObj3_a = null, gEventSourceObj3_b = null, var gEventSourceObj3_a = null, gEventSourceObj3_b = null,
gEventSourceObj3_c = null, gEventSourceObj3_d = null, gEventSourceObj3_c = null, gEventSourceObj3_d = null,
gEventSourceObj3_e = null, gEventSourceObj3_f = null, gEventSourceObj3_e = null, gEventSourceObj3_f = null,
gEventSourceObj3_g = null, gEventSourceObj3_h = null; gEventSourceObj3_g = null, gEventSourceObj3_h = null;
var gEventSourceObj4_a = null, gEventSourceObj4_b = null; var gEventSourceObj4_a = null, gEventSourceObj4_b = null;
var gEventSourceObj5_a = null, gEventSourceObj5_b = null, var gEventSourceObj5_a = null, gEventSourceObj5_b = null;
gEventSourceObj5_c = null, gEventSourceObj5_d = null,
gEventSourceObj5_e = null, gEventSourceObj5_f = null;
var gEventSourceObj6 = null; var gEventSourceObj6 = null;
var gEventSourceObj7 = null; var gEventSourceObj7 = null;
var stress_factor; // used in the setTimeouts in order to help var stress_factor; // used in the setTimeouts in order to help
@ -110,17 +96,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
// b) let its fn_onmessage, fn_event_listener_message, and fn_other_event_name functions listeners be hit four times each // 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) // c) the close method (we expect readyState == CLOSED)
// d) the close method (we expect no message events anymore) // 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"); gEventSourceObj1 = new EventSource("eventsource.resource");
ok(gEventSourceObj1.url == "http://mochi.test:8888/tests/content/base/test/eventsource.resource", "Test 1.a failed."); 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."); 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 = [];
gEventSourceObj1.hits['fn_onmessage'] = 0; gEventSourceObj1.hits['fn_onmessage'] = 0;
gEventSourceObj1.onmessage = fn_onmessage; gEventSourceObj1.onmessage = fn_onmessage;
@ -134,18 +119,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
bhits = hasBeenHitFor1And2(gEventSourceObj1, 4); bhits = hasBeenHitFor1And2(gEventSourceObj1, 4);
ok(bhits, "Test 1.b failed."); ok(bhits, "Test 1.b failed.");
doTest1_c(test_id); doTest1_c();
}, parseInt(6000*stress_factor)); }, parseInt(6000*stress_factor));
} }
function doTest1_c(test_id) { function doTest1_c() {
gEventSourceObj1.close(); gEventSourceObj1.close();
ok(gEventSourceObj1.readyState == 2, "Test 1.c failed."); 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_onmessage'] = 0;
gEventSourceObj1.hits['fn_event_listener_message'] = 0; gEventSourceObj1.hits['fn_event_listener_message'] = 0;
gEventSourceObj1.hits['fn_other_event_name'] = 0; gEventSourceObj1.hits['fn_other_event_name'] = 0;
@ -154,26 +139,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
bhits = hasBeenHitFor1And2(gEventSourceObj1, 1); bhits = hasBeenHitFor1And2(gEventSourceObj1, 1);
ok(!bhits, "Test 1.d failed."); ok(!bhits, "Test 1.d failed.");
gEventSourceObj1.close(); gEventSourceObj1.close();
setTestHasFinished(test_id);
}, parseInt(2000*stress_factor)); }, 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) // in order to test (2)
// a) set a eventsource that give the dom events messages // a) set a eventsource that give the dom events messages
// b) expect trusted events // b) expect trusted events
function doTest2(test_id) { function doTest2() {
var func = function(e) { var func = function(e) {
ok(e.isTrusted, "Test 2 failed"); ok(e.isTrusted, "Test 2 failed");
gEventSourceObj2.close(); gEventSourceObj2.close();
@ -182,9 +155,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
gEventSourceObj2 = new EventSource("eventsource.resource"); gEventSourceObj2 = new EventSource("eventsource.resource");
gEventSourceObj2.onmessage = func; gEventSourceObj2.onmessage = func;
setTimeout(function() { // just to clean... setTimeout(function(){ // just to clean...
gEventSourceObj2.close(); gEventSourceObj2.close();
setTestHasFinished(test_id);
}, parseInt(5000*stress_factor)); }, parseInt(5000*stress_factor));
} }
@ -198,7 +170,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
// g) eventsource with invalid NCName char in the event field test // g) eventsource with invalid NCName char in the event field test
// h) DNS error // h) DNS error
function doTest3(test_id) { function doTest3() {
gEventSourceObj3_a = new EventSource("http://example.org/tests/content/base/test/eventsource.resource"); gEventSourceObj3_a = new EventSource("http://example.org/tests/content/base/test/eventsource.resource");
gEventSourceObj3_a.onmessage = fn_onmessage; gEventSourceObj3_a.onmessage = fn_onmessage;
@ -208,11 +180,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj3_a.hits['fn_onmessage'] == 0, "Test 3.a failed"); ok(gEventSourceObj3_a.hits['fn_onmessage'] == 0, "Test 3.a failed");
gEventSourceObj3_a.close(); gEventSourceObj3_a.close();
setTestHasFinished(test_id);
}, parseInt(1500*stress_factor)); }, parseInt(1500*stress_factor));
} }
function doTest3_b(test_id) { function doTest3_b() {
var xhr = new XMLHttpRequest; var xhr = new XMLHttpRequest;
xhr.open("GET", "/dynamic/getMyDirectory.sjs", false); xhr.open("GET", "/dynamic/getMyDirectory.sjs", false);
xhr.send(); xhr.send();
@ -227,7 +198,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj3_b.hits['fn_onmessage'] == 0, "Test 3.b failed"); ok(gEventSourceObj3_b.hits['fn_onmessage'] == 0, "Test 3.b failed");
gEventSourceObj3_b.close(); gEventSourceObj3_b.close();
setTestHasFinished(test_id);
}, parseInt(1500*stress_factor)); }, parseInt(1500*stress_factor));
} }
@ -237,7 +207,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
"data: 1\n\n"; "data: 1\n\n";
} }
function doTest3_c(test_id) { function doTest3_c() {
gEventSourceObj3_c = new EventSource("javascript: return jsEvtSource()"); gEventSourceObj3_c = new EventSource("javascript: return jsEvtSource()");
gEventSourceObj3_c.onmessage = fn_onmessage; gEventSourceObj3_c.onmessage = fn_onmessage;
@ -247,11 +217,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj3_c.hits['fn_onmessage'] == 0, "Test 3.c failed"); ok(gEventSourceObj3_c.hits['fn_onmessage'] == 0, "Test 3.c failed");
gEventSourceObj3_c.close(); gEventSourceObj3_c.close();
setTestHasFinished(test_id);
}, parseInt(1500*stress_factor)); }, parseInt(1500*stress_factor));
} }
function doTest3_d(test_id) { function doTest3_d() {
gEventSourceObj3_d = new EventSource("badContentType.eventsource"); gEventSourceObj3_d = new EventSource("badContentType.eventsource");
gEventSourceObj3_d.onmessage = fn_onmessage; gEventSourceObj3_d.onmessage = fn_onmessage;
@ -261,11 +230,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj3_d.hits['fn_onmessage'] == 0, "Test 3.d failed"); ok(gEventSourceObj3_d.hits['fn_onmessage'] == 0, "Test 3.d failed");
gEventSourceObj3_d.close(); gEventSourceObj3_d.close();
setTestHasFinished(test_id);
}, parseInt(1500*stress_factor)); }, parseInt(1500*stress_factor));
} }
function doTest3_e(test_id) { function doTest3_e() {
gEventSourceObj3_e = new EventSource("badHTTPResponseCode.eventsource"); gEventSourceObj3_e = new EventSource("badHTTPResponseCode.eventsource");
gEventSourceObj3_e.onmessage = fn_onmessage; gEventSourceObj3_e.onmessage = fn_onmessage;
@ -275,11 +243,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj3_e.hits['fn_onmessage'] == 0, "Test 3.e failed"); ok(gEventSourceObj3_e.hits['fn_onmessage'] == 0, "Test 3.e failed");
gEventSourceObj3_e.close(); gEventSourceObj3_e.close();
setTestHasFinished(test_id);
}, parseInt(1500*stress_factor)); }, parseInt(1500*stress_factor));
} }
function doTest3_f(test_id) { function doTest3_f() {
gEventSourceObj3_f = new EventSource("badMessageEvent.eventsource"); gEventSourceObj3_f = new EventSource("badMessageEvent.eventsource");
gEventSourceObj3_f.onmessage = fn_onmessage; gEventSourceObj3_f.onmessage = fn_onmessage;
@ -289,7 +256,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj3_f.hits['fn_onmessage'] == 0, "Test 3.f failed"); ok(gEventSourceObj3_f.hits['fn_onmessage'] == 0, "Test 3.f failed");
gEventSourceObj3_f.close(); gEventSourceObj3_f.close();
setTestHasFinished(test_id);
}, parseInt(1500*stress_factor)); }, parseInt(1500*stress_factor));
} }
@ -297,7 +263,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
fnInvalidNCName.hits++; fnInvalidNCName.hits++;
} }
function doTest3_g(test_id) { function doTest3_g() {
gEventSourceObj3_g = new EventSource("badEventFieldName.eventsource"); gEventSourceObj3_g = new EventSource("badEventFieldName.eventsource");
fnInvalidNCName.hits = 0; fnInvalidNCName.hits = 0;
@ -306,11 +272,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(fnInvalidNCName.hits != 0, "Test 3.g failed"); ok(fnInvalidNCName.hits != 0, "Test 3.g failed");
gEventSourceObj3_g.close(); gEventSourceObj3_g.close();
setTestHasFinished(test_id);
}, parseInt(1500*stress_factor)); }, parseInt(1500*stress_factor));
} }
function doTest3_h(test_id) { function doTest3_h() {
gEventSourceObj3_h = new EventSource("http://hdfskjghsbg.jtiyoejowe.dafsgbhjab.com"); gEventSourceObj3_h = new EventSource("http://hdfskjghsbg.jtiyoejowe.dafsgbhjab.com");
gEventSourceObj3_h.onmessage = fn_onmessage; gEventSourceObj3_h.onmessage = fn_onmessage;
@ -320,7 +285,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj3_h.hits['fn_onmessage'] == 0, "Test 3.h failed"); ok(gEventSourceObj3_h.hits['fn_onmessage'] == 0, "Test 3.h failed");
gEventSourceObj3_h.close(); gEventSourceObj3_h.close();
setTestHasFinished(test_id);
}, parseInt(1500*stress_factor)); }, parseInt(1500*stress_factor));
} }
@ -345,7 +309,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
gEventSourceObj4_b.removeEventListener('message', fn_onmessage4_b, true); gEventSourceObj4_b.removeEventListener('message', fn_onmessage4_b, true);
} }
function doTest4(test_id) { function doTest4() {
gEventSourceObj4_a = new EventSource("forRemoval.resource"); gEventSourceObj4_a = new EventSource("forRemoval.resource");
gEventSourceObj4_a.lastData = 0; gEventSourceObj4_a.lastData = 0;
gEventSourceObj4_a.onmessage = fn_onmessage4_a; gEventSourceObj4_a.onmessage = fn_onmessage4_a;
@ -353,11 +317,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj4_a.lastData == 2, "Test 4.a failed"); ok(gEventSourceObj4_a.lastData == 2, "Test 4.a failed");
gEventSourceObj4_a.close(); gEventSourceObj4_a.close();
setTestHasFinished(test_id);
}, parseInt(3000*stress_factor)); }, parseInt(3000*stress_factor));
} }
function doTest4_b(test_id) function doTest4_b()
{ {
gEventSourceObj4_b = new EventSource("forRemoval.resource"); gEventSourceObj4_b = new EventSource("forRemoval.resource");
gEventSourceObj4_b.lastData = 0; gEventSourceObj4_b.lastData = 0;
@ -366,19 +329,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj4_b.lastData == 2, "Test 4.b failed"); ok(gEventSourceObj4_b.lastData == 2, "Test 4.b failed");
gEventSourceObj4_b.close(); gEventSourceObj4_b.close();
setTestHasFinished(test_id);
}, parseInt(3000*stress_factor)); }, parseInt(3000*stress_factor));
} }
// in order to test (5) // 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 // 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 mozWithCredentials is a getter
// f) valid access-control xsite request on a restricted page when the parameter mozWithCredentials is missing
function doTest5(test_id) function doTest5()
{ {
gEventSourceObj5_a = new EventSource("http://example.org/tests/content/base/test/accesscontrol.resource"); gEventSourceObj5_a = new EventSource("http://example.org/tests/content/base/test/accesscontrol.resource");
@ -387,13 +345,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
gEventSourceObj5_a.hits['fn_onmessage'] = 0; gEventSourceObj5_a.hits['fn_onmessage'] = 0;
setTimeout(function() { 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(); gEventSourceObj5_a.close();
setTestHasFinished(test_id);
}, parseInt(3000*stress_factor)); }, 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 = new EventSource("http://example.org/tests/content/base/test/invalid_accesscontrol.resource");
@ -404,117 +361,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
ok(gEventSourceObj5_b.hits['fn_onmessage'] == 0, "Test 5.b failed"); ok(gEventSourceObj5_b.hits['fn_onmessage'] == 0, "Test 5.b failed");
gEventSourceObj5_b.close(); gEventSourceObj5_b.close();
setTestHasFinished(test_id);
}, parseInt(3000*stress_factor)); }, parseInt(3000*stress_factor));
} }
function doTest5_c(test_id) function doTest6()
{
// 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",
{ mozWithCredentials: true } );
ok(gEventSourceObj5_c.mozWithCredentials, "Wrong mozWithCredentials 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.mozWithCredentials, "Wrong mozWithCredentials 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 mozWithCredentials() { return true; } } );
ok(gEventSourceObj5_e.mozWithCredentials, "Wrong mozWithCredentials 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(3000*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.mozWithCredentials, "Wrong mozWithCredentials 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)
{ {
gEventSourceObj6 = new EventSource("somedatas.resource"); gEventSourceObj6 = new EventSource("somedatas.resource");
var fn_somedata = function(e) { var fn_somedata = function(e) {
@ -537,11 +387,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
setTimeout(function() { setTimeout(function() {
gEventSourceObj6.close(); gEventSourceObj6.close();
setTestHasFinished(test_id);
}, parseInt(2500*stress_factor)); }, parseInt(2500*stress_factor));
} }
function doTest7(test_id) function doTest7()
{ {
gEventSourceObj7 = new EventSource("delayedServerEvents.sjs"); gEventSourceObj7 = new EventSource("delayedServerEvents.sjs");
gEventSourceObj7.msg_received = []; gEventSourceObj7.msg_received = [];
@ -559,11 +408,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
SpecialPowers.setBoolPref("dom.server-events.enabled", oldPrefVal); SpecialPowers.setBoolPref("dom.server-events.enabled", oldPrefVal);
document.getElementById('waitSpan').innerHTML = ''; document.getElementById('waitSpan').innerHTML = '';
setTestHasFinished(test_id); SimpleTest.finish();
}, parseInt(8000*stress_factor)); }, parseInt(8000*stress_factor));
} }
function doTest(test_id) function doTest()
{ {
oldPrefVal = SpecialPowers.getBoolPref("dom.server-events.enabled"); oldPrefVal = SpecialPowers.getBoolPref("dom.server-events.enabled");
SpecialPowers.setBoolPref("dom.server-events.enabled", true); SpecialPowers.setBoolPref("dom.server-events.enabled", true);