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

Unified Diff: third_party/WebKit/Source/core/dom/ModulatorTest.cpp

Issue 2640723002: [ES6 modules] Implement https://html.spec.whatwg.org/#resolve-a-module-specifier (Closed)
Patch Set: absoluteURL 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/Modulator.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/ModulatorTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/ModulatorTest.cpp b/third_party/WebKit/Source/core/dom/ModulatorTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3cf09dddb14420409c5ec239502ffb70c045cad5
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ModulatorTest.cpp
@@ -0,0 +1,70 @@
+// 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/dom/Modulator.h"
+
+#include "platform/testing/TestingPlatformSupport.h"
+#include "public/platform/Platform.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+TEST(ModulatorTest, resolveModuleSpecifier) {
+ // Taken from examples listed in
+ // https://html.spec.whatwg.org/#resolve-a-module-specifier
+
+ // "The following are valid module specifiers according to the above
+ // algorithm:"
+ EXPECT_TRUE(
+ Modulator::resolveModuleSpecifier("https://example.com/apples.js", KURL())
+ .isValid());
+
+ KURL resolved =
+ Modulator::resolveModuleSpecifier("http:example.com\\pears.mjs", KURL());
+ EXPECT_TRUE(resolved.isValid());
+ EXPECT_STREQ("http://example.com/pears.mjs",
yhirano 2017/01/19 03:53:53 You can compare strings, e.g, EXPECT_EQ("http://ex
kouhei (in TOK) 2017/01/19 04:07:01 Done.
+ resolved.elidedString().utf8().data());
yhirano 2017/01/19 03:53:53 Should we use getString() instead?
kouhei (in TOK) 2017/01/19 04:07:01 Done.
+
+ KURL baseURL(KURL(), "https://example.com");
+ EXPECT_TRUE(
+ Modulator::resolveModuleSpecifier("//example.com/", baseURL).isValid());
+ EXPECT_TRUE(
+ Modulator::resolveModuleSpecifier("./strawberries.js.cgi", baseURL)
+ .isValid());
+ EXPECT_TRUE(
+ Modulator::resolveModuleSpecifier("../lychees", baseURL).isValid());
+ EXPECT_TRUE(
+ Modulator::resolveModuleSpecifier("/limes.jsx", baseURL).isValid());
+ EXPECT_TRUE(Modulator::resolveModuleSpecifier(
+ "data:text/javascript,export default 'grapes';", KURL())
+ .isValid());
+ EXPECT_TRUE(
+ Modulator::resolveModuleSpecifier(
+ "blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f",
+ KURL())
+ .isValid());
+
+ // "The following are valid module specifiers according to the above
+ // algorithm, but will invariably cause failures when they are fetched:"
+ EXPECT_TRUE(Modulator::resolveModuleSpecifier(
+ "javascript:export default 'artichokes';", KURL())
+ .isValid());
+ EXPECT_TRUE(Modulator::resolveModuleSpecifier(
+ "data:text/plain,export default 'kale';", KURL())
+ .isValid());
+ EXPECT_TRUE(
+ Modulator::resolveModuleSpecifier("about:legumes", KURL()).isValid());
+ EXPECT_TRUE(
+ Modulator::resolveModuleSpecifier("wss://example.com/celery", KURL())
+ .isValid());
+
+ // "The following are not valid module specifiers according to the above
+ // algorithm:"
+ EXPECT_FALSE(
+ Modulator::resolveModuleSpecifier("https://f:b/c", KURL()).isValid());
+ EXPECT_FALSE(
+ Modulator::resolveModuleSpecifier("pumpkins.js", KURL()).isValid());
yhirano 2017/01/19 03:53:53 Can we have a case for having a valid base url whi
kouhei (in TOK) 2017/01/19 04:07:00 Done.
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/Modulator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698