Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: Source/WebKit/chromium/tests/IDBDatabaseBackendTest.cpp

Issue 10630009: Merge 120828 - [Chromium] IndexedDB: Don't close database if pending connections are in flight (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1180/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/WebCore/inspector/InspectorIndexedDBAgent.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 EXPECT_GT(backingStore->refCount(), 1); 60 EXPECT_GT(backingStore->refCount(), 1);
61 61
62 db.clear(); 62 db.clear();
63 EXPECT_TRUE(backingStore->hasOneRef()); 63 EXPECT_TRUE(backingStore->hasOneRef());
64 store.clear(); 64 store.clear();
65 EXPECT_TRUE(backingStore->hasOneRef()); 65 EXPECT_TRUE(backingStore->hasOneRef());
66 index.clear(); 66 index.clear();
67 EXPECT_TRUE(backingStore->hasOneRef()); 67 EXPECT_TRUE(backingStore->hasOneRef());
68 } 68 }
69 69
70 class MockIDBCallbacks : public IDBCallbacks {
71 public:
72 static PassRefPtr<MockIDBCallbacks> create() { return adoptRef(new MockIDBCa llbacks()); }
73 virtual ~MockIDBCallbacks() OVERRIDE
74 {
75 EXPECT_TRUE(m_wasSuccessDBCalled);
76 }
77 virtual void onError(PassRefPtr<IDBDatabaseError>) OVERRIDE { }
78 virtual void onSuccess(PassRefPtr<DOMStringList>) OVERRIDE { }
79 virtual void onSuccess(PassRefPtr<IDBCursorBackendInterface>) OVERRIDE { }
80 virtual void onSuccess(PassRefPtr<IDBDatabaseBackendInterface>) OVERRIDE
81 {
82 m_wasSuccessDBCalled = true;
83 }
84 virtual void onSuccess(PassRefPtr<IDBKey>) OVERRIDE { }
85 virtual void onSuccess(PassRefPtr<IDBTransactionBackendInterface>) OVERRIDE { }
86 virtual void onSuccess(PassRefPtr<SerializedScriptValue>) OVERRIDE { }
87 virtual void onSuccessWithContinuation() OVERRIDE { }
88 virtual void onSuccessWithPrefetch(const Vector<RefPtr<IDBKey> >&, const Vec tor<RefPtr<IDBKey> >&, const Vector<RefPtr<SerializedScriptValue> >&) OVERRIDE { }
89 virtual void onBlocked() OVERRIDE { }
90 private:
91 MockIDBCallbacks()
92 : m_wasSuccessDBCalled(false) { }
93 bool m_wasSuccessDBCalled;
94 };
95
96 class FakeIDBDatabaseCallbacks : public IDBDatabaseCallbacks {
97 public:
98 static PassRefPtr<FakeIDBDatabaseCallbacks> create() { return adoptRef(new F akeIDBDatabaseCallbacks()); }
99 virtual ~FakeIDBDatabaseCallbacks() OVERRIDE { }
100 virtual void onVersionChange(const String& version) OVERRIDE { }
101 private:
102 FakeIDBDatabaseCallbacks() { }
103 };
104
105 TEST(IDBDatabaseBackendTest, ConnectionLifecycle)
106 {
107 RefPtr<IDBFakeBackingStore> backingStore = adoptRef(new IDBFakeBackingStore( ));
108 EXPECT_TRUE(backingStore->hasOneRef());
109
110 IDBTransactionCoordinator* coordinator = 0;
111 IDBFactoryBackendImpl* factory = 0;
112 RefPtr<IDBDatabaseBackendImpl> db = IDBDatabaseBackendImpl::create("db", bac kingStore.get(), coordinator, factory, "uniqueid");
113 EXPECT_GT(backingStore->refCount(), 1);
114
115 RefPtr<MockIDBCallbacks> request1 = MockIDBCallbacks::create();
116 db->openConnection(request1);
117
118 RefPtr<FakeIDBDatabaseCallbacks> connection1 = FakeIDBDatabaseCallbacks::cre ate();
119 db->registerFrontendCallbacks(connection1);
120
121 RefPtr<MockIDBCallbacks> request2 = MockIDBCallbacks::create();
122 db->openConnection(request2);
123
124 db->close(connection1);
125 EXPECT_GT(backingStore->refCount(), 1);
126
127 RefPtr<FakeIDBDatabaseCallbacks> connection2 = FakeIDBDatabaseCallbacks::cre ate();
128 db->registerFrontendCallbacks(connection2);
129
130 db->close(connection2);
131 EXPECT_TRUE(backingStore->hasOneRef());
132 }
133
70 } // namespace 134 } // namespace
71 135
72 #endif // ENABLE(INDEXED_DATABASE) 136 #endif // ENABLE(INDEXED_DATABASE)
OLDNEW
« no previous file with comments | « Source/WebCore/inspector/InspectorIndexedDBAgent.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698