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