2018-08-20 15:33:10 +03:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
var disableWorkerTest = "SimpleDB doesn't work in workers yet";
|
|
|
|
|
2018-09-28 00:25:16 +03:00
|
|
|
async function testSteps()
|
2018-08-20 15:33:10 +03:00
|
|
|
{
|
|
|
|
const name = "data";
|
|
|
|
const bufferSize = 100;
|
|
|
|
|
|
|
|
let database = getSimpleDatabase();
|
|
|
|
|
|
|
|
let request = database.open(name);
|
2018-09-28 00:25:16 +03:00
|
|
|
await requestFinished(request);
|
2018-08-20 15:33:10 +03:00
|
|
|
|
|
|
|
let buffer1 = getRandomBuffer(bufferSize);
|
|
|
|
|
|
|
|
request = database.write(buffer1);
|
2018-09-28 00:25:16 +03:00
|
|
|
await requestFinished(request);
|
2018-08-20 15:33:10 +03:00
|
|
|
|
|
|
|
request = database.seek(0);
|
2018-09-28 00:25:16 +03:00
|
|
|
await requestFinished(request);
|
2018-08-20 15:33:10 +03:00
|
|
|
|
|
|
|
request = database.read(bufferSize);
|
2018-09-28 00:25:16 +03:00
|
|
|
let result = await requestFinished(request);
|
2018-08-20 15:33:10 +03:00
|
|
|
|
|
|
|
let buffer2 = result.getAsArrayBuffer();
|
|
|
|
|
|
|
|
ok(compareBuffers(buffer1, buffer2), "Buffers equal.");
|
|
|
|
|
|
|
|
let database2 = getSimpleDatabase();
|
|
|
|
|
|
|
|
try {
|
|
|
|
request = database2.open(name);
|
2018-09-28 00:25:16 +03:00
|
|
|
await requestFinished(request);
|
2018-08-20 15:33:10 +03:00
|
|
|
ok(false, "Should have thrown!");
|
|
|
|
} catch(ex) {
|
|
|
|
ok(request.resultCode == NS_ERROR_STORAGE_BUSY, "Good result code.");
|
|
|
|
}
|
|
|
|
|
|
|
|
request = database.close();
|
2018-09-28 00:25:16 +03:00
|
|
|
await requestFinished(request);
|
2018-08-20 15:33:10 +03:00
|
|
|
|
|
|
|
request = database2.open(name);
|
2018-09-28 00:25:16 +03:00
|
|
|
await requestFinished(request);
|
2018-08-20 15:33:10 +03:00
|
|
|
|
|
|
|
request = database2.close();
|
2018-09-28 00:25:16 +03:00
|
|
|
await requestFinished(request);
|
2018-08-20 15:33:10 +03:00
|
|
|
}
|