2016-10-26 07:51:33 +03:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
var testGenerator = testSteps();
|
|
|
|
|
2016-12-01 12:11:32 +03:00
|
|
|
function* testSteps()
|
2016-10-26 07:51:33 +03:00
|
|
|
{
|
|
|
|
const name =
|
|
|
|
this.window ? window.location.pathname : "test_wasm_getAll.js";
|
|
|
|
|
2017-02-08 13:12:00 +03:00
|
|
|
const objectStoreName = "Wasm";
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-02-08 13:12:00 +03:00
|
|
|
const wasmData = [
|
|
|
|
{ key: 1, value: 42 },
|
|
|
|
{ key: 2, value: [null, null, null] },
|
|
|
|
{ key: 3, value: [null, null, null, null, null] }
|
|
|
|
];
|
2016-10-26 07:51:33 +03:00
|
|
|
|
|
|
|
if (!isWasmSupported()) {
|
|
|
|
finishTest();
|
2016-12-01 12:11:32 +03:00
|
|
|
return;
|
2016-10-26 07:51:33 +03:00
|
|
|
}
|
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
getWasmBinary("(module (func (result i32) (i32.const 1)))");
|
2016-10-26 07:51:33 +03:00
|
|
|
let binary = yield undefined;
|
2017-02-08 13:12:00 +03:00
|
|
|
wasmData[1].value[0] = getWasmModule(binary);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
getWasmBinary("(module (func (result i32) (i32.const 2)))");
|
2016-10-26 07:51:33 +03:00
|
|
|
binary = yield undefined;
|
2017-02-08 13:12:00 +03:00
|
|
|
wasmData[1].value[1] = getWasmModule(binary);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
getWasmBinary("(module (func (result i32) (i32.const 3)))");
|
2016-10-26 07:51:33 +03:00
|
|
|
binary = yield undefined;
|
2017-02-08 13:12:00 +03:00
|
|
|
wasmData[1].value[2] = getWasmModule(binary);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
getWasmBinary("(module (func (result i32) (i32.const 4)))");
|
2016-10-26 07:51:33 +03:00
|
|
|
binary = yield undefined;
|
2017-02-08 13:12:00 +03:00
|
|
|
wasmData[2].value[0] = getWasmModule(binary);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
getWasmBinary("(module (func (result i32) (i32.const 5)))");
|
2016-10-26 07:51:33 +03:00
|
|
|
binary = yield undefined;
|
2017-02-08 13:12:00 +03:00
|
|
|
wasmData[2].value[1] = getWasmModule(binary);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
getWasmBinary("(module (func (result i32) (i32.const 6)))");
|
2016-10-26 07:51:33 +03:00
|
|
|
binary = yield undefined;
|
2017-02-08 13:12:00 +03:00
|
|
|
wasmData[2].value[2] = getWasmModule(binary);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
getWasmBinary("(module (func (result i32) (i32.const 7)))");
|
2016-10-26 07:51:33 +03:00
|
|
|
binary = yield undefined;
|
2017-02-08 13:12:00 +03:00
|
|
|
wasmData[2].value[3] = getWasmModule(binary);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-05-03 19:30:48 +03:00
|
|
|
getWasmBinary("(module (func (result i32) (i32.const 8)))");
|
2016-10-26 07:51:33 +03:00
|
|
|
binary = yield undefined;
|
2017-02-08 13:12:00 +03:00
|
|
|
wasmData[2].value[4] = getWasmModule(binary);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
|
|
|
let request = indexedDB.open(name, 1);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = continueToNextStepSync;
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
|
|
|
yield undefined;
|
|
|
|
|
|
|
|
// upgradeneeded
|
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
request.onsuccess = continueToNextStepSync;
|
|
|
|
|
|
|
|
info("Creating objectStore");
|
|
|
|
|
2017-02-08 13:12:00 +03:00
|
|
|
request.result.createObjectStore(objectStoreName);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
|
|
|
yield undefined;
|
|
|
|
|
|
|
|
// success
|
|
|
|
let db = request.result;
|
|
|
|
db.onerror = errorHandler;
|
|
|
|
|
|
|
|
info("Storing values");
|
|
|
|
|
2017-02-08 13:12:00 +03:00
|
|
|
let objectStore = db.transaction([objectStoreName], "readwrite")
|
|
|
|
.objectStore(objectStoreName);
|
2016-10-26 07:51:33 +03:00
|
|
|
let addedCount = 0;
|
2017-02-08 13:12:00 +03:00
|
|
|
for (let i in wasmData) {
|
|
|
|
request = objectStore.add(wasmData[i].value, wasmData[i].key);
|
2016-10-26 07:51:33 +03:00
|
|
|
request.onsuccess = function(event) {
|
2017-02-08 13:12:00 +03:00
|
|
|
if (++addedCount == wasmData.length) {
|
2016-10-26 07:51:33 +03:00
|
|
|
continueToNextStep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yield undefined;
|
|
|
|
|
|
|
|
info("Getting values");
|
|
|
|
|
2017-02-08 13:12:00 +03:00
|
|
|
request = db.transaction(objectStoreName)
|
|
|
|
.objectStore(objectStoreName)
|
|
|
|
.getAll();
|
2016-10-26 07:51:33 +03:00
|
|
|
request.onsuccess = continueToNextStepSync;
|
|
|
|
yield undefined;
|
|
|
|
|
2017-02-08 13:12:00 +03:00
|
|
|
info("Verifying values");
|
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
// Can't call yield inside of the verify function.
|
2017-02-08 13:12:00 +03:00
|
|
|
let modulesToProcess = [];
|
|
|
|
|
|
|
|
function verifyArray(array1, array2) {
|
|
|
|
is(array1 instanceof Array, true, "Got an array object");
|
|
|
|
is(array1.length, array2.length, "Same length");
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyData(data1, data2) {
|
|
|
|
if (data2 instanceof Array) {
|
|
|
|
verifyArray(data1, data2);
|
|
|
|
for (let i in data2) {
|
|
|
|
verifyData(data1[i], data2[i]);
|
2016-10-26 07:51:33 +03:00
|
|
|
}
|
2017-02-08 13:12:00 +03:00
|
|
|
} else if (data2 instanceof WebAssembly.Module) {
|
|
|
|
modulesToProcess.push({ module1: data1, module2: data2 });
|
2016-10-26 07:51:33 +03:00
|
|
|
} else {
|
2017-02-08 13:12:00 +03:00
|
|
|
is(data1, data2, "Same value");
|
2016-10-26 07:51:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-08 13:12:00 +03:00
|
|
|
verifyArray(request.result, wasmData);
|
|
|
|
for (let i in wasmData) {
|
|
|
|
verifyData(request.result[i], wasmData[i].value);
|
|
|
|
}
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2017-02-08 13:12:00 +03:00
|
|
|
for (let moduleToProcess of modulesToProcess) {
|
|
|
|
verifyWasmModule(moduleToProcess.module1, moduleToProcess.module2);
|
2016-10-26 07:51:33 +03:00
|
|
|
yield undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
finishTest();
|
|
|
|
}
|