Bug 901343 - Tests that use createSystemXHR are failing on b2g mochitest. r=sicking

This commit is contained in:
Martijn Wargers 2013-10-12 02:18:34 +02:00
parent 176c547fd6
commit e6a1d72158
10 changed files with 75 additions and 63 deletions

View File

@ -89,9 +89,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
e.target.hits['fn_other_event_name']++; e.target.hits['fn_other_event_name']++;
} }
var domBranch;
var oldPrefVal;
var gEventSourceObj1 = null, gEventSourceObj1_e, gEventSourceObj1_f; var gEventSourceObj1 = null, gEventSourceObj1_e, gEventSourceObj1_f;
var gEventSourceObj2 = null; var gEventSourceObj2 = null;
var gEventSourceObj3_a = null, gEventSourceObj3_b = null, var gEventSourceObj3_a = null, gEventSourceObj3_b = null,
@ -250,6 +247,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
} }
function doTest3_b(test_id) { function doTest3_b(test_id) {
// currently no support yet for local files for b2g/Android mochitest, see bug 838726
if (navigator.appVersion.indexOf("Android") != -1 || SpecialPowers.Services.appinfo.name == "B2G") {
setTestHasFinished(test_id);
return;
}
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();
@ -462,7 +465,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
function doTest5_c(test_id) function doTest5_c(test_id)
{ {
// credentials using the auth cache and cookies // credentials using the auth cache and cookies
var xhr = SpecialPowers.createSystemXHR(); var xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
xhr.withCredentials = true; xhr.withCredentials = true;
// also, test mixed mode UI // also, test mixed mode UI
xhr.open("GET", "https://example.com/tests/content/base/test/file_restrictedEventSource.sjs?test=user1_xhr", true, "user 1", "password 1"); xhr.open("GET", "https://example.com/tests/content/base/test/file_restrictedEventSource.sjs?test=user1_xhr", true, "user 1", "password 1");
@ -491,7 +494,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
function doTest5_d(test_id) function doTest5_d(test_id)
{ {
var xhr = SpecialPowers.createSystemXHR(); var xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
xhr.withCredentials = true; xhr.withCredentials = true;
xhr.open("GET", "https://example.com/tests/content/base/test/file_restrictedEventSource.sjs?test=user2_xhr", true, "user 2", "password 2"); xhr.open("GET", "https://example.com/tests/content/base/test/file_restrictedEventSource.sjs?test=user2_xhr", true, "user 2", "password 2");
xhr.send(); xhr.send();
@ -519,7 +522,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
function doTest5_e(test_id) function doTest5_e(test_id)
{ {
// credentials using the auth cache and cookies // credentials using the auth cache and cookies
var xhr = SpecialPowers.createSystemXHR(); var xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
xhr.withCredentials = true; xhr.withCredentials = true;
xhr.open("GET", "http://example.org/tests/content/base/test/file_restrictedEventSource.sjs?test=user1_xhr", true, "user 1", "password 1"); xhr.open("GET", "http://example.org/tests/content/base/test/file_restrictedEventSource.sjs?test=user1_xhr", true, "user 1", "password 1");
xhr.send(); xhr.send();
@ -547,7 +550,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
function doTest5_f(test_id) function doTest5_f(test_id)
{ {
var xhr = SpecialPowers.createSystemXHR(); var xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
xhr.withCredentials = true; xhr.withCredentials = true;
xhr.open("GET", "http://example.org/tests/content/base/test/file_restrictedEventSource.sjs?test=user2_xhr", true, "user 2", "password 2"); xhr.open("GET", "http://example.org/tests/content/base/test/file_restrictedEventSource.sjs?test=user2_xhr", true, "user 2", "password 2");
xhr.send(); xhr.send();
@ -614,7 +617,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
gEventSourceObj7.msg_received[1] == "delayed1" && gEventSourceObj7.msg_received[1] == "delayed1" &&
gEventSourceObj7.msg_received[2] == "delayed2", "Test 7 failed"); gEventSourceObj7.msg_received[2] == "delayed2", "Test 7 failed");
SpecialPowers.setBoolPref("dom.server-events.enabled", oldPrefVal);
document.getElementById('waitSpan').innerHTML = ''; document.getElementById('waitSpan').innerHTML = '';
setTestHasFinished(test_id); setTestHasFinished(test_id);
}, parseInt(8000*stress_factor)); }, parseInt(8000*stress_factor));
@ -623,13 +625,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338583
function doTest() function doTest()
{ {
// Allow all cookies, then run the actual test // Allow all cookies, then run the actual test
SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0]]}, doTestCallback); SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0], ["dom.server-events.enabled", true]]}, function() { SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], doTestCallback);});
} }
function doTestCallback() function doTestCallback()
{ {
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 // we get a good stress_factor by testing 10 setTimeouts and some float
// arithmetic taking my machine as stress_factor==1 (time=589) // arithmetic taking my machine as stress_factor==1 (time=589)

View File

@ -21,12 +21,21 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=426308
const SJS_URL = "http://example.org:80/tests/content/base/test/bug426308-redirect.sjs"; const SJS_URL = "http://example.org:80/tests/content/base/test/bug426308-redirect.sjs";
var req = SpecialPowers.createSystemXHR(); function startTest() {
req.open("GET", SJS_URL + "?" + window.location.href, false); var req = new XMLHttpRequest({mozAnon: false, mozSystem: true});
req.send(null); req.open("GET", SJS_URL + "?" + window.location.href, false);
req.send(null);
is(req.status, 200, "Redirect did not happen"); is(req.status, 200, "Redirect did not happen");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], startTest);
});
</script> </script>
</pre> </pre>
</body> </body>

