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

Side by Side Diff: content/public/test/render_view_test.cc

Issue 1508293006: Check url path as well as document title to detect formless autofill page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo in comment Created 5 years 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
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 <cctype> 7 #include <cctype>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/renderer/history_serialization.h" 26 #include "content/renderer/history_serialization.h"
27 #include "content/renderer/render_thread_impl.h" 27 #include "content/renderer/render_thread_impl.h"
28 #include "content/renderer/render_view_impl.h" 28 #include "content/renderer/render_view_impl.h"
29 #include "content/renderer/renderer_blink_platform_impl.h" 29 #include "content/renderer/renderer_blink_platform_impl.h"
30 #include "content/renderer/renderer_main_platform_delegate.h" 30 #include "content/renderer/renderer_main_platform_delegate.h"
31 #include "content/test/fake_compositor_dependencies.h" 31 #include "content/test/fake_compositor_dependencies.h"
32 #include "content/test/mock_render_process.h" 32 #include "content/test/mock_render_process.h"
33 #include "content/test/test_content_client.h" 33 #include "content/test/test_content_client.h"
34 #include "content/test/test_render_frame.h" 34 #include "content/test/test_render_frame.h"
35 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 35 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
36 #include "third_party/WebKit/public/platform/WebURLLoader.h"
36 #include "third_party/WebKit/public/platform/WebURLRequest.h" 37 #include "third_party/WebKit/public/platform/WebURLRequest.h"
37 #include "third_party/WebKit/public/web/WebDocument.h" 38 #include "third_party/WebKit/public/web/WebDocument.h"
38 #include "third_party/WebKit/public/web/WebHistoryItem.h" 39 #include "third_party/WebKit/public/web/WebHistoryItem.h"
39 #include "third_party/WebKit/public/web/WebInputElement.h" 40 #include "third_party/WebKit/public/web/WebInputElement.h"
40 #include "third_party/WebKit/public/web/WebInputEvent.h" 41 #include "third_party/WebKit/public/web/WebInputEvent.h"
41 #include "third_party/WebKit/public/web/WebKit.h" 42 #include "third_party/WebKit/public/web/WebKit.h"
42 #include "third_party/WebKit/public/web/WebLocalFrame.h" 43 #include "third_party/WebKit/public/web/WebLocalFrame.h"
43 #include "third_party/WebKit/public/web/WebScriptSource.h" 44 #include "third_party/WebKit/public/web/WebScriptSource.h"
44 #include "third_party/WebKit/public/web/WebView.h" 45 #include "third_party/WebKit/public/web/WebView.h"
45 #include "ui/base/resource/resource_bundle.h" 46 #include "ui/base/resource/resource_bundle.h"
46 #include "ui/events/keycodes/keyboard_codes.h" 47 #include "ui/events/keycodes/keyboard_codes.h"
47 #include "v8/include/v8.h" 48 #include "v8/include/v8.h"
48 49
49 #if defined(OS_MACOSX) 50 #if defined(OS_MACOSX)
50 #include "base/mac/scoped_nsautorelease_pool.h" 51 #include "base/mac/scoped_nsautorelease_pool.h"
51 #endif 52 #endif
52 53
53 using blink::WebGestureEvent; 54 using blink::WebGestureEvent;
54 using blink::WebInputEvent; 55 using blink::WebInputEvent;
55 using blink::WebLocalFrame; 56 using blink::WebLocalFrame;
56 using blink::WebMouseEvent; 57 using blink::WebMouseEvent;
57 using blink::WebScriptSource; 58 using blink::WebScriptSource;
58 using blink::WebString; 59 using blink::WebString;
60 using blink::WebURLLoader;
59 using blink::WebURLRequest; 61 using blink::WebURLRequest;
60 62
61 namespace { 63 namespace {
62 64
63 const int32 kRouteId = 5; 65 const int32 kRouteId = 5;
64 const int32 kMainFrameRouteId = 6; 66 const int32 kMainFrameRouteId = 6;
65 // TODO(avi): Widget routing IDs should be distinct from the view routing IDs, 67 // TODO(avi): Widget routing IDs should be distinct from the view routing IDs,
66 // once RenderWidgetHost is distilled from RenderViewHostImpl. 68 // once RenderWidgetHost is distilled from RenderViewHostImpl.
67 // https://crbug.com/545684 69 // https://crbug.com/545684
68 const int32_t kMainFrameWidgetRouteId = 5; 70 const int32_t kMainFrameWidgetRouteId = 5;
(...skipping 20 matching lines...) Expand all
89 *key_code = ui::VKEY_OEM_PERIOD; 91 *key_code = ui::VKEY_OEM_PERIOD;
90 return true; 92 return true;
91 case ui::VKEY_BACK: 93 case ui::VKEY_BACK:
92 *key_code = ui::VKEY_BACK; 94 *key_code = ui::VKEY_BACK;
93 return true; 95 return true;
94 default: 96 default:
95 return false; 97 return false;
96 } 98 }
97 } 99 }
98 100
101 WebURLRequest createDataRequest(const std::string& html) {
102 std::string url_str = "data:text/html;charset=utf-8,";
103 url_str.append(html);
104 GURL url(url_str);
105 WebURLRequest request(url);
106 request.setCheckForBrowserSideNavigation(false);
107 return request;
108 }
109
99 } // namespace 110 } // namespace
100 111
101 namespace content { 112 namespace content {
102 113
103 class RendererBlinkPlatformImplNoSandboxImpl 114 const char kWrappedHTMLDataHeader[] = "X-WrappedHTMLData";
115
116 // This loader checks all requests for the presence of the X-WrappedHTMLData
117 // header and, if it's found, substitutes a data: url with the header's value
118 // instead of loading the original request. It is used to implement
119 // LoadHTMLWithURLOverride.
120 class WebURLLoaderWrapper : public WebURLLoader {
121 public:
122 WebURLLoaderWrapper(WebURLLoader* wrapped_loader)
123 : wrapped_loader_(wrapped_loader) { }
124
125 virtual void loadSynchronously(const WebURLRequest& request,
126 blink::WebURLResponse& response,
127 blink::WebURLError& error,
128 blink::WebData& data) override {
129 std::string html = request.httpHeaderField(kWrappedHTMLDataHeader).utf8();
130 if (html.empty())
131 wrapped_loader_->loadSynchronously(request, response, error, data);
Evan Stade 2015/12/11 23:44:45 ternary operator
132 else
133 wrapped_loader_->loadSynchronously(createDataRequest(html),
134 response,
135 error,
136 data);
137 }
138
139 virtual void loadAsynchronously(const WebURLRequest& request,
140 blink::WebURLLoaderClient* client) override {
141 std::string html = request.httpHeaderField(kWrappedHTMLDataHeader).utf8();
142 if (html.empty())
Evan Stade 2015/12/11 23:44:45 ternary operator
143 wrapped_loader_->loadAsynchronously(request, client);
144 else
145 wrapped_loader_->loadAsynchronously(createDataRequest(html), client);
146 }
147
148 virtual void cancel() override {
149 wrapped_loader_->cancel();
150 }
151
152 virtual void setDefersLoading(bool defer) {
153 wrapped_loader_->setDefersLoading(defer);
154 }
155
156 virtual void setLoadingTaskRunner(blink::WebTaskRunner* runner) override {
157 wrapped_loader_->setLoadingTaskRunner(runner);
158 }
159
160 private:
161 std::unique_ptr<WebURLLoader> wrapped_loader_;
162 };
163
164 class RendererBlinkPlatformImplTestOverrideImpl
104 : public RendererBlinkPlatformImpl { 165 : public RendererBlinkPlatformImpl {
105 public: 166 public:
106 RendererBlinkPlatformImplNoSandboxImpl( 167 RendererBlinkPlatformImplTestOverrideImpl(
107 scheduler::RendererScheduler* scheduler) 168 scheduler::RendererScheduler* scheduler)
108 : RendererBlinkPlatformImpl(scheduler) {} 169 : RendererBlinkPlatformImpl(scheduler) {}
109 170
171 // Get rid of the dependency to the sandbox, which is not available in
172 // RenderViewTest.
110 blink::WebSandboxSupport* sandboxSupport() override { return NULL; } 173 blink::WebSandboxSupport* sandboxSupport() override { return NULL; }
174
175 // Inject a WebURLLoader which rewrites requests that have the
176 // X-WrappedHTMLData header.
177 WebURLLoader* createURLLoader() override {
178 return new WebURLLoaderWrapper(
179 RendererBlinkPlatformImpl::createURLLoader());
180 }
111 }; 181 };
112 182
113 RenderViewTest::RendererBlinkPlatformImplNoSandbox:: 183 RenderViewTest::RendererBlinkPlatformImplTestOverride::
114 RendererBlinkPlatformImplNoSandbox() { 184 RendererBlinkPlatformImplTestOverride() {
115 renderer_scheduler_ = scheduler::RendererScheduler::Create(); 185 renderer_scheduler_ = scheduler::RendererScheduler::Create();
116 blink_platform_impl_.reset( 186 blink_platform_impl_.reset(
117 new RendererBlinkPlatformImplNoSandboxImpl(renderer_scheduler_.get())); 187 new RendererBlinkPlatformImplTestOverrideImpl(renderer_scheduler_.get()));
118 } 188 }
119 189
120 RenderViewTest::RendererBlinkPlatformImplNoSandbox:: 190 RenderViewTest::RendererBlinkPlatformImplTestOverride::
121 ~RendererBlinkPlatformImplNoSandbox() { 191 ~RendererBlinkPlatformImplTestOverride() {
122 } 192 }
123 193
124 blink::Platform* 194 blink::Platform*
125 RenderViewTest::RendererBlinkPlatformImplNoSandbox::Get() const { 195 RenderViewTest::RendererBlinkPlatformImplTestOverride::Get() const {
126 return blink_platform_impl_.get(); 196 return blink_platform_impl_.get();
127 } 197 }
128 198
129 void RenderViewTest::RendererBlinkPlatformImplNoSandbox::Shutdown() { 199 void RenderViewTest::RendererBlinkPlatformImplTestOverride::Shutdown() {
130 renderer_scheduler_->Shutdown(); 200 renderer_scheduler_->Shutdown();
131 blink_platform_impl_->Shutdown(); 201 blink_platform_impl_->Shutdown();
132 } 202 }
133 203
134 RenderViewTest::RenderViewTest() 204 RenderViewTest::RenderViewTest()
135 : view_(NULL) { 205 : view_(NULL) {
136 RenderFrameImpl::InstallCreateHook(&TestRenderFrame::CreateTestRenderFrame); 206 RenderFrameImpl::InstallCreateHook(&TestRenderFrame::CreateTestRenderFrame);
137 } 207 }
138 208
139 RenderViewTest::~RenderViewTest() { 209 RenderViewTest::~RenderViewTest() {
(...skipping 22 matching lines...) Expand all
162 if (result.IsEmpty() || !result->IsInt32()) 232 if (result.IsEmpty() || !result->IsInt32())
163 return false; 233 return false;
164 234
165 if (int_result) 235 if (int_result)
166 *int_result = result->Int32Value(); 236 *int_result = result->Int32Value();
167 237
168 return true; 238 return true;
169 } 239 }
170 240
171 void RenderViewTest::LoadHTML(const char* html) { 241 void RenderViewTest::LoadHTML(const char* html) {
172 std::string url_str = "data:text/html;charset=utf-8,"; 242 GetMainFrame()->loadRequest(createDataRequest(html));
173 url_str.append(html); 243 // The load actually happens asynchronously, so we pump messages to process
174 GURL url(url_str); 244 // the pending continuation.
245 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
246 }
247
248 void RenderViewTest::LoadHTMLWithUrlOverride(const char* html,
249 const char* url_override) {
250 GURL url(url_override);
175 WebURLRequest request(url); 251 WebURLRequest request(url);
176 request.setCheckForBrowserSideNavigation(false); 252 request.setCheckForBrowserSideNavigation(false);
253 request.addHTTPHeaderField(kWrappedHTMLDataHeader, WebString::fromUTF8(html));
254
177 GetMainFrame()->loadRequest(request); 255 GetMainFrame()->loadRequest(request);
178 // The load actually happens asynchronously, so we pump messages to process 256 // The load actually happens asynchronously, so we pump messages to process
179 // the pending continuation. 257 // the pending continuation.
180 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); 258 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
181 } 259 }
182 260
183 PageState RenderViewTest::GetCurrentPageState() { 261 PageState RenderViewTest::GetCurrentPageState() {
184 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_); 262 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
185 263
186 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 264 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 TestRenderFrame* frame = 692 TestRenderFrame* frame =
615 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); 693 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame());
616 frame->Navigate(common_params, StartNavigationParams(), request_params); 694 frame->Navigate(common_params, StartNavigationParams(), request_params);
617 695
618 // The load actually happens asynchronously, so we pump messages to process 696 // The load actually happens asynchronously, so we pump messages to process
619 // the pending continuation. 697 // the pending continuation.
620 FrameLoadWaiter(frame).Wait(); 698 FrameLoadWaiter(frame).Wait();
621 } 699 }
622 700
623 } // namespace content 701 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698