test_wasm_indexes.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_indexes.js";
  10. const objectStoreName = "Wasm";
  11. const wasmData = { key: 1, value: { name: "foo", data: null } };
  12. const indexData = { name: "nameIndex", keyPath: "name", options: { } };
  13. if (!isWasmSupported()) {
  14. finishTest();
  15. yield undefined;
  16. }
  17. getWasmBinary('(module (func (nop)))');
  18. let binary = yield undefined;
  19. wasmData.value.data = getWasmModule(binary);
  20. info("Opening database");
  21. let request = indexedDB.open(name);
  22. request.onerror = errorHandler;
  23. request.onupgradeneeded = continueToNextStepSync;
  24. request.onsuccess = unexpectedSuccessHandler;
  25. yield undefined;
  26. // upgradeneeded
  27. request.onupgradeneeded = unexpectedSuccessHandler;
  28. request.onsuccess = continueToNextStepSync;
  29. info("Creating objectStore");
  30. let objectStore = request.result.createObjectStore(objectStoreName);
  31. info("Creating index");
  32. objectStore.createIndex(indexData.name, indexData.keyPath, indexData.options);
  33. yield undefined;
  34. // success
  35. let db = request.result;
  36. db.onerror = errorHandler;
  37. info("Storing wasm");
  38. objectStore = db.transaction([objectStoreName], "readwrite")
  39. .objectStore(objectStoreName);
  40. request = objectStore.add(wasmData.value, wasmData.key);
  41. request.onsuccess = continueToNextStepSync;
  42. yield undefined;
  43. is(request.result, wasmData.key, "Got correct key");
  44. info("Getting wasm");
  45. request = objectStore.index("nameIndex").get("foo");
  46. request.addEventListener("error", new ExpectError("UnknownError", true));
  47. request.onsuccess = unexpectedSuccessHandler;
  48. yield undefined;
  49. info("Opening cursor");
  50. request = objectStore.index("nameIndex").openCursor();
  51. request.addEventListener("error", new ExpectError("UnknownError", true));
  52. request.onsuccess = unexpectedSuccessHandler;
  53. yield undefined;
  54. finishTest();
  55. yield undefined;
  56. }