cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / content / test / web_layer_tree_view_impl_for_testing.cc
blob51d1a7154c483eeb60e12c97c4116ce50309e173
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/test/web_layer_tree_view_impl_for_testing.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/synchronization/lock.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "cc/base/switches.h"
12 #include "cc/blink/web_layer_impl.h"
13 #include "cc/input/input_handler.h"
14 #include "cc/layers/layer.h"
15 #include "cc/scheduler/begin_frame_source.h"
16 #include "cc/test/pixel_test_output_surface.h"
17 #include "cc/test/test_context_provider.h"
18 #include "cc/trees/layer_tree_host.h"
19 #include "content/test/test_blink_web_unit_test_support.h"
20 #include "third_party/WebKit/public/platform/Platform.h"
21 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
22 #include "third_party/WebKit/public/platform/WebLayer.h"
23 #include "third_party/WebKit/public/platform/WebLayerTreeView.h"
24 #include "third_party/WebKit/public/platform/WebSize.h"
26 using blink::WebColor;
27 using blink::WebGraphicsContext3D;
28 using blink::WebRect;
29 using blink::WebSize;
31 namespace content {
33 WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {}
35 WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {}
37 void WebLayerTreeViewImplForTesting::Initialize() {
38 cc::LayerTreeSettings settings;
40 // For web contents, layer transforms should scale up the contents of layers
41 // to keep content always crisp when possible.
42 settings.layer_transforms_should_scale_layer_contents = true;
44 // Accelerated animations are enabled for unit tests.
45 settings.accelerated_animation_enabled = true;
46 cc::LayerTreeHost::InitParams params;
47 params.client = this;
48 params.settings = &settings;
49 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
50 params.task_graph_runner = &task_graph_runner_;
51 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params);
52 DCHECK(layer_tree_host_);
55 void WebLayerTreeViewImplForTesting::setRootLayer(
56 const blink::WebLayer& root) {
57 layer_tree_host_->SetRootLayer(
58 static_cast<const cc_blink::WebLayerImpl*>(&root)->layer());
61 void WebLayerTreeViewImplForTesting::clearRootLayer() {
62 layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
65 void WebLayerTreeViewImplForTesting::setViewportSize(
66 const WebSize& unused_deprecated,
67 const WebSize& device_viewport_size) {
68 layer_tree_host_->SetViewportSize(device_viewport_size);
71 void WebLayerTreeViewImplForTesting::setViewportSize(
72 const WebSize& device_viewport_size) {
73 layer_tree_host_->SetViewportSize(device_viewport_size);
76 void WebLayerTreeViewImplForTesting::setDeviceScaleFactor(
77 float device_scale_factor) {
78 layer_tree_host_->SetDeviceScaleFactor(device_scale_factor);
81 float WebLayerTreeViewImplForTesting::deviceScaleFactor() const {
82 return layer_tree_host_->device_scale_factor();
85 void WebLayerTreeViewImplForTesting::setBackgroundColor(WebColor color) {
86 layer_tree_host_->set_background_color(color);
89 void WebLayerTreeViewImplForTesting::setHasTransparentBackground(
90 bool transparent) {
91 layer_tree_host_->set_has_transparent_background(transparent);
94 void WebLayerTreeViewImplForTesting::setVisible(bool visible) {
95 layer_tree_host_->SetVisible(visible);
98 void WebLayerTreeViewImplForTesting::setPageScaleFactorAndLimits(
99 float page_scale_factor,
100 float minimum,
101 float maximum) {
102 layer_tree_host_->SetPageScaleFactorAndLimits(
103 page_scale_factor, minimum, maximum);
106 void WebLayerTreeViewImplForTesting::startPageScaleAnimation(
107 const blink::WebPoint& scroll,
108 bool use_anchor,
109 float new_page_scale,
110 double duration_sec) {}
112 void WebLayerTreeViewImplForTesting::setNeedsAnimate() {
113 layer_tree_host_->SetNeedsAnimate();
116 void WebLayerTreeViewImplForTesting::didStopFlinging() {}
118 void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) {
119 layer_tree_host_->SetDeferCommits(defer_commits);
122 void WebLayerTreeViewImplForTesting::Layout() {
125 void WebLayerTreeViewImplForTesting::ApplyViewportDeltas(
126 const gfx::Vector2dF& inner_delta,
127 const gfx::Vector2dF& outer_delta,
128 const gfx::Vector2dF& elastic_overscroll_delta,
129 float page_scale,
130 float top_controls_delta) {
133 void WebLayerTreeViewImplForTesting::RequestNewOutputSurface() {
134 bool flipped_output_surface = false;
135 layer_tree_host_->SetOutputSurface(
136 make_scoped_ptr(new cc::PixelTestOutputSurface(
137 cc::TestContextProvider::Create(), flipped_output_surface)));
140 void WebLayerTreeViewImplForTesting::DidFailToInitializeOutputSurface() {
141 RequestNewOutputSurface();
144 void WebLayerTreeViewImplForTesting::registerForAnimations(
145 blink::WebLayer* layer) {
146 cc::Layer* cc_layer = static_cast<cc_blink::WebLayerImpl*>(layer)->layer();
147 cc_layer->RegisterForAnimations(layer_tree_host_->animation_registrar());
150 void WebLayerTreeViewImplForTesting::registerViewportLayers(
151 const blink::WebLayer* overscrollElasticityLayer,
152 const blink::WebLayer* pageScaleLayer,
153 const blink::WebLayer* innerViewportScrollLayer,
154 const blink::WebLayer* outerViewportScrollLayer) {
155 layer_tree_host_->RegisterViewportLayers(
156 // The scroll elasticity layer will only exist when using pinch virtual
157 // viewports.
158 overscrollElasticityLayer
159 ? static_cast<const cc_blink::WebLayerImpl*>(
160 overscrollElasticityLayer)->layer()
161 : NULL,
162 static_cast<const cc_blink::WebLayerImpl*>(pageScaleLayer)->layer(),
163 static_cast<const cc_blink::WebLayerImpl*>(innerViewportScrollLayer)
164 ->layer(),
165 // The outer viewport layer will only exist when using pinch virtual
166 // viewports.
167 outerViewportScrollLayer
168 ? static_cast<const cc_blink::WebLayerImpl*>(outerViewportScrollLayer)
169 ->layer()
170 : NULL);
173 void WebLayerTreeViewImplForTesting::clearViewportLayers() {
174 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
175 scoped_refptr<cc::Layer>(),
176 scoped_refptr<cc::Layer>(),
177 scoped_refptr<cc::Layer>());
180 void WebLayerTreeViewImplForTesting::registerSelection(
181 const blink::WebSelection& selection) {
184 void WebLayerTreeViewImplForTesting::clearSelection() {
187 } // namespace content