| 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" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 // Process tasks on the main thread until the streaming background thread | 157 // Process tasks on the main thread until the streaming background thread |
| 158 // has completed its tasks. | 158 // has completed its tasks. |
| 159 processTasksUntilStreamingComplete(); | 159 processTasksUntilStreamingComplete(); |
| 160 EXPECT_TRUE(client.finished()); | 160 EXPECT_TRUE(client.finished()); |
| 161 bool errorOccurred = false; | 161 bool errorOccurred = false; |
| 162 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 162 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
| 163 EXPECT_FALSE(errorOccurred); | 163 EXPECT_FALSE(errorOccurred); |
| 164 EXPECT_TRUE(sourceCode.streamer()); | 164 EXPECT_TRUE(sourceCode.streamer()); |
| 165 v8::TryCatch tryCatch; | 165 v8::TryCatch tryCatch; |
| 166 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); | 166 v8::Local<v8::Script> script; |
| 167 EXPECT_FALSE(script.IsEmpty()); | 167 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
| 168 EXPECT_FALSE(tryCatch.HasCaught()); | 168 EXPECT_FALSE(tryCatch.HasCaught()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) | 171 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) |
| 172 { | 172 { |
| 173 // Test that scripts with parse errors are handled properly. In those cases, | 173 // Test that scripts with parse errors are handled properly. In those cases, |
| 174 // the V8 side typically finished before loading finishes: make sure we | 174 // the V8 side typically finished before loading finishes: make sure we |
| 175 // handle it gracefully. | 175 // handle it gracefully. |
| 176 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState()); | 176 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState()); |
| 177 TestScriptResourceClient client; | 177 TestScriptResourceClient client; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 189 EXPECT_FALSE(client.finished()); | 189 EXPECT_FALSE(client.finished()); |
| 190 | 190 |
| 191 finish(); | 191 finish(); |
| 192 EXPECT_TRUE(client.finished()); | 192 EXPECT_TRUE(client.finished()); |
| 193 | 193 |
| 194 bool errorOccurred = false; | 194 bool errorOccurred = false; |
| 195 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 195 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
| 196 EXPECT_FALSE(errorOccurred); | 196 EXPECT_FALSE(errorOccurred); |
| 197 EXPECT_TRUE(sourceCode.streamer()); | 197 EXPECT_TRUE(sourceCode.streamer()); |
| 198 v8::TryCatch tryCatch; | 198 v8::TryCatch tryCatch; |
| 199 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); | 199 v8::Local<v8::Script> script; |
| 200 EXPECT_TRUE(script.IsEmpty()); | 200 EXPECT_FALSE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&s
cript)); |
| 201 EXPECT_TRUE(tryCatch.HasCaught()); | 201 EXPECT_TRUE(tryCatch.HasCaught()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 TEST_F(ScriptStreamingTest, CancellingStreaming) | 204 TEST_F(ScriptStreamingTest, CancellingStreaming) |
| 205 { | 205 { |
| 206 // Test that the upper layers (PendingScript and up) can be ramped down | 206 // Test that the upper layers (PendingScript and up) can be ramped down |
| 207 // while streaming is ongoing, and ScriptStreamer handles it gracefully. | 207 // while streaming is ongoing, and ScriptStreamer handles it gracefully. |
| 208 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState()); | 208 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState()); |
| 209 TestScriptResourceClient client; | 209 TestScriptResourceClient client; |
| 210 pendingScript().watchForLoad(&client); | 210 pendingScript().watchForLoad(&client); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 320 |
| 321 finish(); | 321 finish(); |
| 322 | 322 |
| 323 processTasksUntilStreamingComplete(); | 323 processTasksUntilStreamingComplete(); |
| 324 EXPECT_TRUE(client.finished()); | 324 EXPECT_TRUE(client.finished()); |
| 325 bool errorOccurred = false; | 325 bool errorOccurred = false; |
| 326 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 326 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
| 327 EXPECT_FALSE(errorOccurred); | 327 EXPECT_FALSE(errorOccurred); |
| 328 EXPECT_TRUE(sourceCode.streamer()); | 328 EXPECT_TRUE(sourceCode.streamer()); |
| 329 v8::TryCatch tryCatch; | 329 v8::TryCatch tryCatch; |
| 330 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); | 330 v8::Local<v8::Script> script; |
| 331 EXPECT_FALSE(script.IsEmpty()); | 331 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
| 332 EXPECT_FALSE(tryCatch.HasCaught()); | 332 EXPECT_FALSE(tryCatch.HasCaught()); |
| 333 } | 333 } |
| 334 | 334 |
| 335 TEST_F(ScriptStreamingTest, EncodingChanges) | 335 TEST_F(ScriptStreamingTest, EncodingChanges) |
| 336 { | 336 { |
| 337 // It's possible that the encoding of the Resource changes after we start | 337 // It's possible that the encoding of the Resource changes after we start |
| 338 // loading it. | 338 // loading it. |
| 339 m_resource->setEncoding("windows-1252"); | 339 m_resource->setEncoding("windows-1252"); |
| 340 | 340 |
| 341 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState()); | 341 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState()); |
| 342 TestScriptResourceClient client; | 342 TestScriptResourceClient client; |
| 343 pendingScript().watchForLoad(&client); | 343 pendingScript().watchForLoad(&client); |
| 344 | 344 |
| 345 m_resource->setEncoding("UTF-8"); | 345 m_resource->setEncoding("UTF-8"); |
| 346 // \xec\x92\x81 are the raw bytes for \uc481. | 346 // \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();"); | 347 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92
\x81r; } foo();"); |
| 348 | 348 |
| 349 finish(); | 349 finish(); |
| 350 | 350 |
| 351 processTasksUntilStreamingComplete(); | 351 processTasksUntilStreamingComplete(); |
| 352 EXPECT_TRUE(client.finished()); | 352 EXPECT_TRUE(client.finished()); |
| 353 bool errorOccurred = false; | 353 bool errorOccurred = false; |
| 354 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 354 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
| 355 EXPECT_FALSE(errorOccurred); | 355 EXPECT_FALSE(errorOccurred); |
| 356 EXPECT_TRUE(sourceCode.streamer()); | 356 EXPECT_TRUE(sourceCode.streamer()); |
| 357 v8::TryCatch tryCatch; | 357 v8::TryCatch tryCatch; |
| 358 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); | 358 v8::Local<v8::Script> script; |
| 359 EXPECT_FALSE(script.IsEmpty()); | 359 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
| 360 EXPECT_FALSE(tryCatch.HasCaught()); | 360 EXPECT_FALSE(tryCatch.HasCaught()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 | 363 |
| 364 TEST_F(ScriptStreamingTest, EncodingFromBOM) | 364 TEST_F(ScriptStreamingTest, EncodingFromBOM) |
| 365 { | 365 { |
| 366 // Byte order marks should be removed before giving the data to V8. They | 366 // Byte order marks should be removed before giving the data to V8. They |
| 367 // will also affect encoding detection. | 367 // will also affect encoding detection. |
| 368 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. | 368 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. |
| 369 | 369 |
| 370 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState()); | 370 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState()); |
| 371 TestScriptResourceClient client; | 371 TestScriptResourceClient client; |
| 372 pendingScript().watchForLoad(&client); | 372 pendingScript().watchForLoad(&client); |
| 373 | 373 |
| 374 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes | 374 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes |
| 375 // for \uc481. | 375 // for \uc481. |
| 376 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return
foob\xec\x92\x81r; } foo();"); | 376 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return
foob\xec\x92\x81r; } foo();"); |
| 377 | 377 |
| 378 finish(); | 378 finish(); |
| 379 processTasksUntilStreamingComplete(); | 379 processTasksUntilStreamingComplete(); |
| 380 EXPECT_TRUE(client.finished()); | 380 EXPECT_TRUE(client.finished()); |
| 381 bool errorOccurred = false; | 381 bool errorOccurred = false; |
| 382 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 382 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
| 383 EXPECT_FALSE(errorOccurred); | 383 EXPECT_FALSE(errorOccurred); |
| 384 EXPECT_TRUE(sourceCode.streamer()); | 384 EXPECT_TRUE(sourceCode.streamer()); |
| 385 v8::TryCatch tryCatch; | 385 v8::TryCatch tryCatch; |
| 386 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); | 386 v8::Local<v8::Script> script; |
| 387 EXPECT_FALSE(script.IsEmpty()); | 387 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc
ript)); |
| 388 EXPECT_FALSE(tryCatch.HasCaught()); | 388 EXPECT_FALSE(tryCatch.HasCaught()); |
| 389 } | 389 } |
| 390 | 390 |
| 391 } // namespace | 391 } // namespace |
| 392 | 392 |
| 393 } // namespace blink | 393 } // namespace blink |
| OLD | NEW |