| 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 #include "bindings/core/v8/ScriptStreamer.h" | 5 #include "bindings/core/v8/ScriptStreamer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // has completed its tasks. | 127 // has completed its tasks. |
| 128 processTasksUntilStreamingComplete(); | 128 processTasksUntilStreamingComplete(); |
| 129 EXPECT_TRUE(client->finished()); | 129 EXPECT_TRUE(client->finished()); |
| 130 bool errorOccurred = false; | 130 bool errorOccurred = false; |
| 131 ScriptSourceCode sourceCode = | 131 ScriptSourceCode sourceCode = |
| 132 getPendingScript()->getSource(KURL(), errorOccurred); | 132 getPendingScript()->getSource(KURL(), errorOccurred); |
| 133 EXPECT_FALSE(errorOccurred); | 133 EXPECT_FALSE(errorOccurred); |
| 134 EXPECT_TRUE(sourceCode.streamer()); | 134 EXPECT_TRUE(sourceCode.streamer()); |
| 135 v8::TryCatch tryCatch(scope.isolate()); | 135 v8::TryCatch tryCatch(scope.isolate()); |
| 136 v8::Local<v8::Script> script; | 136 v8::Local<v8::Script> script; |
| 137 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()) | 137 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate(), |
| 138 SharableCrossOrigin, |
| 139 V8CacheOptionsDefault) |
| 138 .ToLocal(&script)); | 140 .ToLocal(&script)); |
| 139 EXPECT_FALSE(tryCatch.HasCaught()); | 141 EXPECT_FALSE(tryCatch.HasCaught()); |
| 140 } | 142 } |
| 141 | 143 |
| 142 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) { | 144 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) { |
| 143 // Test that scripts with parse errors are handled properly. In those cases, | 145 // Test that scripts with parse errors are handled properly. In those cases, |
| 144 // the V8 side typically finished before loading finishes: make sure we | 146 // the V8 side typically finished before loading finishes: make sure we |
| 145 // handle it gracefully. | 147 // handle it gracefully. |
| 146 V8TestingScope scope; | 148 V8TestingScope scope; |
| 147 ScriptStreamer::startStreaming( | 149 ScriptStreamer::startStreaming( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 164 finish(); | 166 finish(); |
| 165 EXPECT_TRUE(client->finished()); | 167 EXPECT_TRUE(client->finished()); |
| 166 | 168 |
| 167 bool errorOccurred = false; | 169 bool errorOccurred = false; |
| 168 ScriptSourceCode sourceCode = | 170 ScriptSourceCode sourceCode = |
| 169 getPendingScript()->getSource(KURL(), errorOccurred); | 171 getPendingScript()->getSource(KURL(), errorOccurred); |
| 170 EXPECT_FALSE(errorOccurred); | 172 EXPECT_FALSE(errorOccurred); |
| 171 EXPECT_TRUE(sourceCode.streamer()); | 173 EXPECT_TRUE(sourceCode.streamer()); |
| 172 v8::TryCatch tryCatch(scope.isolate()); | 174 v8::TryCatch tryCatch(scope.isolate()); |
| 173 v8::Local<v8::Script> script; | 175 v8::Local<v8::Script> script; |
| 174 EXPECT_FALSE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()) | 176 EXPECT_FALSE(V8ScriptRunner::compileScript(sourceCode, scope.isolate(), |
| 177 SharableCrossOrigin, |
| 178 V8CacheOptionsDefault) |
| 175 .ToLocal(&script)); | 179 .ToLocal(&script)); |
| 176 EXPECT_TRUE(tryCatch.HasCaught()); | 180 EXPECT_TRUE(tryCatch.HasCaught()); |
| 177 } | 181 } |
| 178 | 182 |
| 179 TEST_F(ScriptStreamingTest, CancellingStreaming) { | 183 TEST_F(ScriptStreamingTest, CancellingStreaming) { |
| 180 // Test that the upper layers (PendingScript and up) can be ramped down | 184 // Test that the upper layers (PendingScript and up) can be ramped down |
| 181 // while streaming is ongoing, and ScriptStreamer handles it gracefully. | 185 // while streaming is ongoing, and ScriptStreamer handles it gracefully. |
| 182 V8TestingScope scope; | 186 V8TestingScope scope; |
| 183 ScriptStreamer::startStreaming( | 187 ScriptStreamer::startStreaming( |
| 184 getPendingScript(), ScriptStreamer::ParsingBlocking, m_settings.get(), | 188 getPendingScript(), ScriptStreamer::ParsingBlocking, m_settings.get(), |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 314 |
| 311 processTasksUntilStreamingComplete(); | 315 processTasksUntilStreamingComplete(); |
| 312 EXPECT_TRUE(client->finished()); | 316 EXPECT_TRUE(client->finished()); |
| 313 bool errorOccurred = false; | 317 bool errorOccurred = false; |
| 314 ScriptSourceCode sourceCode = | 318 ScriptSourceCode sourceCode = |
| 315 getPendingScript()->getSource(KURL(), errorOccurred); | 319 getPendingScript()->getSource(KURL(), errorOccurred); |
| 316 EXPECT_FALSE(errorOccurred); | 320 EXPECT_FALSE(errorOccurred); |
| 317 EXPECT_TRUE(sourceCode.streamer()); | 321 EXPECT_TRUE(sourceCode.streamer()); |
| 318 v8::TryCatch tryCatch(scope.isolate()); | 322 v8::TryCatch tryCatch(scope.isolate()); |
| 319 v8::Local<v8::Script> script; | 323 v8::Local<v8::Script> script; |
| 320 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()) | 324 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate(), |
| 325 SharableCrossOrigin, |
| 326 V8CacheOptionsDefault) |
| 321 .ToLocal(&script)); | 327 .ToLocal(&script)); |
| 322 EXPECT_FALSE(tryCatch.HasCaught()); | 328 EXPECT_FALSE(tryCatch.HasCaught()); |
| 323 } | 329 } |
| 324 | 330 |
| 325 TEST_F(ScriptStreamingTest, EncodingChanges) { | 331 TEST_F(ScriptStreamingTest, EncodingChanges) { |
| 326 // It's possible that the encoding of the Resource changes after we start | 332 // It's possible that the encoding of the Resource changes after we start |
| 327 // loading it. | 333 // loading it. |
| 328 V8TestingScope scope; | 334 V8TestingScope scope; |
| 329 m_resource->setEncoding("windows-1252"); | 335 m_resource->setEncoding("windows-1252"); |
| 330 | 336 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 344 | 350 |
| 345 processTasksUntilStreamingComplete(); | 351 processTasksUntilStreamingComplete(); |
| 346 EXPECT_TRUE(client->finished()); | 352 EXPECT_TRUE(client->finished()); |
| 347 bool errorOccurred = false; | 353 bool errorOccurred = false; |
| 348 ScriptSourceCode sourceCode = | 354 ScriptSourceCode sourceCode = |
| 349 getPendingScript()->getSource(KURL(), errorOccurred); | 355 getPendingScript()->getSource(KURL(), errorOccurred); |
| 350 EXPECT_FALSE(errorOccurred); | 356 EXPECT_FALSE(errorOccurred); |
| 351 EXPECT_TRUE(sourceCode.streamer()); | 357 EXPECT_TRUE(sourceCode.streamer()); |
| 352 v8::TryCatch tryCatch(scope.isolate()); | 358 v8::TryCatch tryCatch(scope.isolate()); |
| 353 v8::Local<v8::Script> script; | 359 v8::Local<v8::Script> script; |
| 354 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()) | 360 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate(), |
| 361 SharableCrossOrigin, |
| 362 V8CacheOptionsDefault) |
| 355 .ToLocal(&script)); | 363 .ToLocal(&script)); |
| 356 EXPECT_FALSE(tryCatch.HasCaught()); | 364 EXPECT_FALSE(tryCatch.HasCaught()); |
| 357 } | 365 } |
| 358 | 366 |
| 359 TEST_F(ScriptStreamingTest, EncodingFromBOM) { | 367 TEST_F(ScriptStreamingTest, EncodingFromBOM) { |
| 360 // Byte order marks should be removed before giving the data to V8. They | 368 // Byte order marks should be removed before giving the data to V8. They |
| 361 // will also affect encoding detection. | 369 // will also affect encoding detection. |
| 362 V8TestingScope scope; | 370 V8TestingScope scope; |
| 363 m_resource->setEncoding( | 371 m_resource->setEncoding( |
| 364 "windows-1252"); // This encoding is wrong on purpose. | 372 "windows-1252"); // This encoding is wrong on purpose. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 378 finish(); | 386 finish(); |
| 379 processTasksUntilStreamingComplete(); | 387 processTasksUntilStreamingComplete(); |
| 380 EXPECT_TRUE(client->finished()); | 388 EXPECT_TRUE(client->finished()); |
| 381 bool errorOccurred = false; | 389 bool errorOccurred = false; |
| 382 ScriptSourceCode sourceCode = | 390 ScriptSourceCode sourceCode = |
| 383 getPendingScript()->getSource(KURL(), errorOccurred); | 391 getPendingScript()->getSource(KURL(), errorOccurred); |
| 384 EXPECT_FALSE(errorOccurred); | 392 EXPECT_FALSE(errorOccurred); |
| 385 EXPECT_TRUE(sourceCode.streamer()); | 393 EXPECT_TRUE(sourceCode.streamer()); |
| 386 v8::TryCatch tryCatch(scope.isolate()); | 394 v8::TryCatch tryCatch(scope.isolate()); |
| 387 v8::Local<v8::Script> script; | 395 v8::Local<v8::Script> script; |
| 388 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()) | 396 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate(), |
| 397 SharableCrossOrigin, |
| 398 V8CacheOptionsDefault) |
| 389 .ToLocal(&script)); | 399 .ToLocal(&script)); |
| 390 EXPECT_FALSE(tryCatch.HasCaught()); | 400 EXPECT_FALSE(tryCatch.HasCaught()); |
| 391 } | 401 } |
| 392 | 402 |
| 393 } // namespace | 403 } // namespace |
| 394 | 404 |
| 395 } // namespace blink | 405 } // namespace blink |
| OLD | NEW |