Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: content/child/indexed_db/webidbdatabase_impl_unittest.cc

Issue 2449953008: Port messages sent by WebIDBDatabaseImpl to Mojo. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/platform/WebBlobInfo.h"
18 #include "third_party/WebKit/public/platform/WebData.h"
19 #include "third_party/WebKit/public/web/WebHeap.h"
20
21 using blink::WebBlobInfo;
22 using blink::WebData;
23 using blink::WebIDBCursor;
24 using blink::WebIDBKey;
25 using blink::WebVector;
26 using testing::_;
27 using testing::Invoke;
28 using testing::StrictMock;
29 using testing::WithArgs;
30
31 namespace content {
32
33 class WebIDBDatabaseImplTest : public testing::Test {
34 public:
35 WebIDBDatabaseImplTest() {}
36
37 void TearDown() override { blink::WebHeap::collectAllGarbageForTesting(); }
38
39 private:
40 base::MessageLoop message_loop_;
41
42 DISALLOW_COPY_AND_ASSIGN(WebIDBDatabaseImplTest);
43 };
44
45 TEST_F(WebIDBDatabaseImplTest, ValueSizeTest) {
46 // For testing use a much smaller maximum size to prevent allocating >100 MB
47 // of memory, which crashes on memory-constrained systems.
48 const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB
49
50 const std::vector<char> data(kMaxValueSizeForTesting + 1);
51 const WebData value(&data.front(), data.size());
52 const WebVector<WebBlobInfo> web_blob_info;
53
54 const int64_t transaction_id = 1;
55 const int64_t object_store_id = 2;
56
57 StrictMock<MockWebIDBCallbacks> callbacks;
58 EXPECT_CALL(callbacks, onError(_)).Times(1);
59
60 WebIDBDatabaseImpl database_impl(nullptr, base::ThreadTaskRunnerHandle::Get(),
61 nullptr);
62 database_impl.max_put_value_size_ = kMaxValueSizeForTesting;
63 database_impl.put(transaction_id, object_store_id, value, web_blob_info,
64 WebIDBKey::createNumber(0), blink::WebIDBPutModeAddOrUpdate,
65 &callbacks, WebVector<long long>(),
66 WebVector<WebVector<WebIDBKey>>());
67 }
68
69 TEST_F(WebIDBDatabaseImplTest, KeyAndValueSizeTest) {
70 // For testing use a much smaller maximum size to prevent allocating >100 MB
71 // of memory, which crashes on memory-constrained systems.
72 const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB
73 const size_t kKeySize = 1024 * 1024;
74
75 const std::vector<char> data(kMaxValueSizeForTesting - kKeySize);
76 const WebData value(&data.front(), data.size());
77 const WebVector<WebBlobInfo> web_blob_info;
78 const WebIDBKey key = WebIDBKey::createString(
79 base::string16(kKeySize / sizeof(base::string16::value_type), 'x'));
80
81 const int64_t transaction_id = 1;
82 const int64_t object_store_id = 2;
83
84 StrictMock<MockWebIDBCallbacks> callbacks;
85 EXPECT_CALL(callbacks, onError(_)).Times(1);
86
87 WebIDBDatabaseImpl database_impl(nullptr, base::ThreadTaskRunnerHandle::Get(),
88 nullptr);
89 database_impl.max_put_value_size_ = kMaxValueSizeForTesting;
90 database_impl.put(transaction_id, object_store_id, value, web_blob_info, key,
91 blink::WebIDBPutModeAddOrUpdate, &callbacks,
92 WebVector<long long>(), WebVector<WebVector<WebIDBKey>>());
93 }
94
95 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698