OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 5 |
6 #include "bindings/core/v8/ScriptStreamer.h" | 6 #include "bindings/core/v8/ScriptStreamer.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptSourceCode.h" | 8 #include "bindings/core/v8/ScriptSourceCode.h" |
9 #include "bindings/core/v8/ScriptStreamerThread.h" | 9 #include "bindings/core/v8/ScriptStreamerThread.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/V8ScriptRunner.h" | 12 #include "bindings/core/v8/V8ScriptRunner.h" |
13 #include "core/dom/Element.h" | 13 #include "core/dom/Element.h" |
14 #include "core/dom/PendingScript.h" | 14 #include "core/dom/PendingScript.h" |
15 #include "core/frame/Settings.h" | 15 #include "core/frame/Settings.h" |
16 #include "platform/Task.h" | 16 #include "platform/Task.h" |
17 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
18 #include "platform/testing/UnitTestHelpers.h" | 18 #include "platform/testing/UnitTestHelpers.h" |
19 #include "public/platform/Platform.h" | 19 #include "public/platform/Platform.h" |
20 #include "public/platform/WebScheduler.h" | 20 #include "public/platform/WebScheduler.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include <v8.h> | 22 #include <v8.h> |
23 | 23 |
24 namespace blink { | 24 namespace blink { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // For the benefit of Oilpan, put the part object PendingScript inside | |
29 // a wrapper that's on the Oilpan heap and hold a reference to that wrapper | |
30 // from ScriptStreamingTest. | |
31 class PendingScriptWrapper : public NoBaseWillBeGarbageCollectedFinalized<Pendin
gScriptWrapper> { | |
32 public: | |
33 static PassOwnPtrWillBeRawPtr<PendingScriptWrapper> create() | |
34 { | |
35 return adoptPtrWillBeNoop(new PendingScriptWrapper()); | |
36 } | |
37 | |
38 static PassOwnPtrWillBeRawPtr<PendingScriptWrapper> create(Element* element,
ScriptResource* resource) | |
39 { | |
40 return adoptPtrWillBeNoop(new PendingScriptWrapper(element, resource)); | |
41 } | |
42 | |
43 PendingScript& get() { return m_pendingScript; } | |
44 | |
45 DEFINE_INLINE_TRACE() | |
46 { | |
47 visitor->trace(m_pendingScript); | |
48 } | |
49 | |
50 private: | |
51 PendingScriptWrapper() | |
52 { | |
53 } | |
54 | |
55 PendingScriptWrapper(Element* element, ScriptResource* resource) | |
56 : m_pendingScript(PendingScript(element, resource)) | |
57 { | |
58 } | |
59 | |
60 PendingScript m_pendingScript; | |
61 }; | |
62 | |
63 class ScriptStreamingTest : public ::testing::Test { | 28 class ScriptStreamingTest : public ::testing::Test { |
64 public: | 29 public: |
65 ScriptStreamingTest() | 30 ScriptStreamingTest() |
66 : m_loadingTaskRunner(Platform::current()->currentThread()->scheduler()-
>loadingTaskRunner()) | 31 : m_loadingTaskRunner(Platform::current()->currentThread()->scheduler()-
>loadingTaskRunner()) |
67 , m_scope(v8::Isolate::GetCurrent()) | 32 , m_scope(v8::Isolate::GetCurrent()) |
68 , m_settings(Settings::create()) | 33 , m_settings(Settings::create()) |
69 , m_resourceRequest("http://www.streaming-test.com/") | 34 , m_resourceRequest("http://www.streaming-test.com/") |
70 , m_resource(new ScriptResource(m_resourceRequest, "UTF-8")) | 35 , m_resource(new ScriptResource(m_resourceRequest, "UTF-8")) |
71 , m_pendingScript(PendingScriptWrapper::create(0, m_resource.get())) | 36 , m_pendingScript(PendingScript::create(0, m_resource.get())) |
72 { | 37 { |
73 m_resource->setLoading(true); | 38 m_resource->setLoading(true); |
74 m_pendingScript = PendingScriptWrapper::create(0, m_resource.get()); | 39 m_pendingScript = PendingScript::create(0, m_resource.get()); |
75 ScriptStreamer::setSmallScriptThresholdForTesting(0); | 40 ScriptStreamer::setSmallScriptThresholdForTesting(0); |
76 } | 41 } |
77 | 42 |
78 ScriptState* scriptState() const { return m_scope.scriptState(); } | 43 ScriptState* scriptState() const { return m_scope.scriptState(); } |
79 v8::Isolate* isolate() const { return m_scope.isolate(); } | 44 v8::Isolate* isolate() const { return m_scope.isolate(); } |
80 | 45 |
81 PendingScript& pendingScript() const { return m_pendingScript->get(); } | 46 PendingScript* pendingScript() const { return m_pendingScript.get(); } |
82 | 47 |
83 protected: | 48 protected: |
84 void appendData(const char* data) | 49 void appendData(const char* data) |
85 { | 50 { |
86 m_resource->appendData(data, strlen(data)); | 51 m_resource->appendData(data, strlen(data)); |
87 // Yield control to the background thread, so that V8 gets a chance to | 52 // Yield control to the background thread, so that V8 gets a chance to |
88 // process the data before the main thread adds more. Note that we | 53 // process the data before the main thread adds more. Note that we |
89 // cannot fully control in what kind of chunks the data is passed to V8 | 54 // cannot fully control in what kind of chunks the data is passed to V8 |
90 // (if V8 is not requesting more data between two appendData calls, it | 55 // (if V8 is not requesting more data between two appendData calls, it |
91 // will get both chunks together). | 56 // will get both chunks together). |
(...skipping 26 matching lines...) Expand all Loading... |
118 } | 83 } |
119 | 84 |
120 WebTaskRunner* m_loadingTaskRunner; // NOT OWNED | 85 WebTaskRunner* m_loadingTaskRunner; // NOT OWNED |
121 V8TestingScope m_scope; | 86 V8TestingScope m_scope; |
122 OwnPtr<Settings> m_settings; | 87 OwnPtr<Settings> m_settings; |
123 // The Resource and PendingScript where we stream from. These don't really | 88 // The Resource and PendingScript where we stream from. These don't really |
124 // fetch any data outside the test; the test controls the data by calling | 89 // fetch any data outside the test; the test controls the data by calling |
125 // ScriptResource::appendData. | 90 // ScriptResource::appendData. |
126 ResourceRequest m_resourceRequest; | 91 ResourceRequest m_resourceRequest; |
127 ResourcePtr<ScriptResource> m_resource; | 92 ResourcePtr<ScriptResource> m_resource; |
128 OwnPtrWillBePersistent<PendingScriptWrapper> m_pendingScript; | 93 OwnPtrWillBePersistent<PendingScript> m_pendingScript; |
129 }; | 94 }; |
130 | 95 |
131 class TestScriptResourceClient : public ScriptResourceClient { | 96 class TestScriptResourceClient : public ScriptResourceClient { |
132 public: | 97 public: |
133 TestScriptResourceClient() | 98 TestScriptResourceClient() |
134 : m_finished(false) { } | 99 : m_finished(false) { } |
135 | 100 |
136 void notifyFinished(Resource*) override { m_finished = true; } | 101 void notifyFinished(Resource*) override { m_finished = true; } |
137 String debugName() const override { return "TestScriptResourceClient"; } | 102 String debugName() const override { return "TestScriptResourceClient"; } |
138 | 103 |
139 bool finished() const { return m_finished; } | 104 bool finished() const { return m_finished; } |
140 | 105 |
141 private: | 106 private: |
142 bool m_finished; | 107 bool m_finished; |
143 }; | 108 }; |
144 | 109 |
145 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) | 110 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) |
146 // TODO(marja): Fix this test, http://crbug.com/572987 | 111 // TODO(marja): Fix this test, http://crbug.com/572987 |
147 #define MAYBE_CompilingStreamedScript DISABLED_CompilingStreamedScript | 112 #define MAYBE_CompilingStreamedScript DISABLED_CompilingStreamedScript |
148 #else | 113 #else |
149 #define MAYBE_CompilingStreamedScript CompilingStreamedScript | 114 #define MAYBE_CompilingStreamedScript CompilingStreamedScript |
150 #endif | 115 #endif |
151 TEST_F(ScriptStreamingTest, MAYBE_CompilingStreamedScript) | 116 TEST_F(ScriptStreamingTest, MAYBE_CompilingStreamedScript) |
152 { | 117 { |
153 // Test that we can successfully compile a streamed script. | 118 // Test that we can successfully compile a streamed script. |
154 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 119 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
155 TestScriptResourceClient client; | 120 TestScriptResourceClient client; |
156 pendingScript().watchForLoad(&client); | 121 pendingScript()->watchForLoad(&client); |
157 | 122 |
158 appendData("function foo() {"); | 123 appendData("function foo() {"); |
159 appendPadding(); | 124 appendPadding(); |
160 appendData("return 5; }"); | 125 appendData("return 5; }"); |
161 appendPadding(); | 126 appendPadding(); |
162 appendData("foo();"); | 127 appendData("foo();"); |
163 EXPECT_FALSE(client.finished()); | 128 EXPECT_FALSE(client.finished()); |
164 finish(); | 129 finish(); |
165 | 130 |
166 // Process tasks on the main thread until the streaming background thread | 131 // Process tasks on the main thread until the streaming background thread |
167 // has completed its tasks. | 132 // has completed its tasks. |
168 processTasksUntilStreamingComplete(); | 133 processTasksUntilStreamingComplete(); |
169 EXPECT_TRUE(client.finished()); | 134 EXPECT_TRUE(client.finished()); |
170 bool errorOccurred = false; | 135 bool errorOccurred = false; |
171 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 136 ScriptSourceCode sourceCode = pendingScript()->getSource(KURL(), errorOccurr
ed); |
172 EXPECT_FALSE(errorOccurred); | 137 EXPECT_FALSE(errorOccurred); |
173 EXPECT_TRUE(sourceCode.streamer()); | 138 EXPECT_TRUE(sourceCode.streamer()); |
174 v8::TryCatch tryCatch(isolate()); | 139 v8::TryCatch tryCatch(isolate()); |
175 v8::Local<v8::Script> script; | 140 v8::Local<v8::Script> script; |
176 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); | 141 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
177 EXPECT_FALSE(tryCatch.HasCaught()); | 142 EXPECT_FALSE(tryCatch.HasCaught()); |
178 } | 143 } |
179 | 144 |
180 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) | 145 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) |
181 { | 146 { |
182 // Test that scripts with parse errors are handled properly. In those cases, | 147 // Test that scripts with parse errors are handled properly. In those cases, |
183 // the V8 side typically finished before loading finishes: make sure we | 148 // the V8 side typically finished before loading finishes: make sure we |
184 // handle it gracefully. | 149 // handle it gracefully. |
185 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 150 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
186 TestScriptResourceClient client; | 151 TestScriptResourceClient client; |
187 pendingScript().watchForLoad(&client); | 152 pendingScript()->watchForLoad(&client); |
188 appendData("function foo() {"); | 153 appendData("function foo() {"); |
189 appendData("this is the part which will be a parse error"); | 154 appendData("this is the part which will be a parse error"); |
190 // V8 won't realize the parse error until it actually starts parsing the | 155 // V8 won't realize the parse error until it actually starts parsing the |
191 // script, and this happens only when its buffer is filled. | 156 // script, and this happens only when its buffer is filled. |
192 appendPadding(); | 157 appendPadding(); |
193 | 158 |
194 EXPECT_FALSE(client.finished()); | 159 EXPECT_FALSE(client.finished()); |
195 | 160 |
196 // Force the V8 side to finish before the loading. | 161 // Force the V8 side to finish before the loading. |
197 processTasksUntilStreamingComplete(); | 162 processTasksUntilStreamingComplete(); |
198 EXPECT_FALSE(client.finished()); | 163 EXPECT_FALSE(client.finished()); |
199 | 164 |
200 finish(); | 165 finish(); |
201 EXPECT_TRUE(client.finished()); | 166 EXPECT_TRUE(client.finished()); |
202 | 167 |
203 bool errorOccurred = false; | 168 bool errorOccurred = false; |
204 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 169 ScriptSourceCode sourceCode = pendingScript()->getSource(KURL(), errorOccurr
ed); |
205 EXPECT_FALSE(errorOccurred); | 170 EXPECT_FALSE(errorOccurred); |
206 EXPECT_TRUE(sourceCode.streamer()); | 171 EXPECT_TRUE(sourceCode.streamer()); |
207 v8::TryCatch tryCatch(isolate()); | 172 v8::TryCatch tryCatch(isolate()); |
208 v8::Local<v8::Script> script; | 173 v8::Local<v8::Script> script; |
209 EXPECT_FALSE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&s
cript)); | 174 EXPECT_FALSE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&s
cript)); |
210 EXPECT_TRUE(tryCatch.HasCaught()); | 175 EXPECT_TRUE(tryCatch.HasCaught()); |
211 } | 176 } |
212 | 177 |
213 TEST_F(ScriptStreamingTest, CancellingStreaming) | 178 TEST_F(ScriptStreamingTest, CancellingStreaming) |
214 { | 179 { |
215 // Test that the upper layers (PendingScript and up) can be ramped down | 180 // Test that the upper layers (PendingScript and up) can be ramped down |
216 // while streaming is ongoing, and ScriptStreamer handles it gracefully. | 181 // while streaming is ongoing, and ScriptStreamer handles it gracefully. |
217 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 182 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
218 TestScriptResourceClient client; | 183 TestScriptResourceClient client; |
219 pendingScript().watchForLoad(&client); | 184 pendingScript()->watchForLoad(&client); |
220 appendData("function foo() {"); | 185 appendData("function foo() {"); |
221 | 186 |
222 // In general, we cannot control what the background thread is doing | 187 // In general, we cannot control what the background thread is doing |
223 // (whether it's parsing or waiting for more data). In this test, we have | 188 // (whether it's parsing or waiting for more data). In this test, we have |
224 // given it so little data that it's surely waiting for more. | 189 // given it so little data that it's surely waiting for more. |
225 | 190 |
226 // Simulate cancelling the network load (e.g., because the user navigated | 191 // Simulate cancelling the network load (e.g., because the user navigated |
227 // away). | 192 // away). |
228 EXPECT_FALSE(client.finished()); | 193 EXPECT_FALSE(client.finished()); |
229 pendingScript().stopWatchingForLoad(&client); | 194 pendingScript()->stopWatchingForLoad(&client); |
230 pendingScript().releaseElementAndClear(); | 195 pendingScript()->releaseElementAndClear(); |
231 m_pendingScript = PendingScriptWrapper::create(); // This will destroy m_res
ource. | 196 m_pendingScript = nullptr; // This will destroy m_resource. |
232 m_resource = 0; | 197 m_resource = 0; |
233 | 198 |
234 // The V8 side will complete too. This should not crash. We don't receive | 199 // The V8 side will complete too. This should not crash. We don't receive |
235 // any results from the streaming and the client doesn't get notified. | 200 // any results from the streaming and the client doesn't get notified. |
236 processTasksUntilStreamingComplete(); | 201 processTasksUntilStreamingComplete(); |
237 EXPECT_FALSE(client.finished()); | 202 EXPECT_FALSE(client.finished()); |
238 } | 203 } |
239 | 204 |
240 TEST_F(ScriptStreamingTest, SuppressingStreaming) | 205 TEST_F(ScriptStreamingTest, SuppressingStreaming) |
241 { | 206 { |
242 // If we notice during streaming that there is a code cache, streaming | 207 // If we notice during streaming that there is a code cache, streaming |
243 // is suppressed (V8 doesn't parse while the script is loading), and the | 208 // is suppressed (V8 doesn't parse while the script is loading), and the |
244 // upper layer (ScriptResourceClient) should get a notification when the | 209 // upper layer (ScriptResourceClient) should get a notification when the |
245 // script is loaded. | 210 // script is loaded. |
246 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 211 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
247 TestScriptResourceClient client; | 212 TestScriptResourceClient client; |
248 pendingScript().watchForLoad(&client); | 213 pendingScript()->watchForLoad(&client); |
249 appendData("function foo() {"); | 214 appendData("function foo() {"); |
250 appendPadding(); | 215 appendPadding(); |
251 | 216 |
252 CachedMetadataHandler* cacheHandler = m_resource->cacheHandler(); | 217 CachedMetadataHandler* cacheHandler = m_resource->cacheHandler(); |
253 EXPECT_TRUE(cacheHandler); | 218 EXPECT_TRUE(cacheHandler); |
254 cacheHandler->setCachedMetadata(V8ScriptRunner::tagForCodeCache(cacheHandler
), "X", 1, CachedMetadataHandler::CacheLocally); | 219 cacheHandler->setCachedMetadata(V8ScriptRunner::tagForCodeCache(cacheHandler
), "X", 1, CachedMetadataHandler::CacheLocally); |
255 | 220 |
256 appendPadding(); | 221 appendPadding(); |
257 finish(); | 222 finish(); |
258 processTasksUntilStreamingComplete(); | 223 processTasksUntilStreamingComplete(); |
259 EXPECT_TRUE(client.finished()); | 224 EXPECT_TRUE(client.finished()); |
260 | 225 |
261 bool errorOccurred = false; | 226 bool errorOccurred = false; |
262 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 227 ScriptSourceCode sourceCode = pendingScript()->getSource(KURL(), errorOccurr
ed); |
263 EXPECT_FALSE(errorOccurred); | 228 EXPECT_FALSE(errorOccurred); |
264 // ScriptSourceCode doesn't refer to the streamer, since we have suppressed | 229 // ScriptSourceCode doesn't refer to the streamer, since we have suppressed |
265 // the streaming and resumed the non-streaming code path for script | 230 // the streaming and resumed the non-streaming code path for script |
266 // compilation. | 231 // compilation. |
267 EXPECT_FALSE(sourceCode.streamer()); | 232 EXPECT_FALSE(sourceCode.streamer()); |
268 } | 233 } |
269 | 234 |
270 TEST_F(ScriptStreamingTest, EmptyScripts) | 235 TEST_F(ScriptStreamingTest, EmptyScripts) |
271 { | 236 { |
272 // Empty scripts should also be streamed properly, that is, the upper layer | 237 // Empty scripts should also be streamed properly, that is, the upper layer |
273 // (ScriptResourceClient) should be notified when an empty script has been | 238 // (ScriptResourceClient) should be notified when an empty script has been |
274 // loaded. | 239 // loaded. |
275 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 240 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
276 TestScriptResourceClient client; | 241 TestScriptResourceClient client; |
277 pendingScript().watchForLoad(&client); | 242 pendingScript()->watchForLoad(&client); |
278 | 243 |
279 // Finish the script without sending any data. | 244 // Finish the script without sending any data. |
280 finish(); | 245 finish(); |
281 // The finished notification should arrive immediately and not be cycled | 246 // The finished notification should arrive immediately and not be cycled |
282 // through a background thread. | 247 // through a background thread. |
283 EXPECT_TRUE(client.finished()); | 248 EXPECT_TRUE(client.finished()); |
284 | 249 |
285 bool errorOccurred = false; | 250 bool errorOccurred = false; |
286 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 251 ScriptSourceCode sourceCode = pendingScript()->getSource(KURL(), errorOccurr
ed); |
287 EXPECT_FALSE(errorOccurred); | 252 EXPECT_FALSE(errorOccurred); |
288 EXPECT_FALSE(sourceCode.streamer()); | 253 EXPECT_FALSE(sourceCode.streamer()); |
289 } | 254 } |
290 | 255 |
291 TEST_F(ScriptStreamingTest, SmallScripts) | 256 TEST_F(ScriptStreamingTest, SmallScripts) |
292 { | 257 { |
293 // Small scripts shouldn't be streamed. | 258 // Small scripts shouldn't be streamed. |
294 ScriptStreamer::setSmallScriptThresholdForTesting(100); | 259 ScriptStreamer::setSmallScriptThresholdForTesting(100); |
295 | 260 |
296 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 261 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
297 TestScriptResourceClient client; | 262 TestScriptResourceClient client; |
298 pendingScript().watchForLoad(&client); | 263 pendingScript()->watchForLoad(&client); |
299 | 264 |
300 appendData("function foo() { }"); | 265 appendData("function foo() { }"); |
301 | 266 |
302 finish(); | 267 finish(); |
303 | 268 |
304 // The finished notification should arrive immediately and not be cycled | 269 // The finished notification should arrive immediately and not be cycled |
305 // through a background thread. | 270 // through a background thread. |
306 EXPECT_TRUE(client.finished()); | 271 EXPECT_TRUE(client.finished()); |
307 | 272 |
308 bool errorOccurred = false; | 273 bool errorOccurred = false; |
309 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 274 ScriptSourceCode sourceCode = pendingScript()->getSource(KURL(), errorOccurr
ed); |
310 EXPECT_FALSE(errorOccurred); | 275 EXPECT_FALSE(errorOccurred); |
311 EXPECT_FALSE(sourceCode.streamer()); | 276 EXPECT_FALSE(sourceCode.streamer()); |
312 } | 277 } |
313 | 278 |
314 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) | 279 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) |
315 // TODO(marja): Fix this test, http://crbug.com/572987 | 280 // TODO(marja): Fix this test, http://crbug.com/572987 |
316 #define MAYBE_ScriptsWithSmallFirstChunk DISABLED_ScriptsWithSmallFirstChunk | 281 #define MAYBE_ScriptsWithSmallFirstChunk DISABLED_ScriptsWithSmallFirstChunk |
317 #else | 282 #else |
318 #define MAYBE_ScriptsWithSmallFirstChunk ScriptsWithSmallFirstChunk | 283 #define MAYBE_ScriptsWithSmallFirstChunk ScriptsWithSmallFirstChunk |
319 #endif | 284 #endif |
320 TEST_F(ScriptStreamingTest, MAYBE_ScriptsWithSmallFirstChunk) | 285 TEST_F(ScriptStreamingTest, MAYBE_ScriptsWithSmallFirstChunk) |
321 { | 286 { |
322 // If a script is long enough, if should be streamed, even if the first data | 287 // If a script is long enough, if should be streamed, even if the first data |
323 // chunk is small. | 288 // chunk is small. |
324 ScriptStreamer::setSmallScriptThresholdForTesting(100); | 289 ScriptStreamer::setSmallScriptThresholdForTesting(100); |
325 | 290 |
326 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 291 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
327 TestScriptResourceClient client; | 292 TestScriptResourceClient client; |
328 pendingScript().watchForLoad(&client); | 293 pendingScript()->watchForLoad(&client); |
329 | 294 |
330 // This is the first data chunk which is small. | 295 // This is the first data chunk which is small. |
331 appendData("function foo() { }"); | 296 appendData("function foo() { }"); |
332 appendPadding(); | 297 appendPadding(); |
333 appendPadding(); | 298 appendPadding(); |
334 appendPadding(); | 299 appendPadding(); |
335 | 300 |
336 finish(); | 301 finish(); |
337 | 302 |
338 processTasksUntilStreamingComplete(); | 303 processTasksUntilStreamingComplete(); |
339 EXPECT_TRUE(client.finished()); | 304 EXPECT_TRUE(client.finished()); |
340 bool errorOccurred = false; | 305 bool errorOccurred = false; |
341 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 306 ScriptSourceCode sourceCode = pendingScript()->getSource(KURL(), errorOccurr
ed); |
342 EXPECT_FALSE(errorOccurred); | 307 EXPECT_FALSE(errorOccurred); |
343 EXPECT_TRUE(sourceCode.streamer()); | 308 EXPECT_TRUE(sourceCode.streamer()); |
344 v8::TryCatch tryCatch(isolate()); | 309 v8::TryCatch tryCatch(isolate()); |
345 v8::Local<v8::Script> script; | 310 v8::Local<v8::Script> script; |
346 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); | 311 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
347 EXPECT_FALSE(tryCatch.HasCaught()); | 312 EXPECT_FALSE(tryCatch.HasCaught()); |
348 } | 313 } |
349 | 314 |
350 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) | 315 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) |
351 // TODO(marja): Fix this test, http://crbug.com/572987 | 316 // TODO(marja): Fix this test, http://crbug.com/572987 |
352 #define MAYBE_EncodingChanges DISABLED_EncodingChanges | 317 #define MAYBE_EncodingChanges DISABLED_EncodingChanges |
353 #else | 318 #else |
354 #define MAYBE_EncodingChanges EncodingChanges | 319 #define MAYBE_EncodingChanges EncodingChanges |
355 #endif | 320 #endif |
356 TEST_F(ScriptStreamingTest, MAYBE_EncodingChanges) | 321 TEST_F(ScriptStreamingTest, MAYBE_EncodingChanges) |
357 { | 322 { |
358 // It's possible that the encoding of the Resource changes after we start | 323 // It's possible that the encoding of the Resource changes after we start |
359 // loading it. | 324 // loading it. |
360 m_resource->setEncoding("windows-1252"); | 325 m_resource->setEncoding("windows-1252"); |
361 | 326 |
362 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 327 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
363 TestScriptResourceClient client; | 328 TestScriptResourceClient client; |
364 pendingScript().watchForLoad(&client); | 329 pendingScript()->watchForLoad(&client); |
365 | 330 |
366 m_resource->setEncoding("UTF-8"); | 331 m_resource->setEncoding("UTF-8"); |
367 // \xec\x92\x81 are the raw bytes for \uc481. | 332 // \xec\x92\x81 are the raw bytes for \uc481. |
368 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92
\x81r; } foo();"); | 333 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92
\x81r; } foo();"); |
369 | 334 |
370 finish(); | 335 finish(); |
371 | 336 |
372 processTasksUntilStreamingComplete(); | 337 processTasksUntilStreamingComplete(); |
373 EXPECT_TRUE(client.finished()); | 338 EXPECT_TRUE(client.finished()); |
374 bool errorOccurred = false; | 339 bool errorOccurred = false; |
375 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 340 ScriptSourceCode sourceCode = pendingScript()->getSource(KURL(), errorOccurr
ed); |
376 EXPECT_FALSE(errorOccurred); | 341 EXPECT_FALSE(errorOccurred); |
377 EXPECT_TRUE(sourceCode.streamer()); | 342 EXPECT_TRUE(sourceCode.streamer()); |
378 v8::TryCatch tryCatch(isolate()); | 343 v8::TryCatch tryCatch(isolate()); |
379 v8::Local<v8::Script> script; | 344 v8::Local<v8::Script> script; |
380 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); | 345 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
381 EXPECT_FALSE(tryCatch.HasCaught()); | 346 EXPECT_FALSE(tryCatch.HasCaught()); |
382 } | 347 } |
383 | 348 |
384 | 349 |
385 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) | 350 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) |
386 // TODO(marja): Fix this test, http://crbug.com/572987 | 351 // TODO(marja): Fix this test, http://crbug.com/572987 |
387 #define MAYBE_EncodingFromBOM DISABLED_EncodingFromBOM | 352 #define MAYBE_EncodingFromBOM DISABLED_EncodingFromBOM |
388 #else | 353 #else |
389 #define MAYBE_EncodingFromBOM EncodingFromBOM | 354 #define MAYBE_EncodingFromBOM EncodingFromBOM |
390 #endif | 355 #endif |
391 TEST_F(ScriptStreamingTest, MAYBE_EncodingFromBOM) | 356 TEST_F(ScriptStreamingTest, MAYBE_EncodingFromBOM) |
392 { | 357 { |
393 // Byte order marks should be removed before giving the data to V8. They | 358 // Byte order marks should be removed before giving the data to V8. They |
394 // will also affect encoding detection. | 359 // will also affect encoding detection. |
395 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. | 360 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. |
396 | 361 |
397 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); | 362 ScriptStreamer::startStreaming(pendingScript(), ScriptStreamer::ParsingBlock
ing, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
398 TestScriptResourceClient client; | 363 TestScriptResourceClient client; |
399 pendingScript().watchForLoad(&client); | 364 pendingScript()->watchForLoad(&client); |
400 | 365 |
401 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes | 366 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes |
402 // for \uc481. | 367 // for \uc481. |
403 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return
foob\xec\x92\x81r; } foo();"); | 368 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return
foob\xec\x92\x81r; } foo();"); |
404 | 369 |
405 finish(); | 370 finish(); |
406 processTasksUntilStreamingComplete(); | 371 processTasksUntilStreamingComplete(); |
407 EXPECT_TRUE(client.finished()); | 372 EXPECT_TRUE(client.finished()); |
408 bool errorOccurred = false; | 373 bool errorOccurred = false; |
409 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 374 ScriptSourceCode sourceCode = pendingScript()->getSource(KURL(), errorOccurr
ed); |
410 EXPECT_FALSE(errorOccurred); | 375 EXPECT_FALSE(errorOccurred); |
411 EXPECT_TRUE(sourceCode.streamer()); | 376 EXPECT_TRUE(sourceCode.streamer()); |
412 v8::TryCatch tryCatch(isolate()); | 377 v8::TryCatch tryCatch(isolate()); |
413 v8::Local<v8::Script> script; | 378 v8::Local<v8::Script> script; |
414 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); | 379 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
415 EXPECT_FALSE(tryCatch.HasCaught()); | 380 EXPECT_FALSE(tryCatch.HasCaught()); |
416 } | 381 } |
417 | 382 |
418 } // namespace | 383 } // namespace |
419 | 384 |
420 } // namespace blink | 385 } // namespace blink |
OLD | NEW |