Bug 1048615 - Test case for multiple simultaneous access. r=fabrice

This commit is contained in:
Shian-Yow Wu 2014-08-21 19:09:37 +08:00
parent c62134df9b
commit a52f2ebbf3

View File

@ -30,7 +30,7 @@
sendMessage("KO: " + a + " != " + b + " - " + msg);
}
function testXHR(file, data_head, mapped, cb) {
function check_XHR(file, data_head, mapped, cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', file);
xhr.responseType = 'arraybuffer';
@ -60,19 +60,57 @@
xhr.send();
}
function check_XHR_mapped(file, cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', file);
xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = function xhrReadystatechange() {
if (xhr.readyState !== xhr.DONE) {
return;
}
if (xhr.status && xhr.status == 200) {
var ct = xhr.getResponseHeader("Content-Type");
cb(ct.indexOf("mem-mapped") != -1);
} else {
cb(false);
}
}
xhr.send();
}
// Reading multiple mapped array buffer by XHR simultaneously
function test_simultaneous() {
var count = 0;
var num = 100;
var succeed = true;
function cb(result) {
if (!result) {
succeed = false;
}
if (++count == num) {
ok(succeed, "Succeeded on simultaneous access test");
runTests();
}
}
for (var i = 0; i < num; i++) {
check_XHR_mapped('data_1.txt', cb);
}
}
// Memory-mapped array buffer.
function test_mapped() {
testXHR('data_1.txt', gData1, true, runTests);
check_XHR('data_1.txt', gData1, true, runTests);
}
// Non memory-mapped array buffer.
function test_non_mapped() {
// Make sure array buffer retrieved from compressed file in package is
// handled by memory allocation instead of memory mapping.
testXHR('data_2.txt', gData2, false, runTests);
check_XHR('data_2.txt', gData2, false, runTests);
}
var tests = [
test_simultaneous,
test_mapped,
test_non_mapped
];