Commit 16b181b3 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

ES6 Modules: Fix wrong test expectations in ModuleScriptLoaderTest

Before this CL, some tests in ModuleScriptLoaderTest have wrong test
expectations and test helpers have wrong implementation as follows:

1) Dummy Modulator doesn't have a valid SecurityOrigin, so the CORS handling
   fails.
2) Mocked ResourceResponse doesn't have a Content-Type header, so a generated
   ScriptResource doesn't have a valid MIME type (ScriptResource respects the
   header instead of ResourceResponse::MimeType()).

This CL fixes them and corrects the test expectations.

In addition, this CL...

3) replaces NullURL() on the KURL constructor calls with kParsedURLString
   because they generate KURL instances from URL strings.
4) makes TouchActionTests specify the MIME types. Without this change, these
   tests set the Content-Type header to the default MIME type "text/html" and
   start to fail.

Bug: n/a
Change-Id: Ifffa734dcb4e44a670172f27c30efcdcc075e5be
Reviewed-on: https://chromium-review.googlesource.com/627523
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496608}
parent 9ce7836f
......@@ -97,13 +97,13 @@ class TouchActionTest : public ::testing::Test {
TouchActionTest() : base_url_("http://www.test.com/") {
URLTestHelpers::RegisterMockedURLLoadFromBase(
WebString::FromUTF8(base_url_), testing::CoreTestDataPath(),
"touch-action-tests.css");
"touch-action-tests.css", "text/css");
URLTestHelpers::RegisterMockedURLLoadFromBase(
WebString::FromUTF8(base_url_), testing::CoreTestDataPath(),
"touch-action-tests.js");
"touch-action-tests.js", "text/javascript");
URLTestHelpers::RegisterMockedURLLoadFromBase(
WebString::FromUTF8(base_url_), testing::CoreTestDataPath(),
"white-1x1.png");
"white-1x1.png", "image/png");
}
void TearDown() override {
......
......@@ -139,7 +139,8 @@ class ModuleScriptLoaderTest : public ::testing::Test {
void ModuleScriptLoaderTest::SetUp() {
platform_->AdvanceClockSeconds(1.); // For non-zero DocumentParserTimings
dummy_page_holder_ = DummyPageHolder::Create(IntSize(500, 500));
GetDocument().SetURL(KURL(NullURL(), "https://example.test"));
GetDocument().SetURL(KURL(kParsedURLString, "https://example.test"));
GetDocument().SetSecurityOrigin(SecurityOrigin::Create(GetDocument().Url()));
auto* context =
MockFetchContext::Create(MockFetchContext::kShouldLoadNewResource);
fetcher_ = ResourceFetcher::Create(context);
......@@ -153,7 +154,7 @@ void ModuleScriptLoaderTest::InitializeForDocument() {
void ModuleScriptLoaderTest::InitializeForWorklet() {
global_scope_ = new MainThreadWorkletGlobalScope(
&GetFrame(), KURL(NullURL(), "https://example.test/worklet.js"),
&GetFrame(), KURL(kParsedURLString, "https://example.test/worklet.js"),
"fake user agent", GetDocument().GetSecurityOrigin(),
ToIsolate(&GetDocument()));
global_scope_->ScriptController()->InitializeContextIfNeeded("Dummy Context");
......@@ -170,7 +171,7 @@ void ModuleScriptLoaderTest::InitializeForWorklet() {
void ModuleScriptLoaderTest::TestFetchDataURL(
TestModuleScriptLoaderClient* client) {
ModuleScriptLoaderRegistry* registry = ModuleScriptLoaderRegistry::Create();
KURL url(NullURL(), "data:text/javascript,export default 'grapes';");
KURL url(kParsedURLString, "data:text/javascript,export default 'grapes';");
ModuleScriptFetchRequest module_request(
url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit);
registry->Fetch(module_request, ModuleGraphLevel::kTopLevelModuleFetch,
......@@ -218,7 +219,7 @@ TEST_F(ModuleScriptLoaderTest, FetchDataURL_OnWorklet) {
void ModuleScriptLoaderTest::TestInvalidSpecifier(
TestModuleScriptLoaderClient* client) {
ModuleScriptLoaderRegistry* registry = ModuleScriptLoaderRegistry::Create();
KURL url(NullURL(),
KURL url(kParsedURLString,
"data:text/javascript,import 'invalid';export default 'grapes';");
ModuleScriptFetchRequest module_request(
url, String(), kParserInserted, WebURLRequest::kFetchCredentialsModeOmit);
......@@ -288,7 +289,7 @@ TEST_F(ModuleScriptLoaderTest, FetchInvalidURL_OnWorklet) {
void ModuleScriptLoaderTest::TestFetchURL(
TestModuleScriptLoaderClient* client) {
KURL url(kParsedURLString, "http://127.0.0.1:8000/module.js");
KURL url(kParsedURLString, "https://example.test/module.js");
URLTestHelpers::RegisterMockedURLLoad(
url, testing::CoreTestDataPath("module.js"), "text/javascript");
......@@ -309,7 +310,7 @@ TEST_F(ModuleScriptLoaderTest, FetchURL) {
platform_->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
EXPECT_TRUE(client->WasNotifyFinished());
EXPECT_FALSE(client->GetModuleScript());
EXPECT_TRUE(client->GetModuleScript());
}
TEST_F(ModuleScriptLoaderTest, FetchURL_OnWorklet) {
......@@ -327,7 +328,7 @@ TEST_F(ModuleScriptLoaderTest, FetchURL_OnWorklet) {
platform_->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
EXPECT_TRUE(client->WasNotifyFinished());
EXPECT_FALSE(client->GetModuleScript());
EXPECT_TRUE(client->GetModuleScript());
}
} // namespace blink
......@@ -33,6 +33,7 @@
#include <string>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "platform/HTTPNames.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/FilePathConversion.h"
#include "public/platform/Platform.h"
......@@ -68,6 +69,7 @@ void RegisterMockedURLLoad(const WebURL& full_url,
WebURLResponse response(full_url);
response.SetMIMEType(mime_type);
response.SetHTTPHeaderField(HTTPNames::Content_Type, mime_type);
response.SetHTTPStatusCode(200);
response.SetLoadTiming(timing);
......@@ -80,6 +82,7 @@ void RegisterMockedErrorURLLoad(const WebURL& full_url) {
WebURLResponse response;
response.SetMIMEType("image/png");
response.SetHTTPHeaderField(HTTPNames::Content_Type, "image/png");
response.SetHTTPStatusCode(404);
response.SetLoadTiming(timing);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment