| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 7 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 8 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" | 8 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" |
| 9 #include "content/child/thread_safe_sender.h" |
| 9 #include "content/common/indexed_db/indexed_db_key.h" | 10 #include "content/common/indexed_db/indexed_db_key.h" |
| 11 #include "ipc/ipc_sync_message_filter.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/WebKit/public/platform/WebData.h" | 13 #include "third_party/WebKit/public/platform/WebData.h" |
| 12 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | 14 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" |
| 13 | 15 |
| 14 using WebKit::WebData; | 16 using WebKit::WebData; |
| 15 using WebKit::WebIDBCallbacks; | 17 using WebKit::WebIDBCallbacks; |
| 16 using WebKit::WebIDBDatabase; | 18 using WebKit::WebIDBDatabase; |
| 17 using WebKit::WebIDBDatabaseError; | 19 using WebKit::WebIDBDatabaseError; |
| 18 using WebKit::WebIDBKey; | 20 using WebKit::WebIDBKey; |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 class MockDispatcher : public IndexedDBDispatcher { | 26 class MockDispatcher : public IndexedDBDispatcher { |
| 25 public: | 27 public: |
| 26 MockDispatcher() | 28 MockDispatcher(ThreadSafeSender* thread_safe_sender) |
| 27 : prefetch_calls_(0), | 29 : IndexedDBDispatcher(thread_safe_sender), |
| 30 prefetch_calls_(0), |
| 28 last_prefetch_count_(0), | 31 last_prefetch_count_(0), |
| 29 continue_calls_(0), | 32 continue_calls_(0), |
| 30 destroyed_cursor_id_(0) {} | 33 destroyed_cursor_id_(0) {} |
| 31 | 34 |
| 32 virtual void RequestIDBCursorPrefetch(int n, | 35 virtual void RequestIDBCursorPrefetch(int n, |
| 33 WebIDBCallbacks* callbacks, | 36 WebIDBCallbacks* callbacks, |
| 34 int32 ipc_cursor_id) OVERRIDE { | 37 int32 ipc_cursor_id) OVERRIDE { |
| 35 ++prefetch_calls_; | 38 ++prefetch_calls_; |
| 36 last_prefetch_count_ = n; | 39 last_prefetch_count_ = n; |
| 37 callbacks_.reset(callbacks); | 40 callbacks_.reset(callbacks); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 IndexedDBKey* key_; | 80 IndexedDBKey* key_; |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 } // namespace | 83 } // namespace |
| 81 | 84 |
| 82 TEST(RendererWebIDBCursorImplTest, PrefetchTest) { | 85 TEST(RendererWebIDBCursorImplTest, PrefetchTest) { |
| 83 | 86 |
| 84 WebIDBKey null_key; | 87 WebIDBKey null_key; |
| 85 null_key.assignNull(); | 88 null_key.assignNull(); |
| 86 | 89 |
| 87 MockDispatcher dispatcher; | 90 scoped_refptr<base::MessageLoopProxy> message_loop_proxy( |
| 91 base::MessageLoopProxy::current()); |
| 92 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter( |
| 93 new IPC::SyncMessageFilter(NULL)); |
| 94 scoped_refptr<ThreadSafeSender> thread_safe_sender(new ThreadSafeSender( |
| 95 message_loop_proxy, sync_message_filter)); |
| 96 |
| 97 MockDispatcher dispatcher(thread_safe_sender); |
| 88 | 98 |
| 89 { | 99 { |
| 90 RendererWebIDBCursorImpl cursor(RendererWebIDBCursorImpl::kInvalidCursorId); | 100 RendererWebIDBCursorImpl cursor( |
| 101 RendererWebIDBCursorImpl::kInvalidCursorId, thread_safe_sender); |
| 91 | 102 |
| 92 // Call continue() until prefetching should kick in. | 103 // Call continue() until prefetching should kick in. |
| 93 int continue_calls = 0; | 104 int continue_calls = 0; |
| 94 EXPECT_EQ(dispatcher.continue_calls(), 0); | 105 EXPECT_EQ(dispatcher.continue_calls(), 0); |
| 95 for (int i = 0; i < RendererWebIDBCursorImpl::kPrefetchContinueThreshold; | 106 for (int i = 0; i < RendererWebIDBCursorImpl::kPrefetchContinueThreshold; |
| 96 ++i) { | 107 ++i) { |
| 97 cursor.continueFunction(null_key, new MockContinueCallbacks()); | 108 cursor.continueFunction(null_key, new MockContinueCallbacks()); |
| 98 EXPECT_EQ(++continue_calls, dispatcher.continue_calls()); | 109 EXPECT_EQ(++continue_calls, dispatcher.continue_calls()); |
| 99 EXPECT_EQ(0, dispatcher.prefetch_calls()); | 110 EXPECT_EQ(0, dispatcher.prefetch_calls()); |
| 100 } | 111 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 EXPECT_EQ(expected_key++, key.number()); | 153 EXPECT_EQ(expected_key++, key.number()); |
| 143 } | 154 } |
| 144 } | 155 } |
| 145 } | 156 } |
| 146 | 157 |
| 147 EXPECT_EQ(dispatcher.destroyed_cursor_id(), | 158 EXPECT_EQ(dispatcher.destroyed_cursor_id(), |
| 148 RendererWebIDBCursorImpl::kInvalidCursorId); | 159 RendererWebIDBCursorImpl::kInvalidCursorId); |
| 149 } | 160 } |
| 150 | 161 |
| 151 } // namespace content | 162 } // namespace content |
| OLD | NEW |