test_filehandle_serialization.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 READ_WRITE = "readwrite";
  14. const databaseInfo = [
  15. { name: window.location.pathname + "1" },
  16. { name: window.location.pathname + "2" }
  17. ];
  18. const objectStoreName = "Blobs";
  19. const testFile = getRandomFile("random.bin", 100000);
  20. let databases = [];
  21. for (let info of databaseInfo) {
  22. let request = indexedDB.open(info.name, 1);
  23. request.onerror = errorHandler;
  24. request.onupgradeneeded = grabEventAndContinueHandler;
  25. request.onsuccess = grabEventAndContinueHandler;
  26. let event = yield undefined;
  27. is(event.type, "upgradeneeded", "Got correct event type");
  28. let db = event.target.result;
  29. db.onerror = errorHandler;
  30. db.createObjectStore(objectStoreName, { });
  31. event = yield undefined;
  32. is(event.type, "success", "Got correct event type");
  33. databases.push(db);
  34. }
  35. let db1 = databases[0];
  36. let request = db1.createMutableFile("random.bin", "binary/random");
  37. request.onsuccess = grabEventAndContinueHandler;
  38. event = yield undefined;
  39. let mutableFile = event.target.result;
  40. is(getFileId(mutableFile), 1, "Correct file id");
  41. is(mutableFile.name, "random.bin", "Correct name");
  42. is(mutableFile.type, "binary/random", "Correct type");
  43. let trans = db1.transaction([objectStoreName], READ_WRITE);
  44. let objectStore = trans.objectStore(objectStoreName);
  45. request = objectStore.add(mutableFile, 42);
  46. request.onsuccess = grabEventAndContinueHandler;
  47. event = yield undefined;
  48. request = objectStore.get(42);
  49. request.onsuccess = grabEventAndContinueHandler;
  50. event = yield undefined;
  51. let result = event.target.result;
  52. is(getFileId(result), 1, "Correct file id");
  53. is(result.name, mutableFile.name, "Correct name");
  54. is(result.type, mutableFile.type, "Correct type");
  55. let db2 = databases[1];
  56. trans = db2.transaction([objectStoreName], READ_WRITE);
  57. objectStore = trans.objectStore(objectStoreName);
  58. try {
  59. objectStore.add(mutableFile, 42);
  60. ok(false, "Should have thrown!");
  61. }
  62. catch (e) {
  63. ok(e instanceof DOMException, "Got exception.");
  64. is(e.name, "DataCloneError", "Good error.");
  65. is(e.code, DOMException.DATA_CLONE_ERR, "Good error code.");
  66. }
  67. finishTest();
  68. yield undefined;
  69. }
  70. </script>
  71. <script type="text/javascript;version=1.7" src="file.js"></script>
  72. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  73. </head>
  74. <body onload="runTest();"></body>
  75. </html>