| 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" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 void notifyFinished(Resource*) override { m_finished = true; } | 103 void notifyFinished(Resource*) override { m_finished = true; } |
| 104 String debugName() const override { return "TestScriptResourceClient"; } | 104 String debugName() const override { return "TestScriptResourceClient"; } |
| 105 | 105 |
| 106 bool finished() const { return m_finished; } | 106 bool finished() const { return m_finished; } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 bool m_finished; | 109 bool m_finished; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) | 112 TEST_F(ScriptStreamingTest, CompilingStreamedScript) |
| 113 // TODO(marja): Fix this test, http://crbug.com/572987 | |
| 114 #define MAYBE_CompilingStreamedScript DISABLED_CompilingStreamedScript | |
| 115 #else | |
| 116 #define MAYBE_CompilingStreamedScript CompilingStreamedScript | |
| 117 #endif | |
| 118 TEST_F(ScriptStreamingTest, MAYBE_CompilingStreamedScript) | |
| 119 { | 113 { |
| 120 // Test that we can successfully compile a streamed script. | 114 // Test that we can successfully compile a streamed script. |
| 121 V8TestingScope scope; | 115 V8TestingScope scope; |
| 122 ScriptStreamer::startStreaming(getPendingScript(), ScriptStreamer::ParsingBl
ocking, m_settings.get(), scope.getScriptState(), m_loadingTaskRunner); | 116 ScriptStreamer::startStreaming(getPendingScript(), ScriptStreamer::ParsingBl
ocking, m_settings.get(), scope.getScriptState(), m_loadingTaskRunner); |
| 123 TestScriptResourceClient* client = new TestScriptResourceClient; | 117 TestScriptResourceClient* client = new TestScriptResourceClient; |
| 124 getPendingScript()->watchForLoad(client); | 118 getPendingScript()->watchForLoad(client); |
| 125 | 119 |
| 126 appendData("function foo() {"); | 120 appendData("function foo() {"); |
| 127 appendPadding(); | 121 appendPadding(); |
| 128 appendData("return 5; }"); | 122 appendData("return 5; }"); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // The finished notification should arrive immediately and not be cycled | 271 // The finished notification should arrive immediately and not be cycled |
| 278 // through a background thread. | 272 // through a background thread. |
| 279 EXPECT_TRUE(client->finished()); | 273 EXPECT_TRUE(client->finished()); |
| 280 | 274 |
| 281 bool errorOccurred = false; | 275 bool errorOccurred = false; |
| 282 ScriptSourceCode sourceCode = getPendingScript()->getSource(KURL(), errorOcc
urred); | 276 ScriptSourceCode sourceCode = getPendingScript()->getSource(KURL(), errorOcc
urred); |
| 283 EXPECT_FALSE(errorOccurred); | 277 EXPECT_FALSE(errorOccurred); |
| 284 EXPECT_FALSE(sourceCode.streamer()); | 278 EXPECT_FALSE(sourceCode.streamer()); |
| 285 } | 279 } |
| 286 | 280 |
| 287 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) | 281 TEST_F(ScriptStreamingTest, ScriptsWithSmallFirstChunk) |
| 288 // TODO(marja): Fix this test, http://crbug.com/572987 | |
| 289 #define MAYBE_ScriptsWithSmallFirstChunk DISABLED_ScriptsWithSmallFirstChunk | |
| 290 #else | |
| 291 #define MAYBE_ScriptsWithSmallFirstChunk ScriptsWithSmallFirstChunk | |
| 292 #endif | |
| 293 TEST_F(ScriptStreamingTest, MAYBE_ScriptsWithSmallFirstChunk) | |
| 294 { | 282 { |
| 295 // If a script is long enough, if should be streamed, even if the first data | 283 // If a script is long enough, if should be streamed, even if the first data |
| 296 // chunk is small. | 284 // chunk is small. |
| 297 V8TestingScope scope; | 285 V8TestingScope scope; |
| 298 ScriptStreamer::setSmallScriptThresholdForTesting(100); | 286 ScriptStreamer::setSmallScriptThresholdForTesting(100); |
| 299 | 287 |
| 300 ScriptStreamer::startStreaming(getPendingScript(), ScriptStreamer::ParsingBl
ocking, m_settings.get(), scope.getScriptState(), m_loadingTaskRunner); | 288 ScriptStreamer::startStreaming(getPendingScript(), ScriptStreamer::ParsingBl
ocking, m_settings.get(), scope.getScriptState(), m_loadingTaskRunner); |
| 301 TestScriptResourceClient* client = new TestScriptResourceClient; | 289 TestScriptResourceClient* client = new TestScriptResourceClient; |
| 302 getPendingScript()->watchForLoad(client); | 290 getPendingScript()->watchForLoad(client); |
| 303 | 291 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 314 bool errorOccurred = false; | 302 bool errorOccurred = false; |
| 315 ScriptSourceCode sourceCode = getPendingScript()->getSource(KURL(), errorOcc
urred); | 303 ScriptSourceCode sourceCode = getPendingScript()->getSource(KURL(), errorOcc
urred); |
| 316 EXPECT_FALSE(errorOccurred); | 304 EXPECT_FALSE(errorOccurred); |
| 317 EXPECT_TRUE(sourceCode.streamer()); | 305 EXPECT_TRUE(sourceCode.streamer()); |
| 318 v8::TryCatch tryCatch(scope.isolate()); | 306 v8::TryCatch tryCatch(scope.isolate()); |
| 319 v8::Local<v8::Script> script; | 307 v8::Local<v8::Script> script; |
| 320 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()).ToLoc
al(&script)); | 308 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()).ToLoc
al(&script)); |
| 321 EXPECT_FALSE(tryCatch.HasCaught()); | 309 EXPECT_FALSE(tryCatch.HasCaught()); |
| 322 } | 310 } |
| 323 | 311 |
| 324 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) | 312 TEST_F(ScriptStreamingTest, EncodingChanges) |
| 325 // TODO(marja): Fix this test, http://crbug.com/572987 | |
| 326 #define MAYBE_EncodingChanges DISABLED_EncodingChanges | |
| 327 #else | |
| 328 #define MAYBE_EncodingChanges EncodingChanges | |
| 329 #endif | |
| 330 TEST_F(ScriptStreamingTest, MAYBE_EncodingChanges) | |
| 331 { | 313 { |
| 332 // It's possible that the encoding of the Resource changes after we start | 314 // It's possible that the encoding of the Resource changes after we start |
| 333 // loading it. | 315 // loading it. |
| 334 V8TestingScope scope; | 316 V8TestingScope scope; |
| 335 m_resource->setEncoding("windows-1252"); | 317 m_resource->setEncoding("windows-1252"); |
| 336 | 318 |
| 337 ScriptStreamer::startStreaming(getPendingScript(), ScriptStreamer::ParsingBl
ocking, m_settings.get(), scope.getScriptState(), m_loadingTaskRunner); | 319 ScriptStreamer::startStreaming(getPendingScript(), ScriptStreamer::ParsingBl
ocking, m_settings.get(), scope.getScriptState(), m_loadingTaskRunner); |
| 338 TestScriptResourceClient* client = new TestScriptResourceClient; | 320 TestScriptResourceClient* client = new TestScriptResourceClient; |
| 339 getPendingScript()->watchForLoad(client); | 321 getPendingScript()->watchForLoad(client); |
| 340 | 322 |
| 341 m_resource->setEncoding("UTF-8"); | 323 m_resource->setEncoding("UTF-8"); |
| 342 // \xec\x92\x81 are the raw bytes for \uc481. | 324 // \xec\x92\x81 are the raw bytes for \uc481. |
| 343 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92
\x81r; } foo();"); | 325 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92
\x81r; } foo();"); |
| 344 | 326 |
| 345 finish(); | 327 finish(); |
| 346 | 328 |
| 347 processTasksUntilStreamingComplete(); | 329 processTasksUntilStreamingComplete(); |
| 348 EXPECT_TRUE(client->finished()); | 330 EXPECT_TRUE(client->finished()); |
| 349 bool errorOccurred = false; | 331 bool errorOccurred = false; |
| 350 ScriptSourceCode sourceCode = getPendingScript()->getSource(KURL(), errorOcc
urred); | 332 ScriptSourceCode sourceCode = getPendingScript()->getSource(KURL(), errorOcc
urred); |
| 351 EXPECT_FALSE(errorOccurred); | 333 EXPECT_FALSE(errorOccurred); |
| 352 EXPECT_TRUE(sourceCode.streamer()); | 334 EXPECT_TRUE(sourceCode.streamer()); |
| 353 v8::TryCatch tryCatch(scope.isolate()); | 335 v8::TryCatch tryCatch(scope.isolate()); |
| 354 v8::Local<v8::Script> script; | 336 v8::Local<v8::Script> script; |
| 355 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()).ToLoc
al(&script)); | 337 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()).ToLoc
al(&script)); |
| 356 EXPECT_FALSE(tryCatch.HasCaught()); | 338 EXPECT_FALSE(tryCatch.HasCaught()); |
| 357 } | 339 } |
| 358 | 340 |
| 359 | 341 |
| 360 #if OS(MACOSX) && defined(ADDRESS_SANITIZER) | 342 TEST_F(ScriptStreamingTest, EncodingFromBOM) |
| 361 // TODO(marja): Fix this test, http://crbug.com/572987 | |
| 362 #define MAYBE_EncodingFromBOM DISABLED_EncodingFromBOM | |
| 363 #else | |
| 364 #define MAYBE_EncodingFromBOM EncodingFromBOM | |
| 365 #endif | |
| 366 TEST_F(ScriptStreamingTest, MAYBE_EncodingFromBOM) | |
| 367 { | 343 { |
| 368 // Byte order marks should be removed before giving the data to V8. They | 344 // Byte order marks should be removed before giving the data to V8. They |
| 369 // will also affect encoding detection. | 345 // will also affect encoding detection. |
| 370 V8TestingScope scope; | 346 V8TestingScope scope; |
| 371 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. | 347 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. |
| 372 | 348 |
| 373 ScriptStreamer::startStreaming(getPendingScript(), ScriptStreamer::ParsingBl
ocking, m_settings.get(), scope.getScriptState(), m_loadingTaskRunner); | 349 ScriptStreamer::startStreaming(getPendingScript(), ScriptStreamer::ParsingBl
ocking, m_settings.get(), scope.getScriptState(), m_loadingTaskRunner); |
| 374 TestScriptResourceClient* client = new TestScriptResourceClient; | 350 TestScriptResourceClient* client = new TestScriptResourceClient; |
| 375 getPendingScript()->watchForLoad(client); | 351 getPendingScript()->watchForLoad(client); |
| 376 | 352 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 387 EXPECT_TRUE(sourceCode.streamer()); | 363 EXPECT_TRUE(sourceCode.streamer()); |
| 388 v8::TryCatch tryCatch(scope.isolate()); | 364 v8::TryCatch tryCatch(scope.isolate()); |
| 389 v8::Local<v8::Script> script; | 365 v8::Local<v8::Script> script; |
| 390 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()).ToLoc
al(&script)); | 366 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate()).ToLoc
al(&script)); |
| 391 EXPECT_FALSE(tryCatch.HasCaught()); | 367 EXPECT_FALSE(tryCatch.HasCaught()); |
| 392 } | 368 } |
| 393 | 369 |
| 394 } // namespace | 370 } // namespace |
| 395 | 371 |
| 396 } // namespace blink | 372 } // namespace blink |
| OLD | NEW |