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 21 matching lines...) Expand all Loading... |
32 class MockCallbacks : public WebIDBCallbacks { | 32 class MockCallbacks : public WebIDBCallbacks { |
33 public: | 33 public: |
34 MockCallbacks() : error_seen_(false) {} | 34 MockCallbacks() : error_seen_(false) {} |
35 | 35 |
36 virtual void onError(const WebIDBDatabaseError&) { error_seen_ = true; } | 36 virtual void onError(const WebIDBDatabaseError&) { error_seen_ = true; } |
37 | 37 |
38 bool error_seen() const { return error_seen_; } | 38 bool error_seen() const { return error_seen_; } |
39 | 39 |
40 private: | 40 private: |
41 bool error_seen_; | 41 bool error_seen_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(MockCallbacks); |
42 }; | 44 }; |
43 | 45 |
44 class MockDispatcher : public IndexedDBDispatcher { | 46 class MockDispatcher : public IndexedDBDispatcher { |
45 public: | 47 public: |
46 MockDispatcher(ThreadSafeSender* sender) : IndexedDBDispatcher(sender) {} | 48 MockDispatcher(ThreadSafeSender* sender) : IndexedDBDispatcher(sender) {} |
47 | 49 |
48 virtual bool Send(IPC::Message* msg) OVERRIDE { | 50 virtual bool Send(IPC::Message* msg) OVERRIDE { |
49 delete msg; | 51 delete msg; |
50 return true; | 52 return true; |
51 } | 53 } |
| 54 |
| 55 private: |
| 56 DISALLOW_COPY_AND_ASSIGN(MockDispatcher); |
52 }; | 57 }; |
53 | 58 |
54 } // namespace | 59 } // namespace |
55 | 60 |
56 class IndexedDBDispatcherTest : public testing::Test { | 61 class IndexedDBDispatcherTest : public testing::Test { |
57 public: | 62 public: |
58 IndexedDBDispatcherTest() | 63 IndexedDBDispatcherTest() |
59 : message_loop_proxy_(base::MessageLoopProxy::current()), | 64 : message_loop_proxy_(base::MessageLoopProxy::current()), |
60 sync_message_filter_(new IPC::SyncMessageFilter(NULL)), | 65 sync_message_filter_(new IPC::SyncMessageFilter(NULL)), |
61 thread_safe_sender_(new ThreadSafeSender(message_loop_proxy_.get(), | 66 thread_safe_sender_(new ThreadSafeSender(message_loop_proxy_.get(), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 virtual void onSuccess(WebIDBCursor* cursor, | 140 virtual void onSuccess(WebIDBCursor* cursor, |
136 const WebIDBKey& key, | 141 const WebIDBKey& key, |
137 const WebIDBKey& primaryKey, | 142 const WebIDBKey& primaryKey, |
138 const WebData& value, | 143 const WebData& value, |
139 const WebVector<WebBlobInfo>&) OVERRIDE { | 144 const WebVector<WebBlobInfo>&) OVERRIDE { |
140 cursor_->reset(cursor); | 145 cursor_->reset(cursor); |
141 } | 146 } |
142 | 147 |
143 private: | 148 private: |
144 scoped_ptr<WebIDBCursor>* cursor_; | 149 scoped_ptr<WebIDBCursor>* cursor_; |
| 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(CursorCallbacks); |
145 }; | 152 }; |
146 | 153 |
147 } // namespace | 154 } // namespace |
148 | 155 |
149 TEST_F(IndexedDBDispatcherTest, CursorTransactionId) { | 156 TEST_F(IndexedDBDispatcherTest, CursorTransactionId) { |
150 const int32 ipc_database_id = -1; | 157 const int32 ipc_database_id = -1; |
151 const int64 transaction_id = 1234; | 158 const int64 transaction_id = 1234; |
152 const int64 object_store_id = 2; | 159 const int64 object_store_id = 2; |
153 const int32 index_id = 3; | 160 const int32 index_id = 3; |
154 const WebIDBCursor::Direction direction = WebIDBCursor::Next; | 161 const WebIDBCursor::Direction direction = WebIDBCursor::Next; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 : WebIDBCursorImpl(ipc_cursor_id, transaction_id, thread_safe_sender), | 248 : WebIDBCursorImpl(ipc_cursor_id, transaction_id, thread_safe_sender), |
242 reset_count_(0) {} | 249 reset_count_(0) {} |
243 | 250 |
244 // This method is virtual so it can be overridden in unit tests. | 251 // This method is virtual so it can be overridden in unit tests. |
245 virtual void ResetPrefetchCache() OVERRIDE { ++reset_count_; } | 252 virtual void ResetPrefetchCache() OVERRIDE { ++reset_count_; } |
246 | 253 |
247 int reset_count() const { return reset_count_; } | 254 int reset_count() const { return reset_count_; } |
248 | 255 |
249 private: | 256 private: |
250 int reset_count_; | 257 int reset_count_; |
| 258 |
| 259 DISALLOW_COPY_AND_ASSIGN(MockCursor); |
251 }; | 260 }; |
252 | 261 |
253 } // namespace | 262 } // namespace |
254 | 263 |
255 TEST_F(IndexedDBDispatcherTest, CursorReset) { | 264 TEST_F(IndexedDBDispatcherTest, CursorReset) { |
256 scoped_ptr<WebIDBCursor> cursor; | 265 scoped_ptr<WebIDBCursor> cursor; |
257 MockDispatcher dispatcher(thread_safe_sender_.get()); | 266 MockDispatcher dispatcher(thread_safe_sender_.get()); |
258 | 267 |
259 const int32 ipc_database_id = 0; | 268 const int32 ipc_database_id = 0; |
260 const int32 object_store_id = 0; | 269 const int32 object_store_id = 0; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 cursor1_transaction_id); | 334 cursor1_transaction_id); |
326 | 335 |
327 EXPECT_EQ(2, cursor1->reset_count()); | 336 EXPECT_EQ(2, cursor1->reset_count()); |
328 EXPECT_EQ(0, cursor2->reset_count()); | 337 EXPECT_EQ(0, cursor2->reset_count()); |
329 | 338 |
330 cursor1.reset(); | 339 cursor1.reset(); |
331 cursor2.reset(); | 340 cursor2.reset(); |
332 } | 341 } |
333 | 342 |
334 } // namespace content | 343 } // namespace content |
OLD | NEW |