Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/indexed_db/proxy_webidbcursor_impl.h" | |
| 6 | |
| 7 #include "base/compiler_specific.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 class RendererWebIDBCursorImplTest : public testing::Test { | |
| 11 }; | |
| 12 | |
| 13 class MockIDBCallbacks : public WebKit::WebIDBCallbacks { | |
| 14 public: | |
| 15 MockIDBCallbacks() : m_called(false) { } | |
| 16 void reset() { m_called = false; } | |
| 17 bool wasCalled() { return m_called; } | |
| 18 virtual void onSuccessWithContinuation() OVERRIDE { m_called = true; }; | |
| 19 private: | |
| 20 bool m_called; | |
| 21 }; | |
| 22 | |
| 23 TEST_F(RendererWebIDBCursorImplTest, PrefetchTest) { | |
| 24 RendererWebIDBCursorImpl cursor(kInvalidIDBCursorId); | |
|
michaeln
2012/03/13 18:39:48
I was wondering how the kInvalidIDBCursorId value
| |
| 25 | |
| 26 MockIDBCallbacks callbacks; | |
| 27 | |
| 28 std::vector<IndexedDBKey> keys; | |
| 29 std::vector<IndexedDBKey> primary_keys; | |
| 30 std::vector<content::SerializedScriptValue> values; | |
| 31 for (int i = 0; i < 3; ++i) { | |
| 32 IndexedDBKey key; | |
| 33 IndexedDBKey primary_key; | |
| 34 content::SerializedScriptValue value; | |
| 35 key.SetNumber(i); | |
| 36 primary_key.SetNumber(i); | |
| 37 keys.push_back(key); | |
| 38 primary_keys.push_back(primary_key); | |
| 39 values.push_back(value); | |
| 40 } | |
| 41 | |
| 42 cursor.SetPrefetchData(keys, primary_keys, values); | |
| 43 | |
| 44 for (int i = 0; i < 3; ++i) { | |
| 45 callbacks.reset(); | |
| 46 WebKit::WebIDBKey continueKey = WebKit::WebIDBKey::createNull(); | |
| 47 WebKit::WebExceptionCode ec; | |
| 48 cursor.continueFunction(continueKey, &callbacks, ec); | |
| 49 EXPECT_TRUE(callbacks.wasCalled()); | |
| 50 EXPECT_EQ(cursor.key().type(), WebKit::WebIDBKey::NumberType); | |
| 51 EXPECT_EQ(cursor.key().number(), i); | |
| 52 } | |
| 53 } | |
| 54 | |
| OLD | NEW |