View File

@ -51,7 +51,7 @@ function createDoc() {
function xhrDoc(idx) { function xhrDoc(idx) {
return function() { return function() {
// Defy same-origin restrictions! // Defy same-origin restrictions!
var xhr = SpecialPowers.createSystemXHR(); var xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
xhr.open("GET", docSources[idx], false); xhr.open("GET", docSources[idx], false);
xhr.send(); xhr.send();
return xhr.responseXML; return xhr.responseXML;
@ -87,6 +87,10 @@ function doTest(idx) {
} }
addLoadEvent(function() { addLoadEvent(function() {
SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], startTest);
});
function startTest() {
// sanity check // sanity check
isnot("", null, "Shouldn't be equal!"); isnot("", null, "Shouldn't be equal!");
@ -104,7 +108,7 @@ addLoadEvent(function() {
xhr.abort(); xhr.abort();
SimpleTest.finish(); SimpleTest.finish();
}); };

View File

@ -19,7 +19,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=804395
<script type="application/javascript"> <script type="application/javascript">
function test200() { function test200() {
var xhr = SpecialPowers.createSystemXHR(); var xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.bar', true); xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.bar', true);
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState == 4) { if (xhr.readyState == 4) {
@ -31,7 +31,7 @@ function test200() {
} }
function test404() { function test404() {
var xhr = SpecialPowers.createSystemXHR(); var xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.do_not_exist', true); xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.do_not_exist', true);
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState == 4) { if (xhr.readyState == 4) {
@ -43,7 +43,7 @@ function test404() {
} }
function test0() { function test0() {
var xhr = SpecialPowers.createSystemXHR(); var xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.bar', true); xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.bar', true);
ok(xhr.status == 0, "Not Sent request must have status 0"); ok(xhr.status == 0, "Not Sent request must have status 0");
runTests(); runTests();
@ -61,9 +61,11 @@ function runTests() {
} }
/** Test for Bug 804395 **/ /** Test for Bug 804395 **/
runTests();
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], runTests);
});
</script> </script>
</pre> </pre>
</body> </body>

View File

@ -49,37 +49,47 @@ var headers = [
]; ];
var i, request; var i, request;
// Try setting headers in unprivileged context function startTest() {
request = new XMLHttpRequest(); // Try setting headers in unprivileged context
request.open("GET", window.location.href); request = new XMLHttpRequest();
for (i = 0; i < headers.length; i++) request.open("GET", window.location.href);
request.setRequestHeader(headers[i], "test" + i); for (i = 0; i < headers.length; i++)
request.setRequestHeader(headers[i], "test" + i);
// Read out headers // Read out headers
var channel = SpecialPowers.wrap(request).channel.QueryInterface(SpecialPowers.Ci.nsIHttpChannel); var channel = SpecialPowers.wrap(request).channel.QueryInterface(SpecialPowers.Ci.nsIHttpChannel);
for (i = 0; i < headers.length; i++) { for (i = 0; i < headers.length; i++) {
// Retrieving Content-Length will throw an exception // Retrieving Content-Length will throw an exception
var value = null; var value = null;
try { try {
value = channel.getRequestHeader(headers[i]); value = channel.getRequestHeader(headers[i]);
}
catch(e) {}
isnot(value, "test" + i, "Setting " + headers[i] + " header in unprivileged context");
} }
catch(e) {}
isnot(value, "test" + i, "Setting " + headers[i] + " header in unprivileged context"); // Try setting headers in privileged context
request = new XMLHttpRequest({mozAnon: false, mozSystem: true});
request.open("GET", window.location.href);
for (i = 0; i < headers.length; i++)
request.setRequestHeader(headers[i], "test" + i);
// Read out headers
var channel = SpecialPowers.wrap(request).channel.QueryInterface(SpecialPowers.Ci.nsIHttpChannel);
for (i = 0; i < headers.length; i++) {
var value = channel.getRequestHeader(headers[i]);
is(value, "test" + i, "Setting " + headers[i] + " header in privileged context");
}
SimpleTest.finish();
} }
// Try setting headers in privileged context SimpleTest.waitForExplicitFinish();
request = SpecialPowers.createSystemXHR();
request.open("GET", window.location.href);
for (i = 0; i < headers.length; i++)
request.setRequestHeader(headers[i], "test" + i);
// Read out headers addLoadEvent(function() {
var channel = request.channel.QueryInterface(SpecialPowers.Ci.nsIHttpChannel); SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], startTest);
for (i = 0; i < headers.length; i++) { });
var value = channel.getRequestHeader(headers[i]);
is(value, "test" + i, "Setting " + headers[i] + " header in privileged context");
}
</script> </script>
</pre> </pre>
</body> </body>

