Permalink
Browse files

Dispose the Cursor object after getAll completes.

R=nicksantos
DELTA=55 (54 added, 0 deleted, 1 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=6193


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2463 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
1 parent a0f1162 commit aef01b4fab98d762596fb3e72b23a81ea493bfa6 scr@google.com committed Jan 24, 2013
Showing with 55 additions and 1 deletion.
  1. +53 −0 closure/goog/db/db_test.html
  2. +2 −1 closure/goog/db/objectstore.js
@@ -12,6 +12,7 @@
<title>Closure Integration Tests - goog.db</title>
<script src="../base.js"></script>
<script>
+goog.require('goog.array');
goog.require('goog.async.Deferred');
goog.require('goog.db');
goog.require('goog.db.IndexedDb');
@@ -21,6 +22,7 @@
goog.require('goog.db.Transaction.TransactionMode');
goog.require('goog.events');
goog.require('goog.events.EventTarget');
+goog.require('goog.object');
goog.require('goog.testing.AsyncTestCase');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
@@ -38,6 +40,7 @@
var dbName;
var dbBaseName = 'testDb';
var globalDb = null;
+var propertyReplacer;
// On Chrome 24+, the database reports its default version as 1 as opposed to
// the empty string (as per the new spec).
@@ -110,6 +113,20 @@
});
}
+function assertStoreValuesAndCursorsDisposed(values, cursors, db) {
+ var assertStoreTx = db.createTransaction(['store']);
+ assertStoreTx.objectStore('store').getAll().addCallback(function(results) {
+ assertSameElements(values, results);
+ assertTrue(cursors.length > 0);
+ goog.array.forEach(cursors, function(elem, index, array) {
+ console.log(elem);
+ assertTrue('array[' + index + '] (' + elem + ') is not disposed',
+ goog.Disposable.isDisposed(elem));
+ });
+ closeAndContinue(db);
+ });
+}
+
function assertStoreDoesntExist(db) {
try {
db.createTransaction(['store']);
@@ -134,6 +151,10 @@
asyncTestCase.continueTesting();
}
+function setUpPage() {
+ propertyReplacer = new goog.testing.PropertyReplacer();
+}
+
function setUp() {
if (!idbSupported) {
return;
@@ -144,6 +165,10 @@
globalDb = openDatabase();
}
+function tearDown() {
+ propertyReplacer.reset();
+}
+
function testDatabaseOpened() {
if (!idbSupported) {
return;
@@ -649,6 +674,34 @@
.addCallback(checkStore);
}
+function testGetAllFreesCursor() {
+ if (!idbSupported) {
+ return;
+ }
+ var values = ['1', '2', '3'];
+ var keys = ['a', 'b', 'c'];
+
+ var addData = goog.partial(populateStore, values, keys);
+ var origCursor = goog.db.Cursor;
+ var cursors = [];
+ /** @constructor */
+ var testCursor = function() {
+ origCursor.call(this);
+ cursors.push(this);
+ };
+ goog.object.extend(testCursor, origCursor);
+ goog.inherits(testCursor, origCursor);
+ propertyReplacer.replace(goog.db, 'Cursor', testCursor);
+ var checkStoreAndCursorDisposed =
+ goog.partial(assertStoreValuesAndCursorsDisposed, values, cursors);
+
+ asyncTestCase.waitForAsync('getting all');
+ globalDb.branch()
+ .addCallbacks(addStore, failOnError)
+ .addCallback(addData)
+ .addCallback(checkStoreAndCursorDisposed);
+}
+
function testCursorGet() {
if (!idbSupported) {
return;
@@ -244,7 +244,7 @@ goog.db.ObjectStore.prototype.getAll = function(opt_range, opt_direction) {
goog.db.Cursor.EventType.ERROR,
goog.db.Cursor.EventType.COMPLETE
], function(evt) {
- goog.events.unlistenByKey(key);
+ cursor.dispose();
if (evt.type == goog.db.Cursor.EventType.COMPLETE) {
d.callback(result);
} else {
@@ -298,6 +298,7 @@ goog.db.ObjectStore.prototype.openCursor = function(opt_range, opt_direction) {
request = this.store_.openCursor(range);
}
} catch (err) {
+ cursor.dispose();
throw goog.db.Error.create(err, msg);
}
request.onsuccess = function(ev) {

0 comments on commit aef01b4

Please sign in to comment.