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

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

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: ModuleScriptLoaderTest Created 3 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/loader/modulescript/ModuleScriptLoader.h"
6
7 #include "bindings/core/v8/ModuleController.h"
8 #include "core/dom/Document.h"
9 #include "core/dom/ModuleScript.h"
10 #include "core/fetch/MockFetchContext.h"
11 #include "core/fetch/ResourceFetcher.h"
12 #include "core/loader/modulescript/ModuleScriptLoaderClient.h"
13 #include "core/loader/modulescript/ModuleScriptLoaderRegistry.h"
14 #include "core/testing/DummyPageHolder.h"
15 #include "platform/heap/Handle.h"
16 #include "platform/testing/TestingPlatformSupport.h"
17 #include "public/platform/Platform.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace blink {
21
22 namespace {
23
24 class TestModuleScriptLoaderClient
25 : public GarbageCollected<TestModuleScriptLoaderClient>,
26 public ModuleScriptLoaderClient {
27 USING_GARBAGE_COLLECTED_MIXIN(TestModuleScriptLoaderClient);
28
29 public:
30 TestModuleScriptLoaderClient() = default;
31 virtual ~TestModuleScriptLoaderClient() = default;
32
33 DEFINE_INLINE_TRACE() { visitor->trace(m_moduleScript); }
34
35 void notifyFinishedNewSingleModule(ModuleScript* moduleScript) override {
36 m_wasNotifyFinished = true;
37 m_moduleScript = moduleScript;
38 }
39
40 bool wasNotifyFinished() const { return m_wasNotifyFinished; }
41 ModuleScript* moduleScript() { return m_moduleScript; }
42
43 private:
44 bool m_wasNotifyFinished = false;
45 Member<ModuleScript> m_moduleScript;
46 };
47
48 } // namespace
49
50 class ModuleScriptLoaderTest : public testing::Test {
51 public:
52 void SetUp() override;
53
54 LocalFrame& frame() { return m_dummyPageHolder->frame(); }
55 Document& document() { return m_dummyPageHolder->document(); }
56 ModuleController* moduleController() { return m_moduleController.get(); }
57 ResourceFetcher* fetcher() { return m_fetcher.get(); }
58
59 protected:
60 TestingPlatformSupportWithMockScheduler m_platform;
61 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
62 Persistent<ModuleController> m_moduleController;
63 Persistent<ResourceFetcher> m_fetcher;
64 };
65
66 void ModuleScriptLoaderTest::SetUp() {
67 m_platform.advanceClockSeconds(1.); // For non-zero DocumentParserTimings
68 m_dummyPageHolder = DummyPageHolder::create(IntSize(500, 500));
69 document().setURL(KURL(KURL(), "https://example.test"));
70 m_moduleController =
71 ModuleController::create(ScriptState::forMainWorld(&frame()));
72 m_fetcher = ResourceFetcher::create(
73 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
74 }
75
76 TEST_F(ModuleScriptLoaderTest, fetchDataURL) {
77 ModuleScriptLoaderRegistry* registry = ModuleScriptLoaderRegistry::create();
78 KURL url(KURL(), "data:text/javascript,export default 'grapes';");
79
80 TestModuleScriptLoaderClient* client = new TestModuleScriptLoaderClient;
81 registry->fetch(url, document().baseURL(), moduleController(), fetcher(),
82 client);
83
84 m_platform.runUntilIdle();
85
86 EXPECT_TRUE(client->wasNotifyFinished());
87 EXPECT_TRUE(client->moduleScript());
88 EXPECT_EQ(client->moduleScript()->instantiationState(),
89 InstantiationState::Uninstantiated);
90 }
91
92 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698