View File

@ -36,7 +36,6 @@
"content/base/test/test_websocket_hello.html": "", "content/base/test/test_websocket_hello.html": "",
"content/base/test/test_x-frame-options.html": "", "content/base/test/test_x-frame-options.html": "",
"content/base/test/test_xhr_abort_after_load.html": "", "content/base/test/test_xhr_abort_after_load.html": "",
"content/base/test/test_xhr_forbidden_headers.html": "",
"content/base/test/test_xhr_progressevents.html": "", "content/base/test/test_xhr_progressevents.html": "",
"content/base/test/websocket_hybi/test_receive-arraybuffer.html": "", "content/base/test/websocket_hybi/test_receive-arraybuffer.html": "",
"content/base/test/websocket_hybi/test_receive-blob.html": "", "content/base/test/websocket_hybi/test_receive-blob.html": "",

View File

@ -37,7 +37,6 @@
"content/base/test/test_websocket_hello.html": "", "content/base/test/test_websocket_hello.html": "",
"content/base/test/test_x-frame-options.html": "", "content/base/test/test_x-frame-options.html": "",
"content/base/test/test_xhr_abort_after_load.html": "", "content/base/test/test_xhr_abort_after_load.html": "",
"content/base/test/test_xhr_forbidden_headers.html": "",
"content/base/test/test_xhr_progressevents.html": "", "content/base/test/test_xhr_progressevents.html": "",
"content/base/test/websocket_hybi/test_receive-arraybuffer.html": "", "content/base/test/websocket_hybi/test_receive-arraybuffer.html": "",
"content/base/test/websocket_hybi/test_receive-blob.html": "", "content/base/test/websocket_hybi/test_receive-blob.html": "",

View File

