| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 8 #include "base/macros.h" |
| 5 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 7 #include "base/values.h" | 11 #include "base/values.h" |
| 8 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 12 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 9 #include "content/child/indexed_db/indexed_db_key_builders.h" | 13 #include "content/child/indexed_db/indexed_db_key_builders.h" |
| 10 #include "content/child/indexed_db/mock_webidbcallbacks.h" | 14 #include "content/child/indexed_db/mock_webidbcallbacks.h" |
| 11 #include "content/child/indexed_db/webidbcursor_impl.h" | 15 #include "content/child/indexed_db/webidbcursor_impl.h" |
| 12 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
| 13 #include "content/common/indexed_db/indexed_db_key.h" | 17 #include "content/common/indexed_db/indexed_db_key.h" |
| 14 #include "ipc/ipc_sync_message_filter.h" | 18 #include "ipc/ipc_sync_message_filter.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 35 prefetch_calls_(0), | 39 prefetch_calls_(0), |
| 36 last_prefetch_count_(0), | 40 last_prefetch_count_(0), |
| 37 reset_calls_(0), | 41 reset_calls_(0), |
| 38 last_used_count_(0), | 42 last_used_count_(0), |
| 39 advance_calls_(0), | 43 advance_calls_(0), |
| 40 continue_calls_(0), | 44 continue_calls_(0), |
| 41 destroyed_cursor_id_(0) {} | 45 destroyed_cursor_id_(0) {} |
| 42 | 46 |
| 43 void RequestIDBCursorPrefetch(int n, | 47 void RequestIDBCursorPrefetch(int n, |
| 44 WebIDBCallbacks* callbacks, | 48 WebIDBCallbacks* callbacks, |
| 45 int32 ipc_cursor_id) override { | 49 int32_t ipc_cursor_id) override { |
| 46 ++prefetch_calls_; | 50 ++prefetch_calls_; |
| 47 last_prefetch_count_ = n; | 51 last_prefetch_count_ = n; |
| 48 callbacks_.reset(callbacks); | 52 callbacks_.reset(callbacks); |
| 49 } | 53 } |
| 50 | 54 |
| 51 void RequestIDBCursorPrefetchReset(int used_prefetches, | 55 void RequestIDBCursorPrefetchReset(int used_prefetches, |
| 52 int unused_prefetches, | 56 int unused_prefetches, |
| 53 int32 ipc_cursor_id) override { | 57 int32_t ipc_cursor_id) override { |
| 54 ++reset_calls_; | 58 ++reset_calls_; |
| 55 last_used_count_ = used_prefetches; | 59 last_used_count_ = used_prefetches; |
| 56 } | 60 } |
| 57 | 61 |
| 58 void RequestIDBCursorAdvance(unsigned long count, | 62 void RequestIDBCursorAdvance(unsigned long count, |
| 59 WebIDBCallbacks* callbacks, | 63 WebIDBCallbacks* callbacks, |
| 60 int32 ipc_cursor_id, | 64 int32_t ipc_cursor_id, |
| 61 int64 transaction_id) override { | 65 int64_t transaction_id) override { |
| 62 ++advance_calls_; | 66 ++advance_calls_; |
| 63 callbacks_.reset(callbacks); | 67 callbacks_.reset(callbacks); |
| 64 } | 68 } |
| 65 | 69 |
| 66 void RequestIDBCursorContinue(const IndexedDBKey& key, | 70 void RequestIDBCursorContinue(const IndexedDBKey& key, |
| 67 const IndexedDBKey& primary_key, | 71 const IndexedDBKey& primary_key, |
| 68 WebIDBCallbacks* callbacks, | 72 WebIDBCallbacks* callbacks, |
| 69 int32 ipc_cursor_id, | 73 int32_t ipc_cursor_id, |
| 70 int64 transaction_id) override { | 74 int64_t transaction_id) override { |
| 71 ++continue_calls_; | 75 ++continue_calls_; |
| 72 callbacks_.reset(callbacks); | 76 callbacks_.reset(callbacks); |
| 73 } | 77 } |
| 74 | 78 |
| 75 void CursorDestroyed(int32 ipc_cursor_id) override { | 79 void CursorDestroyed(int32_t ipc_cursor_id) override { |
| 76 destroyed_cursor_id_ = ipc_cursor_id; | 80 destroyed_cursor_id_ = ipc_cursor_id; |
| 77 } | 81 } |
| 78 | 82 |
| 79 int prefetch_calls() { return prefetch_calls_; } | 83 int prefetch_calls() { return prefetch_calls_; } |
| 80 int last_prefetch_count() { return last_prefetch_count_; } | 84 int last_prefetch_count() { return last_prefetch_count_; } |
| 81 int reset_calls() { return reset_calls_; } | 85 int reset_calls() { return reset_calls_; } |
| 82 int last_used_count() { return last_used_count_; } | 86 int last_used_count() { return last_used_count_; } |
| 83 int advance_calls() { return advance_calls_; } | 87 int advance_calls() { return advance_calls_; } |
| 84 int continue_calls() { return continue_calls_; } | 88 int continue_calls() { return continue_calls_; } |
| 85 int32 destroyed_cursor_id() { return destroyed_cursor_id_; } | 89 int32_t destroyed_cursor_id() { return destroyed_cursor_id_; } |
| 86 | 90 |
| 87 private: | 91 private: |
| 88 int prefetch_calls_; | 92 int prefetch_calls_; |
| 89 int last_prefetch_count_; | 93 int last_prefetch_count_; |
| 90 int reset_calls_; | 94 int reset_calls_; |
| 91 int last_used_count_; | 95 int last_used_count_; |
| 92 int advance_calls_; | 96 int advance_calls_; |
| 93 int continue_calls_; | 97 int continue_calls_; |
| 94 int32 destroyed_cursor_id_; | 98 int32_t destroyed_cursor_id_; |
| 95 scoped_ptr<WebIDBCallbacks> callbacks_; | 99 scoped_ptr<WebIDBCallbacks> callbacks_; |
| 96 }; | 100 }; |
| 97 | 101 |
| 98 class MockContinueCallbacks : public StrictMock<MockWebIDBCallbacks> { | 102 class MockContinueCallbacks : public StrictMock<MockWebIDBCallbacks> { |
| 99 public: | 103 public: |
| 100 MockContinueCallbacks(IndexedDBKey* key = 0, | 104 MockContinueCallbacks(IndexedDBKey* key = 0, |
| 101 WebVector<WebBlobInfo>* webBlobInfo = 0) | 105 WebVector<WebBlobInfo>* webBlobInfo = 0) |
| 102 : key_(key), web_blob_info_(webBlobInfo) {} | 106 : key_(key), web_blob_info_(webBlobInfo) {} |
| 103 | 107 |
| 104 void onSuccess(const WebIDBKey& key, | 108 void onSuccess(const WebIDBKey& key, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 base::MessageLoop message_loop_; | 144 base::MessageLoop message_loop_; |
| 141 WebIDBKey null_key_; | 145 WebIDBKey null_key_; |
| 142 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 146 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 143 scoped_ptr<MockDispatcher> dispatcher_; | 147 scoped_ptr<MockDispatcher> dispatcher_; |
| 144 | 148 |
| 145 private: | 149 private: |
| 146 DISALLOW_COPY_AND_ASSIGN(WebIDBCursorImplTest); | 150 DISALLOW_COPY_AND_ASSIGN(WebIDBCursorImplTest); |
| 147 }; | 151 }; |
| 148 | 152 |
| 149 TEST_F(WebIDBCursorImplTest, PrefetchTest) { | 153 TEST_F(WebIDBCursorImplTest, PrefetchTest) { |
| 150 const int64 transaction_id = 1; | 154 const int64_t transaction_id = 1; |
| 151 { | 155 { |
| 152 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId, | 156 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId, |
| 153 transaction_id, | 157 transaction_id, |
| 154 thread_safe_sender_.get()); | 158 thread_safe_sender_.get()); |
| 155 | 159 |
| 156 // Call continue() until prefetching should kick in. | 160 // Call continue() until prefetching should kick in. |
| 157 int continue_calls = 0; | 161 int continue_calls = 0; |
| 158 EXPECT_EQ(dispatcher_->continue_calls(), 0); | 162 EXPECT_EQ(dispatcher_->continue_calls(), 0); |
| 159 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { | 163 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { |
| 160 cursor.continueFunction(null_key_, new MockContinueCallbacks()); | 164 cursor.continueFunction(null_key_, new MockContinueCallbacks()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 EXPECT_EQ(expected_key++, key.number()); | 213 EXPECT_EQ(expected_key++, key.number()); |
| 210 } | 214 } |
| 211 } | 215 } |
| 212 } | 216 } |
| 213 | 217 |
| 214 EXPECT_EQ(dispatcher_->destroyed_cursor_id(), | 218 EXPECT_EQ(dispatcher_->destroyed_cursor_id(), |
| 215 WebIDBCursorImpl::kInvalidCursorId); | 219 WebIDBCursorImpl::kInvalidCursorId); |
| 216 } | 220 } |
| 217 | 221 |
| 218 TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { | 222 TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { |
| 219 const int64 transaction_id = 1; | 223 const int64_t transaction_id = 1; |
| 220 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId, | 224 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId, |
| 221 transaction_id, | 225 transaction_id, |
| 222 thread_safe_sender_.get()); | 226 thread_safe_sender_.get()); |
| 223 | 227 |
| 224 // Call continue() until prefetching should kick in. | 228 // Call continue() until prefetching should kick in. |
| 225 EXPECT_EQ(0, dispatcher_->continue_calls()); | 229 EXPECT_EQ(0, dispatcher_->continue_calls()); |
| 226 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { | 230 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { |
| 227 cursor.continueFunction(null_key_, new MockContinueCallbacks()); | 231 cursor.continueFunction(null_key_, new MockContinueCallbacks()); |
| 228 } | 232 } |
| 229 EXPECT_EQ(0, dispatcher_->prefetch_calls()); | 233 EXPECT_EQ(0, dispatcher_->prefetch_calls()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // IDBCursor.advance(lots) - beyond the fetched amount | 283 // IDBCursor.advance(lots) - beyond the fetched amount |
| 280 cursor.advance(WebIDBCursorImpl::kMaxPrefetchAmount, | 284 cursor.advance(WebIDBCursorImpl::kMaxPrefetchAmount, |
| 281 new MockContinueCallbacks(&key)); | 285 new MockContinueCallbacks(&key)); |
| 282 EXPECT_EQ(1, dispatcher_->advance_calls()); | 286 EXPECT_EQ(1, dispatcher_->advance_calls()); |
| 283 EXPECT_EQ(1, dispatcher_->prefetch_calls()); | 287 EXPECT_EQ(1, dispatcher_->prefetch_calls()); |
| 284 EXPECT_EQ(static_cast<int>(WebIDBCursorImpl::kPrefetchContinueThreshold), | 288 EXPECT_EQ(static_cast<int>(WebIDBCursorImpl::kPrefetchContinueThreshold), |
| 285 dispatcher_->continue_calls()); | 289 dispatcher_->continue_calls()); |
| 286 } | 290 } |
| 287 | 291 |
| 288 TEST_F(WebIDBCursorImplTest, PrefetchReset) { | 292 TEST_F(WebIDBCursorImplTest, PrefetchReset) { |
| 289 const int64 transaction_id = 1; | 293 const int64_t transaction_id = 1; |
| 290 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId, | 294 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId, |
| 291 transaction_id, | 295 transaction_id, |
| 292 thread_safe_sender_.get()); | 296 thread_safe_sender_.get()); |
| 293 | 297 |
| 294 // Call continue() until prefetching should kick in. | 298 // Call continue() until prefetching should kick in. |
| 295 int continue_calls = 0; | 299 int continue_calls = 0; |
| 296 EXPECT_EQ(dispatcher_->continue_calls(), 0); | 300 EXPECT_EQ(dispatcher_->continue_calls(), 0); |
| 297 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { | 301 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { |
| 298 cursor.continueFunction(null_key_, new MockContinueCallbacks()); | 302 cursor.continueFunction(null_key_, new MockContinueCallbacks()); |
| 299 EXPECT_EQ(++continue_calls, dispatcher_->continue_calls()); | 303 EXPECT_EQ(++continue_calls, dispatcher_->continue_calls()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 325 // The real dispatcher would call cursor->CachedContinue(), so do that: | 329 // The real dispatcher would call cursor->CachedContinue(), so do that: |
| 326 MockContinueCallbacks callbacks; | 330 MockContinueCallbacks callbacks; |
| 327 cursor.CachedContinue(&callbacks); | 331 cursor.CachedContinue(&callbacks); |
| 328 | 332 |
| 329 // Now the cursor should have reset the rest of the cache. | 333 // Now the cursor should have reset the rest of the cache. |
| 330 EXPECT_EQ(1, dispatcher_->reset_calls()); | 334 EXPECT_EQ(1, dispatcher_->reset_calls()); |
| 331 EXPECT_EQ(1, dispatcher_->last_used_count()); | 335 EXPECT_EQ(1, dispatcher_->last_used_count()); |
| 332 } | 336 } |
| 333 | 337 |
| 334 } // namespace content | 338 } // namespace content |
| OLD | NEW |