Tests for Bug 706088. r=khuey. Also removes a now-obsolete test. r=bent. a=khuey
authorJonas Sicking <jonas@sicking.cc>
Tue, 13 Dec 2011 11:46:19 -0800
changeset 84155 0414fe2f9d735d645bfcffb27bcb2be95403e8c3
parent 84154 0e227df7b536a0d8c48404e1f70f9efcc9c839df
child 84156 300849c3dd10038d19a6cad6b10d8bae780ba0b7
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey, bent, khuey
bugs706088
milestone11.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
Tests for Bug 706088. r=khuey. Also removes a now-obsolete test. r=bent. a=khuey
dom/indexedDB/test/Makefile.in
dom/indexedDB/test/test_add_put.html
dom/indexedDB/test/test_bad_keypath.html
--- a/dom/indexedDB/test/Makefile.in
+++ b/dom/indexedDB/test/Makefile.in
@@ -47,20 +47,20 @@ include $(topsrcdir)/config/rules.mk
 TEST_FILES = \
   bfcache_iframe1.html \
   bfcache_iframe2.html \
   error_events_abort_transactions_iframe.html \
   event_propagation_iframe.html \
   exceptions_in_success_events_iframe.html \
   helpers.js \
   leaving_page_iframe.html \
+  test_add_put.html \
   test_add_twice_failure.html \
   test_advance.html \
   test_autoIncrement_indexes.html \
-  test_bad_keypath.html \
   test_bfcache.html \
   test_clear.html \
   test_cmp.html \
   test_complex_keyPaths.html \
   test_count.html \
   test_create_index.html \
   test_create_index_with_integer_keys.html \
   test_create_objectStore.html \
