зеркало из https://github.com/mozilla/gecko-dev.git
71 строка
2.0 KiB
HTML
71 строка
2.0 KiB
HTML
<!--
|
|
Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
-->
|
|
<html>
|
|
<head>
|
|
<title>File Handle Test</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
<script type="text/javascript;version=1.7">
|
|
function testSteps()
|
|
{
|
|
var testBuffer = getRandomBuffer(100000);
|
|
|
|
for each (let fileStorage in fileStorages) {
|
|
let request = getFileHandle(fileStorage.key, "test.txt");
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
let event = yield;
|
|
|
|
let fileHandle = event.target.result;
|
|
fileHandle.onerror = errorHandler;
|
|
|
|
let lockedFile = fileHandle.open("readwrite");
|
|
|
|
let sum = 0;
|
|
|
|
request = lockedFile.write(testBuffer);
|
|
request.onprogress = function(event) {
|
|
let loaded = event.loaded;
|
|
let total = event.total;
|
|
ok(loaded >= 0 && loaded <= total, "Correct loaded progress");
|
|
is(total, testBuffer.byteLength, "Correct total progress");
|
|
sum += event.loaded - sum;
|
|
}
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield;
|
|
|
|
is(sum, testBuffer.byteLength, "Correct loaded progress sum");
|
|
|
|
sum = 0;
|
|
|
|
lockedFile.location = 0;
|
|
request = lockedFile.readAsArrayBuffer(testBuffer.byteLength);
|
|
request.onprogress = function(event) {
|
|
let loaded = event.loaded;
|
|
let total = event.total;
|
|
ok(loaded >= 0 && loaded <= total, "Correct loaded progress");
|
|
is(total, testBuffer.byteLength, "Correct total progress");
|
|
sum += event.loaded - sum;
|
|
}
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield;
|
|
|
|
is(sum, testBuffer.byteLength, "Correct loaded progress sum");
|
|
}
|
|
|
|
finishTest();
|
|
yield;
|
|
}
|
|
</script>
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
</html>
|