OLD | NEW |
(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/dom/Modulator.h" |
| 6 |
| 7 #include "platform/testing/TestingPlatformSupport.h" |
| 8 #include "public/platform/Platform.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 TEST(ModulatorTest, resolveModuleSpecifier) { |
| 14 // Taken from examples listed in |
| 15 // https://html.spec.whatwg.org/#resolve-a-module-specifier |
| 16 |
| 17 // "The following are valid module specifiers according to the above |
| 18 // algorithm:" |
| 19 EXPECT_TRUE( |
| 20 Modulator::resolveModuleSpecifier("https://example.com/apples.js", KURL()) |
| 21 .isValid()); |
| 22 |
| 23 KURL resolved = |
| 24 Modulator::resolveModuleSpecifier("http:example.com\\pears.mjs", KURL()); |
| 25 EXPECT_TRUE(resolved.isValid()); |
| 26 EXPECT_EQ("http://example.com/pears.mjs", resolved.getString()); |
| 27 |
| 28 KURL baseURL(KURL(), "https://example.com"); |
| 29 EXPECT_TRUE( |
| 30 Modulator::resolveModuleSpecifier("//example.com/", baseURL).isValid()); |
| 31 EXPECT_TRUE( |
| 32 Modulator::resolveModuleSpecifier("./strawberries.js.cgi", baseURL) |
| 33 .isValid()); |
| 34 EXPECT_TRUE( |
| 35 Modulator::resolveModuleSpecifier("../lychees", baseURL).isValid()); |
| 36 EXPECT_TRUE( |
| 37 Modulator::resolveModuleSpecifier("/limes.jsx", baseURL).isValid()); |
| 38 EXPECT_TRUE(Modulator::resolveModuleSpecifier( |
| 39 "data:text/javascript,export default 'grapes';", KURL()) |
| 40 .isValid()); |
| 41 EXPECT_TRUE( |
| 42 Modulator::resolveModuleSpecifier( |
| 43 "blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f", |
| 44 KURL()) |
| 45 .isValid()); |
| 46 |
| 47 // "The following are valid module specifiers according to the above |
| 48 // algorithm, but will invariably cause failures when they are fetched:" |
| 49 EXPECT_TRUE(Modulator::resolveModuleSpecifier( |
| 50 "javascript:export default 'artichokes';", KURL()) |
| 51 .isValid()); |
| 52 EXPECT_TRUE(Modulator::resolveModuleSpecifier( |
| 53 "data:text/plain,export default 'kale';", KURL()) |
| 54 .isValid()); |
| 55 EXPECT_TRUE( |
| 56 Modulator::resolveModuleSpecifier("about:legumes", KURL()).isValid()); |
| 57 EXPECT_TRUE( |
| 58 Modulator::resolveModuleSpecifier("wss://example.com/celery", KURL()) |
| 59 .isValid()); |
| 60 |
| 61 // "The following are not valid module specifiers according to the above |
| 62 // algorithm:" |
| 63 EXPECT_FALSE( |
| 64 Modulator::resolveModuleSpecifier("https://f:b/c", KURL()).isValid()); |
| 65 EXPECT_FALSE( |
| 66 Modulator::resolveModuleSpecifier("pumpkins.js", KURL()).isValid()); |
| 67 |
| 68 // Unprefixed module specifiers should still fail w/ a valid baseURL. |
| 69 EXPECT_FALSE( |
| 70 Modulator::resolveModuleSpecifier("avocados.js", baseURL).isValid()); |
| 71 } |
| 72 |
| 73 } // namespace blink |
OLD | NEW |