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

Side by Side Diff: third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinkerTest.cpp

Issue 2826423002: [ES6 modules] Cosmetic changes to ModuleTreeLinker (Closed)
Patch Set: nhiroki/hiroshige Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "core/loader/modulescript/ModuleTreeLinker.h" 5 #include "core/loader/modulescript/ModuleTreeLinker.h"
6 6
7 #include "bindings/core/v8/ScriptModule.h" 7 #include "bindings/core/v8/ScriptModule.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8BindingForTesting.h" 10 #include "bindings/core/v8/V8BindingForTesting.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 Persistent<ModuleTreeLinkerTestModulator> modulator_; 218 Persistent<ModuleTreeLinkerTestModulator> modulator_;
219 }; 219 };
220 220
221 void ModuleTreeLinkerTest::SetUp() { 221 void ModuleTreeLinkerTest::SetUp() {
222 dummy_page_holder_ = DummyPageHolder::Create(IntSize(500, 500)); 222 dummy_page_holder_ = DummyPageHolder::Create(IntSize(500, 500));
223 RefPtr<ScriptState> script_state = 223 RefPtr<ScriptState> script_state =
224 ToScriptStateForMainWorld(&dummy_page_holder_->GetFrame()); 224 ToScriptStateForMainWorld(&dummy_page_holder_->GetFrame());
225 modulator_ = new ModuleTreeLinkerTestModulator(script_state); 225 modulator_ = new ModuleTreeLinkerTestModulator(script_state);
226 } 226 }
227 227
228 TEST_F(ModuleTreeLinkerTest, fetchTreeNoDeps) { 228 TEST_F(ModuleTreeLinkerTest, FetchTreeNoDeps) {
229 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); 229 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create();
230 230
231 KURL url(kParsedURLString, "http://example.com/root.js"); 231 KURL url(kParsedURLString, "http://example.com/root.js");
232 ModuleScriptFetchRequest module_request( 232 ModuleScriptFetchRequest module_request(
233 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); 233 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit);
234 TestModuleTreeClient* client = new TestModuleTreeClient; 234 TestModuleTreeClient* client = new TestModuleTreeClient;
235 registry->Fetch(module_request, AncestorList(), 235 registry->Fetch(module_request, AncestorList(),
236 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), 236 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(),
237 client); 237 client);
238 238
239 EXPECT_FALSE(client->WasNotifyFinished()) 239 EXPECT_FALSE(client->WasNotifyFinished())
240 << "ModuleTreeLinker should always finish asynchronously."; 240 << "ModuleTreeLinker should always finish asynchronously.";
241 EXPECT_FALSE(client->GetModuleScript()); 241 EXPECT_FALSE(client->GetModuleScript());
242 242
243 GetModulator()->ResolveSingleModuleScriptFetch(url, {}); 243 GetModulator()->ResolveSingleModuleScriptFetch(url, {});
244 EXPECT_TRUE(client->WasNotifyFinished()); 244 EXPECT_TRUE(client->WasNotifyFinished());
245 ASSERT_TRUE(client->GetModuleScript()); 245 ASSERT_TRUE(client->GetModuleScript());
246 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), 246 EXPECT_EQ(client->GetModuleScript()->InstantiationState(),
247 ModuleInstantiationState::kInstantiated); 247 ModuleInstantiationState::kInstantiated);
248 } 248 }
249 249
250 TEST_F(ModuleTreeLinkerTest, fetchTreeInstantiationFailure) { 250 TEST_F(ModuleTreeLinkerTest, FetchTreeInstantiationFailure) {
251 GetModulator()->SetInstantiateShouldFail(true); 251 GetModulator()->SetInstantiateShouldFail(true);
252 252
253 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); 253 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create();
254 254
255 KURL url(kParsedURLString, "http://example.com/root.js"); 255 KURL url(kParsedURLString, "http://example.com/root.js");
256 ModuleScriptFetchRequest module_request( 256 ModuleScriptFetchRequest module_request(
257 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); 257 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit);
258 TestModuleTreeClient* client = new TestModuleTreeClient; 258 TestModuleTreeClient* client = new TestModuleTreeClient;
259 registry->Fetch(module_request, AncestorList(), 259 registry->Fetch(module_request, AncestorList(),
260 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), 260 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(),
261 client); 261 client);
262 262
263 EXPECT_FALSE(client->WasNotifyFinished()) 263 EXPECT_FALSE(client->WasNotifyFinished())
264 << "ModuleTreeLinker should always finish asynchronously."; 264 << "ModuleTreeLinker should always finish asynchronously.";
265 EXPECT_FALSE(client->GetModuleScript()); 265 EXPECT_FALSE(client->GetModuleScript());
266 266
267 GetModulator()->ResolveSingleModuleScriptFetch(url, {}); 267 GetModulator()->ResolveSingleModuleScriptFetch(url, {});
268 EXPECT_TRUE(client->WasNotifyFinished()); 268 EXPECT_TRUE(client->WasNotifyFinished());
269 ASSERT_TRUE(client->GetModuleScript()); 269 ASSERT_TRUE(client->GetModuleScript());
270 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), 270 EXPECT_EQ(client->GetModuleScript()->InstantiationState(),
271 ModuleInstantiationState::kErrored); 271 ModuleInstantiationState::kErrored);
272 } 272 }
273 273
274 TEST_F(ModuleTreeLinkerTest, fetchTreeWithSingleDependency) { 274 TEST_F(ModuleTreeLinkerTest, FetchTreeWithSingleDependency) {
275 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); 275 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create();
276 276
277 KURL url(kParsedURLString, "http://example.com/root.js"); 277 KURL url(kParsedURLString, "http://example.com/root.js");
278 ModuleScriptFetchRequest module_request( 278 ModuleScriptFetchRequest module_request(
279 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); 279 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit);
280 TestModuleTreeClient* client = new TestModuleTreeClient; 280 TestModuleTreeClient* client = new TestModuleTreeClient;
281 registry->Fetch(module_request, AncestorList(), 281 registry->Fetch(module_request, AncestorList(),
282 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), 282 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(),
283 client); 283 client);
284 284
(...skipping 12 matching lines...) Expand all
297 297
298 GetModulator()->ResolveDependentTreeFetch( 298 GetModulator()->ResolveDependentTreeFetch(
299 url_dep1, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess); 299 url_dep1, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess);
300 EXPECT_TRUE(client->WasNotifyFinished()); 300 EXPECT_TRUE(client->WasNotifyFinished());
301 301
302 ASSERT_TRUE(client->GetModuleScript()); 302 ASSERT_TRUE(client->GetModuleScript());
303 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), 303 EXPECT_EQ(client->GetModuleScript()->InstantiationState(),
304 ModuleInstantiationState::kInstantiated); 304 ModuleInstantiationState::kInstantiated);
305 } 305 }
306 306
307 TEST_F(ModuleTreeLinkerTest, fetchTreeWith3Deps) { 307 TEST_F(ModuleTreeLinkerTest, FetchTreeWith3Deps) {
308 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); 308 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create();
309 309
310 KURL url(kParsedURLString, "http://example.com/root.js"); 310 KURL url(kParsedURLString, "http://example.com/root.js");
311 ModuleScriptFetchRequest module_request( 311 ModuleScriptFetchRequest module_request(
312 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); 312 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit);
313 TestModuleTreeClient* client = new TestModuleTreeClient; 313 TestModuleTreeClient* client = new TestModuleTreeClient;
314 registry->Fetch(module_request, AncestorList(), 314 registry->Fetch(module_request, AncestorList(),
315 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), 315 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(),
316 client); 316 client);
317 317
(...skipping 29 matching lines...) Expand all
347 GetModulator()->ResolveDependentTreeFetch( 347 GetModulator()->ResolveDependentTreeFetch(
348 url_dep, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess); 348 url_dep, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess);
349 } 349 }
350 350
351 EXPECT_TRUE(client->WasNotifyFinished()); 351 EXPECT_TRUE(client->WasNotifyFinished());
352 ASSERT_TRUE(client->GetModuleScript()); 352 ASSERT_TRUE(client->GetModuleScript());
353 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), 353 EXPECT_EQ(client->GetModuleScript()->InstantiationState(),
354 ModuleInstantiationState::kInstantiated); 354 ModuleInstantiationState::kInstantiated);
355 } 355 }
356 356
357 TEST_F(ModuleTreeLinkerTest, fetchTreeWith3Deps1Fail) { 357 TEST_F(ModuleTreeLinkerTest, FetchTreeWith3Deps1Fail) {
358 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); 358 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create();
359 359
360 KURL url(kParsedURLString, "http://example.com/root.js"); 360 KURL url(kParsedURLString, "http://example.com/root.js");
361 ModuleScriptFetchRequest module_request( 361 ModuleScriptFetchRequest module_request(
362 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); 362 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit);
363 TestModuleTreeClient* client = new TestModuleTreeClient; 363 TestModuleTreeClient* client = new TestModuleTreeClient;
364 registry->Fetch(module_request, AncestorList(), 364 registry->Fetch(module_request, AncestorList(),
365 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), 365 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(),
366 client); 366 client);
367 367
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 EXPECT_FALSE(client->GetModuleScript()); 406 EXPECT_FALSE(client->GetModuleScript());
407 407
408 // Check below doesn't crash. 408 // Check below doesn't crash.
409 url_dep = url_deps.back(); 409 url_dep = url_deps.back();
410 url_deps.pop_back(); 410 url_deps.pop_back();
411 GetModulator()->ResolveDependentTreeFetch( 411 GetModulator()->ResolveDependentTreeFetch(
412 url_dep, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess); 412 url_dep, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess);
413 EXPECT_TRUE(url_deps.IsEmpty()); 413 EXPECT_TRUE(url_deps.IsEmpty());
414 } 414 }
415 415
416 TEST_F(ModuleTreeLinkerTest, fetchDependencyTree) { 416 TEST_F(ModuleTreeLinkerTest, FetchDependencyTree) {
417 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); 417 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create();
418 418
419 KURL url(kParsedURLString, "http://example.com/depth1.js"); 419 KURL url(kParsedURLString, "http://example.com/depth1.js");
420 ModuleScriptFetchRequest module_request( 420 ModuleScriptFetchRequest module_request(
421 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); 421 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit);
422 TestModuleTreeClient* client = new TestModuleTreeClient; 422 TestModuleTreeClient* client = new TestModuleTreeClient;
423 registry->Fetch( 423 registry->Fetch(
424 module_request, 424 module_request,
425 AncestorList{KURL(kParsedURLString, "http://example.com/root.js")}, 425 AncestorList{KURL(kParsedURLString, "http://example.com/root.js")},
426 ModuleGraphLevel::kDependentModuleFetch, GetModulator(), client); 426 ModuleGraphLevel::kDependentModuleFetch, GetModulator(), client);
(...skipping 15 matching lines...) Expand all
442 GetModulator()->ResolveDependentTreeFetch( 442 GetModulator()->ResolveDependentTreeFetch(
443 url_dep2, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess); 443 url_dep2, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess);
444 444
445 EXPECT_TRUE(client->WasNotifyFinished()); 445 EXPECT_TRUE(client->WasNotifyFinished());
446 ASSERT_TRUE(client->GetModuleScript()); 446 ASSERT_TRUE(client->GetModuleScript());
447 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), 447 EXPECT_EQ(client->GetModuleScript()->InstantiationState(),
448 ModuleInstantiationState::kInstantiated); 448 ModuleInstantiationState::kInstantiated);
449 } 449 }
450 450
451 } // namespace blink 451 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698