Bug 1118504 - Add test for <input type='file'> blobs in indexedDB,
☠☠ backed out by f34d4207cb44 ☠ ☠
authorBen Turner <bent.mozilla@gmail.com>
Wed, 07 Jan 2015 08:55:44 -0800
changeset 248345 4af240ffb89940b95ee0eaa34b5e2ddc79f1f183
parent 248344 175c011226e3326758cd8728d09f3d199f75b27a
child 248346 69814624bb027225c02da63ab5a6d37940fe64fb
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1118504
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1118504 - Add test for <input type='file'> blobs in indexedDB, r=khuey.
dom/indexedDB/test/mochitest.ini
dom/indexedDB/test/test_input_file.html
--- a/dom/indexedDB/test/mochitest.ini
+++ b/dom/indexedDB/test/mochitest.ini
@@ -265,16 +265,18 @@ skip-if = (buildapp == 'b2g' && toolkit 
 [test_index_update_delete.html]
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
 [test_indexes.html]
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
 [test_indexes_bad_values.html]
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
 [test_indexes_funny_things.html]
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
+[test_input_file.html]
+skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
 [test_invalid_cursor.html]
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
 [test_invalid_version.html]
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
 [test_invalidate.html]
 # disabled for the moment
 skip-if = true
 # skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
new file mode 100644
--- /dev/null
+++ b/dom/indexedDB/test/test_input_file.html
@@ -0,0 +1,130 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+  <title>Storing &lt;input type=&quot;file&quot;&gt; in IndexedDB</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">
+
+    let dbName = window.location.pathname;
+    let dbVersion = 1;
+    let objectStoreName = "foo";
+
+    let fileName = "temp_input_type_file_indexedDB_data.txt";
+    let fileData = "abcdefghijklmnopqrstuvwxyz";
+    let fileType = "text/plain";
+
+    function testSteps()
+    {
+      info("Creating temporary file");
+
+      let inputElement = document.getElementById("inputElement");
+
+      {
+        let { Cc: Cc, Ci: Ci } = SpecialPowers;
+
+        let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
+                      getService(Ci.nsIProperties);
+
+        let tempFile = dirSvc.get("ProfD", Ci.nsIFile);
+        tempFile.append(fileName);
+
+        {
+          let stream = Cc["@mozilla.org/network/file-output-stream;1"].
+                        createInstance(Ci.nsIFileOutputStream);
+
+          let flags = /* PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE */
+                      0x2 | 0x8 | 0x20;
+          stream.init(tempFile, flags, 0666, 0);
+
+          stream.write(fileData, fileData.length);
+          stream.close();
+        }
+
+        SpecialPowers.wrap(inputElement).value = tempFile.path;
+
+        info("Temporary file created: " + tempFile.path);
+      }
+
+      let file = inputElement.files[0];
+      ok(file instanceof File, "Got a File object for the temporary file");
+      is(file.size, fileData.length, "File has correct length");
+      is(file.type, fileType, "File has correct type");
+      is(file.name, fileName, "File has correct name");
+
+      info("Opening database");
+
+      let request = indexedDB.open(window.location.pathname, 1);
+      request.onerror = errorHandler;
+      request.onupgradeneeded = grabEventAndContinueHandler;
+      request.onsuccess = grabEventAndContinueHandler;
+
+      let event = yield undefined;
+
+      is(event.type, "upgradeneeded", "Got upgradeneeded event");
+
+      let db = event.target.result;
+      db.onerror = errorHandler;
+
+      db.createObjectStore("foo", { autoIncrement: true });
+
+      event = yield undefined;
+
+      is(event.type, "success", "Got success event for open()");
+
+      info("Storing file");
+
+      let transaction = db.transaction("foo", "readwrite");
+      transaction.oncomplete = grabEventAndContinueHandler;
+
+      let objectStore = transaction.objectStore("foo");
+      objectStore.put(file).onsuccess = grabEventAndContinueHandler;
+
+      event = yield undefined;
+
+      is(event.type, "success", "Got success event for put()");
+
+      let key = event.target.result;
+      objectStore.get(key).onsuccess = grabEventAndContinueHandler;
+
+      event = yield;
+
+      is(event.type, "success", "Got success event for get()");
+
+      file = event.target.result;
+      ok(file instanceof File, "Got a File object from the database");
+      is(file.size, fileData.length, "File has correct length");
+      is(file.type, fileType, "File has correct type");
+      is(file.name, fileName, "File has correct name");
+
+      event = yield undefined;
+
+      is(event.type, "complete", "Got complete event for transaction");
+
+      db.close();
+
+      let reader = new FileReader();
+      reader.onerror = errorHandler;
+      reader.onload = grabEventAndContinueHandler;
+      reader.readAsText(file);
+
+      event = yield undefined;
+
+      is(event.type, "load", "Got load event for readAsText()");
+
+      is(reader.result, fileData, "Got correct file data");
+
+      finishTest();
+      yield undefined;
+    }
+  </script>
+  <script type="text/javascript;version=1.7" src="helpers.js"></script>
+</head>
+<body onload="runTest();">
+  <input id="inputElement" type="file"></input>
+</body>
+<iframe id="iframe1"></iframe>
+</html>