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

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

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

Powered by Google App Engine
This is Rietveld 408576698