2014-05-15 22:34:44 -07:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<script>
|
|
|
|
|
|
|
|
var gData1 = "TEST_DATA_1:ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
var gData2 = "TEST_DATA_2:1234567890";
|
|
|
|
var gPaddingChar = '.';
|
|
|
|
var gPaddingSize = 10000;
|
|
|
|
var gPadding = "";
|
|
|
|
|
|
|
|
for (var i = 0; i < gPaddingSize; i++) {
|
|
|
|
gPadding += gPaddingChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendMessage(msg) {
|
|
|
|
alert(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ok(p, msg) {
|
|
|
|
if (p)
|
|
|
|
sendMessage("OK: " + msg);
|
|
|
|
else
|
|
|
|
sendMessage("KO: " + msg);
|
|
|
|
}
|
|
|
|
|
2014-07-17 19:46:25 -07:00
|
|
|
function is(a, b, msg) {
|
|
|
|
if (a == b)
|
|
|
|
sendMessage("OK: " + a + " == " + b + " - " + msg);
|
|
|
|
else
|
|
|
|
sendMessage("KO: " + a + " != " + b + " - " + msg);
|
|
|
|
}
|
|
|
|
|
2014-08-21 04:09:37 -07:00
|
|
|
function check_XHR(file, data_head, mapped, cb) {
|
2014-05-15 22:34:44 -07:00
|
|
|
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");
|
|
|
|
if (mapped) {
|
|
|
|
ok(ct.indexOf("mem-mapped") != -1, "Data is memory-mapped");
|
|
|
|
} else {
|
|
|
|
ok(ct.indexOf("mem-mapped") == -1, "Data is not memory-mapped");
|
|
|
|
}
|
|
|
|
var data = xhr.response;
|
|
|
|
ok(data, "Data is non-null");
|
|
|
|
var str = String.fromCharCode.apply(null, Uint8Array(data));
|
2014-07-17 19:46:25 -07:00
|
|
|
is(str.length, data_head.length + gPaddingSize, "Data size is correct");
|
|
|
|
is(str.slice(0, data_head.length), data_head, "Data head is correct");
|
2014-05-15 22:34:44 -07:00
|
|
|
ok(str.slice(data_head.length) == gPadding, "Data padding is correct");
|
|
|
|
cb();
|
|
|
|
} else {
|
|
|
|
ok(false, "XHR error: " + xhr.status + " - " + xhr.statusText + "\n");
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.send();
|
|
|
|
}
|
|
|
|
|
2014-08-21 04:09:37 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 22:34:44 -07:00
|
|
|
// Memory-mapped array buffer.
|
|
|
|
function test_mapped() {
|
2014-08-21 04:09:37 -07:00
|
|
|
check_XHR('data_1.txt', gData1, true, runTests);
|
2014-05-15 22:34:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2014-08-21 04:09:37 -07:00
|
|
|
check_XHR('data_2.txt', gData2, false, runTests);
|
2014-05-15 22:34:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var tests = [
|
2014-08-21 04:09:37 -07:00
|
|
|
test_simultaneous,
|
2014-05-15 22:34:44 -07:00
|
|
|
test_mapped,
|
|
|
|
test_non_mapped
|
|
|
|
];
|
|
|
|
|
|
|
|
function runTests() {
|
|
|
|
if (!tests.length) {
|
|
|
|
sendMessage("DONE");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var test = tests.shift();
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
function go() {
|
|
|
|
ok(true, "Launched app");
|
|
|
|
runTests();
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body onload="go();">
|
|
|
|
</body>
|
|
|
|
</html>
|