test_filehandle_iteration.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <html>
  6. <head>
  7. <title>Indexed Database Property Test</title>
  8. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. <script type="text/javascript;version=1.7">
  11. function testSteps()
  12. {
  13. const dbName = window.location.pathname;
  14. const dbVersion = 1;
  15. const objectStoreName = "foo";
  16. const entryCount = 10;
  17. let request = indexedDB.open(dbName, dbVersion);
  18. request.onerror = errorHandler;
  19. request.onupgradeneeded = grabEventAndContinueHandler;
  20. request.onsuccess = unexpectedSuccessHandler;
  21. let event = yield undefined;
  22. is(event.type, "upgradeneeded", "Got correct event type");
  23. let db = event.target.result;
  24. db.onerror = errorHandler;
  25. db.createObjectStore(objectStoreName, { autoIncrement: true });
  26. request.onupgradeneeded = unexpectedSuccessHandler;
  27. request.onsuccess = grabEventAndContinueHandler;
  28. event = yield undefined;
  29. is(event.type, "success", "Got correct event type");
  30. request = db.createMutableFile("bar");
  31. request.onsuccess = grabEventAndContinueHandler;
  32. event = yield undefined;
  33. let mutableFile = event.target.result;
  34. let trans = db.transaction(objectStoreName, "readwrite");
  35. let objectStore = trans.objectStore(objectStoreName);
  36. for (let i = 0; i < entryCount; i++) {
  37. request = objectStore.add(mutableFile);
  38. }
  39. let seenEntryCount = 0;
  40. request = objectStore.openCursor().onsuccess = event => {
  41. let cursor = event.target.result;
  42. if (cursor) {
  43. seenEntryCount++;
  44. cursor.continue();
  45. } else {
  46. continueToNextStep();
  47. }
  48. }
  49. yield undefined;
  50. is(seenEntryCount, entryCount, "Correct entry count");
  51. finishTest();
  52. yield undefined;
  53. }
  54. </script>
  55. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  56. </head>
  57. <body onload="runTest();"></body>
  58. </html>