Skip to content

Commit

Permalink
IndexedDB review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
odinho committed Mar 27, 2014
1 parent 974a4ac commit 024366e
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 155 deletions.
12 changes: 6 additions & 6 deletions IndexedDB/idbcursor_continue_index.htm
Expand Up @@ -16,13 +16,13 @@

var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result
var objStore = db.createObjectStore("test", { keyPath:"pKey" })
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath:"pKey" });

objStore.createIndex("index", "iKey")
objStore.createIndex("index", "iKey");

for (var i = 0; i < records.length; i++)
objStore.add(records[i])
objStore.add(records[i]);
};

open_rq.onsuccess = function(e) {
Expand All @@ -34,8 +34,8 @@
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, records.length, "cursor run count")
t.done()
assert_equals(count, records.length, "cursor run count");
t.done();
}

var record = cursor.value;
Expand Down
9 changes: 2 additions & 7 deletions IndexedDB/idbcursor_continue_objectstore.htm
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<title>IDBCursor.continue() - object store - iterate to the next record</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand All @@ -23,15 +23,10 @@

open_rq.onsuccess = function(e) {
var store = db.transaction("test")
.objectStore("test")

store.get('primaryKey_0').onsuccess = function(e) {
console.log(e.target.result);
}
.objectStore("test");

cursor_rq = store.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
console.log("onsuccess");
var cursor = e.target.result;
if (!cursor) {
assert_equals(count, records.length, "cursor run count");
Expand Down
4 changes: 2 additions & 2 deletions IndexedDB/idbcursor_continue_objectstore2.htm
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<title>IDBCursor.continue() - object store - attempt to pass a key parameter is not a valid key </title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand Down Expand Up @@ -27,7 +27,7 @@
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;

assert_true(cursor != null, "cursor exist");
assert_true(cursor instanceof IDBCursor, "cursor exists");
assert_throws("DataError",
function() { cursor.continue(document); });

Expand Down
7 changes: 2 additions & 5 deletions IndexedDB/idbcursor_continue_objectstore3.htm
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<title>IDBCursor.continue() - object store - attempt to iterate to the previous record when the direction is set for the next record</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand All @@ -20,17 +20,14 @@
};

open_rq.onsuccess = function(e) {
console.log("før");
var cursor_rq = db.transaction("test")
.objectStore("test")
.openCursor(undefined, "next");
console.log("etter");

cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;

assert_true(cursor != null, "cursor exist");
try { cursor.continue(records[0].pKey); } catch(e) { console.log(e); }
assert_true(cursor instanceof IDBCursor, "cursor exist");
assert_throws("DataError",
function() { cursor.continue(records[0].pKey); });

Expand Down
5 changes: 2 additions & 3 deletions IndexedDB/idbcursor_delete_index.htm
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<title>IDBCursor.delete() - index - remove a record from the object store</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand Down Expand Up @@ -35,7 +35,7 @@
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;

assert_true(cursor != null, "cursor exist");
assert_true(cursor instanceof IDBCursor, "cursor exist");
cursor.delete();
});

Expand All @@ -49,7 +49,6 @@
.openCursor();

cursor_rq.onsuccess = t.step_func(function(e) {
console.log(e);
var cursor = e.target.result;

if (!cursor) {
Expand Down
2 changes: 1 addition & 1 deletion IndexedDB/idbcursor_delete_index2.htm
Expand Up @@ -30,7 +30,7 @@
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;

assert_true(cursor != null, "cursor exist");
assert_true(cursor instanceof IDBCursor, "cursor exist");
assert_throws('ReadOnlyError', function() { cursor.delete(); });
t.done();
});
Expand Down
2 changes: 1 addition & 1 deletion IndexedDB/idbcursor_delete_index3.htm
Expand Up @@ -24,7 +24,7 @@

cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
assert_true(cursor instanceof IDBCursor, "cursor exist");
window.cursor = cursor;
});

Expand Down
2 changes: 1 addition & 1 deletion IndexedDB/idbcursor_delete_objectstore3.htm
Expand Up @@ -23,7 +23,7 @@

cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
assert_true(cursor instanceof IDBCursor, "cursor exist");
window.cursor = cursor;
});

Expand Down
2 changes: 1 addition & 1 deletion IndexedDB/idbcursor_update_index3.htm
Expand Up @@ -24,7 +24,7 @@

cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
assert_true(cursor instanceof IDBCursor, "cursor exist");
window.cursor = cursor;
window.record = cursor.value;
});
Expand Down
2 changes: 1 addition & 1 deletion IndexedDB/idbcursor_update_objectstore3.htm
Expand Up @@ -23,7 +23,7 @@

cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor != null, "cursor exist");
assert_true(cursor instanceof IDBCursor, "cursor exist");
window.cursor = cursor;
window.record = cursor.value;
});
Expand Down
44 changes: 19 additions & 25 deletions IndexedDB/idbfactory_cmp.htm
@@ -1,26 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>IDBFactory.cmp() - compared keys return correct value</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
function RunTest() {
var greater = window.indexedDB.cmp(2, 1);
var equal = window.indexedDB.cmp(2, 2);
var less = window.indexedDB.cmp(1, 2);

assert_equals(greater, 1, "greater");
assert_equals(equal, 0, "equal");
assert_equals(less, -1, "less");
}

test(RunTest, "IDBFactory.cmp()", null);
</script>
</head>
<body>
<div id="log">
</div>
</body>
</html>
<meta charset=utf-8>
<title>IDBFactory.cmp() - compared keys return correct value</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>

