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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/test/render_view_test.h" 5 #include "content/public/test/render_view_test.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cctype> 9 #include <cctype>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "content/renderer/history_serialization.h" 31 #include "content/renderer/history_serialization.h"
32 #include "content/renderer/render_thread_impl.h" 32 #include "content/renderer/render_thread_impl.h"
33 #include "content/renderer/render_view_impl.h" 33 #include "content/renderer/render_view_impl.h"
34 #include "content/renderer/renderer_blink_platform_impl.h" 34 #include "content/renderer/renderer_blink_platform_impl.h"
35 #include "content/renderer/renderer_main_platform_delegate.h" 35 #include "content/renderer/renderer_main_platform_delegate.h"
36 #include "content/test/fake_compositor_dependencies.h" 36 #include "content/test/fake_compositor_dependencies.h"
37 #include "content/test/mock_render_process.h" 37 #include "content/test/mock_render_process.h"
38 #include "content/test/test_content_client.h" 38 #include "content/test/test_content_client.h"
39 #include "content/test/test_render_frame.h" 39 #include "content/test/test_render_frame.h"
40 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 40 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
41 #include "third_party/WebKit/public/platform/WebURLLoader.h"
42 #include "third_party/WebKit/public/platform/WebURLRequest.h" 41 #include "third_party/WebKit/public/platform/WebURLRequest.h"
43 #include "third_party/WebKit/public/web/WebDocument.h" 42 #include "third_party/WebKit/public/web/WebDocument.h"
44 #include "third_party/WebKit/public/web/WebHistoryItem.h" 43 #include "third_party/WebKit/public/web/WebHistoryItem.h"
45 #include "third_party/WebKit/public/web/WebInputElement.h" 44 #include "third_party/WebKit/public/web/WebInputElement.h"
46 #include "third_party/WebKit/public/web/WebInputEvent.h" 45 #include "third_party/WebKit/public/web/WebInputEvent.h"
47 #include "third_party/WebKit/public/web/WebKit.h" 46 #include "third_party/WebKit/public/web/WebKit.h"
48 #include "third_party/WebKit/public/web/WebLocalFrame.h" 47 #include "third_party/WebKit/public/web/WebLocalFrame.h"
49 #include "third_party/WebKit/public/web/WebScriptSource.h" 48 #include "third_party/WebKit/public/web/WebScriptSource.h"
50 #include "third_party/WebKit/public/web/WebView.h" 49 #include "third_party/WebKit/public/web/WebView.h"
51 #include "ui/base/resource/resource_bundle.h" 50 #include "ui/base/resource/resource_bundle.h"
52 #include "ui/events/keycodes/keyboard_codes.h" 51 #include "ui/events/keycodes/keyboard_codes.h"
53 #include "v8/include/v8.h" 52 #include "v8/include/v8.h"
54 53
55 #if defined(OS_MACOSX) 54 #if defined(OS_MACOSX)
56 #include "base/mac/scoped_nsautorelease_pool.h" 55 #include "base/mac/scoped_nsautorelease_pool.h"
57 #endif 56 #endif
58 57
59 #if defined(OS_WIN) 58 #if defined(OS_WIN)
60 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h" 59 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h"
61 #include "content/test/dwrite_font_fake_sender_win.h" 60 #include "content/test/dwrite_font_fake_sender_win.h"
62 #endif 61 #endif
63 62
64 using blink::WebGestureEvent; 63 using blink::WebGestureEvent;
65 using blink::WebInputEvent; 64 using blink::WebInputEvent;
66 using blink::WebLocalFrame; 65 using blink::WebLocalFrame;
67 using blink::WebMouseEvent; 66 using blink::WebMouseEvent;
68 using blink::WebScriptSource; 67 using blink::WebScriptSource;
69 using blink::WebString; 68 using blink::WebString;
70 using blink::WebURLLoader;
71 using blink::WebURLRequest; 69 using blink::WebURLRequest;
72 70
73 namespace { 71 namespace {
74 72
75 const int32_t kRouteId = 5; 73 const int32_t kRouteId = 5;
76 const int32_t kMainFrameRouteId = 6; 74 const int32_t kMainFrameRouteId = 6;
77 // TODO(avi): Widget routing IDs should be distinct from the view routing IDs, 75 // TODO(avi): Widget routing IDs should be distinct from the view routing IDs,
78 // once RenderWidgetHost is distilled from RenderViewHostImpl. 76 // once RenderWidgetHost is distilled from RenderViewHostImpl.
79 // https://crbug.com/545684 77 // https://crbug.com/545684
80 const int32_t kMainFrameWidgetRouteId = 5; 78 const int32_t kMainFrameWidgetRouteId = 5;
(...skipping 20 matching lines...) Expand all
101 *key_code = ui::VKEY_OEM_PERIOD; 99 *key_code = ui::VKEY_OEM_PERIOD;
102 return true; 100 return true;
103 case ui::VKEY_BACK: 101 case ui::VKEY_BACK:
104 *key_code = ui::VKEY_BACK; 102 *key_code = ui::VKEY_BACK;
105 return true; 103 return true;
106 default: 104 default:
107 return false; 105 return false;
108 } 106 }
109 } 107 }
110 108
111 WebURLRequest createDataRequest(const std::string& html) {
112 std::string url_str = "data:text/html;charset=utf-8,";
113 url_str.append(html);
114 GURL url(url_str);
115 WebURLRequest request(url);
116 request.setCheckForBrowserSideNavigation(false);
117 return request;
118 }
119
120 } // namespace 109 } // namespace
121 110
122 namespace content { 111 namespace content {
123 112
124 const char kWrappedHTMLDataHeader[] = "X-WrappedHTMLData";
125
126 // This loader checks all requests for the presence of the X-WrappedHTMLData
127 // header and, if it's found, substitutes a data: url with the header's value
128 // instead of loading the original request. It is used to implement
129 // LoadHTMLWithURLOverride.
130 class WebURLLoaderWrapper : public WebURLLoader {
131 public:
132 WebURLLoaderWrapper(WebURLLoader* wrapped_loader)
133 : wrapped_loader_(wrapped_loader) { }
134
135 void loadSynchronously(const WebURLRequest& request,
136 blink::WebURLResponse& response,
137 blink::WebURLError& error,
138 blink::WebData& data) override {
139 std::string html = request.httpHeaderField(kWrappedHTMLDataHeader).utf8();
140 wrapped_loader_->loadSynchronously(
141 html.empty() ? request : createDataRequest(html),
142 response,
143 error,
144 data);
145 }
146
147 void loadAsynchronously(const WebURLRequest& request,
148 blink::WebURLLoaderClient* client) override {
149 std::string html = request.httpHeaderField(kWrappedHTMLDataHeader).utf8();
150 wrapped_loader_->loadAsynchronously(
151 html.empty() ? request : createDataRequest(html),
152 client);
153 }
154
155 void cancel() override {
156 wrapped_loader_->cancel();
157 }
158
159 void setDefersLoading(bool defer) override {
160 wrapped_loader_->setDefersLoading(defer);
161 }
162
163 void setLoadingTaskRunner(blink::WebTaskRunner* runner) override {
164 wrapped_loader_->setLoadingTaskRunner(runner);
165 }
166
167 private:
168 std::unique_ptr<WebURLLoader> wrapped_loader_;
169 };
170
171 class RendererBlinkPlatformImplTestOverrideImpl 113 class RendererBlinkPlatformImplTestOverrideImpl
172 : public RendererBlinkPlatformImpl { 114 : public RendererBlinkPlatformImpl {
173 public: 115 public:
174 RendererBlinkPlatformImplTestOverrideImpl( 116 RendererBlinkPlatformImplTestOverrideImpl(
175 scheduler::RendererScheduler* scheduler) 117 scheduler::RendererScheduler* scheduler)
176 : RendererBlinkPlatformImpl(scheduler, nullptr) { 118 : RendererBlinkPlatformImpl(scheduler, nullptr) {
177 } 119 }
178 120
179 // Get rid of the dependency to the sandbox, which is not available in 121 // Get rid of the dependency to the sandbox, which is not available in
180 // RenderViewTest. 122 // RenderViewTest.
181 blink::WebSandboxSupport* sandboxSupport() override { return NULL; } 123 blink::WebSandboxSupport* sandboxSupport() override { return NULL; }
182
183 // Inject a WebURLLoader which rewrites requests that have the
184 // X-WrappedHTMLData header.
185 WebURLLoader* createURLLoader() override {
186 return new WebURLLoaderWrapper(
187 RendererBlinkPlatformImpl::createURLLoader());
188 }
189 }; 124 };
190 125
191 RenderViewTest::RendererBlinkPlatformImplTestOverride:: 126 RenderViewTest::RendererBlinkPlatformImplTestOverride::
192 RendererBlinkPlatformImplTestOverride() { 127 RendererBlinkPlatformImplTestOverride() {
193 renderer_scheduler_ = scheduler::RendererScheduler::Create(); 128 renderer_scheduler_ = scheduler::RendererScheduler::Create();
194 blink_platform_impl_.reset( 129 blink_platform_impl_.reset(
195 new RendererBlinkPlatformImplTestOverrideImpl(renderer_scheduler_.get())); 130 new RendererBlinkPlatformImplTestOverrideImpl(renderer_scheduler_.get()));
196 } 131 }
197 132
198 RenderViewTest::RendererBlinkPlatformImplTestOverride:: 133 RenderViewTest::RendererBlinkPlatformImplTestOverride::
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (result.IsEmpty() || !result->IsInt32()) 175 if (result.IsEmpty() || !result->IsInt32())
241 return false; 176 return false;
242 177
243 if (int_result) 178 if (int_result)
244 *int_result = result->Int32Value(); 179 *int_result = result->Int32Value();
245 180
246 return true; 181 return true;
247 } 182 }
248 183
249 void RenderViewTest::LoadHTML(const char* html) { 184 void RenderViewTest::LoadHTML(const char* html) {
250 GetMainFrame()->loadRequest(createDataRequest(html)); 185 std::string url_string = "data:text/html;charset=utf-8,";
186 url_string.append(html);
187 GURL url(url_string);
188 WebURLRequest request(url);
189 request.setCheckForBrowserSideNavigation(false);
190 GetMainFrame()->loadRequest(request);
251 // The load actually happens asynchronously, so we pump messages to process 191 // The load actually happens asynchronously, so we pump messages to process
252 // the pending continuation. 192 // the pending continuation.
253 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); 193 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
254 view_->GetWebView()->updateAllLifecyclePhases(); 194 view_->GetWebView()->updateAllLifecyclePhases();
255 } 195 }
256 196
257 void RenderViewTest::LoadHTMLWithUrlOverride(const char* html, 197 void RenderViewTest::LoadHTMLWithUrlOverride(const char* html,
258 const char* url_override) { 198 const char* url_override) {
259 GURL url(url_override); 199 GetMainFrame()->loadHTMLString(std::string(html),
260 WebURLRequest request(url); 200 blink::WebURL(GURL(url_override)));
261 request.setCheckForBrowserSideNavigation(false);
262 request.addHTTPHeaderField(kWrappedHTMLDataHeader, WebString::fromUTF8(html));
263
264 GetMainFrame()->loadRequest(request);
265 // The load actually happens asynchronously, so we pump messages to process 201 // The load actually happens asynchronously, so we pump messages to process
266 // the pending continuation. 202 // the pending continuation.
267 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); 203 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
268 view_->GetWebView()->updateAllLifecyclePhases(); 204 view_->GetWebView()->updateAllLifecyclePhases();
269 } 205 }
270 206
271 PageState RenderViewTest::GetCurrentPageState() { 207 PageState RenderViewTest::GetCurrentPageState() {
272 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_); 208 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
273 209
274 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 210 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); 659 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame());
724 frame->Navigate(common_params, StartNavigationParams(), request_params); 660 frame->Navigate(common_params, StartNavigationParams(), request_params);
725 661
726 // The load actually happens asynchronously, so we pump messages to process 662 // The load actually happens asynchronously, so we pump messages to process
727 // the pending continuation. 663 // the pending continuation.
728 FrameLoadWaiter(frame).Wait(); 664 FrameLoadWaiter(frame).Wait();
729 view_->GetWebView()->updateAllLifecyclePhases(); 665 view_->GetWebView()->updateAllLifecyclePhases();
730 } 666 }
731 667
732 } // namespace content 668 } // namespace content
OLDNEW
« 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