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/child/thread_safe_sender.h" |
10 #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" | 11 #include "ipc/ipc_sync_message_filter.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/WebKit/public/platform/WebData.h" | 13 #include "third_party/WebKit/public/platform/WebData.h" |
14 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | 14 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" |
15 | 15 |
16 using WebKit::WebData; | 16 using WebKit::WebData; |
17 using WebKit::WebIDBCallbacks; | 17 using WebKit::WebIDBCallbacks; |
18 using WebKit::WebIDBDatabase; | 18 using WebKit::WebIDBDatabase; |
19 using WebKit::WebIDBKey; | 19 using WebKit::WebIDBKey; |
| 20 using WebKit::WebIDBKeyTypeNumber; |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 class MockDispatcher : public IndexedDBDispatcher { | 26 class MockDispatcher : public IndexedDBDispatcher { |
26 public: | 27 public: |
27 MockDispatcher(ThreadSafeSender* thread_safe_sender) | 28 MockDispatcher(ThreadSafeSender* thread_safe_sender) |
28 : IndexedDBDispatcher(thread_safe_sender), | 29 : IndexedDBDispatcher(thread_safe_sender), |
29 prefetch_calls_(0), | 30 prefetch_calls_(0), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // Verify that the requested count has increased since last time. | 127 // Verify that the requested count has increased since last time. |
127 int prefetch_count = dispatcher.last_prefetch_count(); | 128 int prefetch_count = dispatcher.last_prefetch_count(); |
128 EXPECT_GT(prefetch_count, last_prefetch_count); | 129 EXPECT_GT(prefetch_count, last_prefetch_count); |
129 last_prefetch_count = prefetch_count; | 130 last_prefetch_count = prefetch_count; |
130 | 131 |
131 // Fill the prefetch cache as requested. | 132 // Fill the prefetch cache as requested. |
132 std::vector<IndexedDBKey> keys; | 133 std::vector<IndexedDBKey> keys; |
133 std::vector<IndexedDBKey> primary_keys(prefetch_count); | 134 std::vector<IndexedDBKey> primary_keys(prefetch_count); |
134 std::vector<WebData> values(prefetch_count); | 135 std::vector<WebData> values(prefetch_count); |
135 for (int i = 0; i < prefetch_count; ++i) { | 136 for (int i = 0; i < prefetch_count; ++i) { |
136 keys.push_back(IndexedDBKey(expected_key + i, WebIDBKey::NumberType)); | 137 keys.push_back(IndexedDBKey(expected_key + i, WebIDBKeyTypeNumber)); |
137 } | 138 } |
138 cursor.SetPrefetchData(keys, primary_keys, values); | 139 cursor.SetPrefetchData(keys, primary_keys, values); |
139 | 140 |
140 // Note that the real dispatcher would call cursor->CachedContinue() | 141 // Note that the real dispatcher would call cursor->CachedContinue() |
141 // immediately after cursor->SetPrefetchData() to service the request | 142 // immediately after cursor->SetPrefetchData() to service the request |
142 // that initiated the prefetch. | 143 // that initiated the prefetch. |
143 | 144 |
144 // Verify that the cache is used for subsequent continue() calls. | 145 // Verify that the cache is used for subsequent continue() calls. |
145 for (int i = 0; i < prefetch_count; ++i) { | 146 for (int i = 0; i < prefetch_count; ++i) { |
146 IndexedDBKey key; | 147 IndexedDBKey key; |
147 cursor.continueFunction(null_key, new MockContinueCallbacks(&key)); | 148 cursor.continueFunction(null_key, new MockContinueCallbacks(&key)); |
148 EXPECT_EQ(continue_calls, dispatcher.continue_calls()); | 149 EXPECT_EQ(continue_calls, dispatcher.continue_calls()); |
149 EXPECT_EQ(repetitions + 1, dispatcher.prefetch_calls()); | 150 EXPECT_EQ(repetitions + 1, dispatcher.prefetch_calls()); |
150 | 151 |
151 EXPECT_EQ(WebIDBKey::NumberType, key.type()); | 152 EXPECT_EQ(WebIDBKeyTypeNumber, key.type()); |
152 EXPECT_EQ(expected_key++, key.number()); | 153 EXPECT_EQ(expected_key++, key.number()); |
153 } | 154 } |
154 } | 155 } |
155 } | 156 } |
156 | 157 |
157 EXPECT_EQ(dispatcher.destroyed_cursor_id(), | 158 EXPECT_EQ(dispatcher.destroyed_cursor_id(), |
158 RendererWebIDBCursorImpl::kInvalidCursorId); | 159 RendererWebIDBCursorImpl::kInvalidCursorId); |
159 } | 160 } |
160 | 161 |
161 } // namespace content | 162 } // namespace content |
OLD | NEW |