test_wasm_cursors.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. var testGenerator = testSteps();
  6. function testSteps()
  7. {
  8. const name =
  9. this.window ? window.location.pathname : "test_wasm_cursors.js";
  10. const objectStoreName = "Wasm";
  11. const wasmData = { key: 1, value: null };
  12. if (!isWasmSupported()) {
  13. finishTest();
  14. yield undefined;
  15. }
  16. getWasmBinary('(module (func (nop)))');
  17. let binary = yield undefined;
  18. wasmData.value = getWasmModule(binary);
  19. info("Opening database");
  20. let request = indexedDB.open(name);
  21. request.onerror = errorHandler;
  22. request.onupgradeneeded = continueToNextStepSync;
  23. request.onsuccess = unexpectedSuccessHandler;
  24. yield undefined;
  25. // upgradeneeded
  26. request.onupgradeneeded = unexpectedSuccessHandler;
  27. request.onsuccess = continueToNextStepSync;
  28. info("Creating objectStore");
  29. request.result.createObjectStore(objectStoreName);
  30. yield undefined;
  31. // success
  32. let db = request.result;
  33. db.onerror = errorHandler;
  34. info("Storing wasm");
  35. let objectStore = db.transaction([objectStoreName], "readwrite")
  36. .objectStore(objectStoreName);
  37. request = objectStore.add(wasmData.value, wasmData.key);
  38. request.onsuccess = continueToNextStepSync;
  39. yield undefined;
  40. is(request.result, wasmData.key, "Got correct key");
  41. info("Opening cursor");
  42. request = objectStore.openCursor();
  43. request.addEventListener("error", new ExpectError("UnknownError", true));
  44. request.onsuccess = unexpectedSuccessHandler;
  45. yield undefined;
  46. finishTest();
  47. yield undefined;
  48. }