<script>
test(function() {
var greater = window.indexedDB.cmp(2, 1);
var equal = window.indexedDB.cmp(2, 2);
var less = window.indexedDB.cmp(1, 2);

assert_equals(greater, 1, "greater");
assert_equals(equal, 0, "equal");
assert_equals(less, -1, "less");
}, "IDBFactory.cmp()");
</script>

<div id=log></div>
2 changes: 0 additions & 2 deletions IndexedDB/idbindex_getKey.htm
Expand Up @@ -15,15 +15,13 @@
db = e.target.result;
var objStore = db.createObjectStore("test", { keyPath: "key" });
objStore.createIndex("index", "indexedProperty");
console.log(objStore.indexNames[0]);

objStore.add(record);
};

open_rq.onsuccess = function(e) {
var rq = db.transaction("test")
.objectStore("test");
console.log(rq.indexNames[0]);

rq = rq.index("index");

Expand Down
128 changes: 62 additions & 66 deletions IndexedDB/idbkeyrange.htm
@@ -1,70 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>IDBKeyRange Tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

// only
test( function() {
var keyRange = IDBKeyRange.only(1);
<meta charset=utf-8>
<title>IDBKeyRange Tests</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>

<script>
// only
test( function() {
var keyRange = IDBKeyRange.only(1);
assert_true(keyRange instanceof IDBKeyRange, "keyRange instanceof IDBKeyRange");
assert_equals(keyRange.lower, 1, "keyRange");
assert_equals(keyRange.upper, 1, "keyRange");
assert_false(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_false(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.only() - returns an IDBKeyRange and the properties are set correctly");

// lowerBound
test( function() {
var keyRange = IDBKeyRange.lowerBound(1, true)
assert_true(keyRange instanceof IDBKeyRange, "keyRange instanceof IDBKeyRange");
assert_equals(keyRange.lower, 1, "keyRange.lower");
assert_equals(keyRange.upper, undefined, "keyRange.upper");
assert_true(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_true(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.lowerBound() - returns an IDBKeyRange and the properties are set correctly");

test( function() {
var keyRange = IDBKeyRange.lowerBound(1);
assert_false(keyRange.lowerOpen, "keyRange.lowerOpen");
}, "IDBKeyRange.lowerBound() - 'open' parameter has correct default set");

// upperBound
test( function() {
var keyRange = IDBKeyRange.upperBound(1, true);
assert_true(keyRange instanceof IDBKeyRange, "keyRange instanceof IDBKeyRange");
assert_equals(keyRange.lower, 1, "keyRange");
assert_equals(keyRange.upper, 1, "keyRange");
assert_false(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_false(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.only() - returns an IDBKeyRange and the properties are set correctly");

// lowerBound
test( function() {
var keyRange = IDBKeyRange.lowerBound(1, true)
assert_true(keyRange instanceof IDBKeyRange, "keyRange instanceof IDBKeyRange");
assert_equals(keyRange.lower, 1, "keyRange.lower");
assert_equals(keyRange.upper, undefined, "keyRange.upper");
assert_true(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_true(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.lowerBound() - returns an IDBKeyRange and the properties are set correctly");

test( function() {
var keyRange = IDBKeyRange.lowerBound(1);
assert_false(keyRange.lowerOpen, "keyRange.lowerOpen");
}, "IDBKeyRange.lowerBound() - 'open' parameter has correct default set");

// upperBound
test( function() {
var keyRange = IDBKeyRange.upperBound(1, true);
assert_true(keyRange instanceof IDBKeyRange, "keyRange instanceof IDBKeyRange");
assert_equals(keyRange.lower, undefined, "keyRange.lower");
assert_equals(keyRange.upper, 1, "keyRange.upper");
assert_true(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_true(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.upperBound() - returns an IDBKeyRange and the properties are set correctly");

test( function() {
var keyRange = IDBKeyRange.upperBound(1);
assert_false(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.upperBound() - 'open' parameter has correct default set");

// bound
test( function() {
var keyRange = IDBKeyRange.bound(1, 2, true, true);
assert_true(keyRange instanceof IDBKeyRange, "keyRange instanceof IDBKeyRange");
assert_equals(keyRange.lower, 1, "keyRange");
assert_equals(keyRange.upper, 2, "keyRange");
assert_equals(keyRange.lower, undefined, "keyRange.lower");
assert_equals(keyRange.upper, 1, "keyRange.upper");
assert_true(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_true(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.bound() - returns an IDBKeyRange and the properties are set correctly");

test( function() {
var keyRange = IDBKeyRange.bound(1, 2);
assert_false(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_false(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.bound() - 'lowerOpen' and 'upperOpen' parameters have correct defaults set");
</script>
</head>
<body>
<div id="log"></div>
</body>
</html>
}, "IDBKeyRange.upperBound() - returns an IDBKeyRange and the properties are set correctly");

test( function() {
var keyRange = IDBKeyRange.upperBound(1);
assert_false(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.upperBound() - 'open' parameter has correct default set");

// bound
test( function() {
var keyRange = IDBKeyRange.bound(1, 2, true, true);
assert_true(keyRange instanceof IDBKeyRange, "keyRange instanceof IDBKeyRange");
assert_equals(keyRange.lower, 1, "keyRange");
assert_equals(keyRange.upper, 2, "keyRange");
assert_true(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_true(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.bound() - returns an IDBKeyRange and the properties are set correctly");

test( function() {
var keyRange = IDBKeyRange.bound(1, 2);
assert_false(keyRange.lowerOpen, "keyRange.lowerOpen");
assert_false(keyRange.upperOpen, "keyRange.upperOpen");
}, "IDBKeyRange.bound() - 'lowerOpen' and 'upperOpen' parameters have correct defaults set");
</script>

<div id=log></div>

0 comments on commit 024366e

Please sign in to comment.