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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptModuleResolverImplTest.cpp

Issue 2845743003: Move "create a module script" from ModuleScriptLoader to ModuleScript (Closed)
Patch Set: Rebase Created 3 years, 7 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 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/dom/ScriptModuleResolverImpl.h" 5 #include "core/dom/ScriptModuleResolverImpl.h"
6 6
7 #include "bindings/core/v8/V8BindingForTesting.h" 7 #include "bindings/core/v8/V8BindingForTesting.h"
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "core/dom/Modulator.h" 9 #include "core/dom/Modulator.h"
10 #include "core/dom/ModuleScript.h" 10 #include "core/dom/ModuleScript.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 fetched_url_ = url; 54 fetched_url_ = url;
55 return module_script_.Get(); 55 return module_script_.Get();
56 } 56 }
57 57
58 ModuleScript* CreateReferrerModuleScript(Modulator* modulator, 58 ModuleScript* CreateReferrerModuleScript(Modulator* modulator,
59 V8TestingScope& scope) { 59 V8TestingScope& scope) {
60 ScriptModule referrer_record = ScriptModule::Compile( 60 ScriptModule referrer_record = ScriptModule::Compile(
61 scope.GetIsolate(), "import './target.js'; export const a = 42;", 61 scope.GetIsolate(), "import './target.js'; export const a = 42;",
62 "referrer.js", kSharableCrossOrigin); 62 "referrer.js", kSharableCrossOrigin);
63 KURL referrer_url(kParsedURLString, "https://example.com/referrer.js"); 63 KURL referrer_url(kParsedURLString, "https://example.com/referrer.js");
64 ModuleScript* referrer_module_script = ModuleScript::Create( 64 ModuleScript* referrer_module_script = ModuleScript::CreateForTest(
65 modulator, referrer_record, referrer_url, "", kParserInserted, 65 modulator, referrer_record, referrer_url, "", kParserInserted,
66 WebURLRequest::kFetchCredentialsModeOmit); 66 WebURLRequest::kFetchCredentialsModeOmit);
67 // TODO(kouhei): moduleScript->setInstantiateSuccess(); once 67 // TODO(kouhei): moduleScript->setInstantiateSuccess(); once
68 // https://codereview.chromium.org/2782403002/ landed. 68 // https://codereview.chromium.org/2782403002/ landed.
69 return referrer_module_script; 69 return referrer_module_script;
70 } 70 }
71 71
72 ModuleScript* CreateTargetModuleScript(Modulator* modulator, 72 ModuleScript* CreateTargetModuleScript(Modulator* modulator,
73 V8TestingScope& scope) { 73 V8TestingScope& scope) {
74 ScriptModule record = 74 ScriptModule record =
75 ScriptModule::Compile(scope.GetIsolate(), "export const pi = 3.14;", 75 ScriptModule::Compile(scope.GetIsolate(), "export const pi = 3.14;",
76 "target.js", kSharableCrossOrigin); 76 "target.js", kSharableCrossOrigin);
77 KURL url(kParsedURLString, "https://example.com/target.js"); 77 KURL url(kParsedURLString, "https://example.com/target.js");
78 ModuleScript* module_script = 78 ModuleScript* module_script =
79 ModuleScript::Create(modulator, record, url, "", kParserInserted, 79 ModuleScript::CreateForTest(modulator, record, url, "", kParserInserted,
80 WebURLRequest::kFetchCredentialsModeOmit); 80 WebURLRequest::kFetchCredentialsModeOmit);
81 // TODO(kouhei): moduleScript->setInstantiateSuccess(); once 81 // TODO(kouhei): moduleScript->setInstantiateSuccess(); once
82 // https://codereview.chromium.org/2782403002/ landed. 82 // https://codereview.chromium.org/2782403002/ landed.
83 return module_script; 83 return module_script;
84 } 84 }
85 85
86 } // namespace 86 } // namespace
87 87
88 class ScriptModuleResolverImplTest : public testing::Test { 88 class ScriptModuleResolverImplTest : public testing::Test {
89 public: 89 public:
90 void SetUp() override; 90 void SetUp() override;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 scope.GetExceptionState()); 168 scope.GetExceptionState());
169 EXPECT_TRUE(scope.GetExceptionState().HadException()); 169 EXPECT_TRUE(scope.GetExceptionState().HadException());
170 EXPECT_EQ(kV8TypeError, scope.GetExceptionState().Code()); 170 EXPECT_EQ(kV8TypeError, scope.GetExceptionState().Code());
171 EXPECT_TRUE(resolved.IsNull()); 171 EXPECT_TRUE(resolved.IsNull());
172 EXPECT_EQ(1, modulator_->GetFetchedModuleScriptCalled()); 172 EXPECT_EQ(1, modulator_->GetFetchedModuleScriptCalled());
173 EXPECT_EQ(modulator_->FetchedUrl(), target_module_script->BaseURL()) 173 EXPECT_EQ(modulator_->FetchedUrl(), target_module_script->BaseURL())
174 << "Unexpectedly fetched URL: " << modulator_->FetchedUrl().GetString(); 174 << "Unexpectedly fetched URL: " << modulator_->FetchedUrl().GetString();
175 } 175 }
176 176
177 } // namespace blink 177 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698