1 // Copyright 2012 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/heads_up_display_layer.h"
7 #include "cc/layer_tree_host.h"
8 #include "cc/test/layer_tree_test_common.h"
13 class HeadsUpDisplayTest
: public ThreadedTest
{
15 virtual void initializeSettings(LayerTreeSettings
& settings
) OVERRIDE
17 // Enable the HUD without requiring text.
18 settings
.initialDebugState
.showPropertyChangedRects
= true;
22 class DrawsContentLayer
: public Layer
{
24 static scoped_refptr
<DrawsContentLayer
> create() { return make_scoped_refptr(new DrawsContentLayer()); }
25 virtual bool drawsContent() const OVERRIDE
{ return true; }
28 DrawsContentLayer() : Layer() { }
29 virtual ~DrawsContentLayer()
34 class HudWithRootLayerChange
: public HeadsUpDisplayTest
{
36 HudWithRootLayerChange()
37 : m_rootLayer1(DrawsContentLayer::create())
38 , m_rootLayer2(DrawsContentLayer::create())
43 virtual void beginTest() OVERRIDE
45 m_rootLayer1
->setBounds(gfx::Size(30, 30));
46 m_rootLayer2
->setBounds(gfx::Size(30, 30));
48 postSetNeedsCommitToMainThread();
51 virtual void didCommit() OVERRIDE
55 ASSERT_TRUE(m_layerTreeHost
->hudLayer());
57 switch (m_numCommits
) {
59 // Change directly to a new root layer.
60 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
63 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
64 // Unset the root layer.
65 m_layerTreeHost
->setRootLayer(0);
68 EXPECT_EQ(0, m_layerTreeHost
->hudLayer()->parent());
69 // Change back to the previous root layer.
70 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
73 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
74 // Unset the root layer.
75 m_layerTreeHost
->setRootLayer(0);
78 EXPECT_EQ(0, m_layerTreeHost
->hudLayer()->parent());
79 // Change to a new root layer from a null root.
80 m_layerTreeHost
->setRootLayer(m_rootLayer2
);
83 EXPECT_EQ(m_rootLayer2
.get(), m_layerTreeHost
->hudLayer()->parent());
84 // Change directly back to the last root layer/
85 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
88 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
94 virtual void afterTest() OVERRIDE
99 scoped_refptr
<DrawsContentLayer
> m_rootLayer1
;
100 scoped_refptr
<DrawsContentLayer
> m_rootLayer2
;
104 TEST_F(HudWithRootLayerChange
, runMultiThread
)