| Index: content/child/indexed_db/webidbcursor_impl_unittest.cc
|
| diff --git a/content/child/indexed_db/webidbcursor_impl_unittest.cc b/content/child/indexed_db/webidbcursor_impl_unittest.cc
|
| index 14842df9c3e802a8ec50ed8f444fd04d1ddbeeab..111595048cb52eaffa7aee16dee97bc9a1e61700 100644
|
| --- a/content/child/indexed_db/webidbcursor_impl_unittest.cc
|
| +++ b/content/child/indexed_db/webidbcursor_impl_unittest.cc
|
| @@ -30,6 +30,8 @@ class MockDispatcher : public IndexedDBDispatcher {
|
| : IndexedDBDispatcher(thread_safe_sender),
|
| prefetch_calls_(0),
|
| last_prefetch_count_(0),
|
| + reset_calls_(0),
|
| + last_used_count_(0),
|
| advance_calls_(0),
|
| continue_calls_(0),
|
| destroyed_cursor_id_(0) {}
|
| @@ -42,6 +44,13 @@ class MockDispatcher : public IndexedDBDispatcher {
|
| callbacks_.reset(callbacks);
|
| }
|
|
|
| + virtual void RequestIDBCursorPrefetchReset(int used_prefetches,
|
| + int unused_prefetches,
|
| + int32 ipc_cursor_id) OVERRIDE {
|
| + ++reset_calls_;
|
| + last_used_count_ = used_prefetches;
|
| + }
|
| +
|
| virtual void RequestIDBCursorAdvance(unsigned long count,
|
| WebIDBCallbacks* callbacks,
|
| int32 ipc_cursor_id) OVERRIDE {
|
| @@ -62,14 +71,18 @@ class MockDispatcher : public IndexedDBDispatcher {
|
| }
|
|
|
| int prefetch_calls() { return prefetch_calls_; }
|
| + int last_prefetch_count() { return last_prefetch_count_; }
|
| + int reset_calls() { return reset_calls_; }
|
| + int last_used_count() { return last_used_count_; }
|
| int advance_calls() { return advance_calls_; }
|
| int continue_calls() { return continue_calls_; }
|
| - int last_prefetch_count() { return last_prefetch_count_; }
|
| int32 destroyed_cursor_id() { return destroyed_cursor_id_; }
|
|
|
| private:
|
| int prefetch_calls_;
|
| int last_prefetch_count_;
|
| + int reset_calls_;
|
| + int last_used_count_;
|
| int advance_calls_;
|
| int continue_calls_;
|
| int32 destroyed_cursor_id_;
|
| @@ -247,4 +260,48 @@ TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) {
|
| dispatcher_->continue_calls());
|
| }
|
|
|
| +TEST_F(WebIDBCursorImplTest, PrefetchReset) {
|
| + WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId,
|
| + thread_safe_sender_.get());
|
| +
|
| + // Call continue() until prefetching should kick in.
|
| + int continue_calls = 0;
|
| + EXPECT_EQ(dispatcher_->continue_calls(), 0);
|
| + for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) {
|
| + cursor.continueFunction(null_key_, new MockContinueCallbacks());
|
| + EXPECT_EQ(++continue_calls, dispatcher_->continue_calls());
|
| + EXPECT_EQ(0, dispatcher_->prefetch_calls());
|
| + }
|
| +
|
| + // Initiate the prefetch
|
| + cursor.continueFunction(null_key_, new MockContinueCallbacks());
|
| + EXPECT_EQ(continue_calls, dispatcher_->continue_calls());
|
| + EXPECT_EQ(1, dispatcher_->prefetch_calls());
|
| + EXPECT_EQ(0, dispatcher_->reset_calls());
|
| +
|
| + // Now invalidate it
|
| + cursor.ResetPrefetchCache();
|
| +
|
| + // No reset should have been sent since nothing has been received yet.
|
| + EXPECT_EQ(0, dispatcher_->reset_calls());
|
| +
|
| + // Fill the prefetch cache as requested.
|
| + int prefetch_count = dispatcher_->last_prefetch_count();
|
| + std::vector<IndexedDBKey> keys(prefetch_count);
|
| + std::vector<IndexedDBKey> primary_keys(prefetch_count);
|
| + std::vector<WebData> values(prefetch_count);
|
| + cursor.SetPrefetchData(keys, primary_keys, values);
|
| +
|
| + // No reset should have been sent since prefetch data hasn't been used.
|
| + EXPECT_EQ(0, dispatcher_->reset_calls());
|
| +
|
| + // The real dispatcher would call cursor->CachedContinue(), so do that:
|
| + scoped_ptr<WebIDBCallbacks> callbacks(new MockContinueCallbacks());
|
| + cursor.CachedContinue(callbacks.get());
|
| +
|
| + // Now the cursor should have reset the rest of the cache.
|
| + EXPECT_EQ(1, dispatcher_->reset_calls());
|
| + EXPECT_EQ(1, dispatcher_->last_used_count());
|
| +}
|
| +
|
| } // namespace content
|
|
|