OLD | NEW |
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 }; | 67 }; |
68 | 68 |
69 NullExecutionContext::NullExecutionContext() | 69 NullExecutionContext::NullExecutionContext() |
70 : m_queue(adoptPtr(new NullEventQueue())) | 70 : m_queue(adoptPtr(new NullEventQueue())) |
71 { | 71 { |
72 } | 72 } |
73 | 73 |
74 class IDBRequestTest : public testing::Test { | 74 class IDBRequestTest : public testing::Test { |
75 public: | 75 public: |
76 IDBRequestTest() | 76 IDBRequestTest() |
77 : m_scope(V8ExecutionScope::create(v8::Isolate::GetCurrent())) | 77 : m_scope(V8TestingScope::create(v8::Isolate::GetCurrent())) |
78 , m_context(adoptRef(new NullExecutionContext())) | |
79 { | 78 { |
| 79 m_scope->scriptState()->setExecutionContext(adoptRef(new NullExecutionCo
ntext())); |
80 } | 80 } |
81 | 81 |
82 ExecutionContext* executionContext() | 82 v8::Isolate* isolate() const { return m_scope->isolate(); } |
83 { | 83 ScriptState* scriptState() const { return m_scope->scriptState(); } |
84 return m_context.get(); | 84 ExecutionContext* executionContext() const { return m_scope->scriptState()->
executionContext(); } |
85 } | |
86 | 85 |
87 private: | 86 private: |
88 OwnPtr<V8ExecutionScope> m_scope; | 87 OwnPtr<V8TestingScope> m_scope; |
89 RefPtr<ExecutionContext> m_context; | |
90 }; | 88 }; |
91 | 89 |
92 TEST_F(IDBRequestTest, EventsAfterStopping) | 90 TEST_F(IDBRequestTest, EventsAfterStopping) |
93 { | 91 { |
94 IDBTransaction* transaction = 0; | 92 IDBTransaction* transaction = 0; |
95 IDBRequest* request = IDBRequest::create(executionContext(), IDBAny::createU
ndefined(), transaction); | 93 IDBRequest* request = IDBRequest::create(scriptState(), IDBAny::createUndefi
ned(), transaction); |
96 EXPECT_EQ(request->readyState(), "pending"); | 94 EXPECT_EQ(request->readyState(), "pending"); |
97 executionContext()->stopActiveDOMObjects(); | 95 executionContext()->stopActiveDOMObjects(); |
98 | 96 |
99 // Ensure none of the following raise assertions in stopped state: | 97 // Ensure none of the following raise assertions in stopped state: |
100 request->onError(DOMError::create(AbortError, "Description goes here.")); | 98 request->onError(DOMError::create(AbortError, "Description goes here.")); |
101 request->onSuccess(Vector<String>()); | 99 request->onSuccess(Vector<String>()); |
102 request->onSuccess(nullptr, IDBKey::createInvalid(), IDBKey::createInvalid()
, nullptr, adoptPtr(new Vector<WebBlobInfo>())); | 100 request->onSuccess(nullptr, IDBKey::createInvalid(), IDBKey::createInvalid()
, nullptr, adoptPtr(new Vector<WebBlobInfo>())); |
103 request->onSuccess(IDBKey::createInvalid()); | 101 request->onSuccess(IDBKey::createInvalid()); |
104 request->onSuccess(PassRefPtr<SharedBuffer>(nullptr), adoptPtr(new Vector<We
bBlobInfo>())); | 102 request->onSuccess(PassRefPtr<SharedBuffer>(nullptr), adoptPtr(new Vector<We
bBlobInfo>())); |
105 request->onSuccess(PassRefPtr<SharedBuffer>(nullptr), adoptPtr(new Vector<We
bBlobInfo>()), IDBKey::createInvalid(), IDBKeyPath()); | 103 request->onSuccess(PassRefPtr<SharedBuffer>(nullptr), adoptPtr(new Vector<We
bBlobInfo>()), IDBKey::createInvalid(), IDBKeyPath()); |
106 request->onSuccess(static_cast<int64_t>(0)); | 104 request->onSuccess(static_cast<int64_t>(0)); |
107 request->onSuccess(); | 105 request->onSuccess(); |
108 request->onSuccess(IDBKey::createInvalid(), IDBKey::createInvalid(), nullptr
, adoptPtr(new Vector<WebBlobInfo>())); | 106 request->onSuccess(IDBKey::createInvalid(), IDBKey::createInvalid(), nullptr
, adoptPtr(new Vector<WebBlobInfo>())); |
109 } | 107 } |
110 | 108 |
111 TEST_F(IDBRequestTest, AbortErrorAfterAbort) | 109 TEST_F(IDBRequestTest, AbortErrorAfterAbort) |
112 { | 110 { |
113 IDBTransaction* transaction = 0; | 111 IDBTransaction* transaction = 0; |
114 IDBRequest* request = IDBRequest::create(executionContext(), IDBAny::createU
ndefined(), transaction); | 112 IDBRequest* request = IDBRequest::create(scriptState(), IDBAny::createUndefi
ned(), transaction); |
115 EXPECT_EQ(request->readyState(), "pending"); | 113 EXPECT_EQ(request->readyState(), "pending"); |
116 | 114 |
117 // Simulate the IDBTransaction having received onAbort from back end and abo
rting the request: | 115 // Simulate the IDBTransaction having received onAbort from back end and abo
rting the request: |
118 request->abort(); | 116 request->abort(); |
119 | 117 |
120 // Now simulate the back end having fired an abort error at the request to c
lear up any intermediaries. | 118 // Now simulate the back end having fired an abort error at the request to c
lear up any intermediaries. |
121 // Ensure an assertion is not raised. | 119 // Ensure an assertion is not raised. |
122 request->onError(DOMError::create(AbortError, "Description goes here.")); | 120 request->onError(DOMError::create(AbortError, "Description goes here.")); |
123 } | 121 } |
124 | 122 |
(...skipping 26 matching lines...) Expand all Loading... |
151 TEST_F(IDBRequestTest, ConnectionsAfterStopping) | 149 TEST_F(IDBRequestTest, ConnectionsAfterStopping) |
152 { | 150 { |
153 const int64_t transactionId = 1234; | 151 const int64_t transactionId = 1234; |
154 const int64_t version = 1; | 152 const int64_t version = 1; |
155 const int64_t oldVersion = 0; | 153 const int64_t oldVersion = 0; |
156 const IDBDatabaseMetadata metadata; | 154 const IDBDatabaseMetadata metadata; |
157 Persistent<IDBDatabaseCallbacks> callbacks = IDBDatabaseCallbacks::create(); | 155 Persistent<IDBDatabaseCallbacks> callbacks = IDBDatabaseCallbacks::create(); |
158 | 156 |
159 { | 157 { |
160 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 158 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
161 IDBOpenDBRequest* request = IDBOpenDBRequest::create(executionContext(),
callbacks, transactionId, version); | 159 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState(), call
backs, transactionId, version); |
162 EXPECT_EQ(request->readyState(), "pending"); | 160 EXPECT_EQ(request->readyState(), "pending"); |
163 | 161 |
164 executionContext()->stopActiveDOMObjects(); | 162 executionContext()->stopActiveDOMObjects(); |
165 request->onUpgradeNeeded(oldVersion, backend.release(), metadata, blink:
:WebIDBDataLossNone, String()); | 163 request->onUpgradeNeeded(oldVersion, backend.release(), metadata, blink:
:WebIDBDataLossNone, String()); |
166 } | 164 } |
167 | 165 |
168 { | 166 { |
169 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 167 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
170 IDBOpenDBRequest* request = IDBOpenDBRequest::create(executionContext(),
callbacks, transactionId, version); | 168 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState(), call
backs, transactionId, version); |
171 EXPECT_EQ(request->readyState(), "pending"); | 169 EXPECT_EQ(request->readyState(), "pending"); |
172 | 170 |
173 executionContext()->stopActiveDOMObjects(); | 171 executionContext()->stopActiveDOMObjects(); |
174 request->onSuccess(backend.release(), metadata); | 172 request->onSuccess(backend.release(), metadata); |
175 } | 173 } |
176 } | 174 } |
177 | 175 |
178 } // namespace | 176 } // namespace |
OLD | NEW |