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

Unified Diff: content/public/test/render_view_test.cc

Issue 2071983002: Use loadHTMLString instead of data: and a mock WebURLLoader for loading html in RenderViewTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: url_str->url_string Created 4 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/render_view_test.cc
diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc
index b4728b4b03ae5229ca80d4e2c4b676af46d13956..89d501147f37f6edd9fc13401ab3a681c0177cbf 100644
--- a/content/public/test/render_view_test.cc
+++ b/content/public/test/render_view_test.cc
@@ -38,7 +38,6 @@
#include "content/test/test_content_client.h"
#include "content/test/test_render_frame.h"
#include "third_party/WebKit/public/platform/WebScreenInfo.h"
-#include "third_party/WebKit/public/platform/WebURLLoader.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebHistoryItem.h"
@@ -67,7 +66,6 @@ using blink::WebLocalFrame;
using blink::WebMouseEvent;
using blink::WebScriptSource;
using blink::WebString;
-using blink::WebURLLoader;
using blink::WebURLRequest;
namespace {
@@ -108,66 +106,10 @@ bool GetWindowsKeyCode(char ascii_character, int* key_code) {
}
}
-WebURLRequest createDataRequest(const std::string& html) {
- std::string url_str = "data:text/html;charset=utf-8,";
- url_str.append(html);
- GURL url(url_str);
- WebURLRequest request(url);
- request.setCheckForBrowserSideNavigation(false);
- return request;
-}
-
} // namespace
namespace content {
-const char kWrappedHTMLDataHeader[] = "X-WrappedHTMLData";
-
-// This loader checks all requests for the presence of the X-WrappedHTMLData
-// header and, if it's found, substitutes a data: url with the header's value
-// instead of loading the original request. It is used to implement
-// LoadHTMLWithURLOverride.
-class WebURLLoaderWrapper : public WebURLLoader {
-public:
- WebURLLoaderWrapper(WebURLLoader* wrapped_loader)
- : wrapped_loader_(wrapped_loader) { }
-
- void loadSynchronously(const WebURLRequest& request,
- blink::WebURLResponse& response,
- blink::WebURLError& error,
- blink::WebData& data) override {
- std::string html = request.httpHeaderField(kWrappedHTMLDataHeader).utf8();
- wrapped_loader_->loadSynchronously(
- html.empty() ? request : createDataRequest(html),
- response,
- error,
- data);
- }
-
- void loadAsynchronously(const WebURLRequest& request,
- blink::WebURLLoaderClient* client) override {
- std::string html = request.httpHeaderField(kWrappedHTMLDataHeader).utf8();
- wrapped_loader_->loadAsynchronously(
- html.empty() ? request : createDataRequest(html),
- client);
- }
-
- void cancel() override {
- wrapped_loader_->cancel();
- }
-
- void setDefersLoading(bool defer) override {
- wrapped_loader_->setDefersLoading(defer);
- }
-
- void setLoadingTaskRunner(blink::WebTaskRunner* runner) override {
- wrapped_loader_->setLoadingTaskRunner(runner);
- }
-
-private:
- std::unique_ptr<WebURLLoader> wrapped_loader_;
-};
-
class RendererBlinkPlatformImplTestOverrideImpl
: public RendererBlinkPlatformImpl {
public:
@@ -179,13 +121,6 @@ class RendererBlinkPlatformImplTestOverrideImpl
// Get rid of the dependency to the sandbox, which is not available in
// RenderViewTest.
blink::WebSandboxSupport* sandboxSupport() override { return NULL; }
-
- // Inject a WebURLLoader which rewrites requests that have the
- // X-WrappedHTMLData header.
- WebURLLoader* createURLLoader() override {
- return new WebURLLoaderWrapper(
- RendererBlinkPlatformImpl::createURLLoader());
- }
};
RenderViewTest::RendererBlinkPlatformImplTestOverride::
@@ -247,7 +182,12 @@ bool RenderViewTest::ExecuteJavaScriptAndReturnIntValue(
}
void RenderViewTest::LoadHTML(const char* html) {
- GetMainFrame()->loadRequest(createDataRequest(html));
+ std::string url_string = "data:text/html;charset=utf-8,";
+ url_string.append(html);
+ GURL url(url_string);
+ WebURLRequest request(url);
+ request.setCheckForBrowserSideNavigation(false);
+ GetMainFrame()->loadRequest(request);
// The load actually happens asynchronously, so we pump messages to process
// the pending continuation.
FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
@@ -256,12 +196,8 @@ void RenderViewTest::LoadHTML(const char* html) {
void RenderViewTest::LoadHTMLWithUrlOverride(const char* html,
const char* url_override) {
- GURL url(url_override);
- WebURLRequest request(url);
- request.setCheckForBrowserSideNavigation(false);
- request.addHTTPHeaderField(kWrappedHTMLDataHeader, WebString::fromUTF8(html));
-
- GetMainFrame()->loadRequest(request);
+ GetMainFrame()->loadHTMLString(std::string(html),
+ blink::WebURL(GURL(url_override)));
// The load actually happens asynchronously, so we pump messages to process
// the pending continuation.
FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698