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/message_loop/message_loop_proxy.h" | 6 #include "base/message_loop/message_loop_proxy.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 8 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
9 #include "content/child/indexed_db/webidbcursor_impl.h" | 9 #include "content/child/indexed_db/webidbcursor_impl.h" |
10 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 MockCallbacks callbacks; | 87 MockCallbacks callbacks; |
88 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); | 88 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); |
89 IndexedDBKey key(0, blink::WebIDBKeyTypeNumber); | 89 IndexedDBKey key(0, blink::WebIDBKeyTypeNumber); |
90 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, | 90 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, |
91 transaction_id, | 91 transaction_id, |
92 object_store_id, | 92 object_store_id, |
93 value, | 93 value, |
94 web_blob_info, | 94 web_blob_info, |
95 key, | 95 key, |
96 WebIDBDatabase::AddOrUpdate, | 96 blink::WebIDBPutModeAddOrUpdate, |
97 &callbacks, | 97 &callbacks, |
98 WebVector<long long>(), | 98 WebVector<long long>(), |
99 WebVector<WebVector<WebIDBKey> >()); | 99 WebVector<WebVector<WebIDBKey> >()); |
100 | 100 |
101 EXPECT_TRUE(callbacks.error_seen()); | 101 EXPECT_TRUE(callbacks.error_seen()); |
102 } | 102 } |
103 | 103 |
104 TEST_F(IndexedDBDispatcherTest, KeyAndValueSizeTest) { | 104 TEST_F(IndexedDBDispatcherTest, KeyAndValueSizeTest) { |
105 const size_t kKeySize = 1024 * 1024; | 105 const size_t kKeySize = 1024 * 1024; |
106 | 106 |
107 const std::vector<char> data(kMaxIDBValueSizeInBytes - kKeySize); | 107 const std::vector<char> data(kMaxIDBValueSizeInBytes - kKeySize); |
108 const WebData value(&data.front(), data.size()); | 108 const WebData value(&data.front(), data.size()); |
109 const WebVector<WebBlobInfo> web_blob_info; | 109 const WebVector<WebBlobInfo> web_blob_info; |
110 const IndexedDBKey key( | 110 const IndexedDBKey key( |
111 base::string16(kKeySize / sizeof(base::string16::value_type), 'x')); | 111 base::string16(kKeySize / sizeof(base::string16::value_type), 'x')); |
112 | 112 |
113 const int32 ipc_dummy_id = -1; | 113 const int32 ipc_dummy_id = -1; |
114 const int64 transaction_id = 1; | 114 const int64 transaction_id = 1; |
115 const int64 object_store_id = 2; | 115 const int64 object_store_id = 2; |
116 | 116 |
117 MockCallbacks callbacks; | 117 MockCallbacks callbacks; |
118 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); | 118 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); |
119 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, | 119 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, |
120 transaction_id, | 120 transaction_id, |
121 object_store_id, | 121 object_store_id, |
122 value, | 122 value, |
123 web_blob_info, | 123 web_blob_info, |
124 key, | 124 key, |
125 WebIDBDatabase::AddOrUpdate, | 125 blink::WebIDBPutModeAddOrUpdate, |
126 &callbacks, | 126 &callbacks, |
127 WebVector<long long>(), | 127 WebVector<long long>(), |
128 WebVector<WebVector<WebIDBKey> >()); | 128 WebVector<WebVector<WebIDBKey> >()); |
129 | 129 |
130 EXPECT_TRUE(callbacks.error_seen()); | 130 EXPECT_TRUE(callbacks.error_seen()); |
131 } | 131 } |
132 | 132 |
133 namespace { | 133 namespace { |
134 | 134 |
135 class CursorCallbacks : public WebIDBCallbacks { | 135 class CursorCallbacks : public WebIDBCallbacks { |
(...skipping 17 matching lines...) Expand all Loading... |
153 DISALLOW_COPY_AND_ASSIGN(CursorCallbacks); | 153 DISALLOW_COPY_AND_ASSIGN(CursorCallbacks); |
154 }; | 154 }; |
155 | 155 |
156 } // namespace | 156 } // namespace |
157 | 157 |
158 TEST_F(IndexedDBDispatcherTest, CursorTransactionId) { | 158 TEST_F(IndexedDBDispatcherTest, CursorTransactionId) { |
159 const int32 ipc_database_id = -1; | 159 const int32 ipc_database_id = -1; |
160 const int64 transaction_id = 1234; | 160 const int64 transaction_id = 1234; |
161 const int64 object_store_id = 2; | 161 const int64 object_store_id = 2; |
162 const int32 index_id = 3; | 162 const int32 index_id = 3; |
163 const WebIDBCursor::Direction direction = WebIDBCursor::Next; | 163 const blink::WebIDBCursorDirection direction = |
| 164 blink::WebIDBCursorDirectionNext; |
164 const bool key_only = false; | 165 const bool key_only = false; |
165 | 166 |
166 MockDispatcher dispatcher(thread_safe_sender_.get()); | 167 MockDispatcher dispatcher(thread_safe_sender_.get()); |
167 | 168 |
168 // First case: successful cursor open. | 169 // First case: successful cursor open. |
169 { | 170 { |
170 scoped_ptr<WebIDBCursor> cursor; | 171 scoped_ptr<WebIDBCursor> cursor; |
171 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); | 172 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); |
172 | 173 |
173 // Make a cursor request. This should record the transaction id. | 174 // Make a cursor request. This should record the transaction id. |
174 dispatcher.RequestIDBDatabaseOpenCursor(ipc_database_id, | 175 dispatcher.RequestIDBDatabaseOpenCursor(ipc_database_id, |
175 transaction_id, | 176 transaction_id, |
176 object_store_id, | 177 object_store_id, |
177 index_id, | 178 index_id, |
178 IndexedDBKeyRange(), | 179 IndexedDBKeyRange(), |
179 direction, | 180 direction, |
180 key_only, | 181 key_only, |
181 blink::WebIDBDatabase::NormalTask, | 182 blink::WebIDBTaskTypeNormal, |
182 new CursorCallbacks(&cursor)); | 183 new CursorCallbacks(&cursor)); |
183 | 184 |
184 // Verify that the transaction id was captured. | 185 // Verify that the transaction id was captured. |
185 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); | 186 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); |
186 EXPECT_FALSE(cursor.get()); | 187 EXPECT_FALSE(cursor.get()); |
187 | 188 |
188 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; | 189 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; |
189 | 190 |
190 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params; | 191 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params; |
191 params.ipc_thread_id = dispatcher.CurrentWorkerId(); | 192 params.ipc_thread_id = dispatcher.CurrentWorkerId(); |
(...skipping 20 matching lines...) Expand all Loading... |
212 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); | 213 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); |
213 | 214 |
214 // Make a cursor request. This should record the transaction id. | 215 // Make a cursor request. This should record the transaction id. |
215 dispatcher.RequestIDBDatabaseOpenCursor(ipc_database_id, | 216 dispatcher.RequestIDBDatabaseOpenCursor(ipc_database_id, |
216 transaction_id, | 217 transaction_id, |
217 object_store_id, | 218 object_store_id, |
218 index_id, | 219 index_id, |
219 IndexedDBKeyRange(), | 220 IndexedDBKeyRange(), |
220 direction, | 221 direction, |
221 key_only, | 222 key_only, |
222 blink::WebIDBDatabase::NormalTask, | 223 blink::WebIDBTaskTypeNormal, |
223 new CursorCallbacks(&cursor)); | 224 new CursorCallbacks(&cursor)); |
224 | 225 |
225 // Verify that the transaction id was captured. | 226 // Verify that the transaction id was captured. |
226 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); | 227 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); |
227 EXPECT_FALSE(cursor.get()); | 228 EXPECT_FALSE(cursor.get()); |
228 | 229 |
229 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; | 230 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; |
230 | 231 |
231 // Now simululate a "null cursor" response. | 232 // Now simululate a "null cursor" response. |
232 IndexedDBMsg_CallbacksSuccessValue_Params params; | 233 IndexedDBMsg_CallbacksSuccessValue_Params params; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 cursor1_transaction_id); | 337 cursor1_transaction_id); |
337 | 338 |
338 EXPECT_EQ(2, cursor1->reset_count()); | 339 EXPECT_EQ(2, cursor1->reset_count()); |
339 EXPECT_EQ(0, cursor2->reset_count()); | 340 EXPECT_EQ(0, cursor2->reset_count()); |
340 | 341 |
341 cursor1.reset(); | 342 cursor1.reset(); |
342 cursor2.reset(); | 343 cursor2.reset(); |
343 } | 344 } |
344 | 345 |
345 } // namespace content | 346 } // namespace content |
OLD | NEW |