Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: Source/bindings/core/v8/ScriptStreamerTest.cpp

Issue 1003043002: bindings: Use Maybe APIs in V8ScriptRunner (part 1) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 // Process tasks on the main thread until the streaming background thread 156 // Process tasks on the main thread until the streaming background thread
157 // has completed its tasks. 157 // has completed its tasks.
158 processTasksUntilStreamingComplete(); 158 processTasksUntilStreamingComplete();
159 EXPECT_TRUE(client.finished()); 159 EXPECT_TRUE(client.finished());
160 bool errorOccurred = false; 160 bool errorOccurred = false;
161 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d); 161 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d);
162 EXPECT_FALSE(errorOccurred); 162 EXPECT_FALSE(errorOccurred);
163 EXPECT_TRUE(sourceCode.streamer()); 163 EXPECT_TRUE(sourceCode.streamer());
164 v8::TryCatch tryCatch; 164 v8::TryCatch tryCatch;
165 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()); 165 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()).ToLocalChecked();
haraken 2015/03/13 04:31:16 Can we use ToLocal? (i.e., we might not want to in
Yuki 2015/03/13 04:39:41 optional: Reading v8.h: V8_INLINE Local<T> ToLo
bashi 2015/03/13 05:15:20 Done.
166 EXPECT_FALSE(script.IsEmpty()); 166 EXPECT_FALSE(script.IsEmpty());
167 EXPECT_FALSE(tryCatch.HasCaught()); 167 EXPECT_FALSE(tryCatch.HasCaught());
168 } 168 }
169 169
170 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) 170 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError)
171 { 171 {
172 // Test that scripts with parse errors are handled properly. In those cases, 172 // Test that scripts with parse errors are handled properly. In those cases,
173 // the V8 side typically finished before loading finishes: make sure we 173 // the V8 side typically finished before loading finishes: make sure we
174 // handle it gracefully. 174 // handle it gracefully.
175 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState()); 175 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState());
(...skipping 12 matching lines...) Expand all
188 EXPECT_FALSE(client.finished()); 188 EXPECT_FALSE(client.finished());
189 189
190 finish(); 190 finish();
191 EXPECT_TRUE(client.finished()); 191 EXPECT_TRUE(client.finished());
192 192
193 bool errorOccurred = false; 193 bool errorOccurred = false;
194 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d); 194 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d);
195 EXPECT_FALSE(errorOccurred); 195 EXPECT_FALSE(errorOccurred);
196 EXPECT_TRUE(sourceCode.streamer()); 196 EXPECT_TRUE(sourceCode.streamer());
197 v8::TryCatch tryCatch; 197 v8::TryCatch tryCatch;
198 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()); 198 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()).ToLocalChecked();
199 EXPECT_TRUE(script.IsEmpty()); 199 EXPECT_TRUE(script.IsEmpty());
200 EXPECT_TRUE(tryCatch.HasCaught()); 200 EXPECT_TRUE(tryCatch.HasCaught());
201 } 201 }
202 202
203 TEST_F(ScriptStreamingTest, CancellingStreaming) 203 TEST_F(ScriptStreamingTest, CancellingStreaming)
204 { 204 {
205 // Test that the upper layers (PendingScript and up) can be ramped down 205 // Test that the upper layers (PendingScript and up) can be ramped down
206 // while streaming is ongoing, and ScriptStreamer handles it gracefully. 206 // while streaming is ongoing, and ScriptStreamer handles it gracefully.
207 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState()); 207 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState());
208 TestScriptResourceClient client; 208 TestScriptResourceClient client;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 319
320 finish(); 320 finish();
321 321
322 processTasksUntilStreamingComplete(); 322 processTasksUntilStreamingComplete();
323 EXPECT_TRUE(client.finished()); 323 EXPECT_TRUE(client.finished());
324 bool errorOccurred = false; 324 bool errorOccurred = false;
325 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d); 325 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d);
326 EXPECT_FALSE(errorOccurred); 326 EXPECT_FALSE(errorOccurred);
327 EXPECT_TRUE(sourceCode.streamer()); 327 EXPECT_TRUE(sourceCode.streamer());
328 v8::TryCatch tryCatch; 328 v8::TryCatch tryCatch;
329 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()); 329 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()).ToLocalChecked();
330 EXPECT_FALSE(script.IsEmpty()); 330 EXPECT_FALSE(script.IsEmpty());
331 EXPECT_FALSE(tryCatch.HasCaught()); 331 EXPECT_FALSE(tryCatch.HasCaught());
332 } 332 }
333 333
334 TEST_F(ScriptStreamingTest, EncodingChanges) 334 TEST_F(ScriptStreamingTest, EncodingChanges)
335 { 335 {
336 // It's possible that the encoding of the Resource changes after we start 336 // It's possible that the encoding of the Resource changes after we start
337 // loading it. 337 // loading it.
338 m_resource->setEncoding("windows-1252"); 338 m_resource->setEncoding("windows-1252");
339 339
340 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState()); 340 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState());
341 TestScriptResourceClient client; 341 TestScriptResourceClient client;
342 pendingScript().watchForLoad(&client); 342 pendingScript().watchForLoad(&client);
343 343
344 m_resource->setEncoding("UTF-8"); 344 m_resource->setEncoding("UTF-8");
345 // \xec\x92\x81 are the raw bytes for \uc481. 345 // \xec\x92\x81 are the raw bytes for \uc481.
346 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92 \x81r; } foo();"); 346 appendData("function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92 \x81r; } foo();");
347 347
348 finish(); 348 finish();
349 349
350 processTasksUntilStreamingComplete(); 350 processTasksUntilStreamingComplete();
351 EXPECT_TRUE(client.finished()); 351 EXPECT_TRUE(client.finished());
352 bool errorOccurred = false; 352 bool errorOccurred = false;
353 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d); 353 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d);
354 EXPECT_FALSE(errorOccurred); 354 EXPECT_FALSE(errorOccurred);
355 EXPECT_TRUE(sourceCode.streamer()); 355 EXPECT_TRUE(sourceCode.streamer());
356 v8::TryCatch tryCatch; 356 v8::TryCatch tryCatch;
357 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()); 357 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()).ToLocalChecked();
358 EXPECT_FALSE(script.IsEmpty()); 358 EXPECT_FALSE(script.IsEmpty());
359 EXPECT_FALSE(tryCatch.HasCaught()); 359 EXPECT_FALSE(tryCatch.HasCaught());
360 } 360 }
361 361
362 362
363 TEST_F(ScriptStreamingTest, EncodingFromBOM) 363 TEST_F(ScriptStreamingTest, EncodingFromBOM)
364 { 364 {
365 // Byte order marks should be removed before giving the data to V8. They 365 // Byte order marks should be removed before giving the data to V8. They
366 // will also affect encoding detection. 366 // will also affect encoding detection.
367 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos e. 367 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos e.
368 368
369 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState()); 369 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState());
370 TestScriptResourceClient client; 370 TestScriptResourceClient client;
371 pendingScript().watchForLoad(&client); 371 pendingScript().watchForLoad(&client);
372 372
373 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes 373 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes
374 // for \uc481. 374 // for \uc481.
375 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92\x81r; } foo();"); 375 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92\x81r; } foo();");
376 376
377 finish(); 377 finish();
378 processTasksUntilStreamingComplete(); 378 processTasksUntilStreamingComplete();
379 EXPECT_TRUE(client.finished()); 379 EXPECT_TRUE(client.finished());
380 bool errorOccurred = false; 380 bool errorOccurred = false;
381 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d); 381 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d);
382 EXPECT_FALSE(errorOccurred); 382 EXPECT_FALSE(errorOccurred);
383 EXPECT_TRUE(sourceCode.streamer()); 383 EXPECT_TRUE(sourceCode.streamer());
384 v8::TryCatch tryCatch; 384 v8::TryCatch tryCatch;
385 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()); 385 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate()).ToLocalChecked();
386 EXPECT_FALSE(script.IsEmpty()); 386 EXPECT_FALSE(script.IsEmpty());
387 EXPECT_FALSE(tryCatch.HasCaught()); 387 EXPECT_FALSE(tryCatch.HasCaught());
388 } 388 }
389 389
390 } // namespace 390 } // namespace
391 391
392 } // namespace blink 392 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698