OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "bindings/core/v8/ReadableStreamOperations.h" | 5 #include "bindings/core/v8/ReadableStreamOperations.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptFunction.h" | 8 #include "bindings/core/v8/ScriptFunction.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
11 #include "bindings/core/v8/V8BindingForTesting.h" | 11 #include "bindings/core/v8/V8BindingForTesting.h" |
12 #include "bindings/core/v8/V8BindingMacros.h" | 12 #include "bindings/core/v8/V8BindingMacros.h" |
13 #include "bindings/core/v8/V8IteratorResultValue.h" | 13 #include "bindings/core/v8/V8IteratorResultValue.h" |
14 #include "bindings/core/v8/V8ThrowException.h" | 14 #include "bindings/core/v8/V8ThrowException.h" |
| 15 #include "core/dom/Document.h" |
15 #include "platform/heap/Handle.h" | 16 #include "platform/heap/Handle.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include <v8.h> | 18 #include <v8.h> |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 class NotReached : public ScriptFunction { | 24 class NotReached : public ScriptFunction { |
24 public: | 25 public: |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 { | 104 { |
104 m_iteration->set(value); | 105 m_iteration->set(value); |
105 return value; | 106 return value; |
106 } | 107 } |
107 | 108 |
108 Member<Iteration> m_iteration; | 109 Member<Iteration> m_iteration; |
109 }; | 110 }; |
110 | 111 |
111 class ReadableStreamOperationsTest : public ::testing::Test { | 112 class ReadableStreamOperationsTest : public ::testing::Test { |
112 public: | 113 public: |
113 ReadableStreamOperationsTest() : m_scope(v8::Isolate::GetCurrent()), m_block
(isolate()) {} | 114 ReadableStreamOperationsTest() |
| 115 : m_scope(v8::Isolate::GetCurrent()) |
| 116 , m_block(isolate()) |
| 117 , m_document(Document::create()) |
| 118 { |
| 119 scriptState()->setExecutionContext(m_document.get()); |
| 120 } |
114 ~ReadableStreamOperationsTest() override | 121 ~ReadableStreamOperationsTest() override |
115 { | 122 { |
116 // Execute all pending microtasks | 123 // Execute all pending microtasks |
117 isolate()->RunMicrotasks(); | 124 isolate()->RunMicrotasks(); |
118 EXPECT_FALSE(m_block.HasCaught()); | 125 EXPECT_FALSE(m_block.HasCaught()); |
119 } | 126 } |
120 | 127 |
121 ScriptState* scriptState() const { return m_scope.scriptState(); } | 128 ScriptState* scriptState() const { return m_scope.scriptState(); } |
122 v8::Isolate* isolate() const { return scriptState()->isolate(); } | 129 v8::Isolate* isolate() const { return scriptState()->isolate(); } |
123 | 130 |
(...skipping 17 matching lines...) Expand all Loading... |
141 v8::MaybeLocal<v8::Value> r = eval(s); | 148 v8::MaybeLocal<v8::Value> r = eval(s); |
142 if (block.HasCaught()) { | 149 if (block.HasCaught()) { |
143 ADD_FAILURE() << toCoreString(block.Exception()->ToString(isolate())
).utf8().data(); | 150 ADD_FAILURE() << toCoreString(block.Exception()->ToString(isolate())
).utf8().data(); |
144 block.ReThrow(); | 151 block.ReThrow(); |
145 } | 152 } |
146 return r; | 153 return r; |
147 } | 154 } |
148 | 155 |
149 V8TestingScope m_scope; | 156 V8TestingScope m_scope; |
150 v8::TryCatch m_block; | 157 v8::TryCatch m_block; |
| 158 RefPtrWillBePersistent<Document> m_document; |
151 }; | 159 }; |
152 | 160 |
153 TEST_F(ReadableStreamOperationsTest, IsReadableStream) | 161 TEST_F(ReadableStreamOperationsTest, IsReadableStream) |
154 { | 162 { |
155 EXPECT_FALSE(ReadableStreamOperations::isReadableStream(scriptState(), v8::U
ndefined(isolate()))); | 163 EXPECT_FALSE(ReadableStreamOperations::isReadableStream(scriptState(), v8::U
ndefined(isolate()))); |
156 EXPECT_FALSE(ReadableStreamOperations::isReadableStream(scriptState(), v8::N
ull(isolate()))); | 164 EXPECT_FALSE(ReadableStreamOperations::isReadableStream(scriptState(), v8::N
ull(isolate()))); |
157 EXPECT_FALSE(ReadableStreamOperations::isReadableStream(scriptState(), v8::O
bject::New(isolate()))); | 165 EXPECT_FALSE(ReadableStreamOperations::isReadableStream(scriptState(), v8::O
bject::New(isolate()))); |
158 v8::Local<v8::Value> stream; | 166 v8::Local<v8::Value> stream; |
159 ASSERT_TRUE(v8Call(evalWithPrintingError("new ReadableStream()"), stream)); | 167 ASSERT_TRUE(v8Call(evalWithPrintingError("new ReadableStream()"), stream)); |
160 EXPECT_TRUE(ReadableStreamOperations::isReadableStream(scriptState(), stream
)); | 168 EXPECT_TRUE(ReadableStreamOperations::isReadableStream(scriptState(), stream
)); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 EXPECT_EQ("hello", it1->value()); | 256 EXPECT_EQ("hello", it1->value()); |
249 EXPECT_TRUE(it2->isSet()); | 257 EXPECT_TRUE(it2->isSet()); |
250 EXPECT_TRUE(it2->isValid()); | 258 EXPECT_TRUE(it2->isValid()); |
251 EXPECT_TRUE(it2->isDone()); | 259 EXPECT_TRUE(it2->isDone()); |
252 } | 260 } |
253 | 261 |
254 } // namespace | 262 } // namespace |
255 | 263 |
256 } // namespace blink | 264 } // namespace blink |
257 | 265 |
OLD | NEW |