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/indexed_db_key_builders.h" | 8 #include "content/child/indexed_db/indexed_db_key_builders.h" |
9 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" | 9 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" |
10 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
11 #include "content/common/indexed_db/indexed_db_key.h" | 11 #include "content/common/indexed_db/indexed_db_key.h" |
12 #include "ipc/ipc_sync_message_filter.h" | 12 #include "ipc/ipc_sync_message_filter.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/WebKit/public/platform/WebData.h" | 14 #include "third_party/WebKit/public/platform/WebData.h" |
15 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | 15 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" |
16 | 16 |
| 17 using blink::WebBlobInfo; |
17 using blink::WebData; | 18 using blink::WebData; |
18 using blink::WebIDBCallbacks; | 19 using blink::WebIDBCallbacks; |
19 using blink::WebIDBDatabase; | 20 using blink::WebIDBDatabase; |
20 using blink::WebIDBKey; | 21 using blink::WebIDBKey; |
21 using blink::WebIDBKeyTypeNumber; | 22 using blink::WebIDBKeyTypeNumber; |
| 23 using blink::WebVector; |
22 | 24 |
23 namespace content { | 25 namespace content { |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 class MockDispatcher : public IndexedDBDispatcher { | 29 class MockDispatcher : public IndexedDBDispatcher { |
28 public: | 30 public: |
29 MockDispatcher(ThreadSafeSender* thread_safe_sender) | 31 MockDispatcher(ThreadSafeSender* thread_safe_sender) |
30 : IndexedDBDispatcher(thread_safe_sender), | 32 : IndexedDBDispatcher(thread_safe_sender), |
31 prefetch_calls_(0), | 33 prefetch_calls_(0), |
(...skipping 29 matching lines...) Expand all Loading... |
61 private: | 63 private: |
62 int prefetch_calls_; | 64 int prefetch_calls_; |
63 int last_prefetch_count_; | 65 int last_prefetch_count_; |
64 int continue_calls_; | 66 int continue_calls_; |
65 int32 destroyed_cursor_id_; | 67 int32 destroyed_cursor_id_; |
66 scoped_ptr<WebIDBCallbacks> callbacks_; | 68 scoped_ptr<WebIDBCallbacks> callbacks_; |
67 }; | 69 }; |
68 | 70 |
69 class MockContinueCallbacks : public WebIDBCallbacks { | 71 class MockContinueCallbacks : public WebIDBCallbacks { |
70 public: | 72 public: |
71 MockContinueCallbacks(IndexedDBKey* key = 0) : key_(key) {} | 73 MockContinueCallbacks( |
| 74 IndexedDBKey* key = 0, WebVector<WebBlobInfo>* webBlobInfo = 0) |
| 75 : key_(key), |
| 76 webBlobInfo_(webBlobInfo) { |
| 77 } |
72 | 78 |
73 virtual void onSuccess(const WebIDBKey& key, | 79 virtual void onSuccess(const WebIDBKey& key, |
74 const WebIDBKey& primaryKey, | 80 const WebIDBKey& primaryKey, |
75 const WebData& value) { | 81 const WebData& value, |
| 82 const WebVector<WebBlobInfo>& webBlobInfo) OVERRIDE { |
76 | 83 |
77 if (key_) | 84 if (key_) |
78 *key_ = IndexedDBKeyBuilder::Build(key); | 85 *key_ = IndexedDBKeyBuilder::Build(key); |
| 86 if (webBlobInfo_) |
| 87 *webBlobInfo_ = webBlobInfo; |
79 } | 88 } |
80 | 89 |
81 private: | 90 private: |
82 IndexedDBKey* key_; | 91 IndexedDBKey* key_; |
| 92 WebVector<WebBlobInfo>* webBlobInfo_; |
83 }; | 93 }; |
84 | 94 |
85 } // namespace | 95 } // namespace |
86 | 96 |
87 TEST(RendererWebIDBCursorImplTest, PrefetchTest) { | 97 TEST(RendererWebIDBCursorImplTest, PrefetchTest) { |
88 | 98 |
89 WebIDBKey null_key; | 99 WebIDBKey null_key; |
90 null_key.assignNull(); | 100 null_key.assignNull(); |
91 | 101 |
92 scoped_refptr<base::MessageLoopProxy> message_loop_proxy( | 102 scoped_refptr<base::MessageLoopProxy> message_loop_proxy( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 138 |
129 // Verify that the requested count has increased since last time. | 139 // Verify that the requested count has increased since last time. |
130 int prefetch_count = dispatcher.last_prefetch_count(); | 140 int prefetch_count = dispatcher.last_prefetch_count(); |
131 EXPECT_GT(prefetch_count, last_prefetch_count); | 141 EXPECT_GT(prefetch_count, last_prefetch_count); |
132 last_prefetch_count = prefetch_count; | 142 last_prefetch_count = prefetch_count; |
133 | 143 |
134 // Fill the prefetch cache as requested. | 144 // Fill the prefetch cache as requested. |
135 std::vector<IndexedDBKey> keys; | 145 std::vector<IndexedDBKey> keys; |
136 std::vector<IndexedDBKey> primary_keys(prefetch_count); | 146 std::vector<IndexedDBKey> primary_keys(prefetch_count); |
137 std::vector<WebData> values(prefetch_count); | 147 std::vector<WebData> values(prefetch_count); |
| 148 std::vector<WebVector<WebBlobInfo> > blob_info; |
138 for (int i = 0; i < prefetch_count; ++i) { | 149 for (int i = 0; i < prefetch_count; ++i) { |
139 keys.push_back(IndexedDBKey(expected_key + i, WebIDBKeyTypeNumber)); | 150 keys.push_back(IndexedDBKey(expected_key + i, WebIDBKeyTypeNumber)); |
| 151 blob_info.push_back(WebVector<WebBlobInfo>( |
| 152 static_cast<size_t>(expected_key + i))); |
140 } | 153 } |
141 cursor.SetPrefetchData(keys, primary_keys, values); | 154 cursor.SetPrefetchData(keys, primary_keys, values, blob_info); |
142 | 155 |
143 // Note that the real dispatcher would call cursor->CachedContinue() | 156 // Note that the real dispatcher would call cursor->CachedContinue() |
144 // immediately after cursor->SetPrefetchData() to service the request | 157 // immediately after cursor->SetPrefetchData() to service the request |
145 // that initiated the prefetch. | 158 // that initiated the prefetch. |
146 | 159 |
147 // Verify that the cache is used for subsequent continue() calls. | 160 // Verify that the cache is used for subsequent continue() calls. |
148 for (int i = 0; i < prefetch_count; ++i) { | 161 for (int i = 0; i < prefetch_count; ++i) { |
149 IndexedDBKey key; | 162 IndexedDBKey key; |
150 cursor.continueFunction(null_key, new MockContinueCallbacks(&key)); | 163 WebVector<WebBlobInfo> web_blob_info; |
| 164 cursor.continueFunction(null_key, |
| 165 new MockContinueCallbacks(&key, &web_blob_info)); |
151 EXPECT_EQ(continue_calls, dispatcher.continue_calls()); | 166 EXPECT_EQ(continue_calls, dispatcher.continue_calls()); |
152 EXPECT_EQ(repetitions + 1, dispatcher.prefetch_calls()); | 167 EXPECT_EQ(repetitions + 1, dispatcher.prefetch_calls()); |
153 | 168 |
154 EXPECT_EQ(WebIDBKeyTypeNumber, key.type()); | 169 EXPECT_EQ(WebIDBKeyTypeNumber, key.type()); |
| 170 EXPECT_EQ(expected_key, static_cast<int>(web_blob_info.size())); |
155 EXPECT_EQ(expected_key++, key.number()); | 171 EXPECT_EQ(expected_key++, key.number()); |
156 } | 172 } |
157 } | 173 } |
158 } | 174 } |
159 | 175 |
160 EXPECT_EQ(dispatcher.destroyed_cursor_id(), | 176 EXPECT_EQ(dispatcher.destroyed_cursor_id(), |
161 RendererWebIDBCursorImpl::kInvalidCursorId); | 177 RendererWebIDBCursorImpl::kInvalidCursorId); |
162 } | 178 } |
163 | 179 |
164 } // namespace content | 180 } // namespace content |
OLD | NEW |