OLD | NEW |
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/V8BindingForCore.h" | 9 #include "bindings/core/v8/V8BindingForCore.h" |
10 #include "bindings/core/v8/V8BindingForTesting.h" | 10 #include "bindings/core/v8/V8BindingForTesting.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 bool WasNotifyFinished() const { return was_notify_finished_; } | 44 bool WasNotifyFinished() const { return was_notify_finished_; } |
45 ModuleScript* GetModuleScript() { return module_script_; } | 45 ModuleScript* GetModuleScript() { return module_script_; } |
46 | 46 |
47 private: | 47 private: |
48 bool was_notify_finished_ = false; | 48 bool was_notify_finished_ = false; |
49 Member<ModuleScript> module_script_; | 49 Member<ModuleScript> module_script_; |
50 }; | 50 }; |
51 | 51 |
| 52 } // namespace |
| 53 |
52 class ModuleTreeLinkerTestModulator final : public DummyModulator { | 54 class ModuleTreeLinkerTestModulator final : public DummyModulator { |
53 public: | 55 public: |
54 ModuleTreeLinkerTestModulator(RefPtr<ScriptState> script_state) | 56 ModuleTreeLinkerTestModulator(RefPtr<ScriptState> script_state) |
55 : script_state_(std::move(script_state)) {} | 57 : script_state_(std::move(script_state)) {} |
56 ~ModuleTreeLinkerTestModulator() override {} | 58 ~ModuleTreeLinkerTestModulator() override {} |
57 | 59 |
58 DECLARE_TRACE(); | 60 DECLARE_TRACE(); |
59 | 61 |
60 enum class ResolveResult { kFailure, kSuccess }; | 62 enum class ResolveResult { kFailure, kSuccess }; |
61 | 63 |
62 // Resolve last |Modulator::FetchSingle()| call. | 64 // Resolve last |Modulator::FetchSingle()| call. |
63 ModuleScript* ResolveSingleModuleScriptFetch( | 65 ModuleScript* ResolveSingleModuleScriptFetch( |
64 const KURL& url, | 66 const KURL& url, |
65 const Vector<String>& dependency_module_requests) { | 67 const Vector<String>& dependency_module_requests, |
| 68 ModuleInstantiationState state) { |
66 ScriptState::Scope scope(script_state_.Get()); | 69 ScriptState::Scope scope(script_state_.Get()); |
67 | 70 |
68 StringBuilder source_text; | 71 StringBuilder source_text; |
69 for (const auto& request : dependency_module_requests) { | 72 for (const auto& request : dependency_module_requests) { |
70 source_text.Append("import '"); | 73 source_text.Append("import '"); |
71 source_text.Append(request); | 74 source_text.Append(request); |
72 source_text.Append("';\n"); | 75 source_text.Append("';\n"); |
73 } | 76 } |
74 source_text.Append("export default 'grapes';"); | 77 source_text.Append("export default 'grapes';"); |
75 | 78 |
76 ScriptModule script_module = ScriptModule::Compile( | 79 ScriptModule script_module = ScriptModule::Compile( |
77 script_state_->GetIsolate(), source_text.ToString(), url.GetString(), | 80 script_state_->GetIsolate(), source_text.ToString(), url.GetString(), |
78 kSharableCrossOrigin); | 81 kSharableCrossOrigin); |
79 ModuleScript* module_script = | 82 ModuleScript* module_script = |
80 ModuleScript::Create(this, script_module, url, "", kParserInserted, | 83 ModuleScript::Create(this, script_module, url, "", kParserInserted, |
81 WebURLRequest::kFetchCredentialsModeOmit); | 84 WebURLRequest::kFetchCredentialsModeOmit); |
82 auto result_request = dependency_module_requests_map_.insert( | 85 auto result_request = dependency_module_requests_map_.insert( |
83 script_module, dependency_module_requests); | 86 script_module, dependency_module_requests); |
84 EXPECT_TRUE(result_request.is_new_entry); | 87 EXPECT_TRUE(result_request.is_new_entry); |
85 auto result_map = module_map_.insert(url, module_script); | 88 auto result_map = module_map_.insert(url, module_script); |
86 EXPECT_TRUE(result_map.is_new_entry); | 89 EXPECT_TRUE(result_map.is_new_entry); |
87 | 90 |
| 91 if (state == ModuleInstantiationState::kErrored) { |
| 92 v8::Local<v8::Value> error = V8ThrowException::CreateError( |
| 93 script_state_->GetIsolate(), "Instantiation failure."); |
| 94 module_script->SetInstantiationErrorAndClearRecord( |
| 95 ScriptValue(script_state_.Get(), error)); |
| 96 } |
| 97 |
88 EXPECT_EQ(url, pending_request_url_); | 98 EXPECT_EQ(url, pending_request_url_); |
| 99 EXPECT_EQ(state, module_script->InstantiationState()); |
89 EXPECT_TRUE(pending_client_); | 100 EXPECT_TRUE(pending_client_); |
90 pending_client_->NotifyModuleLoadFinished(module_script); | 101 pending_client_->NotifyModuleLoadFinished(module_script); |
91 pending_client_.Clear(); | 102 pending_client_.Clear(); |
92 | 103 |
93 return module_script; | 104 return module_script; |
94 } | 105 } |
95 | 106 |
96 // Get AncestorList specified in |Modulator::FetchTreeInternal()| call for | 107 // Get AncestorList specified in |Modulator::FetchTreeInternal()| call for |
97 // request matching |url|. | 108 // request matching |url|. |
98 AncestorList GetAncestorListForTreeFetch(const KURL& url) const { | 109 AncestorList GetAncestorListForTreeFetch(const KURL& url) const { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 ScriptValue InstantiateModule(ScriptModule) override { | 180 ScriptValue InstantiateModule(ScriptModule) override { |
170 if (instantiate_should_fail_) { | 181 if (instantiate_should_fail_) { |
171 ScriptState::Scope scope(script_state_.Get()); | 182 ScriptState::Scope scope(script_state_.Get()); |
172 v8::Local<v8::Value> error = V8ThrowException::CreateError( | 183 v8::Local<v8::Value> error = V8ThrowException::CreateError( |
173 script_state_->GetIsolate(), "Instantiation failure."); | 184 script_state_->GetIsolate(), "Instantiation failure."); |
174 return ScriptValue(script_state_.Get(), error); | 185 return ScriptValue(script_state_.Get(), error); |
175 } | 186 } |
176 return ScriptValue(); | 187 return ScriptValue(); |
177 } | 188 } |
178 | 189 |
| 190 ScriptValue GetInstantiationError( |
| 191 const ModuleScript* module_script) override { |
| 192 ScriptState::Scope scope(script_state_.Get()); |
| 193 return ScriptValue(script_state_.Get(), |
| 194 module_script->CreateInstantiationErrorInternal( |
| 195 script_state_->GetIsolate())); |
| 196 } |
| 197 |
179 Vector<String> ModuleRequestsFromScriptModule( | 198 Vector<String> ModuleRequestsFromScriptModule( |
180 ScriptModule script_module) override { | 199 ScriptModule script_module) override { |
| 200 if (script_module.IsNull()) |
| 201 return Vector<String>(); |
| 202 |
181 const auto& it = dependency_module_requests_map_.find(script_module); | 203 const auto& it = dependency_module_requests_map_.find(script_module); |
182 if (it == dependency_module_requests_map_.end()) | 204 if (it == dependency_module_requests_map_.end()) |
183 return Vector<String>(); | 205 return Vector<String>(); |
184 | 206 |
185 return it->value; | 207 return it->value; |
186 } | 208 } |
187 | 209 |
188 RefPtr<ScriptState> script_state_; | 210 RefPtr<ScriptState> script_state_; |
189 KURL pending_request_url_; | 211 KURL pending_request_url_; |
190 Member<SingleModuleClient> pending_client_; | 212 Member<SingleModuleClient> pending_client_; |
191 HashMap<ScriptModule, Vector<String>> dependency_module_requests_map_; | 213 HashMap<ScriptModule, Vector<String>> dependency_module_requests_map_; |
192 HeapHashMap<KURL, Member<ModuleScript>> module_map_; | 214 HeapHashMap<KURL, Member<ModuleScript>> module_map_; |
193 HeapHashMap<KURL, Member<ModuleTreeClient>> pending_tree_client_map_; | 215 HeapHashMap<KURL, Member<ModuleTreeClient>> pending_tree_client_map_; |
194 HashMap<KURL, AncestorList> pending_tree_ancestor_list_; | 216 HashMap<KURL, AncestorList> pending_tree_ancestor_list_; |
195 bool instantiate_should_fail_ = false; | 217 bool instantiate_should_fail_ = false; |
196 }; | 218 }; |
197 | 219 |
198 DEFINE_TRACE(ModuleTreeLinkerTestModulator) { | 220 DEFINE_TRACE(ModuleTreeLinkerTestModulator) { |
199 visitor->Trace(pending_client_); | 221 visitor->Trace(pending_client_); |
200 visitor->Trace(module_map_); | 222 visitor->Trace(module_map_); |
201 visitor->Trace(pending_tree_client_map_); | 223 visitor->Trace(pending_tree_client_map_); |
202 DummyModulator::Trace(visitor); | 224 DummyModulator::Trace(visitor); |
203 } | 225 } |
204 | 226 |
205 } // namespace | |
206 | |
207 class ModuleTreeLinkerTest : public ::testing::Test { | 227 class ModuleTreeLinkerTest : public ::testing::Test { |
208 DISALLOW_COPY_AND_ASSIGN(ModuleTreeLinkerTest); | 228 DISALLOW_COPY_AND_ASSIGN(ModuleTreeLinkerTest); |
209 | 229 |
210 public: | 230 public: |
211 ModuleTreeLinkerTest() = default; | 231 ModuleTreeLinkerTest() = default; |
212 void SetUp() override; | 232 void SetUp() override; |
213 | 233 |
214 ModuleTreeLinkerTestModulator* GetModulator() { return modulator_.Get(); } | 234 ModuleTreeLinkerTestModulator* GetModulator() { return modulator_.Get(); } |
215 | 235 |
216 protected: | 236 protected: |
(...skipping 16 matching lines...) Expand all Loading... |
233 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); | 253 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); |
234 TestModuleTreeClient* client = new TestModuleTreeClient; | 254 TestModuleTreeClient* client = new TestModuleTreeClient; |
235 registry->Fetch(module_request, AncestorList(), | 255 registry->Fetch(module_request, AncestorList(), |
236 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), | 256 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), |
237 client); | 257 client); |
238 | 258 |
239 EXPECT_FALSE(client->WasNotifyFinished()) | 259 EXPECT_FALSE(client->WasNotifyFinished()) |
240 << "ModuleTreeLinker should always finish asynchronously."; | 260 << "ModuleTreeLinker should always finish asynchronously."; |
241 EXPECT_FALSE(client->GetModuleScript()); | 261 EXPECT_FALSE(client->GetModuleScript()); |
242 | 262 |
243 GetModulator()->ResolveSingleModuleScriptFetch(url, {}); | 263 GetModulator()->ResolveSingleModuleScriptFetch( |
| 264 url, {}, ModuleInstantiationState::kUninstantiated); |
244 EXPECT_TRUE(client->WasNotifyFinished()); | 265 EXPECT_TRUE(client->WasNotifyFinished()); |
245 ASSERT_TRUE(client->GetModuleScript()); | 266 ASSERT_TRUE(client->GetModuleScript()); |
246 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), | 267 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), |
247 ModuleInstantiationState::kInstantiated); | 268 ModuleInstantiationState::kInstantiated); |
248 } | 269 } |
249 | 270 |
250 TEST_F(ModuleTreeLinkerTest, FetchTreeInstantiationFailure) { | 271 TEST_F(ModuleTreeLinkerTest, FetchTreeInstantiationFailure) { |
251 GetModulator()->SetInstantiateShouldFail(true); | 272 GetModulator()->SetInstantiateShouldFail(true); |
252 | 273 |
253 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); | 274 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); |
254 | 275 |
255 KURL url(kParsedURLString, "http://example.com/root.js"); | 276 KURL url(kParsedURLString, "http://example.com/root.js"); |
256 ModuleScriptFetchRequest module_request( | 277 ModuleScriptFetchRequest module_request( |
257 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); | 278 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); |
258 TestModuleTreeClient* client = new TestModuleTreeClient; | 279 TestModuleTreeClient* client = new TestModuleTreeClient; |
259 registry->Fetch(module_request, AncestorList(), | 280 registry->Fetch(module_request, AncestorList(), |
260 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), | 281 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), |
261 client); | 282 client); |
262 | 283 |
263 EXPECT_FALSE(client->WasNotifyFinished()) | 284 EXPECT_FALSE(client->WasNotifyFinished()) |
264 << "ModuleTreeLinker should always finish asynchronously."; | 285 << "ModuleTreeLinker should always finish asynchronously."; |
265 EXPECT_FALSE(client->GetModuleScript()); | 286 EXPECT_FALSE(client->GetModuleScript()); |
266 | 287 |
267 GetModulator()->ResolveSingleModuleScriptFetch(url, {}); | 288 GetModulator()->ResolveSingleModuleScriptFetch( |
| 289 url, {}, ModuleInstantiationState::kUninstantiated); |
| 290 |
| 291 // Modulator::InstantiateModule() fails here, as |
| 292 // we SetInstantiateShouldFail(true) earlier. |
| 293 |
268 EXPECT_TRUE(client->WasNotifyFinished()); | 294 EXPECT_TRUE(client->WasNotifyFinished()); |
269 ASSERT_TRUE(client->GetModuleScript()); | 295 ASSERT_TRUE(client->GetModuleScript()); |
270 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), | 296 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), |
271 ModuleInstantiationState::kErrored); | 297 ModuleInstantiationState::kErrored); |
272 } | 298 } |
273 | 299 |
| 300 TEST_F(ModuleTreeLinkerTest, FetchTreePreviousInstantiationFailure) { |
| 301 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); |
| 302 |
| 303 KURL url(kParsedURLString, "http://example.com/root.js"); |
| 304 ModuleScriptFetchRequest module_request( |
| 305 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); |
| 306 TestModuleTreeClient* client = new TestModuleTreeClient; |
| 307 registry->Fetch(module_request, AncestorList(), |
| 308 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), |
| 309 client); |
| 310 |
| 311 EXPECT_FALSE(client->WasNotifyFinished()) |
| 312 << "ModuleTreeLinker should always finish asynchronously."; |
| 313 EXPECT_FALSE(client->GetModuleScript()); |
| 314 |
| 315 // This emulates "previous instantiation failure", where |
| 316 // Modulator::FetchSingle resolves w/ "errored" module script. |
| 317 GetModulator()->ResolveSingleModuleScriptFetch( |
| 318 url, {}, ModuleInstantiationState::kErrored); |
| 319 EXPECT_TRUE(client->WasNotifyFinished()); |
| 320 ASSERT_TRUE(client->GetModuleScript()); |
| 321 EXPECT_EQ(ModuleInstantiationState::kErrored, |
| 322 client->GetModuleScript()->InstantiationState()); |
| 323 } |
| 324 |
274 TEST_F(ModuleTreeLinkerTest, FetchTreeWithSingleDependency) { | 325 TEST_F(ModuleTreeLinkerTest, FetchTreeWithSingleDependency) { |
275 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); | 326 ModuleTreeLinkerRegistry* registry = ModuleTreeLinkerRegistry::Create(); |
276 | 327 |
277 KURL url(kParsedURLString, "http://example.com/root.js"); | 328 KURL url(kParsedURLString, "http://example.com/root.js"); |
278 ModuleScriptFetchRequest module_request( | 329 ModuleScriptFetchRequest module_request( |
279 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); | 330 url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit); |
280 TestModuleTreeClient* client = new TestModuleTreeClient; | 331 TestModuleTreeClient* client = new TestModuleTreeClient; |
281 registry->Fetch(module_request, AncestorList(), | 332 registry->Fetch(module_request, AncestorList(), |
282 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), | 333 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), |
283 client); | 334 client); |
284 | 335 |
285 EXPECT_FALSE(client->WasNotifyFinished()) | 336 EXPECT_FALSE(client->WasNotifyFinished()) |
286 << "ModuleTreeLinker should always finish asynchronously."; | 337 << "ModuleTreeLinker should always finish asynchronously."; |
287 EXPECT_FALSE(client->GetModuleScript()); | 338 EXPECT_FALSE(client->GetModuleScript()); |
288 | 339 |
289 GetModulator()->ResolveSingleModuleScriptFetch(url, {"./dep1.js"}); | 340 GetModulator()->ResolveSingleModuleScriptFetch( |
| 341 url, {"./dep1.js"}, ModuleInstantiationState::kUninstantiated); |
290 EXPECT_FALSE(client->WasNotifyFinished()); | 342 EXPECT_FALSE(client->WasNotifyFinished()); |
291 | 343 |
292 KURL url_dep1(kParsedURLString, "http://example.com/dep1.js"); | 344 KURL url_dep1(kParsedURLString, "http://example.com/dep1.js"); |
293 auto ancestor_list = GetModulator()->GetAncestorListForTreeFetch(url_dep1); | 345 auto ancestor_list = GetModulator()->GetAncestorListForTreeFetch(url_dep1); |
294 EXPECT_EQ(1u, ancestor_list.size()); | 346 EXPECT_EQ(1u, ancestor_list.size()); |
295 EXPECT_TRUE(ancestor_list.Contains( | 347 EXPECT_TRUE(ancestor_list.Contains( |
296 KURL(kParsedURLString, "http://example.com/root.js"))); | 348 KURL(kParsedURLString, "http://example.com/root.js"))); |
297 | 349 |
298 GetModulator()->ResolveDependentTreeFetch( | 350 GetModulator()->ResolveDependentTreeFetch( |
299 url_dep1, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess); | 351 url_dep1, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess); |
(...skipping 13 matching lines...) Expand all Loading... |
313 TestModuleTreeClient* client = new TestModuleTreeClient; | 365 TestModuleTreeClient* client = new TestModuleTreeClient; |
314 registry->Fetch(module_request, AncestorList(), | 366 registry->Fetch(module_request, AncestorList(), |
315 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), | 367 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), |
316 client); | 368 client); |
317 | 369 |
318 EXPECT_FALSE(client->WasNotifyFinished()) | 370 EXPECT_FALSE(client->WasNotifyFinished()) |
319 << "ModuleTreeLinker should always finish asynchronously."; | 371 << "ModuleTreeLinker should always finish asynchronously."; |
320 EXPECT_FALSE(client->GetModuleScript()); | 372 EXPECT_FALSE(client->GetModuleScript()); |
321 | 373 |
322 GetModulator()->ResolveSingleModuleScriptFetch( | 374 GetModulator()->ResolveSingleModuleScriptFetch( |
323 url, {"./dep1.js", "./dep2.js", "./dep3.js"}); | 375 url, {"./dep1.js", "./dep2.js", "./dep3.js"}, |
| 376 ModuleInstantiationState::kUninstantiated); |
324 EXPECT_FALSE(client->WasNotifyFinished()); | 377 EXPECT_FALSE(client->WasNotifyFinished()); |
325 | 378 |
326 Vector<KURL> url_deps; | 379 Vector<KURL> url_deps; |
327 for (int i = 1; i <= 3; ++i) { | 380 for (int i = 1; i <= 3; ++i) { |
328 StringBuilder url_dep_str; | 381 StringBuilder url_dep_str; |
329 url_dep_str.Append("http://example.com/dep"); | 382 url_dep_str.Append("http://example.com/dep"); |
330 url_dep_str.AppendNumber(i); | 383 url_dep_str.AppendNumber(i); |
331 url_dep_str.Append(".js"); | 384 url_dep_str.Append(".js"); |
332 | 385 |
333 KURL url_dep(kParsedURLString, url_dep_str.ToString()); | 386 KURL url_dep(kParsedURLString, url_dep_str.ToString()); |
(...skipping 29 matching lines...) Expand all Loading... |
363 TestModuleTreeClient* client = new TestModuleTreeClient; | 416 TestModuleTreeClient* client = new TestModuleTreeClient; |
364 registry->Fetch(module_request, AncestorList(), | 417 registry->Fetch(module_request, AncestorList(), |
365 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), | 418 ModuleGraphLevel::kTopLevelModuleFetch, GetModulator(), |
366 client); | 419 client); |
367 | 420 |
368 EXPECT_FALSE(client->WasNotifyFinished()) | 421 EXPECT_FALSE(client->WasNotifyFinished()) |
369 << "ModuleTreeLinker should always finish asynchronously."; | 422 << "ModuleTreeLinker should always finish asynchronously."; |
370 EXPECT_FALSE(client->GetModuleScript()); | 423 EXPECT_FALSE(client->GetModuleScript()); |
371 | 424 |
372 GetModulator()->ResolveSingleModuleScriptFetch( | 425 GetModulator()->ResolveSingleModuleScriptFetch( |
373 url, {"./dep1.js", "./dep2.js", "./dep3.js"}); | 426 url, {"./dep1.js", "./dep2.js", "./dep3.js"}, |
| 427 ModuleInstantiationState::kUninstantiated); |
374 EXPECT_FALSE(client->WasNotifyFinished()); | 428 EXPECT_FALSE(client->WasNotifyFinished()); |
375 | 429 |
376 Vector<KURL> url_deps; | 430 Vector<KURL> url_deps; |
377 for (int i = 1; i <= 3; ++i) { | 431 for (int i = 1; i <= 3; ++i) { |
378 StringBuilder url_dep_str; | 432 StringBuilder url_dep_str; |
379 url_dep_str.Append("http://example.com/dep"); | 433 url_dep_str.Append("http://example.com/dep"); |
380 url_dep_str.AppendNumber(i); | 434 url_dep_str.AppendNumber(i); |
381 url_dep_str.Append(".js"); | 435 url_dep_str.Append(".js"); |
382 | 436 |
383 KURL url_dep(kParsedURLString, url_dep_str.ToString()); | 437 KURL url_dep(kParsedURLString, url_dep_str.ToString()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 TestModuleTreeClient* client = new TestModuleTreeClient; | 476 TestModuleTreeClient* client = new TestModuleTreeClient; |
423 registry->Fetch( | 477 registry->Fetch( |
424 module_request, | 478 module_request, |
425 AncestorList{KURL(kParsedURLString, "http://example.com/root.js")}, | 479 AncestorList{KURL(kParsedURLString, "http://example.com/root.js")}, |
426 ModuleGraphLevel::kDependentModuleFetch, GetModulator(), client); | 480 ModuleGraphLevel::kDependentModuleFetch, GetModulator(), client); |
427 | 481 |
428 EXPECT_FALSE(client->WasNotifyFinished()) | 482 EXPECT_FALSE(client->WasNotifyFinished()) |
429 << "ModuleTreeLinker should always finish asynchronously."; | 483 << "ModuleTreeLinker should always finish asynchronously."; |
430 EXPECT_FALSE(client->GetModuleScript()); | 484 EXPECT_FALSE(client->GetModuleScript()); |
431 | 485 |
432 GetModulator()->ResolveSingleModuleScriptFetch(url, {"./depth2.js"}); | 486 GetModulator()->ResolveSingleModuleScriptFetch( |
| 487 url, {"./depth2.js"}, ModuleInstantiationState::kUninstantiated); |
433 | 488 |
434 KURL url_dep2(kParsedURLString, "http://example.com/depth2.js"); | 489 KURL url_dep2(kParsedURLString, "http://example.com/depth2.js"); |
435 auto ancestor_list = GetModulator()->GetAncestorListForTreeFetch(url_dep2); | 490 auto ancestor_list = GetModulator()->GetAncestorListForTreeFetch(url_dep2); |
436 EXPECT_EQ(2u, ancestor_list.size()); | 491 EXPECT_EQ(2u, ancestor_list.size()); |
437 EXPECT_TRUE(ancestor_list.Contains( | 492 EXPECT_TRUE(ancestor_list.Contains( |
438 KURL(kParsedURLString, "http://example.com/root.js"))); | 493 KURL(kParsedURLString, "http://example.com/root.js"))); |
439 EXPECT_TRUE(ancestor_list.Contains( | 494 EXPECT_TRUE(ancestor_list.Contains( |
440 KURL(kParsedURLString, "http://example.com/depth1.js"))); | 495 KURL(kParsedURLString, "http://example.com/depth1.js"))); |
441 | 496 |
442 GetModulator()->ResolveDependentTreeFetch( | 497 GetModulator()->ResolveDependentTreeFetch( |
443 url_dep2, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess); | 498 url_dep2, ModuleTreeLinkerTestModulator::ResolveResult::kSuccess); |
444 | 499 |
445 EXPECT_TRUE(client->WasNotifyFinished()); | 500 EXPECT_TRUE(client->WasNotifyFinished()); |
446 ASSERT_TRUE(client->GetModuleScript()); | 501 ASSERT_TRUE(client->GetModuleScript()); |
447 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), | 502 EXPECT_EQ(client->GetModuleScript()->InstantiationState(), |
448 ModuleInstantiationState::kInstantiated); | 503 ModuleInstantiationState::kInstantiated); |
449 } | 504 } |
450 | 505 |
451 } // namespace blink | 506 } // namespace blink |
OLD | NEW |