| 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::AddOrUpdate, |
| 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::AddOrUpdate, |
| 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::Direction direction = blink::Next; |
| 162 const bool key_only = false; | 162 const bool key_only = false; |
| 163 | 163 |
| 164 MockDispatcher dispatcher(thread_safe_sender_.get()); | 164 MockDispatcher dispatcher(thread_safe_sender_.get()); |
| 165 | 165 |
| 166 // First case: successful cursor open. | 166 // First case: successful cursor open. |
| 167 { | 167 { |
| 168 scoped_ptr<WebIDBCursor> cursor; | 168 scoped_ptr<WebIDBCursor> cursor; |
| 169 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); | 169 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); |
| 170 | 170 |
| 171 // Make a cursor request. This should record the transaction id. | 171 // Make a cursor request. This should record the transaction id. |
| 172 dispatcher.RequestIDBDatabaseOpenCursor(ipc_database_id, | 172 dispatcher.RequestIDBDatabaseOpenCursor(ipc_database_id, |
| 173 transaction_id, | 173 transaction_id, |
| 174 object_store_id, | 174 object_store_id, |
| 175 index_id, | 175 index_id, |
| 176 IndexedDBKeyRange(), | 176 IndexedDBKeyRange(), |
| 177 direction, | 177 direction, |
| 178 key_only, | 178 key_only, |
| 179 blink::WebIDBDatabase::NormalTask, | 179 blink::NormalTask, |
| 180 new CursorCallbacks(&cursor)); | 180 new CursorCallbacks(&cursor)); |
| 181 | 181 |
| 182 // Verify that the transaction id was captured. | 182 // Verify that the transaction id was captured. |
| 183 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); | 183 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); |
| 184 EXPECT_FALSE(cursor.get()); | 184 EXPECT_FALSE(cursor.get()); |
| 185 | 185 |
| 186 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; | 186 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; |
| 187 | 187 |
| 188 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params; | 188 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params; |
| 189 params.ipc_thread_id = dispatcher.CurrentWorkerId(); | 189 params.ipc_thread_id = dispatcher.CurrentWorkerId(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 210 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); | 210 EXPECT_EQ(0UL, dispatcher.cursor_transaction_ids_.size()); |
| 211 | 211 |
| 212 // Make a cursor request. This should record the transaction id. | 212 // Make a cursor request. This should record the transaction id. |
| 213 dispatcher.RequestIDBDatabaseOpenCursor(ipc_database_id, | 213 dispatcher.RequestIDBDatabaseOpenCursor(ipc_database_id, |
| 214 transaction_id, | 214 transaction_id, |
| 215 object_store_id, | 215 object_store_id, |
| 216 index_id, | 216 index_id, |
| 217 IndexedDBKeyRange(), | 217 IndexedDBKeyRange(), |
| 218 direction, | 218 direction, |
| 219 key_only, | 219 key_only, |
| 220 blink::WebIDBDatabase::NormalTask, | 220 blink::NormalTask, |
| 221 new CursorCallbacks(&cursor)); | 221 new CursorCallbacks(&cursor)); |
| 222 | 222 |
| 223 // Verify that the transaction id was captured. | 223 // Verify that the transaction id was captured. |
| 224 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); | 224 EXPECT_EQ(1UL, dispatcher.cursor_transaction_ids_.size()); |
| 225 EXPECT_FALSE(cursor.get()); | 225 EXPECT_FALSE(cursor.get()); |
| 226 | 226 |
| 227 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; | 227 int32 ipc_callbacks_id = dispatcher.cursor_transaction_ids_.begin()->first; |
| 228 | 228 |
| 229 // Now simululate a "null cursor" response. | 229 // Now simululate a "null cursor" response. |
| 230 IndexedDBMsg_CallbacksSuccessValue_Params params; | 230 IndexedDBMsg_CallbacksSuccessValue_Params params; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 cursor1_transaction_id); | 334 cursor1_transaction_id); |
| 335 | 335 |
| 336 EXPECT_EQ(2, cursor1->reset_count()); | 336 EXPECT_EQ(2, cursor1->reset_count()); |
| 337 EXPECT_EQ(0, cursor2->reset_count()); | 337 EXPECT_EQ(0, cursor2->reset_count()); |
| 338 | 338 |
| 339 cursor1.reset(); | 339 cursor1.reset(); |
| 340 cursor2.reset(); | 340 cursor2.reset(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 } // namespace content | 343 } // namespace content |
| OLD | NEW |