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

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

Issue 1544273002: Switch to standard integer types in content/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months 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
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 <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/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
7 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
8 #include "base/values.h" 12 #include "base/values.h"
9 #include "content/child/indexed_db/indexed_db_dispatcher.h" 13 #include "content/child/indexed_db/indexed_db_dispatcher.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 "content/common/indexed_db/indexed_db_key_range.h" 18 #include "content/common/indexed_db/indexed_db_key_range.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 }; 78 };
75 79
76 TEST_F(IndexedDBDispatcherTest, ValueSizeTest) { 80 TEST_F(IndexedDBDispatcherTest, ValueSizeTest) {
77 // For testing use a much smaller maximum size to prevent allocating >100 MB 81 // For testing use a much smaller maximum size to prevent allocating >100 MB
78 // of memory, which crashes on memory-constrained systems. 82 // of memory, which crashes on memory-constrained systems.
79 const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB 83 const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB
80 84
81 const std::vector<char> data(kMaxValueSizeForTesting + 1); 85 const std::vector<char> data(kMaxValueSizeForTesting + 1);
82 const WebData value(&data.front(), data.size()); 86 const WebData value(&data.front(), data.size());
83 const WebVector<WebBlobInfo> web_blob_info; 87 const WebVector<WebBlobInfo> web_blob_info;
84 const int32 ipc_dummy_id = -1; 88 const int32_t ipc_dummy_id = -1;
85 const int64 transaction_id = 1; 89 const int64_t transaction_id = 1;
86 const int64 object_store_id = 2; 90 const int64_t object_store_id = 2;
87 91
88 StrictMock<MockWebIDBCallbacks> callbacks; 92 StrictMock<MockWebIDBCallbacks> callbacks;
89 EXPECT_CALL(callbacks, onError(_)).Times(1); 93 EXPECT_CALL(callbacks, onError(_)).Times(1);
90 94
91 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); 95 IndexedDBDispatcher dispatcher(thread_safe_sender_.get());
92 dispatcher.max_put_value_size_ = kMaxValueSizeForTesting; 96 dispatcher.max_put_value_size_ = kMaxValueSizeForTesting;
93 IndexedDBKey key(0, blink::WebIDBKeyTypeNumber); 97 IndexedDBKey key(0, blink::WebIDBKeyTypeNumber);
94 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, 98 dispatcher.RequestIDBDatabasePut(ipc_dummy_id,
95 transaction_id, 99 transaction_id,
96 object_store_id, 100 object_store_id,
(...skipping 11 matching lines...) Expand all
108 // of memory, which crashes on memory-constrained systems. 112 // of memory, which crashes on memory-constrained systems.
109 const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB 113 const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB
110 const size_t kKeySize = 1024 * 1024; 114 const size_t kKeySize = 1024 * 1024;
111 115
112 const std::vector<char> data(kMaxValueSizeForTesting - kKeySize); 116 const std::vector<char> data(kMaxValueSizeForTesting - kKeySize);
113 const WebData value(&data.front(), data.size()); 117 const WebData value(&data.front(), data.size());
114 const WebVector<WebBlobInfo> web_blob_info; 118 const WebVector<WebBlobInfo> web_blob_info;
115 const IndexedDBKey key( 119 const IndexedDBKey key(
116 base::string16(kKeySize / sizeof(base::string16::value_type), 'x')); 120 base::string16(kKeySize / sizeof(base::string16::value_type), 'x'));
117 121
118 const int32 ipc_dummy_id = -1; 122 const int32_t ipc_dummy_id = -1;
119 const int64 transaction_id = 1; 123 const int64_t transaction_id = 1;
120 const int64 object_store_id = 2; 124 const int64_t object_store_id = 2;
121 125
122 StrictMock<MockWebIDBCallbacks> callbacks; 126 StrictMock<MockWebIDBCallbacks> callbacks;
123 EXPECT_CALL(callbacks, onError(_)).Times(1); 127 EXPECT_CALL(callbacks, onError(_)).Times(1);
124 128
125 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); 129 IndexedDBDispatcher dispatcher(thread_safe_sender_.get());
126 dispatcher.max_put_value_size_ = kMaxValueSizeForTesting; 130 dispatcher.max_put_value_size_ = kMaxValueSizeForTesting;
127 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, 131 dispatcher.RequestIDBDatabasePut(ipc_dummy_id,
128 transaction_id, 132 transaction_id,
129 object_store_id, 133 object_store_id,
130 value, 134 value,
131 web_blob_info, 135 web_blob_info,
132 key, 136 key,
133 blink::WebIDBPutModeAddOrUpdate, 137 blink::WebIDBPutModeAddOrUpdate,
134 &callbacks, 138 &callbacks,
135 WebVector<long long>(), 139 WebVector<long long>(),
136 WebVector<WebVector<WebIDBKey> >()); 140 WebVector<WebVector<WebIDBKey> >());
137 } 141 }
138 142
139 TEST_F(IndexedDBDispatcherTest, CursorTransactionId) { 143 TEST_F(IndexedDBDispatcherTest, CursorTransactionId) {
140 const int32 ipc_database_id = -1; 144 const int32_t ipc_database_id = -1;
141 const int64 transaction_id = 1234; 145 const int64_t transaction_id = 1234;
142 const int64 object_store_id = 2; 146 const int64_t object_store_id = 2;
143 const int32 index_id = 3; 147 const int32_t index_id = 3;
144 const blink::WebIDBCursorDirection direction = 148 const blink::WebIDBCursorDirection direction =
145 blink::WebIDBCursorDirectionNext; 149 blink::WebIDBCursorDirectionNext;
146 const bool key_only = false; 150 const bool key_only = false;
147 151
148 MockDispatcher dispatcher(thread_safe_sender_.get()); 152 MockDispatcher dispatcher(thread_safe_sender_.get());
149 153
150 // First case: successful cursor open. 154 // First case: successful cursor open.
151 { 155 {
152 scoped_ptr<WebIDBCursor> cursor; 156 scoped_ptr<WebIDBCursor> cursor;
153 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); 157 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size());
(...skipping 10 matching lines...) Expand all
164 // Make a cursor request. This should record the transaction id. 168 // Make a cursor request. This should record the transaction id.
165 dispatcher.RequestIDBDatabaseOpenCursor( 169 dispatcher.RequestIDBDatabaseOpenCursor(
166 ipc_database_id, transaction_id, object_store_id, index_id, 170 ipc_database_id, transaction_id, object_store_id, index_id,
167 IndexedDBKeyRange(), direction, key_only, blink::WebIDBTaskTypeNormal, 171 IndexedDBKeyRange(), direction, key_only, blink::WebIDBTaskTypeNormal,
168 callbacks); 172 callbacks);
169 173
170 // Verify that the transaction id was captured. 174 // Verify that the transaction id was captured.
171 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); 175 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size());
172 EXPECT_FALSE(cursor.get()); 176 EXPECT_FALSE(cursor.get());
173 177
174 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; 178 int32_t ipc_callbacks_id =
179 dispatcher.cursor_transaction_ids_.begin()->first;
175 180
176 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params; 181 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params;
177 params.ipc_thread_id = dispatcher.CurrentWorkerId(); 182 params.ipc_thread_id = dispatcher.CurrentWorkerId();
178 params.ipc_callbacks_id = ipc_callbacks_id; 183 params.ipc_callbacks_id = ipc_callbacks_id;
179 184
180 // Now simululate the cursor response. 185 // Now simululate the cursor response.
181 params.ipc_cursor_id = WebIDBCursorImpl::kInvalidCursorId; 186 params.ipc_cursor_id = WebIDBCursorImpl::kInvalidCursorId;
182 dispatcher.OnSuccessOpenCursor(params); 187 dispatcher.OnSuccessOpenCursor(params);
183 188
184 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); 189 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size());
(...skipping 17 matching lines...) Expand all
202 207
203 // Make a cursor request. This should record the transaction id. 208 // Make a cursor request. This should record the transaction id.
204 dispatcher.RequestIDBDatabaseOpenCursor( 209 dispatcher.RequestIDBDatabaseOpenCursor(
205 ipc_database_id, transaction_id, object_store_id, index_id, 210 ipc_database_id, transaction_id, object_store_id, index_id,
206 IndexedDBKeyRange(), direction, key_only, blink::WebIDBTaskTypeNormal, 211 IndexedDBKeyRange(), direction, key_only, blink::WebIDBTaskTypeNormal,
207 callbacks); 212 callbacks);
208 213
209 // Verify that the transaction id was captured. 214 // Verify that the transaction id was captured.
210 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); 215 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size());
211 216
212 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; 217 int32_t ipc_callbacks_id =
218 dispatcher.cursor_transaction_ids_.begin()->first;
213 219
214 // Now simululate a "null cursor" response. 220 // Now simululate a "null cursor" response.
215 IndexedDBMsg_CallbacksSuccessValue_Params params; 221 IndexedDBMsg_CallbacksSuccessValue_Params params;
216 params.ipc_thread_id = dispatcher.CurrentWorkerId(); 222 params.ipc_thread_id = dispatcher.CurrentWorkerId();
217 params.ipc_callbacks_id = ipc_callbacks_id; 223 params.ipc_callbacks_id = ipc_callbacks_id;
218 dispatcher.OnSuccessValue(params); 224 dispatcher.OnSuccessValue(params);
219 225
220 // Ensure the map result was deleted. 226 // Ensure the map result was deleted.
221 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); 227 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size());
222 } 228 }
223 } 229 }
224 230
225 namespace { 231 namespace {
226 232
227 class MockCursor : public WebIDBCursorImpl { 233 class MockCursor : public WebIDBCursorImpl {
228 public: 234 public:
229 MockCursor(int32 ipc_cursor_id, 235 MockCursor(int32_t ipc_cursor_id,
230 int64 transaction_id, 236 int64_t transaction_id,
231 ThreadSafeSender* thread_safe_sender) 237 ThreadSafeSender* thread_safe_sender)
232 : WebIDBCursorImpl(ipc_cursor_id, transaction_id, thread_safe_sender), 238 : WebIDBCursorImpl(ipc_cursor_id, transaction_id, thread_safe_sender),
233 reset_count_(0) {} 239 reset_count_(0) {}
234 240
235 // This method is virtual so it can be overridden in unit tests. 241 // This method is virtual so it can be overridden in unit tests.
236 void ResetPrefetchCache() override { ++reset_count_; } 242 void ResetPrefetchCache() override { ++reset_count_; }
237 243
238 int reset_count() const { return reset_count_; } 244 int reset_count() const { return reset_count_; }
239 245
240 private: 246 private:
241 int reset_count_; 247 int reset_count_;
242 248
243 DISALLOW_COPY_AND_ASSIGN(MockCursor); 249 DISALLOW_COPY_AND_ASSIGN(MockCursor);
244 }; 250 };
245 251
246 } // namespace 252 } // namespace
247 253
248 TEST_F(IndexedDBDispatcherTest, CursorReset) { 254 TEST_F(IndexedDBDispatcherTest, CursorReset) {
249 scoped_ptr<WebIDBCursor> cursor; 255 scoped_ptr<WebIDBCursor> cursor;
250 MockDispatcher dispatcher(thread_safe_sender_.get()); 256 MockDispatcher dispatcher(thread_safe_sender_.get());
251 257
252 const int32 ipc_database_id = 0; 258 const int32_t ipc_database_id = 0;
253 const int32 object_store_id = 0; 259 const int32_t object_store_id = 0;
254 const int32 index_id = 0; 260 const int32_t index_id = 0;
255 const bool key_only = false; 261 const bool key_only = false;
256 const int cursor1_ipc_id = 1; 262 const int cursor1_ipc_id = 1;
257 const int cursor2_ipc_id = 2; 263 const int cursor2_ipc_id = 2;
258 const int other_cursor_ipc_id = 2; 264 const int other_cursor_ipc_id = 2;
259 const int cursor1_transaction_id = 1; 265 const int cursor1_transaction_id = 1;
260 const int cursor2_transaction_id = 2; 266 const int cursor2_transaction_id = 2;
261 const int other_transaction_id = 3; 267 const int other_transaction_id = 3;
262 268
263 scoped_ptr<MockCursor> cursor1( 269 scoped_ptr<MockCursor> cursor1(
264 new MockCursor(WebIDBCursorImpl::kInvalidCursorId, 270 new MockCursor(WebIDBCursorImpl::kInvalidCursorId,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 other_cursor_ipc_id, cursor1_transaction_id); 312 other_cursor_ipc_id, cursor1_transaction_id);
307 313
308 EXPECT_EQ(2, cursor1->reset_count()); 314 EXPECT_EQ(2, cursor1->reset_count());
309 EXPECT_EQ(0, cursor2->reset_count()); 315 EXPECT_EQ(0, cursor2->reset_count());
310 316
311 cursor1.reset(); 317 cursor1.reset();
312 cursor2.reset(); 318 cursor2.reset();
313 } 319 }
314 320
315 } // namespace content 321 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/indexed_db_dispatcher.cc ('k') | content/child/indexed_db/indexed_db_key_builders.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698