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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBRequestTest.cpp

Issue 2822453003: Wrap large IndexedDB values into Blobs before writing to LevelDB. (Closed)
Patch Set: Rebased. Created 3 years, 7 months 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
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 15 matching lines...) Expand all
26 #include "modules/indexeddb/IDBRequest.h" 26 #include "modules/indexeddb/IDBRequest.h"
27 27
28 #include <memory> 28 #include <memory>
29 29
30 #include "bindings/core/v8/V8BindingForCore.h" 30 #include "bindings/core/v8/V8BindingForCore.h"
31 #include "bindings/core/v8/V8BindingForTesting.h" 31 #include "bindings/core/v8/V8BindingForTesting.h"
32 #include "core/dom/DOMException.h" 32 #include "core/dom/DOMException.h"
33 #include "core/dom/ExceptionCode.h" 33 #include "core/dom/ExceptionCode.h"
34 #include "core/dom/ExecutionContext.h" 34 #include "core/dom/ExecutionContext.h"
35 #include "core/testing/NullExecutionContext.h" 35 #include "core/testing/NullExecutionContext.h"
36 #include "modules/indexeddb/IDBDatabase.h"
36 #include "modules/indexeddb/IDBDatabaseCallbacks.h" 37 #include "modules/indexeddb/IDBDatabaseCallbacks.h"
37 #include "modules/indexeddb/IDBKey.h" 38 #include "modules/indexeddb/IDBKey.h"
38 #include "modules/indexeddb/IDBOpenDBRequest.h" 39 #include "modules/indexeddb/IDBOpenDBRequest.h"
40 #include "modules/indexeddb/IDBTransaction.h"
39 #include "modules/indexeddb/IDBValue.h" 41 #include "modules/indexeddb/IDBValue.h"
40 #include "modules/indexeddb/MockWebIDBDatabase.h" 42 #include "modules/indexeddb/MockWebIDBDatabase.h"
41 #include "platform/SharedBuffer.h" 43 #include "platform/SharedBuffer.h"
42 #include "platform/bindings/ScriptState.h" 44 #include "platform/bindings/ScriptState.h"
43 #include "platform/wtf/PassRefPtr.h" 45 #include "platform/wtf/PassRefPtr.h"
44 #include "platform/wtf/Vector.h" 46 #include "platform/wtf/Vector.h"
45 #include "platform/wtf/dtoa/utils.h" 47 #include "platform/wtf/dtoa/utils.h"
46 #include "public/platform/modules/indexeddb/WebIDBCallbacks.h" 48 #include "public/platform/modules/indexeddb/WebIDBCallbacks.h"
47 #include "testing/gtest/include/gtest/gtest.h" 49 #include "testing/gtest/include/gtest/gtest.h"
48 #include "v8/include/v8.h" 50 #include "v8/include/v8.h"
49 51
50 namespace blink { 52 namespace blink {
51 namespace { 53 namespace {
52 54
53 TEST(IDBRequestTest, EventsAfterStopping) { 55 TEST(IDBRequestTest, EventsAfterStopping) {
54 V8TestingScope scope; 56 V8TestingScope scope;
55 IDBTransaction* transaction = nullptr; 57 Persistent<IDBDatabaseCallbacks> callbacks = IDBDatabaseCallbacks::Create();
58 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create();
59 EXPECT_CALL(*backend, Close()).Times(1);
60 IDBDatabase* database =
61 IDBDatabase::Create(scope.GetExecutionContext(), std::move(backend),
62 callbacks, scope.GetIsolate());
63
64 HashSet<String> transaction_scope = {"store"};
65 const int64_t kTransactionId = 1234;
66 IDBTransaction* transaction = IDBTransaction::CreateNonVersionChange(
67 scope.GetScriptState(), kTransactionId, transaction_scope,
68 kWebIDBTransactionModeReadOnly, database);
69 ASSERT_TRUE(!scope.GetExceptionState().HadException());
70 ASSERT_TRUE(transaction);
71
56 IDBRequest* request = IDBRequest::Create( 72 IDBRequest* request = IDBRequest::Create(
57 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction); 73 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction);
58 EXPECT_EQ(request->readyState(), "pending"); 74 EXPECT_EQ(request->readyState(), "pending");
75 ASSERT_TRUE(!scope.GetExceptionState().HadException());
76 ASSERT_TRUE(request->transaction());
59 scope.GetExecutionContext()->NotifyContextDestroyed(); 77 scope.GetExecutionContext()->NotifyContextDestroyed();
jsbell 2017/05/22 21:54:19 We should have a similar unit test where the conte
dmurph 2017/05/23 18:16:39 +1
pwnall 2017/05/25 13:27:11 Acknowledged.
pwnall 2017/05/25 13:27:11 Done. I wrote these tests for IDBRequest and IDBTr
60 78
61 // Ensure none of the following raise assertions in stopped state: 79 // Ensure none of the following raise assertions in stopped state:
62 request->EnqueueResponse( 80 ASSERT_TRUE(request->transaction());
81 request->HandleResponse(
63 DOMException::Create(kAbortError, "Description goes here.")); 82 DOMException::Create(kAbortError, "Description goes here."));
83 request->HandleResponse(nullptr, IDBKey::CreateInvalid(),
84 IDBKey::CreateInvalid(), IDBValue::Create());
85 request->HandleResponse(IDBKey::CreateInvalid());
86 request->HandleResponse(IDBValue::Create());
87 request->HandleResponse(static_cast<int64_t>(0));
88 request->HandleResponse();
89 request->HandleResponse(IDBKey::CreateInvalid(), IDBKey::CreateInvalid(),
90 IDBValue::Create());
91
64 request->EnqueueResponse(Vector<String>()); 92 request->EnqueueResponse(Vector<String>());
65 request->EnqueueResponse(nullptr, IDBKey::CreateInvalid(),
66 IDBKey::CreateInvalid(), IDBValue::Create());
67 request->EnqueueResponse(IDBKey::CreateInvalid());
68 request->EnqueueResponse(IDBValue::Create());
69 request->EnqueueResponse(static_cast<int64_t>(0));
70 request->EnqueueResponse();
71 request->EnqueueResponse(IDBKey::CreateInvalid(), IDBKey::CreateInvalid(),
72 IDBValue::Create());
73 } 93 }
74 94
dmurph 2017/05/23 18:16:39 Can we add testing for the case where we fail to c
pwnall 2017/05/25 13:27:11 Ack. Future work? According to [1-9], the transact
dmurph 2017/05/25 17:28:06 Acknowledged.
75 TEST(IDBRequestTest, AbortErrorAfterAbort) { 95 TEST(IDBRequestTest, AbortErrorAfterAbort) {
76 V8TestingScope scope; 96 V8TestingScope scope;
77 IDBTransaction* transaction = nullptr; 97 IDBTransaction* transaction = nullptr;
78 IDBRequest* request = IDBRequest::Create( 98 IDBRequest* request = IDBRequest::Create(
79 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction); 99 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction);
80 EXPECT_EQ(request->readyState(), "pending"); 100 EXPECT_EQ(request->readyState(), "pending");
81 101
82 // Simulate the IDBTransaction having received OnAbort from back end and 102 // Simulate the IDBTransaction having received OnAbort from back end and
83 // aborting the request: 103 // aborting the request:
84 request->Abort(); 104 request->Abort();
85 105
86 // Now simulate the back end having fired an abort error at the request to 106 // Now simulate the back end having fired an abort error at the request to
87 // clear up any intermediaries. Ensure an assertion is not raised. 107 // clear up any intermediaries. Ensure an assertion is not raised.
88 request->EnqueueResponse( 108 request->HandleResponse(
89 DOMException::Create(kAbortError, "Description goes here.")); 109 DOMException::Create(kAbortError, "Description goes here."));
90 110
91 // Stop the request lest it be GCed and its destructor 111 // Stop the request lest it be GCed and its destructor
92 // finds the object in a pending state (and asserts.) 112 // finds the object in a pending state (and asserts.)
93 scope.GetExecutionContext()->NotifyContextDestroyed(); 113 scope.GetExecutionContext()->NotifyContextDestroyed();
94 } 114 }
95 115
96 TEST(IDBRequestTest, ConnectionsAfterStopping) { 116 TEST(IDBRequestTest, ConnectionsAfterStopping) {
97 V8TestingScope scope; 117 V8TestingScope scope;
98 const int64_t kTransactionId = 1234; 118 const int64_t kTransactionId = 1234;
(...skipping 23 matching lines...) Expand all
122 EXPECT_EQ(request->readyState(), "pending"); 142 EXPECT_EQ(request->readyState(), "pending");
123 std::unique_ptr<WebIDBCallbacks> callbacks = request->CreateWebCallbacks(); 143 std::unique_ptr<WebIDBCallbacks> callbacks = request->CreateWebCallbacks();
124 144
125 scope.GetExecutionContext()->NotifyContextDestroyed(); 145 scope.GetExecutionContext()->NotifyContextDestroyed();
126 callbacks->OnSuccess(backend.release(), metadata); 146 callbacks->OnSuccess(backend.release(), metadata);
127 } 147 }
128 } 148 }
129 149
130 } // namespace 150 } // namespace
131 } // namespace blink 151 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698