OLD | NEW |
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/layouttest_support.h" | 5 #include "content/public/test/layouttest_support.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "content/renderer/layout_test_dependencies.h" | 34 #include "content/renderer/layout_test_dependencies.h" |
35 #include "content/renderer/render_frame_impl.h" | 35 #include "content/renderer/render_frame_impl.h" |
36 #include "content/renderer/render_thread_impl.h" | 36 #include "content/renderer/render_thread_impl.h" |
37 #include "content/renderer/render_view_impl.h" | 37 #include "content/renderer/render_view_impl.h" |
38 #include "content/renderer/render_widget.h" | 38 #include "content/renderer/render_widget.h" |
39 #include "content/renderer/renderer_blink_platform_impl.h" | 39 #include "content/renderer/renderer_blink_platform_impl.h" |
40 #include "content/shell/common/shell_switches.h" | 40 #include "content/shell/common/shell_switches.h" |
41 #include "gpu/ipc/service/image_transport_surface.h" | 41 #include "gpu/ipc/service/image_transport_surface.h" |
42 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 42 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
43 #include "third_party/WebKit/public/platform/WebGamepads.h" | 43 #include "third_party/WebKit/public/platform/WebGamepads.h" |
| 44 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 45 #include "third_party/WebKit/public/platform/WebRect.h" |
44 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic
eMotionData.h" | 46 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic
eMotionData.h" |
45 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic
eOrientationData.h" | 47 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic
eOrientationData.h" |
46 #include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_t
est_support.h" | 48 #include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_t
est_support.h" |
47 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 49 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
48 #include "third_party/WebKit/public/web/WebView.h" | 50 #include "third_party/WebKit/public/web/WebView.h" |
| 51 #include "ui/events/blink/blink_event_util.h" |
| 52 #include "ui/gfx/geometry/vector2d.h" |
49 #include "ui/gfx/icc_profile.h" | 53 #include "ui/gfx/icc_profile.h" |
50 | 54 |
51 #if defined(OS_MACOSX) | 55 #if defined(OS_MACOSX) |
52 #include "content/browser/frame_host/popup_menu_helper_mac.h" | 56 #include "content/browser/frame_host/popup_menu_helper_mac.h" |
53 #elif defined(OS_WIN) | 57 #elif defined(OS_WIN) |
54 #include "content/child/font_warmup_win.h" | 58 #include "content/child/font_warmup_win.h" |
55 #include "third_party/WebKit/public/web/win/WebFontRendering.h" | 59 #include "third_party/WebKit/public/web/win/WebFontRendering.h" |
56 #include "third_party/skia/include/ports/SkFontMgr.h" | 60 #include "third_party/skia/include/ports/SkFontMgr.h" |
57 #include "third_party/skia/include/ports/SkTypeface_win.h" | 61 #include "third_party/skia/include/ports/SkTypeface_win.h" |
58 #include "ui/gfx/win/direct_write.h" | 62 #include "ui/gfx/win/direct_write.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 131 |
128 RenderFrameImpl* CreateWebFrameTestProxy( | 132 RenderFrameImpl* CreateWebFrameTestProxy( |
129 const RenderFrameImpl::CreateParams& params) { | 133 const RenderFrameImpl::CreateParams& params) { |
130 WebFrameTestProxyType* render_frame_proxy = new WebFrameTestProxyType(params); | 134 WebFrameTestProxyType* render_frame_proxy = new WebFrameTestProxyType(params); |
131 if (g_frame_test_proxy_callback == 0) | 135 if (g_frame_test_proxy_callback == 0) |
132 return render_frame_proxy; | 136 return render_frame_proxy; |
133 g_frame_test_proxy_callback.Get().Run(render_frame_proxy, render_frame_proxy); | 137 g_frame_test_proxy_callback.Get().Run(render_frame_proxy, render_frame_proxy); |
134 return render_frame_proxy; | 138 return render_frame_proxy; |
135 } | 139 } |
136 | 140 |
| 141 float GetWindowToViewportScale(RenderWidget* render_widget) { |
| 142 blink::WebFloatRect rect(0, 0, 1.0f, 0.0); |
| 143 render_widget->convertWindowToViewport(&rect); |
| 144 return rect.width; |
| 145 } |
| 146 |
137 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
138 // DirectWrite only has access to %WINDIR%\Fonts by default. For developer | 148 // DirectWrite only has access to %WINDIR%\Fonts by default. For developer |
139 // side-loading, support kRegisterFontFiles to allow access to additional fonts. | 149 // side-loading, support kRegisterFontFiles to allow access to additional fonts. |
140 void RegisterSideloadedTypefaces(SkFontMgr* fontmgr) { | 150 void RegisterSideloadedTypefaces(SkFontMgr* fontmgr) { |
141 std::vector<std::string> files = switches::GetSideloadFontFiles(); | 151 std::vector<std::string> files = switches::GetSideloadFontFiles(); |
142 for (std::vector<std::string>::const_iterator i(files.begin()); | 152 for (std::vector<std::string>::const_iterator i(files.begin()); |
143 i != files.end(); | 153 i != files.end(); |
144 ++i) { | 154 ++i) { |
145 SkTypeface* typeface = fontmgr->createFromFile(i->c_str()); | 155 SkTypeface* typeface = fontmgr->createFromFile(i->c_str()); |
146 blink::WebFontRendering::addSideloadedFontForTesting(typeface); | 156 blink::WebFontRendering::addSideloadedFontForTesting(typeface); |
(...skipping 10 matching lines...) Expand all Loading... |
157 return static_cast<test_runner::WebViewTestProxyBase*>(render_view_proxy); | 167 return static_cast<test_runner::WebViewTestProxyBase*>(render_view_proxy); |
158 } | 168 } |
159 | 169 |
160 test_runner::WebFrameTestProxyBase* GetWebFrameTestProxyBase( | 170 test_runner::WebFrameTestProxyBase* GetWebFrameTestProxyBase( |
161 RenderFrame* render_frame) { | 171 RenderFrame* render_frame) { |
162 WebFrameTestProxyType* render_frame_proxy = | 172 WebFrameTestProxyType* render_frame_proxy = |
163 static_cast<WebFrameTestProxyType*>(render_frame); | 173 static_cast<WebFrameTestProxyType*>(render_frame); |
164 return static_cast<test_runner::WebFrameTestProxyBase*>(render_frame_proxy); | 174 return static_cast<test_runner::WebFrameTestProxyBase*>(render_frame_proxy); |
165 } | 175 } |
166 | 176 |
| 177 test_runner::WebWidgetTestProxyBase* GetWebWidgetTestProxyBase( |
| 178 blink::WebLocalFrame* frame) { |
| 179 DCHECK(frame); |
| 180 RenderFrame* local_root = RenderFrame::FromWebFrame(frame->localRoot()); |
| 181 DCHECK(local_root); |
| 182 // TODO(lfg): Simplify once RenderView no longer inherits from RenderWidget. |
| 183 if (local_root->IsMainFrame()) { |
| 184 test_runner::WebViewTestProxyBase* web_view_test_proxy_base = |
| 185 GetWebViewTestProxyBase(local_root->GetRenderView()); |
| 186 auto* web_widget_test_proxy_base = |
| 187 static_cast<test_runner::WebWidgetTestProxyBase*>( |
| 188 web_view_test_proxy_base); |
| 189 DCHECK(web_widget_test_proxy_base->web_widget()->isWebView()); |
| 190 return web_widget_test_proxy_base; |
| 191 } else { |
| 192 RenderWidget* render_widget = |
| 193 static_cast<RenderFrameImpl*>(local_root)->GetRenderWidget(); |
| 194 DCHECK(render_widget); |
| 195 WebWidgetTestProxyType* render_widget_proxy = |
| 196 static_cast<WebWidgetTestProxyType*>(render_widget); |
| 197 auto* web_widget_test_proxy_base = |
| 198 static_cast<test_runner::WebWidgetTestProxyBase*>(render_widget_proxy); |
| 199 DCHECK(web_widget_test_proxy_base->web_widget()->isWebFrameWidget()); |
| 200 return web_widget_test_proxy_base; |
| 201 } |
| 202 } |
| 203 |
| 204 RenderWidget* GetRenderWidget( |
| 205 test_runner::WebWidgetTestProxyBase* web_widget_test_proxy_base) { |
| 206 DCHECK(web_widget_test_proxy_base); |
| 207 |
| 208 blink::WebWidget* widget = web_widget_test_proxy_base->web_widget(); |
| 209 // TODO(lfg): Simplify once RenderView no longer inherits from RenderWidget. |
| 210 if (widget->isWebView()) { |
| 211 WebViewTestProxyType* render_view_proxy = |
| 212 static_cast<WebViewTestProxyType*>(web_widget_test_proxy_base); |
| 213 RenderViewImpl* render_view_impl = |
| 214 static_cast<RenderViewImpl*>(render_view_proxy); |
| 215 return render_view_impl; |
| 216 } else if (widget->isWebFrameWidget()) { |
| 217 WebWidgetTestProxyType* render_widget_proxy = |
| 218 static_cast<WebWidgetTestProxyType*>(web_widget_test_proxy_base); |
| 219 return static_cast<RenderWidget*>(render_widget_proxy); |
| 220 } else { |
| 221 NOTREACHED(); |
| 222 return nullptr; |
| 223 } |
| 224 } |
| 225 |
167 void EnableWebTestProxyCreation( | 226 void EnableWebTestProxyCreation( |
168 const ViewProxyCreationCallback& view_proxy_creation_callback, | 227 const ViewProxyCreationCallback& view_proxy_creation_callback, |
169 const WidgetProxyCreationCallback& widget_proxy_creation_callback, | 228 const WidgetProxyCreationCallback& widget_proxy_creation_callback, |
170 const FrameProxyCreationCallback& frame_proxy_creation_callback) { | 229 const FrameProxyCreationCallback& frame_proxy_creation_callback) { |
171 g_view_test_proxy_callback.Get() = view_proxy_creation_callback; | 230 g_view_test_proxy_callback.Get() = view_proxy_creation_callback; |
172 g_widget_test_proxy_callback.Get() = widget_proxy_creation_callback; | 231 g_widget_test_proxy_callback.Get() = widget_proxy_creation_callback; |
173 g_frame_test_proxy_callback.Get() = frame_proxy_creation_callback; | 232 g_frame_test_proxy_callback.Get() = frame_proxy_creation_callback; |
174 RenderViewImpl::InstallCreateHook(CreateWebViewTestProxy); | 233 RenderViewImpl::InstallCreateHook(CreateWebViewTestProxy); |
175 RenderWidget::InstallCreateHook(CreateWebWidgetTestProxy, | 234 RenderWidget::InstallCreateHook(CreateWebWidgetTestProxy, |
176 RenderWidgetInitialized); | 235 RenderWidgetInitialized); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 RenderViewImpl* render_view_impl = static_cast<RenderViewImpl*>(render_view); | 444 RenderViewImpl* render_view_impl = static_cast<RenderViewImpl*>(render_view); |
386 render_view_impl->ForceResizeForTesting(new_size); | 445 render_view_impl->ForceResizeForTesting(new_size); |
387 } | 446 } |
388 | 447 |
389 void SetDeviceScaleFactor(RenderView* render_view, float factor) { | 448 void SetDeviceScaleFactor(RenderView* render_view, float factor) { |
390 static_cast<RenderViewImpl*>(render_view)-> | 449 static_cast<RenderViewImpl*>(render_view)-> |
391 SetDeviceScaleFactorForTesting(factor); | 450 SetDeviceScaleFactorForTesting(factor); |
392 } | 451 } |
393 | 452 |
394 float GetWindowToViewportScale(RenderView* render_view) { | 453 float GetWindowToViewportScale(RenderView* render_view) { |
395 blink::WebFloatRect rect(0, 0, 1.0f, 0.0); | 454 return GetWindowToViewportScale( |
396 static_cast<RenderViewImpl*>(render_view)->convertWindowToViewport(&rect); | 455 static_cast<RenderViewImpl*>(render_view)->GetWidget()); |
397 return rect.width; | 456 } |
| 457 |
| 458 std::unique_ptr<blink::WebInputEvent> TransformScreenToWidgetCoordinates( |
| 459 test_runner::WebWidgetTestProxyBase* web_widget_test_proxy_base, |
| 460 const blink::WebInputEvent& event) { |
| 461 DCHECK(web_widget_test_proxy_base); |
| 462 RenderWidget* render_widget = GetRenderWidget(web_widget_test_proxy_base); |
| 463 |
| 464 blink::WebRect view_rect = render_widget->viewRect(); |
| 465 float scale = GetWindowToViewportScale(render_widget); |
| 466 gfx::Vector2d delta(-view_rect.x, -view_rect.y); |
| 467 return ui::TranslateAndScaleWebInputEvent(event, delta, scale); |
398 } | 468 } |
399 | 469 |
400 gfx::ICCProfile GetTestingICCProfile(const std::string& name) { | 470 gfx::ICCProfile GetTestingICCProfile(const std::string& name) { |
401 const unsigned char rgb_profile_data[] = { | 471 const unsigned char rgb_profile_data[] = { |
402 0x00, 0x00, 0x07, 0xd8, 0x61, 0x70, 0x70, 0x6c, 0x02, 0x20, 0x00, 0x00, | 472 0x00, 0x00, 0x07, 0xd8, 0x61, 0x70, 0x70, 0x6c, 0x02, 0x20, 0x00, 0x00, |
403 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59, 0x5a, 0x20, | 473 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59, 0x5a, 0x20, |
404 0x07, 0xd9, 0x00, 0x02, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x1a, 0x00, 0x0b, | 474 0x07, 0xd9, 0x00, 0x02, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x1a, 0x00, 0x0b, |
405 0x61, 0x63, 0x73, 0x70, 0x41, 0x50, 0x50, 0x4c, 0x00, 0x00, 0x00, 0x00, | 475 0x61, 0x63, 0x73, 0x70, 0x41, 0x50, 0x50, 0x4c, 0x00, 0x00, 0x00, 0x00, |
406 0x61, 0x70, 0x70, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 476 0x61, 0x70, 0x70, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, | 477 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 return result; | 1104 return result; |
1035 } | 1105 } |
1036 | 1106 |
1037 void SchedulerRunIdleTasks(const base::Closure& callback) { | 1107 void SchedulerRunIdleTasks(const base::Closure& callback) { |
1038 blink::scheduler::RendererScheduler* scheduler = | 1108 blink::scheduler::RendererScheduler* scheduler = |
1039 content::RenderThreadImpl::current()->GetRendererScheduler(); | 1109 content::RenderThreadImpl::current()->GetRendererScheduler(); |
1040 blink::scheduler::RunIdleTasksForTesting(scheduler, callback); | 1110 blink::scheduler::RunIdleTasksForTesting(scheduler, callback); |
1041 } | 1111 } |
1042 | 1112 |
1043 } // namespace content | 1113 } // namespace content |
OLD | NEW |