Use SCHEME_HTTP for HTTPS proxies on Android.
[chromium-blink-merge.git] / cc / render_surface_unittest.cc
blob0fd5247d52e6c8a3186282deb264493502089b45
1 // Copyright 2011 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 "cc/render_surface_impl.h"
7 #include "cc/append_quads_data.h"
8 #include "cc/layer_impl.h"
9 #include "cc/render_pass_sink.h"
10 #include "cc/scoped_ptr_vector.h"
11 #include "cc/shared_quad_state.h"
12 #include "cc/single_thread_proxy.h"
13 #include "cc/test/fake_impl_proxy.h"
14 #include "cc/test/fake_layer_tree_host_impl.h"
15 #include "cc/test/geometry_test_utils.h"
16 #include "cc/test/mock_quad_culler.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gfx/transform.h"
21 namespace cc {
22 namespace {
24 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest) \
25 renderSurface->resetPropertyChangedFlag(); \
26 codeToTest; \
27 EXPECT_TRUE(renderSurface->surfacePropertyChanged())
29 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \
30 renderSurface->resetPropertyChangedFlag(); \
31 codeToTest; \
32 EXPECT_FALSE(renderSurface->surfacePropertyChanged())
34 TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly)
37 // This test checks that surfacePropertyChanged() has the correct behavior.
40 FakeImplProxy proxy;
41 FakeLayerTreeHostImpl hostImpl(&proxy);
42 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 1);
43 owningLayer->createRenderSurface();
44 ASSERT_TRUE(owningLayer->renderSurface());
45 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
46 gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6));
47 owningLayer->resetAllChangeTrackingForSubtree();
49 // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChanged() are
50 // the only sources of change.
51 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setClipRect(testRect));
52 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setContentRect(testRect));
54 owningLayer->setOpacity(0.5f);
55 EXPECT_TRUE(renderSurface->surfacePropertyChanged());
56 owningLayer->resetAllChangeTrackingForSubtree();
58 // Setting the surface properties to the same values again should not be considered "change".
59 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRect));
60 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(testRect));
62 scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(&hostImpl, 1);
63 gfx::Transform dummyMatrix;
64 dummyMatrix.Translate(1.0, 2.0);
66 // The rest of the surface properties are either internal and should not cause change,
67 // or they are already accounted for by the owninglayer->layerPropertyChanged().
68 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5));
69 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(dummyMatrix));
70 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTransform(dummyMatrix));
71 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists());
74 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState)
76 FakeImplProxy proxy;
77 FakeLayerTreeHostImpl hostImpl(&proxy);
78 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(&hostImpl, 1);
80 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 2);
81 owningLayer->createRenderSurface();
82 ASSERT_TRUE(owningLayer->renderSurface());
83 owningLayer->drawProperties().render_target = owningLayer.get();
84 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
86 rootLayer->addChild(owningLayer.Pass());
88 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50));
89 gfx::Rect clipRect = gfx::Rect(gfx::Point(5, 5), gfx::Size(40, 40));
90 gfx::Transform origin;
92 origin.Translate(30, 40);
94 renderSurface->setDrawTransform(origin);
95 renderSurface->setContentRect(contentRect);
96 renderSurface->setClipRect(clipRect);
97 renderSurface->setDrawOpacity(1);
99 QuadList quadList;
100 SharedQuadStateList sharedStateList;
101 MockQuadCuller mockQuadCuller(quadList, sharedStateList);
102 AppendQuadsData appendQuadsData;
104 bool forReplica = false;
105 renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, RenderPass::Id(2, 0));
107 ASSERT_EQ(1u, sharedStateList.size());
108 SharedQuadState* sharedQuadState = sharedStateList[0];
110 EXPECT_EQ(30, sharedQuadState->content_to_target_transform.matrix().getDouble(0, 3));
111 EXPECT_EQ(40, sharedQuadState->content_to_target_transform.matrix().getDouble(1, 3));
112 EXPECT_RECT_EQ(contentRect, gfx::Rect(sharedQuadState->visible_content_rect));
113 EXPECT_EQ(1, sharedQuadState->opacity);
116 class TestRenderPassSink : public RenderPassSink {
117 public:
118 virtual void appendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE { m_renderPasses.append(renderPass.Pass()); }
120 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPasses; }
122 private:
123 ScopedPtrVector<RenderPass> m_renderPasses;
126 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass)
128 FakeImplProxy proxy;
129 FakeLayerTreeHostImpl hostImpl(&proxy);
130 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(&hostImpl, 1);
132 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 2);
133 owningLayer->createRenderSurface();
134 ASSERT_TRUE(owningLayer->renderSurface());
135 owningLayer->drawProperties().render_target = owningLayer.get();
136 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
138 rootLayer->addChild(owningLayer.Pass());
140 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50));
141 gfx::Transform origin;
142 origin.Translate(30, 40);
144 renderSurface->setScreenSpaceTransform(origin);
145 renderSurface->setContentRect(contentRect);
147 TestRenderPassSink passSink;
149 renderSurface->appendRenderPasses(passSink);
151 ASSERT_EQ(1u, passSink.renderPasses().size());
152 RenderPass* pass = passSink.renderPasses()[0];
154 EXPECT_EQ(RenderPass::Id(2, 0), pass->id);
155 EXPECT_RECT_EQ(contentRect, pass->output_rect);
156 EXPECT_EQ(origin, pass->transform_to_root_target);
159 } // namespace
160 } // namespace cc