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 "config.h" | 6 #include "config.h" |
7 #include "bindings/core/v8/ScriptStreamer.h" | 7 #include "bindings/core/v8/ScriptStreamer.h" |
8 | 8 |
9 #include "bindings/core/v8/ScriptSourceCode.h" | 9 #include "bindings/core/v8/ScriptSourceCode.h" |
10 #include "bindings/core/v8/ScriptStreamerThread.h" | 10 #include "bindings/core/v8/ScriptStreamerThread.h" |
11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
12 #include "bindings/core/v8/V8BindingForTesting.h" | 12 #include "bindings/core/v8/V8BindingForTesting.h" |
13 #include "bindings/core/v8/V8ScriptRunner.h" | 13 #include "bindings/core/v8/V8ScriptRunner.h" |
14 #include "core/dom/Element.h" | 14 #include "core/dom/Element.h" |
15 #include "core/dom/PendingScript.h" | 15 #include "core/dom/PendingScript.h" |
16 #include "core/frame/Settings.h" | 16 #include "core/frame/Settings.h" |
17 #include "platform/Task.h" | 17 #include "platform/Task.h" |
18 #include "platform/heap/Handle.h" | 18 #include "platform/heap/Handle.h" |
19 #include "platform/testing/UnitTestHelpers.h" | 19 #include "platform/testing/UnitTestHelpers.h" |
20 #include "public/platform/Platform.h" | 20 #include "public/platform/Platform.h" |
| 21 #include "public/platform/WebScheduler.h" |
21 | 22 |
22 #include <gtest/gtest.h> | 23 #include <gtest/gtest.h> |
23 #include <v8.h> | 24 #include <v8.h> |
24 | 25 |
25 namespace blink { | 26 namespace blink { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // For the benefit of Oilpan, put the part object PendingScript inside | 30 // For the benefit of Oilpan, put the part object PendingScript inside |
30 // a wrapper that's on the Oilpan heap and hold a reference to that wrapper | 31 // a wrapper that's on the Oilpan heap and hold a reference to that wrapper |
(...skipping 26 matching lines...) Expand all Loading... |
57 : m_pendingScript(PendingScript(element, resource)) | 58 : m_pendingScript(PendingScript(element, resource)) |
58 { | 59 { |
59 } | 60 } |
60 | 61 |
61 PendingScript m_pendingScript; | 62 PendingScript m_pendingScript; |
62 }; | 63 }; |
63 | 64 |
64 class ScriptStreamingTest : public ::testing::Test { | 65 class ScriptStreamingTest : public ::testing::Test { |
65 public: | 66 public: |
66 ScriptStreamingTest() | 67 ScriptStreamingTest() |
67 : m_scope(v8::Isolate::GetCurrent()) | 68 : m_loadingTaskRunner(Platform::current()->currentThread()->scheduler()-
>loadingTaskRunner()) |
| 69 , m_scope(v8::Isolate::GetCurrent()) |
68 , m_settings(Settings::create()) | 70 , m_settings(Settings::create()) |
69 , m_resourceRequest("http://www.streaming-test.com/") | 71 , m_resourceRequest("http://www.streaming-test.com/") |
70 , m_resource(new ScriptResource(m_resourceRequest, "UTF-8")) | 72 , m_resource(new ScriptResource(m_resourceRequest, "UTF-8")) |
71 , m_pendingScript(PendingScriptWrapper::create(0, m_resource.get())) | 73 , m_pendingScript(PendingScriptWrapper::create(0, m_resource.get())) |
72 { | 74 { |
73 m_resource->setLoading(true); | 75 m_resource->setLoading(true); |
74 ScriptStreamer::setSmallScriptThresholdForTesting(0); | 76 ScriptStreamer::setSmallScriptThresholdForTesting(0); |
75 } | 77 } |
76 | 78 |
77 ScriptState* scriptState() const { return m_scope.scriptState(); } | 79 ScriptState* scriptState() const { return m_scope.scriptState(); } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 void processTasksUntilStreamingComplete() | 111 void processTasksUntilStreamingComplete() |
110 { | 112 { |
111 while (ScriptStreamerThread::shared()->isRunningTask()) { | 113 while (ScriptStreamerThread::shared()->isRunningTask()) { |
112 testing::runPendingTasks(); | 114 testing::runPendingTasks(); |
113 } | 115 } |
114 // Once more, because the "streaming complete" notification might only | 116 // Once more, because the "streaming complete" notification might only |
115 // now be in the task queue. | 117 // now be in the task queue. |
116 testing::runPendingTasks(); | 118 testing::runPendingTasks(); |
117 } | 119 } |
118 | 120 |
| 121 WebTaskRunner* m_loadingTaskRunner; // NOT OWNED |
119 V8TestingScope m_scope; | 122 V8TestingScope m_scope; |
120 OwnPtr<Settings> m_settings; | 123 OwnPtr<Settings> m_settings; |
121 // The Resource and PendingScript where we stream from. These don't really | 124 // The Resource and PendingScript where we stream from. These don't really |
122 // fetch any data outside the test; the test controls the data by calling | 125 // fetch any data outside the test; the test controls the data by calling |
123 // ScriptResource::appendData. | 126 // ScriptResource::appendData. |
124 ResourceRequest m_resourceRequest; | 127 ResourceRequest m_resourceRequest; |
125 ResourcePtr<ScriptResource> m_resource; | 128 ResourcePtr<ScriptResource> m_resource; |
126 OwnPtrWillBePersistent<PendingScriptWrapper> m_pendingScript; | 129 OwnPtrWillBePersistent<PendingScriptWrapper> m_pendingScript; |
127 }; | 130 }; |
128 | 131 |
129 class TestScriptResourceClient : public ScriptResourceClient { | 132 class TestScriptResourceClient : public ScriptResourceClient { |
130 public: | 133 public: |
131 TestScriptResourceClient() | 134 TestScriptResourceClient() |
132 : m_finished(false) { } | 135 : m_finished(false) { } |
133 | 136 |
134 void notifyFinished(Resource*) override { m_finished = true; } | 137 void notifyFinished(Resource*) override { m_finished = true; } |
135 | 138 |
136 bool finished() const { return m_finished; } | 139 bool finished() const { return m_finished; } |
137 | 140 |
138 private: | 141 private: |
139 bool m_finished; | 142 bool m_finished; |
140 }; | 143 }; |
141 | 144 |
142 TEST_F(ScriptStreamingTest, CompilingStreamedScript) | 145 TEST_F(ScriptStreamingTest, CompilingStreamedScript) |
143 { | 146 { |
144 // Test that we can successfully compile a streamed script. | 147 // Test that we can successfully compile a streamed script. |
145 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 148 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
146 TestScriptResourceClient client; | 149 TestScriptResourceClient client; |
147 pendingScript().watchForLoad(&client); | 150 pendingScript().watchForLoad(&client); |
148 | 151 |
149 appendData("function foo() {"); | 152 appendData("function foo() {"); |
150 appendPadding(); | 153 appendPadding(); |
151 appendData("return 5; }"); | 154 appendData("return 5; }"); |
152 appendPadding(); | 155 appendPadding(); |
153 appendData("foo();"); | 156 appendData("foo();"); |
154 EXPECT_FALSE(client.finished()); | 157 EXPECT_FALSE(client.finished()); |
155 finish(); | 158 finish(); |
(...skipping 10 matching lines...) Expand all Loading... |
166 v8::Local<v8::Script> script; | 169 v8::Local<v8::Script> script; |
167 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); | 170 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
168 EXPECT_FALSE(tryCatch.HasCaught()); | 171 EXPECT_FALSE(tryCatch.HasCaught()); |
169 } | 172 } |
170 | 173 |
171 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) | 174 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) |
172 { | 175 { |
173 // Test that scripts with parse errors are handled properly. In those cases, | 176 // Test that scripts with parse errors are handled properly. In those cases, |
174 // the V8 side typically finished before loading finishes: make sure we | 177 // the V8 side typically finished before loading finishes: make sure we |
175 // handle it gracefully. | 178 // handle it gracefully. |
176 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 179 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
177 TestScriptResourceClient client; | 180 TestScriptResourceClient client; |
178 pendingScript().watchForLoad(&client); | 181 pendingScript().watchForLoad(&client); |
179 appendData("function foo() {"); | 182 appendData("function foo() {"); |
180 appendData("this is the part which will be a parse error"); | 183 appendData("this is the part which will be a parse error"); |
181 // V8 won't realize the parse error until it actually starts parsing the | 184 // V8 won't realize the parse error until it actually starts parsing the |
182 // script, and this happens only when its buffer is filled. | 185 // script, and this happens only when its buffer is filled. |
183 appendPadding(); | 186 appendPadding(); |
184 | 187 |
185 EXPECT_FALSE(client.finished()); | 188 EXPECT_FALSE(client.finished()); |
186 | 189 |
(...skipping 11 matching lines...) Expand all Loading... |
198 v8::TryCatch tryCatch; | 201 v8::TryCatch tryCatch; |
199 v8::Local<v8::Script> script; | 202 v8::Local<v8::Script> script; |
200 EXPECT_FALSE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&s
cript)); | 203 EXPECT_FALSE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&s
cript)); |
201 EXPECT_TRUE(tryCatch.HasCaught()); | 204 EXPECT_TRUE(tryCatch.HasCaught()); |
202 } | 205 } |
203 | 206 |
204 TEST_F(ScriptStreamingTest, CancellingStreaming) | 207 TEST_F(ScriptStreamingTest, CancellingStreaming) |
205 { | 208 { |
206 // Test that the upper layers (PendingScript and up) can be ramped down | 209 // Test that the upper layers (PendingScript and up) can be ramped down |
207 // while streaming is ongoing, and ScriptStreamer handles it gracefully. | 210 // while streaming is ongoing, and ScriptStreamer handles it gracefully. |
208 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 211 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
209 TestScriptResourceClient client; | 212 TestScriptResourceClient client; |
210 pendingScript().watchForLoad(&client); | 213 pendingScript().watchForLoad(&client); |
211 appendData("function foo() {"); | 214 appendData("function foo() {"); |
212 | 215 |
213 // In general, we cannot control what the background thread is doing | 216 // In general, we cannot control what the background thread is doing |
214 // (whether it's parsing or waiting for more data). In this test, we have | 217 // (whether it's parsing or waiting for more data). In this test, we have |
215 // given it so little data that it's surely waiting for more. | 218 // given it so little data that it's surely waiting for more. |
216 | 219 |
217 // Simulate cancelling the network load (e.g., because the user navigated | 220 // Simulate cancelling the network load (e.g., because the user navigated |
218 // away). | 221 // away). |
219 EXPECT_FALSE(client.finished()); | 222 EXPECT_FALSE(client.finished()); |
220 pendingScript().stopWatchingForLoad(&client); | 223 pendingScript().stopWatchingForLoad(&client); |
221 pendingScript().releaseElementAndClear(); | 224 pendingScript().releaseElementAndClear(); |
222 m_pendingScript = PendingScriptWrapper::create(); // This will destroy m_res
ource. | 225 m_pendingScript = PendingScriptWrapper::create(); // This will destroy m_res
ource. |
223 m_resource = 0; | 226 m_resource = 0; |
224 | 227 |
225 // The V8 side will complete too. This should not crash. We don't receive | 228 // The V8 side will complete too. This should not crash. We don't receive |
226 // any results from the streaming and the client doesn't get notified. | 229 // any results from the streaming and the client doesn't get notified. |
227 processTasksUntilStreamingComplete(); | 230 processTasksUntilStreamingComplete(); |
228 EXPECT_FALSE(client.finished()); | 231 EXPECT_FALSE(client.finished()); |
229 } | 232 } |
230 | 233 |
231 TEST_F(ScriptStreamingTest, SuppressingStreaming) | 234 TEST_F(ScriptStreamingTest, SuppressingStreaming) |
232 { | 235 { |
233 // If we notice during streaming that there is a code cache, streaming | 236 // If we notice during streaming that there is a code cache, streaming |
234 // is suppressed (V8 doesn't parse while the script is loading), and the | 237 // is suppressed (V8 doesn't parse while the script is loading), and the |
235 // upper layer (ScriptResourceClient) should get a notification when the | 238 // upper layer (ScriptResourceClient) should get a notification when the |
236 // script is loaded. | 239 // script is loaded. |
237 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 240 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
238 TestScriptResourceClient client; | 241 TestScriptResourceClient client; |
239 pendingScript().watchForLoad(&client); | 242 pendingScript().watchForLoad(&client); |
240 appendData("function foo() {"); | 243 appendData("function foo() {"); |
241 appendPadding(); | 244 appendPadding(); |
242 | 245 |
243 CachedMetadataHandler* cacheHandler = m_resource->cacheHandler(); | 246 CachedMetadataHandler* cacheHandler = m_resource->cacheHandler(); |
244 EXPECT_TRUE(cacheHandler); | 247 EXPECT_TRUE(cacheHandler); |
245 cacheHandler->setCachedMetadata(V8ScriptRunner::tagForCodeCache(cacheHandler
), "X", 1, CachedMetadataHandler::CacheLocally); | 248 cacheHandler->setCachedMetadata(V8ScriptRunner::tagForCodeCache(cacheHandler
), "X", 1, CachedMetadataHandler::CacheLocally); |
246 | 249 |
247 appendPadding(); | 250 appendPadding(); |
248 finish(); | 251 finish(); |
249 processTasksUntilStreamingComplete(); | 252 processTasksUntilStreamingComplete(); |
250 EXPECT_TRUE(client.finished()); | 253 EXPECT_TRUE(client.finished()); |
251 | 254 |
252 bool errorOccurred = false; | 255 bool errorOccurred = false; |
253 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 256 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
254 EXPECT_FALSE(errorOccurred); | 257 EXPECT_FALSE(errorOccurred); |
255 // ScriptSourceCode doesn't refer to the streamer, since we have suppressed | 258 // ScriptSourceCode doesn't refer to the streamer, since we have suppressed |
256 // the streaming and resumed the non-streaming code path for script | 259 // the streaming and resumed the non-streaming code path for script |
257 // compilation. | 260 // compilation. |
258 EXPECT_FALSE(sourceCode.streamer()); | 261 EXPECT_FALSE(sourceCode.streamer()); |
259 } | 262 } |
260 | 263 |
261 TEST_F(ScriptStreamingTest, EmptyScripts) | 264 TEST_F(ScriptStreamingTest, EmptyScripts) |
262 { | 265 { |
263 // Empty scripts should also be streamed properly, that is, the upper layer | 266 // Empty scripts should also be streamed properly, that is, the upper layer |
264 // (ScriptResourceClient) should be notified when an empty script has been | 267 // (ScriptResourceClient) should be notified when an empty script has been |
265 // loaded. | 268 // loaded. |
266 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 269 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
267 TestScriptResourceClient client; | 270 TestScriptResourceClient client; |
268 pendingScript().watchForLoad(&client); | 271 pendingScript().watchForLoad(&client); |
269 | 272 |
270 // Finish the script without sending any data. | 273 // Finish the script without sending any data. |
271 finish(); | 274 finish(); |
272 // The finished notification should arrive immediately and not be cycled | 275 // The finished notification should arrive immediately and not be cycled |
273 // through a background thread. | 276 // through a background thread. |
274 EXPECT_TRUE(client.finished()); | 277 EXPECT_TRUE(client.finished()); |
275 | 278 |
276 bool errorOccurred = false; | 279 bool errorOccurred = false; |
277 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 280 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
278 EXPECT_FALSE(errorOccurred); | 281 EXPECT_FALSE(errorOccurred); |
279 EXPECT_FALSE(sourceCode.streamer()); | 282 EXPECT_FALSE(sourceCode.streamer()); |
280 } | 283 } |
281 | 284 |
282 TEST_F(ScriptStreamingTest, SmallScripts) | 285 TEST_F(ScriptStreamingTest, SmallScripts) |
283 { | 286 { |
284 // Small scripts shouldn't be streamed. | 287 // Small scripts shouldn't be streamed. |
285 ScriptStreamer::setSmallScriptThresholdForTesting(100); | 288 ScriptStreamer::setSmallScriptThresholdForTesting(100); |
286 | 289 |
287 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 290 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
288 TestScriptResourceClient client; | 291 TestScriptResourceClient client; |
289 pendingScript().watchForLoad(&client); | 292 pendingScript().watchForLoad(&client); |
290 | 293 |
291 appendData("function foo() { }"); | 294 appendData("function foo() { }"); |
292 | 295 |
293 finish(); | 296 finish(); |
294 | 297 |
295 // The finished notification should arrive immediately and not be cycled | 298 // The finished notification should arrive immediately and not be cycled |
296 // through a background thread. | 299 // through a background thread. |
297 EXPECT_TRUE(client.finished()); | 300 EXPECT_TRUE(client.finished()); |
298 | 301 |
299 bool errorOccurred = false; | 302 bool errorOccurred = false; |
300 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 303 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
301 EXPECT_FALSE(errorOccurred); | 304 EXPECT_FALSE(errorOccurred); |
302 EXPECT_FALSE(sourceCode.streamer()); | 305 EXPECT_FALSE(sourceCode.streamer()); |
303 } | 306 } |
304 | 307 |
305 TEST_F(ScriptStreamingTest, ScriptsWithSmallFirstChunk) | 308 TEST_F(ScriptStreamingTest, ScriptsWithSmallFirstChunk) |
306 { | 309 { |
307 // If a script is long enough, if should be streamed, even if the first data | 310 // If a script is long enough, if should be streamed, even if the first data |
308 // chunk is small. | 311 // chunk is small. |
309 ScriptStreamer::setSmallScriptThresholdForTesting(100); | 312 ScriptStreamer::setSmallScriptThresholdForTesting(100); |
310 | 313 |
311 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 314 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
312 TestScriptResourceClient client; | 315 TestScriptResourceClient client; |
313 pendingScript().watchForLoad(&client); | 316 pendingScript().watchForLoad(&client); |
314 | 317 |
315 // This is the first data chunk which is small. | 318 // This is the first data chunk which is small. |
316 appendData("function foo() { }"); | 319 appendData("function foo() { }"); |
317 appendPadding(); | 320 appendPadding(); |
318 appendPadding(); | 321 appendPadding(); |
319 appendPadding(); | 322 appendPadding(); |
320 | 323 |
321 finish(); | 324 finish(); |
322 | 325 |
323 processTasksUntilStreamingComplete(); | 326 processTasksUntilStreamingComplete(); |
324 EXPECT_TRUE(client.finished()); | 327 EXPECT_TRUE(client.finished()); |
325 bool errorOccurred = false; | 328 bool errorOccurred = false; |
326 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 329 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
327 EXPECT_FALSE(errorOccurred); | 330 EXPECT_FALSE(errorOccurred); |
328 EXPECT_TRUE(sourceCode.streamer()); | 331 EXPECT_TRUE(sourceCode.streamer()); |
329 v8::TryCatch tryCatch; | 332 v8::TryCatch tryCatch; |
330 v8::Local<v8::Script> script; | 333 v8::Local<v8::Script> script; |
331 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); | 334 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
332 EXPECT_FALSE(tryCatch.HasCaught()); | 335 EXPECT_FALSE(tryCatch.HasCaught()); |
333 } | 336 } |
334 | 337 |
335 TEST_F(ScriptStreamingTest, EncodingChanges) | 338 TEST_F(ScriptStreamingTest, EncodingChanges) |
336 { | 339 { |
337 // It's possible that the encoding of the Resource changes after we start | 340 // It's possible that the encoding of the Resource changes after we start |
338 // loading it. | 341 // loading it. |
339 m_resource->setEncoding("windows-1252"); | 342 m_resource->setEncoding("windows-1252"); |
340 | 343 |
341 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 344 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
342 TestScriptResourceClient client; | 345 TestScriptResourceClient client; |
343 pendingScript().watchForLoad(&client); | 346 pendingScript().watchForLoad(&client); |
344 | 347 |
345 m_resource->setEncoding("UTF-8"); | 348 m_resource->setEncoding("UTF-8"); |
346 // \xec\x92\x81 are the raw bytes for \uc481. | 349 // \xec\x92\x81 are the raw bytes for \uc481. |
347 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92
\x81r; } foo();"); | 350 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92
\x81r; } foo();"); |
348 | 351 |
349 finish(); | 352 finish(); |
350 | 353 |
351 processTasksUntilStreamingComplete(); | 354 processTasksUntilStreamingComplete(); |
352 EXPECT_TRUE(client.finished()); | 355 EXPECT_TRUE(client.finished()); |
353 bool errorOccurred = false; | 356 bool errorOccurred = false; |
354 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 357 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
355 EXPECT_FALSE(errorOccurred); | 358 EXPECT_FALSE(errorOccurred); |
356 EXPECT_TRUE(sourceCode.streamer()); | 359 EXPECT_TRUE(sourceCode.streamer()); |
357 v8::TryCatch tryCatch; | 360 v8::TryCatch tryCatch; |
358 v8::Local<v8::Script> script; | 361 v8::Local<v8::Script> script; |
359 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); | 362 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
360 EXPECT_FALSE(tryCatch.HasCaught()); | 363 EXPECT_FALSE(tryCatch.HasCaught()); |
361 } | 364 } |
362 | 365 |
363 | 366 |
364 TEST_F(ScriptStreamingTest, EncodingFromBOM) | 367 TEST_F(ScriptStreamingTest, EncodingFromBOM) |
365 { | 368 { |
366 // Byte order marks should be removed before giving the data to V8. They | 369 // Byte order marks should be removed before giving the data to V8. They |
367 // will also affect encoding detection. | 370 // will also affect encoding detection. |
368 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. | 371 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. |
369 | 372 |
370 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState()); | 373 ScriptStreamer::startStreaming(pendingScript(), PendingScript::ParsingBlocki
ng, m_settings.get(), m_scope.scriptState(), m_loadingTaskRunner); |
371 TestScriptResourceClient client; | 374 TestScriptResourceClient client; |
372 pendingScript().watchForLoad(&client); | 375 pendingScript().watchForLoad(&client); |
373 | 376 |
374 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes | 377 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes |
375 // for \uc481. | 378 // for \uc481. |
376 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return
foob\xec\x92\x81r; } foo();"); | 379 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return
foob\xec\x92\x81r; } foo();"); |
377 | 380 |
378 finish(); | 381 finish(); |
379 processTasksUntilStreamingComplete(); | 382 processTasksUntilStreamingComplete(); |
380 EXPECT_TRUE(client.finished()); | 383 EXPECT_TRUE(client.finished()); |
381 bool errorOccurred = false; | 384 bool errorOccurred = false; |
382 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 385 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
383 EXPECT_FALSE(errorOccurred); | 386 EXPECT_FALSE(errorOccurred); |
384 EXPECT_TRUE(sourceCode.streamer()); | 387 EXPECT_TRUE(sourceCode.streamer()); |
385 v8::TryCatch tryCatch; | 388 v8::TryCatch tryCatch; |
386 v8::Local<v8::Script> script; | 389 v8::Local<v8::Script> script; |
387 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); | 390 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
388 EXPECT_FALSE(tryCatch.HasCaught()); | 391 EXPECT_FALSE(tryCatch.HasCaught()); |
389 } | 392 } |
390 | 393 |
391 } // namespace | 394 } // namespace |
392 | 395 |
393 } // namespace blink | 396 } // namespace blink |
OLD | NEW |