Chromium Code Reviews| 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_STREQ("http://example.com/pears.mjs", | |
| 27 resolved.elidedString().utf8().data()); | |
| 28 | |
| 29 KURL baseURL(KURL(), "https://example.com"); | |
| 30 EXPECT_TRUE( | |
| 31 Modulator::resolveModuleSpecifier("//example.com/", baseURL).isValid()); | |
| 32 EXPECT_TRUE( | |
|
domenic
2017/01/18 19:04:48
Do you want to test the serialized form for more t
kouhei (in TOK)
2017/01/19 02:20:43
I think we should defer those to the KURLTest.
| |
| 33 Modulator::resolveModuleSpecifier("./strawberries.js.cgi", baseURL) | |
| 34 .isValid()); | |
| 35 EXPECT_TRUE( | |
| 36 Modulator::resolveModuleSpecifier("../lychees", baseURL).isValid()); | |
| 37 EXPECT_TRUE( | |
| 38 Modulator::resolveModuleSpecifier("/limes.jsx", baseURL).isValid()); | |
| 39 EXPECT_TRUE(Modulator::resolveModuleSpecifier( | |
| 40 "data:text/javascript,export default 'grapes';", KURL()) | |
| 41 .isValid()); | |
| 42 EXPECT_TRUE( | |
| 43 Modulator::resolveModuleSpecifier( | |
| 44 "blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f", | |
| 45 KURL()) | |
| 46 .isValid()); | |
| 47 | |
| 48 // "The following are valid module specifiers according to the above | |
| 49 // algorithm, but will invariably cause failures when they are fetched:" | |
| 50 EXPECT_TRUE(Modulator::resolveModuleSpecifier( | |
| 51 "javascript:export default 'artichokes';", KURL()) | |
| 52 .isValid()); | |
| 53 EXPECT_TRUE(Modulator::resolveModuleSpecifier( | |
| 54 "data:text/plain,export default 'kale';", KURL()) | |
| 55 .isValid()); | |
| 56 EXPECT_TRUE( | |
| 57 Modulator::resolveModuleSpecifier("about:legumes", KURL()).isValid()); | |
| 58 EXPECT_TRUE( | |
| 59 Modulator::resolveModuleSpecifier("wss://example.com/celery", KURL()) | |
| 60 .isValid()); | |
| 61 | |
| 62 // "The following are not valid module specifiers according to the above | |
| 63 // algorithm:" | |
| 64 EXPECT_FALSE( | |
| 65 Modulator::resolveModuleSpecifier("https://f:b/c", KURL()).isValid()); | |
| 66 EXPECT_FALSE( | |
| 67 Modulator::resolveModuleSpecifier("pumpkins.js", KURL()).isValid()); | |
| 68 } | |
| 69 | |
| 70 } // namespace blink | |
| OLD | NEW |