Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | |
michael@0 | 14 | function testSteps() |
michael@0 | 15 | { |
michael@0 | 16 | const BLOB_DATA = |
michael@0 | 17 | "504B03040A00000000002E6BF14000000000000000000000000005001C00746573742F" + |
michael@0 | 18 | "555409000337CA055039CA055075780B000104E803000004E8030000504B0304140000" + |
michael@0 | 19 | "0008002D6BF1401780E15015000000580200000A001C00746573742F612E7478745554" + |
michael@0 | 20 | "09000336CA05503ACA055075780B000104E803000004E8030000CB48CDC9C95728CF2F" + |
michael@0 | 21 | "CA49E1CA18658FB2A9C40600504B03040A00000000002F88EC40662E84701000000010" + |
michael@0 | 22 | "0000000A001C00746573742F622E74787455540900035A65FF4F42C5055075780B0001" + |
michael@0 | 23 | "04E803000004E803000068656C6C6F20776F726C642C2032210A504B01021E030A0000" + |
michael@0 | 24 | "0000002E6BF140000000000000000000000000050018000000000000001000FD410000" + |
michael@0 | 25 | "0000746573742F555405000337CA055075780B000104E803000004E8030000504B0102" + |
michael@0 | 26 | "1E031400000008002D6BF1401780E15015000000580200000A00180000000000010000" + |
michael@0 | 27 | "00B4813F000000746573742F612E747874555405000336CA055075780B000104E80300" + |
michael@0 | 28 | "0004E8030000504B01021E030A00000000002F88EC40662E847010000000100000000A" + |
michael@0 | 29 | "0018000000000001000000B48198000000746573742F622E74787455540500035A65FF" + |
michael@0 | 30 | "4F75780B000104E803000004E8030000504B05060000000003000300EB000000EC0000" + |
michael@0 | 31 | "000000"; |
michael@0 | 32 | |
michael@0 | 33 | const TEST_FILE_1 = "test/a.txt"; |
michael@0 | 34 | const TEST_FILE_2 = "test/b.txt"; |
michael@0 | 35 | |
michael@0 | 36 | let TEST_FILE_1_CONTENTS = ""; |
michael@0 | 37 | for (let i = 0; i < 50; i++) { |
michael@0 | 38 | TEST_FILE_1_CONTENTS += "hello world\n"; |
michael@0 | 39 | } |
michael@0 | 40 | const TEST_FILE_2_CONTENTS = "hello world, 2!\n"; |
michael@0 | 41 | |
michael@0 | 42 | let binaryData = new Uint8Array(BLOB_DATA.length / 2); |
michael@0 | 43 | for (let i = 0, len = BLOB_DATA.length / 2; i < len; i++) { |
michael@0 | 44 | let hex = BLOB_DATA[i * 2] + BLOB_DATA[i * 2 + 1]; |
michael@0 | 45 | binaryData[i] = parseInt(hex, 16); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | let request = indexedDB.open(window.location.pathname, 1); |
michael@0 | 49 | request.onerror = errorHandler; |
michael@0 | 50 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 51 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 52 | let event = yield undefined; |
michael@0 | 53 | |
michael@0 | 54 | let db = event.target.result; |
michael@0 | 55 | db.onerror = errorHandler; |
michael@0 | 56 | |
michael@0 | 57 | let objectStore = db.createObjectStore("foo", { autoIncrement: true }); |
michael@0 | 58 | let index = objectStore.createIndex("foo", "index"); |
michael@0 | 59 | |
michael@0 | 60 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 61 | event = yield undefined; |
michael@0 | 62 | |
michael@0 | 63 | let data = new Blob([binaryData]); |
michael@0 | 64 | |
michael@0 | 65 | objectStore = db.transaction("foo", "readwrite").objectStore("foo"); |
michael@0 | 66 | objectStore.add(data).onsuccess = grabEventAndContinueHandler; |
michael@0 | 67 | event = yield undefined; |
michael@0 | 68 | |
michael@0 | 69 | let key = event.target.result; |
michael@0 | 70 | |
michael@0 | 71 | objectStore = db.transaction("foo").objectStore("foo"); |
michael@0 | 72 | objectStore.get(key).onsuccess = grabEventAndContinueHandler; |
michael@0 | 73 | event = yield undefined; |
michael@0 | 74 | |
michael@0 | 75 | let archiveReader = new ArchiveReader(event.target.result); |
michael@0 | 76 | ok(archiveReader, "Got an ArchiveReader"); |
michael@0 | 77 | |
michael@0 | 78 | request = archiveReader.getFilenames(); |
michael@0 | 79 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 80 | request.onerror = errorHandler; |
michael@0 | 81 | event = yield undefined; |
michael@0 | 82 | |
michael@0 | 83 | is(event.target.result.length, 2, "Got 2 archive items"); |
michael@0 | 84 | is(event.target.result[0], TEST_FILE_1, |
michael@0 | 85 | "First file is '" + TEST_FILE_1 + "'"); |
michael@0 | 86 | is(event.target.result[1], TEST_FILE_2, |
michael@0 | 87 | "Second file is '" + TEST_FILE_2 + "'"); |
michael@0 | 88 | |
michael@0 | 89 | request = archiveReader.getFile(TEST_FILE_1); |
michael@0 | 90 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 91 | request.onerror = errorHandler; |
michael@0 | 92 | event = yield undefined; |
michael@0 | 93 | |
michael@0 | 94 | let fileReader = new FileReader(); |
michael@0 | 95 | fileReader.readAsText(event.target.result); |
michael@0 | 96 | fileReader.onload = grabEventAndContinueHandler; |
michael@0 | 97 | fileReader.onerror = errorHandler; |
michael@0 | 98 | event = yield undefined; |
michael@0 | 99 | |
michael@0 | 100 | // Don't use is() because it prints out 100 lines of text... |
michael@0 | 101 | ok(event.target.result == TEST_FILE_1_CONTENTS, "Correct text"); |
michael@0 | 102 | |
michael@0 | 103 | request = archiveReader.getFile(TEST_FILE_2); |
michael@0 | 104 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 105 | request.onerror = errorHandler; |
michael@0 | 106 | event = yield undefined; |
michael@0 | 107 | |
michael@0 | 108 | fileReader = new FileReader(); |
michael@0 | 109 | fileReader.readAsText(event.target.result); |
michael@0 | 110 | fileReader.onload = grabEventAndContinueHandler; |
michael@0 | 111 | fileReader.onerror = errorHandler; |
michael@0 | 112 | event = yield undefined; |
michael@0 | 113 | |
michael@0 | 114 | // Don't use is() because it prints out a newline... |
michael@0 | 115 | ok(event.target.result == TEST_FILE_2_CONTENTS, "Correct text"); |
michael@0 | 116 | |
michael@0 | 117 | finishTest(); |
michael@0 | 118 | yield undefined; |
michael@0 | 119 | } |
michael@0 | 120 | </script> |
michael@0 | 121 | <script type="text/javascript;version=1.7" src="helpers.js"></script> |
michael@0 | 122 | |
michael@0 | 123 | </head> |
michael@0 | 124 | |
michael@0 | 125 | <body onload="runTest();"></body> |
michael@0 | 126 | |
michael@0 | 127 | </html> |