Bug 648485 - Second try to fix intermittent failure in content/base/test/test_bug482935.html. r=ehsan

This commit is contained in:
Mounir Lamouri 2011-04-12 15:50:25 -07:00
Родитель d632db752b
Коммит 2ed08c1c21
1 изменённых файлов: 46 добавлений и 36 удалений

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

@ -29,13 +29,19 @@ function testCancelInPhase4() {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function(e) { xhr.addEventListener("readystatechange", function(e) {
if (xhr.readyState >= 4) { if (xhr.readyState >= 4) {
xhr.abort(); xhr.addEventListener("abort", function() {
SimpleTest.executeSoon(function() { setTimeout(function() {
// This request was cancelled, so the responseText should be empty string // This request was cancelled, so the responseText should be empty string
is(xhr.responseText, "", "Expected empty response to cancelled request"); is(xhr.responseText, "", "Expected empty response to cancelled request");
// Second request - should be found in cache // Second request - should be found in cache
var xhr2 = new XMLHttpRequest(); var xhr2 = new XMLHttpRequest();
xhr2.addEventListener("load", function() {
is(xhr2.responseText, "0", "Received fresh value for second request");
testCancelBeforePhase4();
}, false);
xhr2.open("GET", url, false); // note : synch-request xhr2.open("GET", url, false); // note : synch-request
xhr2.setRequestHeader("X-Request", "1", false); xhr2.setRequestHeader("X-Request", "1", false);
@ -43,11 +49,10 @@ function testCancelInPhase4() {
catch(e) { catch(e) {
is(xhr2.status, "200", "Exception!"); is(xhr2.status, "200", "Exception!");
} }
}, 0);
}, false);
is(xhr2.responseText, "0", "Received fresh value for second request"); xhr.abort();
testCancelBeforePhase4();
});
} }
}, false); }, false);
@ -69,13 +74,19 @@ function testCancelBeforePhase4() {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function(e) { xhr.addEventListener("readystatechange", function(e) {
if (xhr.readyState == 3) { if (xhr.readyState == 3) {
xhr.abort(); xhr.addEventListener("abort", function() {
SimpleTest.executeSoon(function() { setTimeout(function() {
// This request was cancelled, so the responseText should be empty string // This request was cancelled, so the responseText should be empty string
is(xhr.responseText, "", "Expected empty response to cancelled request"); is(xhr.responseText, "", "Expected empty response to cancelled request");
// Second request - should be found in cache // Second request - should be found in cache
var xhr2 = new XMLHttpRequest(); var xhr2 = new XMLHttpRequest();
xhr2.addEventListener("load", function() {
is(xhr2.responseText, "1", "Received cached value for second request");
SimpleTest.finish();
}, false);
xhr2.open("GET", url, false); // note : synch-request xhr2.open("GET", url, false); // note : synch-request
xhr2.setRequestHeader("X-Request", "1", false); xhr2.setRequestHeader("X-Request", "1", false);
@ -83,11 +94,10 @@ function testCancelBeforePhase4() {
catch(e) { catch(e) {
is(xhr2.status, "200", "Exception!"); is(xhr2.status, "200", "Exception!");
} }
}, 0);
}, false);
is(xhr2.responseText, "1", "Received cached value for second request"); xhr.abort();
SimpleTest.finish();
});
} }
}, false); }, false);