Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | <!-- |
michael@0 | 2 | Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | --> |
michael@0 | 5 | <html> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Indexed Database Property Test</title> |
michael@0 | 8 | |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | |
michael@0 | 12 | <script type="text/javascript;version=1.7"> |
michael@0 | 13 | function testSteps() |
michael@0 | 14 | { |
michael@0 | 15 | const READ_WRITE = "readwrite"; |
michael@0 | 16 | |
michael@0 | 17 | const name = window.location.pathname; |
michael@0 | 18 | |
michael@0 | 19 | const objectStoreName = "Blobs"; |
michael@0 | 20 | |
michael@0 | 21 | const testFile = getRandomFile("random.bin", 100000); |
michael@0 | 22 | |
michael@0 | 23 | let request = indexedDB.open(name, 1); |
michael@0 | 24 | request.onerror = errorHandler; |
michael@0 | 25 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 26 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 27 | let event = yield undefined; |
michael@0 | 28 | |
michael@0 | 29 | is(event.type, "upgradeneeded", "Got correct event type"); |
michael@0 | 30 | |
michael@0 | 31 | let db = event.target.result; |
michael@0 | 32 | db.onerror = errorHandler; |
michael@0 | 33 | |
michael@0 | 34 | let objectStore = db.createObjectStore(objectStoreName, { }); |
michael@0 | 35 | |
michael@0 | 36 | event = yield undefined; |
michael@0 | 37 | |
michael@0 | 38 | is(event.type, "success", "Got correct event type"); |
michael@0 | 39 | |
michael@0 | 40 | request = db.mozCreateFileHandle("random.bin", "binary/random"); |
michael@0 | 41 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 42 | event = yield undefined; |
michael@0 | 43 | |
michael@0 | 44 | let fileHandle = event.target.result; |
michael@0 | 45 | fileHandle.onerror = errorHandler; |
michael@0 | 46 | |
michael@0 | 47 | let lockedFile = fileHandle.open("readwrite"); |
michael@0 | 48 | |
michael@0 | 49 | is(getFileId(fileHandle), 1, "Correct file id"); |
michael@0 | 50 | |
michael@0 | 51 | request = lockedFile.write(testFile); |
michael@0 | 52 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 53 | event = yield undefined; |
michael@0 | 54 | |
michael@0 | 55 | request = fileHandle.getFile(); |
michael@0 | 56 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 57 | event = yield undefined; |
michael@0 | 58 | |
michael@0 | 59 | let file = event.target.result; |
michael@0 | 60 | |
michael@0 | 61 | let trans = db.transaction([objectStoreName], READ_WRITE); |
michael@0 | 62 | let objectStore = trans.objectStore(objectStoreName); |
michael@0 | 63 | |
michael@0 | 64 | request = objectStore.add(file, 42); |
michael@0 | 65 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 66 | event = yield undefined; |
michael@0 | 67 | |
michael@0 | 68 | // At this moment, the file should not be readable anymore. |
michael@0 | 69 | let reader = new FileReader(); |
michael@0 | 70 | try { |
michael@0 | 71 | reader.readAsArrayBuffer(file); |
michael@0 | 72 | ok(false, "Should have thrown!"); |
michael@0 | 73 | } |
michael@0 | 74 | catch (e) { |
michael@0 | 75 | ok(e instanceof DOMException, "Got exception."); |
michael@0 | 76 | is(e.name, "LockedFileInactiveError", "Good error."); |
michael@0 | 77 | is(e.code, 0, "Good error code."); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | request = objectStore.get(42); |
michael@0 | 81 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 82 | event = yield undefined; |
michael@0 | 83 | |
michael@0 | 84 | verifyBlob(event.target.result, testFile, 2); |
michael@0 | 85 | yield undefined; |
michael@0 | 86 | |
michael@0 | 87 | finishTest(); |
michael@0 | 88 | yield undefined; |
michael@0 | 89 | } |
michael@0 | 90 | </script> |
michael@0 | 91 | <script type="text/javascript;version=1.7" src="file.js"></script> |
michael@0 | 92 | <script type="text/javascript;version=1.7" src="helpers.js"></script> |
michael@0 | 93 | |
michael@0 | 94 | </head> |
michael@0 | 95 | |
michael@0 | 96 | <body onload="runTest();"></body> |
michael@0 | 97 | |
michael@0 | 98 | </html> |