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" |
11 #include "content/common/indexed_db/indexed_db_key.h" | 11 #include "content/common/indexed_db/indexed_db_key.h" |
12 #include "content/common/indexed_db/indexed_db_key_range.h" | 12 #include "content/common/indexed_db/indexed_db_key_range.h" |
13 #include "content/common/indexed_db/indexed_db_messages.h" | 13 #include "content/common/indexed_db/indexed_db_messages.h" |
14 #include "ipc/ipc_sync_message_filter.h" | 14 #include "ipc/ipc_sync_message_filter.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/WebKit/public/platform/WebBlobInfo.h" | |
16 #include "third_party/WebKit/public/platform/WebData.h" | 17 #include "third_party/WebKit/public/platform/WebData.h" |
17 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | 18 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" |
18 | 19 |
20 using blink::WebBlobInfo; | |
19 using blink::WebData; | 21 using blink::WebData; |
20 using blink::WebIDBCallbacks; | 22 using blink::WebIDBCallbacks; |
21 using blink::WebIDBCursor; | 23 using blink::WebIDBCursor; |
22 using blink::WebIDBDatabase; | 24 using blink::WebIDBDatabase; |
23 using blink::WebIDBDatabaseError; | 25 using blink::WebIDBDatabaseError; |
24 using blink::WebIDBKey; | 26 using blink::WebIDBKey; |
25 using blink::WebVector; | 27 using blink::WebVector; |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 namespace { | 30 namespace { |
29 | 31 |
30 class MockCallbacks : public WebIDBCallbacks { | 32 class MockCallbacks : public WebIDBCallbacks { |
31 public: | 33 public: |
32 MockCallbacks() : error_seen_(false) {} | 34 MockCallbacks() : error_seen_(false) {} |
33 | 35 |
34 virtual void onError(const WebIDBDatabaseError&) { error_seen_ = true; } | 36 virtual void onError(const WebIDBDatabaseError&) OVERRIDE { |
jsbell
2014/04/09 20:11:08
IIRC, in content/ we don't typically mark override
ericu
2014/04/09 21:14:47
Gotcha; reverted.
| |
37 error_seen_ = true; | |
38 } | |
35 | 39 |
36 bool error_seen() const { return error_seen_; } | 40 bool error_seen() const { return error_seen_; } |
37 | 41 |
38 private: | 42 private: |
39 bool error_seen_; | 43 bool error_seen_; |
40 }; | 44 }; |
41 | 45 |
42 class MockDispatcher : public IndexedDBDispatcher { | 46 class MockDispatcher : public IndexedDBDispatcher { |
43 public: | 47 public: |
44 MockDispatcher(ThreadSafeSender* sender) : IndexedDBDispatcher(sender) {} | 48 MockDispatcher(ThreadSafeSender* sender) : IndexedDBDispatcher(sender) {} |
(...skipping 19 matching lines...) Expand all Loading... | |
64 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; | 68 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; |
65 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 69 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
66 | 70 |
67 private: | 71 private: |
68 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcherTest); | 72 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcherTest); |
69 }; | 73 }; |
70 | 74 |
71 TEST_F(IndexedDBDispatcherTest, ValueSizeTest) { | 75 TEST_F(IndexedDBDispatcherTest, ValueSizeTest) { |
72 const std::vector<char> data(kMaxIDBValueSizeInBytes + 1); | 76 const std::vector<char> data(kMaxIDBValueSizeInBytes + 1); |
73 const WebData value(&data.front(), data.size()); | 77 const WebData value(&data.front(), data.size()); |
78 const WebVector<WebBlobInfo> webBlobInfo; | |
jsbell
2014/04/09 20:11:08
Should be snake_case here (and below)
ericu
2014/04/09 21:14:47
Done.
| |
74 const int32 ipc_dummy_id = -1; | 79 const int32 ipc_dummy_id = -1; |
75 const int64 transaction_id = 1; | 80 const int64 transaction_id = 1; |
76 const int64 object_store_id = 2; | 81 const int64 object_store_id = 2; |
77 | 82 |
78 MockCallbacks callbacks; | 83 MockCallbacks callbacks; |
79 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); | 84 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); |
80 IndexedDBKey key(0, blink::WebIDBKeyTypeNumber); | 85 IndexedDBKey key(0, blink::WebIDBKeyTypeNumber); |
81 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, | 86 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, |
82 transaction_id, | 87 transaction_id, |
83 object_store_id, | 88 object_store_id, |
84 value, | 89 value, |
90 webBlobInfo, | |
85 key, | 91 key, |
86 WebIDBDatabase::AddOrUpdate, | 92 WebIDBDatabase::AddOrUpdate, |
87 &callbacks, | 93 &callbacks, |
88 WebVector<long long>(), | 94 WebVector<long long>(), |
89 WebVector<WebVector<WebIDBKey> >()); | 95 WebVector<WebVector<WebIDBKey> >()); |
90 | 96 |
91 EXPECT_TRUE(callbacks.error_seen()); | 97 EXPECT_TRUE(callbacks.error_seen()); |
92 } | 98 } |
93 | 99 |
94 TEST_F(IndexedDBDispatcherTest, KeyAndValueSizeTest) { | 100 TEST_F(IndexedDBDispatcherTest, KeyAndValueSizeTest) { |
95 const size_t kKeySize = 1024 * 1024; | 101 const size_t kKeySize = 1024 * 1024; |
96 | 102 |
97 const std::vector<char> data(kMaxIDBValueSizeInBytes - kKeySize); | 103 const std::vector<char> data(kMaxIDBValueSizeInBytes - kKeySize); |
98 const WebData value(&data.front(), data.size()); | 104 const WebData value(&data.front(), data.size()); |
105 const WebVector<WebBlobInfo> webBlobInfo; | |
99 const IndexedDBKey key( | 106 const IndexedDBKey key( |
100 base::string16(kKeySize / sizeof(base::string16::value_type), 'x')); | 107 base::string16(kKeySize / sizeof(base::string16::value_type), 'x')); |
101 | 108 |
102 const int32 ipc_dummy_id = -1; | 109 const int32 ipc_dummy_id = -1; |
103 const int64 transaction_id = 1; | 110 const int64 transaction_id = 1; |
104 const int64 object_store_id = 2; | 111 const int64 object_store_id = 2; |
105 | 112 |
106 MockCallbacks callbacks; | 113 MockCallbacks callbacks; |
107 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); | 114 IndexedDBDispatcher dispatcher(thread_safe_sender_.get()); |
108 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, | 115 dispatcher.RequestIDBDatabasePut(ipc_dummy_id, |
109 transaction_id, | 116 transaction_id, |
110 object_store_id, | 117 object_store_id, |
111 value, | 118 value, |
119 webBlobInfo, | |
112 key, | 120 key, |
113 WebIDBDatabase::AddOrUpdate, | 121 WebIDBDatabase::AddOrUpdate, |
114 &callbacks, | 122 &callbacks, |
115 WebVector<long long>(), | 123 WebVector<long long>(), |
116 WebVector<WebVector<WebIDBKey> >()); | 124 WebVector<WebVector<WebIDBKey> >()); |
117 | 125 |
118 EXPECT_TRUE(callbacks.error_seen()); | 126 EXPECT_TRUE(callbacks.error_seen()); |
119 } | 127 } |
120 | 128 |
121 namespace { | 129 namespace { |
122 | 130 |
123 class CursorCallbacks : public WebIDBCallbacks { | 131 class CursorCallbacks : public WebIDBCallbacks { |
124 public: | 132 public: |
125 CursorCallbacks(scoped_ptr<WebIDBCursor>* cursor) : cursor_(cursor) {} | 133 CursorCallbacks(scoped_ptr<WebIDBCursor>* cursor) : cursor_(cursor) {} |
126 | 134 |
127 virtual void onSuccess(const WebData&) {} | 135 virtual void onSuccess(const WebData&) OVERRIDE {} |
128 virtual void onSuccess(WebIDBCursor* cursor, | 136 virtual void onSuccess(WebIDBCursor* cursor, |
129 const WebIDBKey& key, | 137 const WebIDBKey& key, |
130 const WebIDBKey& primaryKey, | 138 const WebIDBKey& primaryKey, |
131 const WebData& value) { | 139 const WebData& value) OVERRIDE { |
132 cursor_->reset(cursor); | 140 cursor_->reset(cursor); |
133 } | 141 } |
134 | 142 |
135 private: | 143 private: |
136 scoped_ptr<WebIDBCursor>* cursor_; | 144 scoped_ptr<WebIDBCursor>* cursor_; |
137 }; | 145 }; |
138 | 146 |
139 } // namespace | 147 } // namespace |
140 | 148 |
141 TEST_F(IndexedDBDispatcherTest, CursorTransactionId) { | 149 TEST_F(IndexedDBDispatcherTest, CursorTransactionId) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 cursor1_transaction_id); | 325 cursor1_transaction_id); |
318 | 326 |
319 EXPECT_EQ(2, cursor1->reset_count()); | 327 EXPECT_EQ(2, cursor1->reset_count()); |
320 EXPECT_EQ(0, cursor2->reset_count()); | 328 EXPECT_EQ(0, cursor2->reset_count()); |
321 | 329 |
322 cursor1.reset(); | 330 cursor1.reset(); |
323 cursor2.reset(); | 331 cursor2.reset(); |
324 } | 332 } |
325 | 333 |
326 } // namespace content | 334 } // namespace content |
OLD | NEW |