OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "content/child/indexed_db/mock_webidbcallbacks.h" |
| 13 #include "content/child/indexed_db/webidbdatabase_impl.h" |
| 14 #include "content/child/thread_safe_sender.h" |
| 15 #include "content/common/indexed_db/indexed_db_key.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/WebBlobInfo.h" |
| 19 #include "third_party/WebKit/public/platform/WebData.h" |
| 20 #include "third_party/WebKit/public/web/WebHeap.h" |
| 21 |
| 22 using blink::WebBlobInfo; |
| 23 using blink::WebData; |
| 24 using blink::WebIDBCursor; |
| 25 using blink::WebIDBKey; |
| 26 using blink::WebVector; |
| 27 using testing::_; |
| 28 using testing::Invoke; |
| 29 using testing::StrictMock; |
| 30 using testing::WithArgs; |
| 31 |
| 32 namespace content { |
| 33 |
| 34 class WebIDBDatabaseImplTest : public testing::Test { |
| 35 public: |
| 36 WebIDBDatabaseImplTest() {} |
| 37 |
| 38 void TearDown() override { blink::WebHeap::collectAllGarbageForTesting(); } |
| 39 |
| 40 private: |
| 41 TestBrowserThreadBundle thread_bundle_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(WebIDBDatabaseImplTest); |
| 44 }; |
| 45 |
| 46 TEST_F(WebIDBDatabaseImplTest, ValueSizeTest) { |
| 47 // For testing use a much smaller maximum size to prevent allocating >100 MB |
| 48 // of memory, which crashes on memory-constrained systems. |
| 49 const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB |
| 50 |
| 51 const std::vector<char> data(kMaxValueSizeForTesting + 1); |
| 52 const WebData value(&data.front(), data.size()); |
| 53 const WebVector<WebBlobInfo> web_blob_info; |
| 54 |
| 55 const int64_t transaction_id = 1; |
| 56 const int64_t object_store_id = 2; |
| 57 |
| 58 StrictMock<MockWebIDBCallbacks> callbacks; |
| 59 EXPECT_CALL(callbacks, onError(_)).Times(1); |
| 60 |
| 61 WebIDBDatabaseImpl database_impl(nullptr, base::ThreadTaskRunnerHandle::Get(), |
| 62 nullptr); |
| 63 database_impl.max_put_value_size_ = kMaxValueSizeForTesting; |
| 64 database_impl.put(transaction_id, object_store_id, value, web_blob_info, |
| 65 WebIDBKey::createNumber(0), blink::WebIDBPutModeAddOrUpdate, |
| 66 &callbacks, WebVector<long long>(), |
| 67 WebVector<WebVector<WebIDBKey>>()); |
| 68 } |
| 69 |
| 70 TEST_F(WebIDBDatabaseImplTest, KeyAndValueSizeTest) { |
| 71 // For testing use a much smaller maximum size to prevent allocating >100 MB |
| 72 // of memory, which crashes on memory-constrained systems. |
| 73 const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB |
| 74 const size_t kKeySize = 1024 * 1024; |
| 75 |
| 76 const std::vector<char> data(kMaxValueSizeForTesting - kKeySize); |
| 77 const WebData value(&data.front(), data.size()); |
| 78 const WebVector<WebBlobInfo> web_blob_info; |
| 79 const WebIDBKey key = WebIDBKey::createString( |
| 80 base::string16(kKeySize / sizeof(base::string16::value_type), 'x')); |
| 81 |
| 82 const int64_t transaction_id = 1; |
| 83 const int64_t object_store_id = 2; |
| 84 |
| 85 StrictMock<MockWebIDBCallbacks> callbacks; |
| 86 EXPECT_CALL(callbacks, onError(_)).Times(1); |
| 87 |
| 88 WebIDBDatabaseImpl database_impl(nullptr, base::ThreadTaskRunnerHandle::Get(), |
| 89 nullptr); |
| 90 database_impl.max_put_value_size_ = kMaxValueSizeForTesting; |
| 91 database_impl.put(transaction_id, object_store_id, value, web_blob_info, key, |
| 92 blink::WebIDBPutModeAddOrUpdate, &callbacks, |
| 93 WebVector<long long>(), WebVector<WebVector<WebIDBKey>>()); |
| 94 } |
| 95 |
| 96 } // namespace content |
OLD | NEW |