Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: content/child/indexed_db/proxy_webidbcursor_impl_unittest.cc

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle the rest of Josh's feedback. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(IndexedDBKey* key = 0,
74 WebVector<WebBlobInfo>* webBlobInfo = 0)
75 : key_(key), webBlobInfo_(webBlobInfo) {}
72 76
73 virtual void onSuccess(const WebIDBKey& key, 77 virtual void onSuccess(const WebIDBKey& key,
74 const WebIDBKey& primaryKey, 78 const WebIDBKey& primaryKey,
75 const WebData& value) { 79 const WebData& value,
80 const WebVector<WebBlobInfo>& webBlobInfo) OVERRIDE {
76 81
77 if (key_) 82 if (key_)
78 *key_ = IndexedDBKeyBuilder::Build(key); 83 *key_ = IndexedDBKeyBuilder::Build(key);
84 if (webBlobInfo_)
85 *webBlobInfo_ = webBlobInfo;
79 } 86 }
80 87
81 private: 88 private:
82 IndexedDBKey* key_; 89 IndexedDBKey* key_;
90 WebVector<WebBlobInfo>* webBlobInfo_;
83 }; 91 };
84 92
85 } // namespace 93 } // namespace
86 94
87 TEST(RendererWebIDBCursorImplTest, PrefetchTest) { 95 TEST(RendererWebIDBCursorImplTest, PrefetchTest) {
88 96
89 WebIDBKey null_key; 97 WebIDBKey null_key;
90 null_key.assignNull(); 98 null_key.assignNull();
91 99
92 scoped_refptr<base::MessageLoopProxy> message_loop_proxy( 100 scoped_refptr<base::MessageLoopProxy> message_loop_proxy(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 136
129 // Verify that the requested count has increased since last time. 137 // Verify that the requested count has increased since last time.
130 int prefetch_count = dispatcher.last_prefetch_count(); 138 int prefetch_count = dispatcher.last_prefetch_count();
131 EXPECT_GT(prefetch_count, last_prefetch_count); 139 EXPECT_GT(prefetch_count, last_prefetch_count);
132 last_prefetch_count = prefetch_count; 140 last_prefetch_count = prefetch_count;
133 141
134 // Fill the prefetch cache as requested. 142 // Fill the prefetch cache as requested.
135 std::vector<IndexedDBKey> keys; 143 std::vector<IndexedDBKey> keys;
136 std::vector<IndexedDBKey> primary_keys(prefetch_count); 144 std::vector<IndexedDBKey> primary_keys(prefetch_count);
137 std::vector<WebData> values(prefetch_count); 145 std::vector<WebData> values(prefetch_count);
146 std::vector<WebVector<WebBlobInfo> > blob_info;
138 for (int i = 0; i < prefetch_count; ++i) { 147 for (int i = 0; i < prefetch_count; ++i) {
139 keys.push_back(IndexedDBKey(expected_key + i, WebIDBKeyTypeNumber)); 148 keys.push_back(IndexedDBKey(expected_key + i, WebIDBKeyTypeNumber));
149 blob_info.push_back(
150 WebVector<WebBlobInfo>(static_cast<size_t>(expected_key + i)));
140 } 151 }
141 cursor.SetPrefetchData(keys, primary_keys, values); 152 cursor.SetPrefetchData(keys, primary_keys, values, blob_info);
142 153
143 // Note that the real dispatcher would call cursor->CachedContinue() 154 // Note that the real dispatcher would call cursor->CachedContinue()
144 // immediately after cursor->SetPrefetchData() to service the request 155 // immediately after cursor->SetPrefetchData() to service the request
145 // that initiated the prefetch. 156 // that initiated the prefetch.
146 157
147 // Verify that the cache is used for subsequent continue() calls. 158 // Verify that the cache is used for subsequent continue() calls.
148 for (int i = 0; i < prefetch_count; ++i) { 159 for (int i = 0; i < prefetch_count; ++i) {
149 IndexedDBKey key; 160 IndexedDBKey key;
150 cursor.continueFunction(null_key, new MockContinueCallbacks(&key)); 161 WebVector<WebBlobInfo> web_blob_info;
162 cursor.continueFunction(
163 null_key, new MockContinueCallbacks(&key, &web_blob_info));
151 EXPECT_EQ(continue_calls, dispatcher.continue_calls()); 164 EXPECT_EQ(continue_calls, dispatcher.continue_calls());
152 EXPECT_EQ(repetitions + 1, dispatcher.prefetch_calls()); 165 EXPECT_EQ(repetitions + 1, dispatcher.prefetch_calls());
153 166
154 EXPECT_EQ(WebIDBKeyTypeNumber, key.type()); 167 EXPECT_EQ(WebIDBKeyTypeNumber, key.type());
168 EXPECT_EQ(expected_key, static_cast<int>(web_blob_info.size()));
155 EXPECT_EQ(expected_key++, key.number()); 169 EXPECT_EQ(expected_key++, key.number());
156 } 170 }
157 } 171 }
158 } 172 }
159 173
160 EXPECT_EQ(dispatcher.destroyed_cursor_id(), 174 EXPECT_EQ(dispatcher.destroyed_cursor_id(),
161 RendererWebIDBCursorImpl::kInvalidCursorId); 175 RendererWebIDBCursorImpl::kInvalidCursorId);
162 } 176 }
163 177
164 } // namespace content 178 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698