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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoaderTest.cpp
diff --git a/third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoaderTest.cpp b/third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoaderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..74521026909a73b682f4bb78e82263dab0331ae6
--- /dev/null
+++ b/third_party/WebKit/Source/core/loader/modulescript/ModuleScriptLoaderTest.cpp
@@ -0,0 +1,92 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/loader/modulescript/ModuleScriptLoader.h"
+
+#include "bindings/core/v8/ModuleController.h"
+#include "core/dom/Document.h"
+#include "core/dom/ModuleScript.h"
+#include "core/fetch/MockFetchContext.h"
+#include "core/fetch/ResourceFetcher.h"
+#include "core/loader/modulescript/ModuleScriptLoaderClient.h"
+#include "core/loader/modulescript/ModuleScriptLoaderRegistry.h"
+#include "core/testing/DummyPageHolder.h"
+#include "platform/heap/Handle.h"
+#include "platform/testing/TestingPlatformSupport.h"
+#include "public/platform/Platform.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+namespace {
+
+class TestModuleScriptLoaderClient
+ : public GarbageCollected<TestModuleScriptLoaderClient>,
+ public ModuleScriptLoaderClient {
+ USING_GARBAGE_COLLECTED_MIXIN(TestModuleScriptLoaderClient);
+
+ public:
+ TestModuleScriptLoaderClient() = default;
+ virtual ~TestModuleScriptLoaderClient() = default;
+
+ DEFINE_INLINE_TRACE() { visitor->trace(m_moduleScript); }
+
+ void notifyFinishedNewSingleModule(ModuleScript* moduleScript) override {
+ m_wasNotifyFinished = true;
+ m_moduleScript = moduleScript;
+ }
+
+ bool wasNotifyFinished() const { return m_wasNotifyFinished; }
+ ModuleScript* moduleScript() { return m_moduleScript; }
+
+ private:
+ bool m_wasNotifyFinished = false;
+ Member<ModuleScript> m_moduleScript;
+};
+
+} // namespace
+
+class ModuleScriptLoaderTest : public testing::Test {
+ public:
+ void SetUp() override;
+
+ LocalFrame& frame() { return m_dummyPageHolder->frame(); }
+ Document& document() { return m_dummyPageHolder->document(); }
+ ModuleController* moduleController() { return m_moduleController.get(); }
+ ResourceFetcher* fetcher() { return m_fetcher.get(); }
+
+ protected:
+ TestingPlatformSupportWithMockScheduler m_platform;
+ std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
+ Persistent<ModuleController> m_moduleController;
+ Persistent<ResourceFetcher> m_fetcher;
+};
+
+void ModuleScriptLoaderTest::SetUp() {
+ m_platform.advanceClockSeconds(1.); // For non-zero DocumentParserTimings
+ m_dummyPageHolder = DummyPageHolder::create(IntSize(500, 500));
+ document().setURL(KURL(KURL(), "https://example.test"));
+ m_moduleController =
+ ModuleController::create(ScriptState::forMainWorld(&frame()));
+ m_fetcher = ResourceFetcher::create(
+ MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
+}
+
+TEST_F(ModuleScriptLoaderTest, fetchDataURL) {
+ ModuleScriptLoaderRegistry* registry = ModuleScriptLoaderRegistry::create();
+ KURL url(KURL(), "data:text/javascript,export default 'grapes';");
+
+ TestModuleScriptLoaderClient* client = new TestModuleScriptLoaderClient;
+ registry->fetch(url, document().baseURL(), moduleController(), fetcher(),
+ client);
+
+ m_platform.runUntilIdle();
+
+ EXPECT_TRUE(client->wasNotifyFinished());
+ EXPECT_TRUE(client->moduleScript());
+ EXPECT_EQ(client->moduleScript()->instantiationState(),
+ InstantiationState::Uninstantiated);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698