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

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: – Rebaseline heuristic test output Created 4 years, 11 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 | « content/public/test/render_view_test.h ('k') | 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 18 matching lines...) Expand all
29 #include "content/renderer/history_serialization.h" 29 #include "content/renderer/history_serialization.h"
30 #include "content/renderer/render_thread_impl.h" 30 #include "content/renderer/render_thread_impl.h"
31 #include "content/renderer/render_view_impl.h" 31 #include "content/renderer/render_view_impl.h"
32 #include "content/renderer/renderer_blink_platform_impl.h" 32 #include "content/renderer/renderer_blink_platform_impl.h"
33 #include "content/renderer/renderer_main_platform_delegate.h" 33 #include "content/renderer/renderer_main_platform_delegate.h"
34 #include "content/test/fake_compositor_dependencies.h" 34 #include "content/test/fake_compositor_dependencies.h"
35 #include "content/test/mock_render_process.h" 35 #include "content/test/mock_render_process.h"
36 #include "content/test/test_content_client.h" 36 #include "content/test/test_content_client.h"
37 #include "content/test/test_render_frame.h" 37 #include "content/test/test_render_frame.h"
38 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 38 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
39 #include "third_party/WebKit/public/platform/WebURLLoader.h"
39 #include "third_party/WebKit/public/platform/WebURLRequest.h" 40 #include "third_party/WebKit/public/platform/WebURLRequest.h"
40 #include "third_party/WebKit/public/web/WebDocument.h" 41 #include "third_party/WebKit/public/web/WebDocument.h"
41 #include "third_party/WebKit/public/web/WebHistoryItem.h" 42 #include "third_party/WebKit/public/web/WebHistoryItem.h"
42 #include "third_party/WebKit/public/web/WebInputElement.h" 43 #include "third_party/WebKit/public/web/WebInputElement.h"
43 #include "third_party/WebKit/public/web/WebInputEvent.h" 44 #include "third_party/WebKit/public/web/WebInputEvent.h"
44 #include "third_party/WebKit/public/web/WebKit.h" 45 #include "third_party/WebKit/public/web/WebKit.h"
45 #include "third_party/WebKit/public/web/WebLocalFrame.h" 46 #include "third_party/WebKit/public/web/WebLocalFrame.h"
46 #include "third_party/WebKit/public/web/WebScriptSource.h" 47 #include "third_party/WebKit/public/web/WebScriptSource.h"
47 #include "third_party/WebKit/public/web/WebView.h" 48 #include "third_party/WebKit/public/web/WebView.h"
48 #include "ui/base/resource/resource_bundle.h" 49 #include "ui/base/resource/resource_bundle.h"
49 #include "ui/events/keycodes/keyboard_codes.h" 50 #include "ui/events/keycodes/keyboard_codes.h"
50 #include "v8/include/v8.h" 51 #include "v8/include/v8.h"
51 52
52 #if defined(OS_MACOSX) 53 #if defined(OS_MACOSX)
53 #include "base/mac/scoped_nsautorelease_pool.h" 54 #include "base/mac/scoped_nsautorelease_pool.h"
54 #endif 55 #endif
55 56
56 #if defined(OS_WIN) 57 #if defined(OS_WIN)
57 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h" 58 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h"
58 #include "content/test/dwrite_font_fake_sender_win.h" 59 #include "content/test/dwrite_font_fake_sender_win.h"
59 #endif 60 #endif
60 61
61 using blink::WebGestureEvent; 62 using blink::WebGestureEvent;
62 using blink::WebInputEvent; 63 using blink::WebInputEvent;
63 using blink::WebLocalFrame; 64 using blink::WebLocalFrame;
64 using blink::WebMouseEvent; 65 using blink::WebMouseEvent;
65 using blink::WebScriptSource; 66 using blink::WebScriptSource;
66 using blink::WebString; 67 using blink::WebString;
68 using blink::WebURLLoader;
67 using blink::WebURLRequest; 69 using blink::WebURLRequest;
68 70
69 namespace { 71 namespace {
70 72
71 const int32_t kRouteId = 5; 73 const int32_t kRouteId = 5;
72 const int32_t kMainFrameRouteId = 6; 74 const int32_t kMainFrameRouteId = 6;
73 // 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,
74 // once RenderWidgetHost is distilled from RenderViewHostImpl. 76 // once RenderWidgetHost is distilled from RenderViewHostImpl.
75 // https://crbug.com/545684 77 // https://crbug.com/545684
76 const int32_t kMainFrameWidgetRouteId = 5; 78 const int32_t kMainFrameWidgetRouteId = 5;
(...skipping 20 matching lines...) Expand all
97 *key_code = ui::VKEY_OEM_PERIOD; 99 *key_code = ui::VKEY_OEM_PERIOD;
98 return true; 100 return true;
99 case ui::VKEY_BACK: 101 case ui::VKEY_BACK:
100 *key_code = ui::VKEY_BACK; 102 *key_code = ui::VKEY_BACK;
101 return true; 103 return true;
102 default: 104 default:
103 return false; 105 return false;
104 } 106 }
105 } 107 }
106 108
109 WebURLRequest createDataRequest(const std::string& html) {
110 std::string url_str = "data:text/html;charset=utf-8,";
111 url_str.append(html);
112 GURL url(url_str);
113 WebURLRequest request(url);
114 request.setCheckForBrowserSideNavigation(false);
115 return request;
116 }
117
107 } // namespace 118 } // namespace
108 119
109 namespace content { 120 namespace content {
110 121
111 class RendererBlinkPlatformImplNoSandboxImpl 122 const char kWrappedHTMLDataHeader[] = "X-WrappedHTMLData";
123
124 // This loader checks all requests for the presence of the X-WrappedHTMLData
125 // header and, if it's found, substitutes a data: url with the header's value
126 // instead of loading the original request. It is used to implement
127 // LoadHTMLWithURLOverride.
128 class WebURLLoaderWrapper : public WebURLLoader {
129 public:
130 WebURLLoaderWrapper(WebURLLoader* wrapped_loader)
131 : wrapped_loader_(wrapped_loader) { }
132
133 void loadSynchronously(const WebURLRequest& request,
134 blink::WebURLResponse& response,
135 blink::WebURLError& error,
136 blink::WebData& data) override {
137 std::string html = request.httpHeaderField(kWrappedHTMLDataHeader).utf8();
138 wrapped_loader_->loadSynchronously(
139 html.empty() ? request : createDataRequest(html),
140 response,
141 error,
142 data);
143 }
144
145 void loadAsynchronously(const WebURLRequest& request,
146 blink::WebURLLoaderClient* client) override {
147 std::string html = request.httpHeaderField(kWrappedHTMLDataHeader).utf8();
148 wrapped_loader_->loadAsynchronously(
149 html.empty() ? request : createDataRequest(html),
150 client);
151 }
152
153 void cancel() override {
154 wrapped_loader_->cancel();
155 }
156
157 void setDefersLoading(bool defer) override {
158 wrapped_loader_->setDefersLoading(defer);
159 }
160
161 void setLoadingTaskRunner(blink::WebTaskRunner* runner) override {
162 wrapped_loader_->setLoadingTaskRunner(runner);
163 }
164
165 private:
166 std::unique_ptr<WebURLLoader> wrapped_loader_;
167 };
168
169 class RendererBlinkPlatformImplTestOverrideImpl
112 : public RendererBlinkPlatformImpl { 170 : public RendererBlinkPlatformImpl {
113 public: 171 public:
114 RendererBlinkPlatformImplNoSandboxImpl( 172 RendererBlinkPlatformImplTestOverrideImpl(
115 scheduler::RendererScheduler* scheduler) 173 scheduler::RendererScheduler* scheduler)
116 : RendererBlinkPlatformImpl(scheduler) {} 174 : RendererBlinkPlatformImpl(scheduler) {}
117 175
176 // Get rid of the dependency to the sandbox, which is not available in
177 // RenderViewTest.
118 blink::WebSandboxSupport* sandboxSupport() override { return NULL; } 178 blink::WebSandboxSupport* sandboxSupport() override { return NULL; }
179
180 // Inject a WebURLLoader which rewrites requests that have the
181 // X-WrappedHTMLData header.
182 WebURLLoader* createURLLoader() override {
183 return new WebURLLoaderWrapper(
184 RendererBlinkPlatformImpl::createURLLoader());
185 }
119 }; 186 };
120 187
121 RenderViewTest::RendererBlinkPlatformImplNoSandbox:: 188 RenderViewTest::RendererBlinkPlatformImplTestOverride::
122 RendererBlinkPlatformImplNoSandbox() { 189 RendererBlinkPlatformImplTestOverride() {
123 renderer_scheduler_ = scheduler::RendererScheduler::Create(); 190 renderer_scheduler_ = scheduler::RendererScheduler::Create();
124 blink_platform_impl_.reset( 191 blink_platform_impl_.reset(
125 new RendererBlinkPlatformImplNoSandboxImpl(renderer_scheduler_.get())); 192 new RendererBlinkPlatformImplTestOverrideImpl(renderer_scheduler_.get()));
126 } 193 }
127 194
128 RenderViewTest::RendererBlinkPlatformImplNoSandbox:: 195 RenderViewTest::RendererBlinkPlatformImplTestOverride::
129 ~RendererBlinkPlatformImplNoSandbox() { 196 ~RendererBlinkPlatformImplTestOverride() {
130 } 197 }
131 198
132 blink::Platform* 199 blink::Platform*
133 RenderViewTest::RendererBlinkPlatformImplNoSandbox::Get() const { 200 RenderViewTest::RendererBlinkPlatformImplTestOverride::Get() const {
134 return blink_platform_impl_.get(); 201 return blink_platform_impl_.get();
135 } 202 }
136 203
137 void RenderViewTest::RendererBlinkPlatformImplNoSandbox::Shutdown() { 204 void RenderViewTest::RendererBlinkPlatformImplTestOverride::Shutdown() {
138 renderer_scheduler_->Shutdown(); 205 renderer_scheduler_->Shutdown();
139 blink_platform_impl_->Shutdown(); 206 blink_platform_impl_->Shutdown();
140 } 207 }
141 208
142 RenderViewTest::RenderViewTest() 209 RenderViewTest::RenderViewTest()
143 : view_(NULL) { 210 : view_(NULL) {
144 RenderFrameImpl::InstallCreateHook(&TestRenderFrame::CreateTestRenderFrame); 211 RenderFrameImpl::InstallCreateHook(&TestRenderFrame::CreateTestRenderFrame);
145 } 212 }
146 213
147 RenderViewTest::~RenderViewTest() { 214 RenderViewTest::~RenderViewTest() {
(...skipping 22 matching lines...) Expand all
170 if (result.IsEmpty() || !result->IsInt32()) 237 if (result.IsEmpty() || !result->IsInt32())
171 return false; 238 return false;
172 239
173 if (int_result) 240 if (int_result)
174 *int_result = result->Int32Value(); 241 *int_result = result->Int32Value();
175 242
176 return true; 243 return true;
177 } 244 }
178 245
179 void RenderViewTest::LoadHTML(const char* html) { 246 void RenderViewTest::LoadHTML(const char* html) {
180 std::string url_str = "data:text/html;charset=utf-8,"; 247 GetMainFrame()->loadRequest(createDataRequest(html));
181 url_str.append(html); 248 // The load actually happens asynchronously, so we pump messages to process
182 GURL url(url_str); 249 // the pending continuation.
250 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
251 }
252
253 void RenderViewTest::LoadHTMLWithUrlOverride(const char* html,
254 const char* url_override) {
255 GURL url(url_override);
183 WebURLRequest request(url); 256 WebURLRequest request(url);
184 request.setCheckForBrowserSideNavigation(false); 257 request.setCheckForBrowserSideNavigation(false);
258 request.addHTTPHeaderField(kWrappedHTMLDataHeader, WebString::fromUTF8(html));
259
185 GetMainFrame()->loadRequest(request); 260 GetMainFrame()->loadRequest(request);
186 // The load actually happens asynchronously, so we pump messages to process 261 // The load actually happens asynchronously, so we pump messages to process
187 // the pending continuation. 262 // the pending continuation.
188 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); 263 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
189 } 264 }
190 265
191 PageState RenderViewTest::GetCurrentPageState() { 266 PageState RenderViewTest::GetCurrentPageState() {
192 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_); 267 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
193 268
194 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 269 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 TestRenderFrame* frame = 715 TestRenderFrame* frame =
641 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); 716 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame());
642 frame->Navigate(common_params, StartNavigationParams(), request_params); 717 frame->Navigate(common_params, StartNavigationParams(), request_params);
643 718
644 // The load actually happens asynchronously, so we pump messages to process 719 // The load actually happens asynchronously, so we pump messages to process
645 // the pending continuation. 720 // the pending continuation.
646 FrameLoadWaiter(frame).Wait(); 721 FrameLoadWaiter(frame).Wait();
647 } 722 }
648 723
649 } // namespace content 724 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/render_view_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698