new file mode 100644
--- /dev/null
+++ b/dom/indexedDB/test/test_add_put.html
@@ -0,0 +1,180 @@
+<!--
+  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 name = window.location.pathname;
+      let openRequest = mozIndexedDB.open(name, 1);
+      openRequest.onerror = errorHandler;
+      openRequest.onupgradeneeded = grabEventAndContinueHandler;
+      openRequest.onsuccess = unexpectedSuccessHandler;
+      let event = yield;
+      let db = event.target.result;
+      let trans = event.target.transaction;
+
+      for each (let autoincrement in [true, false]) {
+        for each (let keypath in [false, true, "missing", "invalid"]) {
+          for each (let method in ["put", "add"]) {
+            for each (let explicit in [true, false, undefined, "invalid"]) {
+              for each (let existing in [true, false]) {
+                let speccedNoKey = (keypath == false || keypath == "missing") &&
+                                   !explicit;
+
+                // We can't do 'existing' checks if we use autogenerated key
+                if (speccedNoKey && autoincrement && existing) {
+                  continue;
+                }
+
+                // Create store
+                if (db.objectStoreNames.contains("mystore"))
+                  db.deleteObjectStore("mystore");
+                let store = db.createObjectStore("mystore",
+                                                 { autoIncrement: autoincrement,
+                                                   keyPath: (keypath ? "id" : null) });
+
+                test = " for test " + JSON.stringify({ autoincrement: autoincrement,
+                                                       keypath: keypath,
+                                                       method: method,
+                                                       explicit: explicit === undefined ? "undefined" : explicit,
+                                                       existing: existing });
+
+                // Insert "existing" data if needed
+                if (existing) {
+                  if (keypath)
+                    store.add({ existing: "data", id: 5 }).onsuccess = grabEventAndContinueHandler;
+                  else
+                    store.add({ existing: "data" }, 5).onsuccess = grabEventAndContinueHandler;
+
+                  let e = yield;
+                  is(e.type, "success", "success inserting existing" + test);
+                  is(e.target.result, 5, "inserted correct key" + test);
+                }
+
+                // Set up value to be inserted
+                let value = { theObj: true };
+                if (keypath === true) {
+                  value.id = 5;
+                }
+                else if (keypath === "invalid") {
+                  value.id = /x/;
+                }
+
+                // Which arguments are passed to function
+                args = [value];
+                if (explicit === true) {
+                  args.push(5);
+                }
+                else if (explicit === undefined) {
+                  args.push(undefined);
+                }
+                else if (explicit === "invalid") {
+                  args.push(/x/);
+                }
+
+                let expected = expectedResult(method, keypath, explicit, autoincrement, existing);
+
+                ok(true, "making call" + test);
+
+                // Make function call for throwing functions
+                if (expected === "throw") {
+                  try {
+                    store[method].apply(store, args);
+                    ok(false, "should have thrown" + test);
+                  }
+                  catch (ex) {
+                    ok(true, "did throw" + test);
+                    ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException" + test);
+                    is(ex.code, IDBDatabaseException.DATA_ERR, "expect a DATA_ERR" + test);
+                  }
+                  continue;
+                }
+
+                // Make non-throwing function call
+                let req = store[method].apply(store, args);
+                req.onsuccess = req.onerror = grabEventAndContinueHandler
+                let e = yield;
+
+                // Figure out what key we used
+                let key = 5;
+                if (autoincrement && speccedNoKey) {
+                  key = 1;
+                }
+
+                // Adjust value if expected
+                if (autoincrement && keypath && speccedNoKey) {
+                  value.id = key;
+                }
+
+                // Check result
+                if (expected === "error") {
+                  is(e.type, "error", "write should fail" + test);
+                  e.preventDefault();
+                  e.stopPropagation();
+                  continue;
+                }
+
+                is(e.type, "success", "write should succeed" + test);
+                if (autoincrement && speccedNoKey) {
+                  todo_is(e.target.result, key, "(fix ai) write should return correct key" + test);
+                  key = e.target.result;
+                  if (keypath) {
+                    value.id = key;
+                  }
+                }
+                else {
+                  is(e.target.result, key, "write should return correct key" + test);
+                }
+
+                store.get(key).onsuccess = grabEventAndContinueHandler;
+                e = yield;
+                is(e.type, "success", "read back should succeed" + test);
+                is(JSON.stringify(e.target.result),
+                   JSON.stringify(value),
+                   "read back should return correct value" + test);
+              }
+            }
+          }
+        }
+      }
+
+      
+      function expectedResult(method, keypath, explicit, autoincrement, existing) {
+        if (keypath && explicit)
+          return "throw";
+        if (!keypath && !explicit && !autoincrement)
+          return "throw";
+        if (keypath == "invalid")
+          return "throw";
+        if (keypath == "missing" && !autoincrement)
+          return "throw";
+        if (explicit == "invalid")
+          return "throw";
+
+        if (method == "add" && existing)
+          return "error";
+
+        return "success";
+      }
+
+      openRequest.onsuccess = grabEventAndContinueHandler;
+      yield;
+
+      finishTest();
+      yield;
+    }
+  </script>
+  <script type="text/javascript;version=1.7" src="helpers.js"></script>
+</head>
+
+<body onload="runTest();"></body>
+
+</html>
deleted file mode 100644
--- a/dom/indexedDB/test/test_bad_keypath.html
+++ /dev/null
@@ -1,49 +0,0 @@
-<!--
-  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 name = window.location.pathname;
-      const description = "My Test Database";
-
-      let request = mozIndexedDB.open(name, 1, description);
-      request.onerror = errorHandler;
-      request.onupgradeneeded = grabEventAndContinueHandler;
-      let event = yield;
-
-      let db = request.result;
-
-      let objectStore = db.createObjectStore("foo", { keyPath: "keyPath" });
-
-      request = objectStore.add({keyPath:"foo"});
-      request.onerror = errorHandler;
-      request.onsuccess = grabEventAndContinueHandler;
-      event = yield;
-
-      try {
-        request = objectStore.add({});
-        ok(false, "Shouldn't get here!");
-      }
-      catch (e) {
-        is(e.code, IDBDatabaseException.DATA_ERR, "Good error");
-      }
-
-      finishTest();
-      yield;
-    }
-  </script>
-  <script type="text/javascript;version=1.7" src="helpers.js"></script>
-</head>
-
-<body onload="runTest();"></body>
-
-</html>