Commit f6d3638e authored by DongJun Kim's avatar DongJun Kim Committed by Commit Bot

Replace Platform::Current() with url_test_helpers to call GetURLLoaderMockFactory.

This patch is for replacing Platform::Current()->GetURLLoaderMockFactory()
calls with "url_test_helpers::" under "third_party/blink/renderer".

It is initial stage of integrating all helper classes to frame_test_helpers.
We will be able to remove url_test_helpers::calls in the future.

Bug: 751425

Change-Id: I3c4d92830423f298ca66edd1365a7a7b4bd2bb63
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1746120
Commit-Queue: DongJun Kim <djmix.kim@samsung.com>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702672}
parent bfd46a33
...@@ -106,9 +106,7 @@ class ListenerLeakTest : public testing::Test { ...@@ -106,9 +106,7 @@ class ListenerLeakTest : public testing::Test {
} }
void TearDown() override { void TearDown() override {
Platform::Current() url_test_helpers::UnregisterAllURLsAndClearMemoryCache();
->GetURLLoaderMockFactory()
->UnregisterAllURLsAndClearMemoryCache();
} }
protected: protected:
......
...@@ -37,11 +37,17 @@ class DocumentLoaderTest : public testing::Test { ...@@ -37,11 +37,17 @@ class DocumentLoaderTest : public testing::Test {
} }
void TearDown() override { void TearDown() override {
Platform::Current() url_test_helpers::UnregisterAllURLsAndClearMemoryCache();
->GetURLLoaderMockFactory()
->UnregisterAllURLsAndClearMemoryCache();
} }
class ScopedLoaderDelegate {
public:
ScopedLoaderDelegate(WebURLLoaderTestDelegate* delegate) {
url_test_helpers::SetLoaderDelegate(delegate);
}
~ScopedLoaderDelegate() { url_test_helpers::SetLoaderDelegate(nullptr); }
};
WebLocalFrameImpl* MainFrame() { return web_view_helper_.LocalMainFrame(); } WebLocalFrameImpl* MainFrame() { return web_view_helper_.LocalMainFrame(); }
frame_test_helpers::WebViewHelper web_view_helper_; frame_test_helpers::WebViewHelper web_view_helper_;
...@@ -58,9 +64,8 @@ TEST_F(DocumentLoaderTest, SingleChunk) { ...@@ -58,9 +64,8 @@ TEST_F(DocumentLoaderTest, SingleChunk) {
} }
} delegate; } delegate;
Platform::Current()->GetURLLoaderMockFactory()->SetLoaderDelegate(&delegate); ScopedLoaderDelegate loader_delegate(&delegate);
frame_test_helpers::LoadFrame(MainFrame(), "https://example.com/foo.html"); frame_test_helpers::LoadFrame(MainFrame(), "https://example.com/foo.html");
Platform::Current()->GetURLLoaderMockFactory()->SetLoaderDelegate(nullptr);
// TODO(dcheng): How should the test verify that the original callback is // TODO(dcheng): How should the test verify that the original callback is
// invoked? The test currently still passes even if the test delegate // invoked? The test currently still passes even if the test delegate
...@@ -82,9 +87,8 @@ TEST_F(DocumentLoaderTest, MultiChunkNoReentrancy) { ...@@ -82,9 +87,8 @@ TEST_F(DocumentLoaderTest, MultiChunkNoReentrancy) {
} }
} delegate; } delegate;
Platform::Current()->GetURLLoaderMockFactory()->SetLoaderDelegate(&delegate); ScopedLoaderDelegate loader_delegate(&delegate);
frame_test_helpers::LoadFrame(MainFrame(), "https://example.com/foo.html"); frame_test_helpers::LoadFrame(MainFrame(), "https://example.com/foo.html");
Platform::Current()->GetURLLoaderMockFactory()->SetLoaderDelegate(nullptr);
} }
// Finally, test reentrant callbacks to DocumentLoader::BodyDataReceived(). // Finally, test reentrant callbacks to DocumentLoader::BodyDataReceived().
...@@ -171,13 +175,13 @@ TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) { ...@@ -171,13 +175,13 @@ TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) {
web_view_helper_.GetWebView()->GetPage()->GetSettings().SetPluginsEnabled( web_view_helper_.GetWebView()->GetPage()->GetSettings().SetPluginsEnabled(
true); true);
Platform::Current()->GetURLLoaderMockFactory()->SetLoaderDelegate( {
&main_frame_client); ScopedLoaderDelegate loader_delegate(&main_frame_client);
frame_test_helpers::LoadFrameDontWait( frame_test_helpers::LoadFrameDontWait(
MainFrame(), url_test_helpers::ToKURL("https://example.com/foo.html")); MainFrame(), url_test_helpers::ToKURL("https://example.com/foo.html"));
main_frame_client.Serve(); main_frame_client.Serve();
frame_test_helpers::PumpPendingRequestsForFrameToLoad(MainFrame()); frame_test_helpers::PumpPendingRequestsForFrameToLoad(MainFrame());
Platform::Current()->GetURLLoaderMockFactory()->SetLoaderDelegate(nullptr); }
// Sanity check that we did actually test reeentrancy. // Sanity check that we did actually test reeentrancy.
EXPECT_TRUE(main_frame_client.ServedReentrantly()); EXPECT_TRUE(main_frame_client.ServedReentrantly());
......
...@@ -449,9 +449,7 @@ class LinkHighlightSquashingImplTest : public testing::Test, ...@@ -449,9 +449,7 @@ class LinkHighlightSquashingImplTest : public testing::Test,
} }
void TearDown() override { void TearDown() override {
Platform::Current() url_test_helpers::UnregisterAllURLsAndClearMemoryCache();
->GetURLLoaderMockFactory()
->UnregisterAllURLsAndClearMemoryCache();
// Ensure we fully clean up while scoped settings are enabled. Without this, // Ensure we fully clean up while scoped settings are enabled. Without this,
// garbage collection would occur after Scoped[setting]ForTest is out of // garbage collection would occur after Scoped[setting]ForTest is out of
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h" #include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/test/fake_task_runner.h" #include "third_party/blink/renderer/platform/scheduler/test/fake_task_runner.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" #include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h" #include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
...@@ -197,8 +198,8 @@ class WebEmbeddedWorkerImplTest : public testing::Test { ...@@ -197,8 +198,8 @@ class WebEmbeddedWorkerImplTest : public testing::Test {
WebURLResponse response(script_url_); WebURLResponse response(script_url_);
response.SetMimeType("text/javascript"); response.SetMimeType("text/javascript");
response.SetHttpStatusCode(200); response.SetHttpStatusCode(200);
Platform::Current()->GetURLLoaderMockFactory()->RegisterURL(script_url_, url_test_helpers::RegisterMockedURLLoadWithCustomResponse(script_url_, "",
response, ""); response);
} }
std::unique_ptr<WebEmbeddedWorkerStartData> CreateStartData() { std::unique_ptr<WebEmbeddedWorkerStartData> CreateStartData() {
...@@ -219,9 +220,7 @@ class WebEmbeddedWorkerImplTest : public testing::Test { ...@@ -219,9 +220,7 @@ class WebEmbeddedWorkerImplTest : public testing::Test {
// QuitClosure to wait until all the tasks run before test completion. // QuitClosure to wait until all the tasks run before test completion.
test::RunPendingTasks(); test::RunPendingTasks();
Platform::Current() url_test_helpers::UnregisterAllURLsAndClearMemoryCache();
->GetURLLoaderMockFactory()
->UnregisterAllURLsAndClearMemoryCache();
} }
WebURL script_url_; WebURL script_url_;
...@@ -268,12 +267,7 @@ TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileWaitingForDebugger) { ...@@ -268,12 +267,7 @@ TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileWaitingForDebugger) {
TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) { TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) {
WebURL script_url = url_test_helpers::ToKURL(kNotFoundScriptURL); WebURL script_url = url_test_helpers::ToKURL(kNotFoundScriptURL);
WebURLResponse response; url_test_helpers::RegisterMockedErrorURLLoad(script_url);
response.SetMimeType("text/javascript");
response.SetHttpStatusCode(404);
ResourceError error = ResourceError::Failure(script_url);
Platform::Current()->GetURLLoaderMockFactory()->RegisterErrorURL(
script_url, response, error);
std::unique_ptr<WebEmbeddedWorkerStartData> start_data = CreateStartData(); std::unique_ptr<WebEmbeddedWorkerStartData> start_data = CreateStartData();
start_data->script_url = script_url; start_data->script_url = script_url;
......
...@@ -81,11 +81,11 @@ constexpr char kTestResourceFilename[] = "white-1x1.png"; ...@@ -81,11 +81,11 @@ constexpr char kTestResourceFilename[] = "white-1x1.png";
constexpr char kTestResourceMimeType[] = "image/png"; constexpr char kTestResourceMimeType[] = "image/png";
constexpr uint32_t kTestResourceSize = 103; // size of white-1x1.png constexpr uint32_t kTestResourceSize = 103; // size of white-1x1.png
void RegisterMockedURLLoadWithCustomResponse(const KURL& url, void RegisterMockedURLLoadWithCustomResponse(const WebURL& full_url,
const ResourceResponse& response) { const WebString& file_path,
url_test_helpers::RegisterMockedURLLoadWithCustomResponse( WebURLResponse response) {
url, test::PlatformTestDataPath(kTestResourceFilename), url_test_helpers::RegisterMockedURLLoadWithCustomResponse(full_url, file_path,
WrappedResourceResponse(response)); response);
} }
void RegisterMockedURLLoad(const KURL& url) { void RegisterMockedURLLoad(const KURL& url) {
...@@ -214,7 +214,9 @@ TEST_F(ResourceFetcherTest, UseExistingResource) { ...@@ -214,7 +214,9 @@ TEST_F(ResourceFetcherTest, UseExistingResource) {
ResourceResponse response(url); ResourceResponse response(url);
response.SetHttpStatusCode(200); response.SetHttpStatusCode(200);
response.SetHttpHeaderField(http_names::kCacheControl, "max-age=3600"); response.SetHttpHeaderField(http_names::kCacheControl, "max-age=3600");
RegisterMockedURLLoadWithCustomResponse(url, response); RegisterMockedURLLoadWithCustomResponse(
url, test::PlatformTestDataPath(kTestResourceFilename),
WrappedResourceResponse(response));
FetchParameters fetch_params{ResourceRequest(url)}; FetchParameters fetch_params{ResourceRequest(url)};
Resource* resource = MockResource::Fetch(fetch_params, fetcher, nullptr); Resource* resource = MockResource::Fetch(fetch_params, fetcher, nullptr);
...@@ -338,7 +340,9 @@ TEST_F(ResourceFetcherTest, VaryResource) { ...@@ -338,7 +340,9 @@ TEST_F(ResourceFetcherTest, VaryResource) {
response.SetHttpStatusCode(200); response.SetHttpStatusCode(200);
response.SetHttpHeaderField(http_names::kCacheControl, "max-age=3600"); response.SetHttpHeaderField(http_names::kCacheControl, "max-age=3600");
response.SetHttpHeaderField(http_names::kVary, "*"); response.SetHttpHeaderField(http_names::kVary, "*");
RegisterMockedURLLoadWithCustomResponse(url, response); RegisterMockedURLLoadWithCustomResponse(
url, test::PlatformTestDataPath(kTestResourceFilename),
WrappedResourceResponse(response));
FetchParameters fetch_params_original{ResourceRequest(url)}; FetchParameters fetch_params_original{ResourceRequest(url)};
Resource* resource = Resource* resource =
...@@ -406,7 +410,9 @@ TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) { ...@@ -406,7 +410,9 @@ TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) {
response.SetHttpStatusCode(200); response.SetHttpStatusCode(200);
response.SetHttpHeaderField(http_names::kCacheControl, "max-age=3600"); response.SetHttpHeaderField(http_names::kCacheControl, "max-age=3600");
response.SetHttpHeaderField(http_names::kETag, "1234567890"); response.SetHttpHeaderField(http_names::kETag, "1234567890");
RegisterMockedURLLoadWithCustomResponse(url, response); RegisterMockedURLLoadWithCustomResponse(
url, test::PlatformTestDataPath(kTestResourceFilename),
WrappedResourceResponse(response));
ResourceFetcher* fetcher1 = CreateFetcher( ResourceFetcher* fetcher1 = CreateFetcher(
*MakeGarbageCollected<TestResourceFetcherProperties>(source_origin)); *MakeGarbageCollected<TestResourceFetcherProperties>(source_origin));
...@@ -446,7 +452,7 @@ class ServeRequestsOnCompleteClient final ...@@ -446,7 +452,7 @@ class ServeRequestsOnCompleteClient final
public: public:
void NotifyFinished(Resource*) override { void NotifyFinished(Resource*) override {
Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests(); url_test_helpers::ServeAsynchronousRequests();
ClearResource(); ClearResource();
} }
...@@ -515,8 +521,9 @@ class ScopedMockRedirectRequester { ...@@ -515,8 +521,9 @@ class ScopedMockRedirectRequester {
redirect_response.SetHttpStatusCode(301); redirect_response.SetHttpStatusCode(301);
redirect_response.SetHttpHeaderField(http_names::kLocation, to_url); redirect_response.SetHttpHeaderField(http_names::kLocation, to_url);
redirect_response.SetEncodedDataLength(kRedirectResponseOverheadBytes); redirect_response.SetEncodedDataLength(kRedirectResponseOverheadBytes);
Platform::Current()->GetURLLoaderMockFactory()->RegisterURL(
redirect_url, redirect_response, ""); RegisterMockedURLLoadWithCustomResponse(redirect_url, "",
redirect_response);
} }
void RegisterFinalResource(const WebString& url) { void RegisterFinalResource(const WebString& url) {
...@@ -533,7 +540,7 @@ class ScopedMockRedirectRequester { ...@@ -533,7 +540,7 @@ class ScopedMockRedirectRequester {
resource_request.SetRequestContext(mojom::RequestContextType::INTERNAL); resource_request.SetRequestContext(mojom::RequestContextType::INTERNAL);
FetchParameters fetch_params(resource_request); FetchParameters fetch_params(resource_request);
RawResource::Fetch(fetch_params, fetcher, nullptr); RawResource::Fetch(fetch_params, fetcher, nullptr);
Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests(); url_test_helpers::ServeAsynchronousRequests();
} }
private: private:
...@@ -903,7 +910,9 @@ TEST_F(ResourceFetcherTest, ContentIdURL) { ...@@ -903,7 +910,9 @@ TEST_F(ResourceFetcherTest, ContentIdURL) {
KURL url("cid:0123456789@example.com"); KURL url("cid:0123456789@example.com");
ResourceResponse response(url); ResourceResponse response(url);
response.SetHttpStatusCode(200); response.SetHttpStatusCode(200);
RegisterMockedURLLoadWithCustomResponse(url, response); RegisterMockedURLLoadWithCustomResponse(
url, test::PlatformTestDataPath(kTestResourceFilename),
WrappedResourceResponse(response));
auto* fetcher = CreateFetcher(); auto* fetcher = CreateFetcher();
...@@ -937,7 +946,9 @@ TEST_F(ResourceFetcherTest, StaleWhileRevalidate) { ...@@ -937,7 +946,9 @@ TEST_F(ResourceFetcherTest, StaleWhileRevalidate) {
response.SetHttpHeaderField(http_names::kCacheControl, response.SetHttpHeaderField(http_names::kCacheControl,
"max-age=0, stale-while-revalidate=40"); "max-age=0, stale-while-revalidate=40");
RegisterMockedURLLoadWithCustomResponse(url, response); RegisterMockedURLLoadWithCustomResponse(
url, test::PlatformTestDataPath(kTestResourceFilename),
WrappedResourceResponse(response));
Resource* resource = MockResource::Fetch(fetch_params, fetcher, nullptr); Resource* resource = MockResource::Fetch(fetch_params, fetcher, nullptr);
ASSERT_TRUE(resource); ASSERT_TRUE(resource);
...@@ -959,7 +970,9 @@ TEST_F(ResourceFetcherTest, StaleWhileRevalidate) { ...@@ -959,7 +970,9 @@ TEST_F(ResourceFetcherTest, StaleWhileRevalidate) {
ResourceResponse revalidate_response(url); ResourceResponse revalidate_response(url);
revalidate_response.SetHttpStatusCode(200); revalidate_response.SetHttpStatusCode(200);
platform_->GetURLLoaderMockFactory()->UnregisterURL(url); platform_->GetURLLoaderMockFactory()->UnregisterURL(url);
RegisterMockedURLLoadWithCustomResponse(url, revalidate_response); RegisterMockedURLLoadWithCustomResponse(
url, test::PlatformTestDataPath(kTestResourceFilename),
WrappedResourceResponse(revalidate_response));
new_resource = MockResource::Fetch(fetch_params, fetcher, nullptr); new_resource = MockResource::Fetch(fetch_params, fetcher, nullptr);
EXPECT_EQ(resource, new_resource); EXPECT_EQ(resource, new_resource);
EXPECT_TRUE(GetMemoryCache()->Contains(resource)); EXPECT_TRUE(GetMemoryCache()->Contains(resource));
...@@ -980,7 +993,9 @@ TEST_F(ResourceFetcherTest, CachedResourceShouldNotCrashByNullURL) { ...@@ -980,7 +993,9 @@ TEST_F(ResourceFetcherTest, CachedResourceShouldNotCrashByNullURL) {
KURL url("http://127.0.0.1:8000/foo.html"); KURL url("http://127.0.0.1:8000/foo.html");
ResourceResponse response(url); ResourceResponse response(url);
response.SetHttpStatusCode(200); response.SetHttpStatusCode(200);
RegisterMockedURLLoadWithCustomResponse(url, response); RegisterMockedURLLoadWithCustomResponse(
url, test::PlatformTestDataPath(kTestResourceFilename),
WrappedResourceResponse(response));
FetchParameters fetch_params{ResourceRequest(url)}; FetchParameters fetch_params{ResourceRequest(url)};
MockResource::Fetch(fetch_params, fetcher, nullptr); MockResource::Fetch(fetch_params, fetcher, nullptr);
ASSERT_NE(fetcher->CachedResource(url), nullptr); ASSERT_NE(fetcher->CachedResource(url), nullptr);
......
...@@ -14,7 +14,7 @@ namespace test { ...@@ -14,7 +14,7 @@ namespace test {
ScopedMockedURL::ScopedMockedURL(const WebURL& url) : url_(url) {} ScopedMockedURL::ScopedMockedURL(const WebURL& url) : url_(url) {}
ScopedMockedURL::~ScopedMockedURL() { ScopedMockedURL::~ScopedMockedURL() {
Platform::Current()->GetURLLoaderMockFactory()->UnregisterURL(url_); url_test_helpers::RegisterMockedURLUnregister(url_);
} }
ScopedMockedURLLoad::ScopedMockedURLLoad(const WebURL& full_url, ScopedMockedURLLoad::ScopedMockedURLLoad(const WebURL& full_url,
......
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