mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
138 lines
3.3 KiB
HTML
138 lines
3.3 KiB
HTML
<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);
|
|
}
|
|
|
|
function is(a, b, msg) {
|
|
if (a == b)
|
|
sendMessage("OK: " + a + " == " + b + " - " + msg);
|
|
else
|
|
sendMessage("KO: " + a + " != " + b + " - " + msg);
|
|
}
|
|
|
|
function check_XHR(file, data_head, mapped, 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");
|
|
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));
|
|
is(str.length, data_head.length + gPaddingSize, "Data size is correct");
|
|
is(str.slice(0, data_head.length), data_head, "Data head is correct");
|
|
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();
|
|
}
|
|
|
|
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() {
|
|
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.
|
|
check_XHR('data_2.txt', gData2, false, runTests);
|
|
}
|
|
|
|
var tests = [
|
|
test_simultaneous,
|
|
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>
|