@ -92,8 +92,7 @@
"content/base/test/test_bug431701.html":"xmlhttprequest causes crash, bug 902271", "content/base/test/test_bug431701.html":"xmlhttprequest causes crash, bug 902271",
"content/base/test/test_bug422537.html":"xmlhttprequest causes crash, bug 902271", "content/base/test/test_bug422537.html":"xmlhttprequest causes crash, bug 902271",
"content/base/test/test_bug338583.html":"43 total - bug 901343, specialpowers.wrap issue createsystemxhr", "content/base/test/test_bug338583.html":"https not working, bug 907770",
"content/base/test/test_bug804395.html":"bug 901343, specialpowers.wrap issue createsystemxhr",
"content/base/test/test_bug475156.html":"36 total - bug 902611", "content/base/test/test_bug475156.html":"36 total - bug 902611",
"content/base/test/test_bug422403-1.html":"bug 901343, specialpowers.wrap issue [nsIChannel.open]", "content/base/test/test_bug422403-1.html":"bug 901343, specialpowers.wrap issue [nsIChannel.open]",
@ -249,7 +248,6 @@
"content/base/test/test_bug422403-2.xhtml":"", "content/base/test/test_bug422403-2.xhtml":"",
"content/base/test/test_bug424359-1.html":"", "content/base/test/test_bug424359-1.html":"",
"content/base/test/test_bug424359-2.html":"", "content/base/test/test_bug424359-2.html":"",
"content/base/test/test_bug426308.html":"",
"content/base/test/test_mixed_content_blocker_bug803225.html":"", "content/base/test/test_mixed_content_blocker_bug803225.html":"",
"content/html/document/test/test_non-ascii-cookie.html":"", "content/html/document/test/test_non-ascii-cookie.html":"",
@ -321,7 +319,7 @@
"dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"", "dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"",
"dom/network/tests/test_networkstats_basics.html":"Will be fixed in bug 858005", "dom/network/tests/test_networkstats_basics.html":"Will be fixed in bug 858005",
"dom/permission/tests/test_permission_basics.html":"Bug 907770", "dom/permission/tests/test_permission_basics.html":"https not working, bug 907770",
"dom/tests/mochitest/bugs/test_bug335976.xhtml":"", "dom/tests/mochitest/bugs/test_bug335976.xhtml":"",
"dom/tests/mochitest/bugs/test_bug369306.html":"test timed out, can't focus back from popup window to opener?", "dom/tests/mochitest/bugs/test_bug369306.html":"test timed out, can't focus back from popup window to opener?",

View File

@ -78,11 +78,6 @@ function starttest(){
// Test a DOMWindowUtils method and property // Test a DOMWindowUtils method and property
is(SpecialPowers.DOMWindowUtils.getClassName(window), "Proxy"); is(SpecialPowers.DOMWindowUtils.getClassName(window), "Proxy");
is(SpecialPowers.DOMWindowUtils.docCharsetIsForced, false); is(SpecialPowers.DOMWindowUtils.docCharsetIsForced, false);
//Run the createSystemXHR method
var xhr = SpecialPowers.createSystemXHR();
ok(xhr, "createSystemXHR should not return null");
is(xhr.readyState, XMLHttpRequest.UNSENT, "createSystemXHR should create an unsent XMLHttpRequest object");
// QueryInterface and getPrivilegedProps tests // QueryInterface and getPrivilegedProps tests
is(SpecialPowers.can_QI(SpecialPowers), false); is(SpecialPowers.can_QI(SpecialPowers), false);
@ -99,7 +94,7 @@ function starttest(){
// Try some basic stuff with XHR. // Try some basic stuff with XHR.
var xhr2 = SpecialPowers.Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(SpecialPowers.Ci.nsIXMLHttpRequest); var xhr2 = SpecialPowers.Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(SpecialPowers.Ci.nsIXMLHttpRequest);
is(xhr.readyState, XMLHttpRequest.UNSENT, "Should be able to get props off privileged objects"); is(xhr2.readyState, XMLHttpRequest.UNSENT, "Should be able to get props off privileged objects");
var testURI = SpecialPowers.Cc['@mozilla.org/network/standard-url;1'] var testURI = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
.createInstance(SpecialPowers.Ci.nsIURI); .createInstance(SpecialPowers.Ci.nsIURI);
testURI.spec = "http://www.foobar.org/"; testURI.spec = "http://www.foobar.org/";

View File

@ -1178,10 +1178,6 @@ SpecialPowersAPI.prototype = {
this._getMUDV(window).stopEmulatingMedium(); this._getMUDV(window).stopEmulatingMedium();
}, },
createSystemXHR: function() {
return this.wrap(Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest));
},
snapshotWindowWithOptions: function (win, rect, bgcolor, options) { snapshotWindowWithOptions: function (win, rect, bgcolor, options) {
var el = this.window.get().document.createElementNS("http://www.w3.org/1999/xhtml", "canvas"); var el = this.window.get().document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
if (rect === undefined) { if (rect === undefined) {