Bug 786003 - 'Add a few extra tests for blobs in IndexedDB'. r=jst.
☠☠ backed out by a7f0beb46374 ☠ ☠
authorBen Turner <bent.mozilla@gmail.com>
Mon, 27 Aug 2012 12:40:06 -0700
changeset 105635 5ff334b7781d869e80740bc19f7dabaff1ba609e
parent 105634 965b4b628696bf16c32a76384ac9907621a5876e
child 105636 721ff7492145e230ba54431548dc8afb7865c1c1
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersjst
bugs786003
milestone17.0a1
Bug 786003 - 'Add a few extra tests for blobs in IndexedDB'. r=jst.
dom/indexedDB/test/Makefile.in
dom/indexedDB/test/test_blob_archive.html
dom/indexedDB/test/test_blob_simple.html
--- a/dom/indexedDB/test/Makefile.in
+++ b/dom/indexedDB/test/Makefile.in
@@ -24,16 +24,17 @@ MOCHITEST_FILES = \
   helpers.js \
   leaving_page_iframe.html \
   test_add_put.html \
   test_add_twice_failure.html \
   test_advance.html \
   test_autoIncrement_indexes.html \
   test_autoIncrement.html \
   test_bfcache.html \
+  test_blob_archive.html \
   test_blob_simple.html \
   test_clear.html \
   test_complex_keyPaths.html \
   test_count.html \
   test_create_index.html \
   test_create_index_with_integer_keys.html \
   test_create_objectStore.html \
   test_cursors.html \
new file mode 100644
--- /dev/null
+++ b/dom/indexedDB/test/test_blob_archive.html
@@ -0,0 +1,127 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+  <title>Indexed Database Property Test</title>
+
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+
+  <script type="text/javascript;version=1.7">
+
+  function testSteps()
+  {
+    const BLOB_DATA =
+      "504B03040A00000000002E6BF14000000000000000000000000005001C00746573742F" +
+      "555409000337CA055039CA055075780B000104E803000004E8030000504B0304140000" +
+      "0008002D6BF1401780E15015000000580200000A001C00746573742F612E7478745554" +
+      "09000336CA05503ACA055075780B000104E803000004E8030000CB48CDC9C95728CF2F" +
+      "CA49E1CA18658FB2A9C40600504B03040A00000000002F88EC40662E84701000000010" +
+      "0000000A001C00746573742F622E74787455540900035A65FF4F42C5055075780B0001" +
+      "04E803000004E803000068656C6C6F20776F726C642C2032210A504B01021E030A0000" +
+      "0000002E6BF140000000000000000000000000050018000000000000001000FD410000" +
+      "0000746573742F555405000337CA055075780B000104E803000004E8030000504B0102" +
+      "1E031400000008002D6BF1401780E15015000000580200000A00180000000000010000" +
+      "00B4813F000000746573742F612E747874555405000336CA055075780B000104E80300" +
+      "0004E8030000504B01021E030A00000000002F88EC40662E847010000000100000000A" +
+      "0018000000000001000000B48198000000746573742F622E74787455540500035A65FF" +
+      "4F75780B000104E803000004E8030000504B05060000000003000300EB000000EC0000" +
+      "000000";
+
+    const TEST_FILE_1 = "test/a.txt";
+    const TEST_FILE_2 = "test/b.txt";
+
+    let TEST_FILE_1_CONTENTS = "";
+    for (let i = 0; i < 50; i++) {
+      TEST_FILE_1_CONTENTS += "hello world\n";
+    }
+    const TEST_FILE_2_CONTENTS = "hello world, 2!\n";
+
+    let binaryData = new Uint8Array(BLOB_DATA.length / 2);
+    for (let i = 0, len = BLOB_DATA.length / 2; i < len; i++) {
+      let hex = BLOB_DATA[i * 2] + BLOB_DATA[i * 2 + 1];
+      binaryData[i] = parseInt(hex, 16);
+    }
+
+    let request = indexedDB.open(window.location.pathname, 1);
+    request.onerror = errorHandler;
+    request.onupgradeneeded = grabEventAndContinueHandler;
+    request.onsuccess = unexpectedSuccessHandler;
+    let event = yield;
+
+    let db = event.target.result;
+    db.onerror = errorHandler;
+
+    let objectStore = db.createObjectStore("foo", { autoIncrement: true });
+    let index = objectStore.createIndex("foo", "index");
+
+    request.onsuccess = grabEventAndContinueHandler;
+    event = yield;
+
+    let data = new Blob([binaryData]);
+
+    objectStore = db.transaction("foo", "readwrite").objectStore("foo");
+    objectStore.add(data).onsuccess = grabEventAndContinueHandler;
+    event = yield;
+
+    let key = event.target.result;
+
+    objectStore = db.transaction("foo").objectStore("foo");
+    objectStore.get(key).onsuccess = grabEventAndContinueHandler;
+    event = yield;
+
+    let archiveReader = new ArchiveReader(event.target.result);
+    ok(archiveReader, "Got an ArchiveReader");
+
+    request = archiveReader.getFilenames();
+    request.onsuccess = grabEventAndContinueHandler;
+    request.onerror = errorHandler;
+    event = yield;
+
+    is(event.target.result.length, 2, "Got 2 archive items");
+    is(event.target.result[0], TEST_FILE_1,
+       "First file is '" + TEST_FILE_1 + "'");
+    is(event.target.result[1], TEST_FILE_2,
+       "Second file is '" + TEST_FILE_2 + "'");
+
+    request = archiveReader.getFile(TEST_FILE_1);
+    request.onsuccess = grabEventAndContinueHandler;
+    request.onerror = errorHandler;
+    event = yield;
+
+    let fileReader = new FileReader();
+    fileReader.readAsText(event.target.result);
+    fileReader.onload = grabEventAndContinueHandler;
+    fileReader.onerror = errorHandler;
+    event = yield;
+
+    // Don't use is() because it prints out 100 lines of text...
+    ok(event.target.result == TEST_FILE_1_CONTENTS, "Correct text");
+
+    request = archiveReader.getFile(TEST_FILE_2);
+    request.onsuccess = grabEventAndContinueHandler;
+    request.onerror = errorHandler;
+    event = yield;
+
+    fileReader = new FileReader();
+    fileReader.readAsText(event.target.result);
+    fileReader.onload = grabEventAndContinueHandler;
+    fileReader.onerror = errorHandler;
+    event = yield;
+
+    // Don't use is() because it prints out a newline...
+    ok(event.target.result == TEST_FILE_2_CONTENTS, "Correct text");
+
+    finishTest();
+    yield;
+  }
+  </script>
+  <script type="text/javascript;version=1.7" src="helpers.js"></script>
+
+</head>
+
+<body onload="runTest();"></body>
+
+</html>
--- a/dom/indexedDB/test/test_blob_simple.html
+++ b/dom/indexedDB/test/test_blob_simple.html
@@ -48,16 +48,34 @@
 
     let fileReader = new FileReader();
     fileReader.onload = grabEventAndContinueHandler;
     fileReader.readAsText(event.target.result.blob);
     event = yield;
 
     is(event.target.result, BLOB_DATA.join(""), "Correct text");
 
+    info("Trying blob url");
+
+    objectStore = db.transaction("foo").objectStore("foo");
+    objectStore.get(key).onsuccess = grabEventAndContinueHandler;
+    event = yield;
+
+    let blobURL = URL.createObjectURL(event.target.result.blob);
+
+    let xhr = new XMLHttpRequest();
+    xhr.open("GET", blobURL);
+    xhr.onload = grabEventAndContinueHandler;
+    xhr.send();
+    yield;
+
+    URL.revokeObjectURL(blobURL);
+
+    is(xhr.responseText, BLOB_DATA.join(""), "Correct responseText");
+
     objectStore = db.transaction("foo").objectStore("foo");
     objectStore.mozGetAll().onsuccess = grabEventAndContinueHandler;
     event = yield;
 
     is(event.target.result.length, 2, "Got right number of items");
 
     fileReader = new FileReader();
     fileReader.onload = grabEventAndContinueHandler;