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.
7 #include "cc/heads_up_display_layer.h"
9 #include "cc/layer_tree_host.h"
10 #include "cc/test/layer_tree_test_common.h"
13 using namespace WebKitTests
;
17 class HeadsUpDisplayTest
: public ThreadedTest
{
19 virtual void initializeSettings(LayerTreeSettings
& settings
) OVERRIDE
21 // Enable the HUD without requiring text.
22 settings
.showPropertyChangedRects
= true;
26 class DrawsContentLayer
: public Layer
{
28 static scoped_refptr
<DrawsContentLayer
> create() { return make_scoped_refptr(new DrawsContentLayer()); }
29 virtual bool drawsContent() const OVERRIDE
{ return true; }
32 DrawsContentLayer() : Layer() { }
33 virtual ~DrawsContentLayer()
38 class HudWithRootLayerChange
: public HeadsUpDisplayTest
{
40 HudWithRootLayerChange()
41 : m_rootLayer1(DrawsContentLayer::create())
42 , m_rootLayer2(DrawsContentLayer::create())
47 virtual void beginTest() OVERRIDE
49 m_rootLayer1
->setBounds(gfx::Size(30, 30));
50 m_rootLayer2
->setBounds(gfx::Size(30, 30));
52 postSetNeedsCommitToMainThread();
55 virtual void didCommit() OVERRIDE
59 ASSERT_TRUE(m_layerTreeHost
->hudLayer());
61 switch (m_numCommits
) {
63 // Change directly to a new root layer.
64 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
67 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
68 // Unset the root layer.
69 m_layerTreeHost
->setRootLayer(0);
72 EXPECT_EQ(0, m_layerTreeHost
->hudLayer()->parent());
73 // Change back to the previous root layer.
74 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
77 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
78 // Unset the root layer.
79 m_layerTreeHost
->setRootLayer(0);
82 EXPECT_EQ(0, m_layerTreeHost
->hudLayer()->parent());
83 // Change to a new root layer from a null root.
84 m_layerTreeHost
->setRootLayer(m_rootLayer2
);
87 EXPECT_EQ(m_rootLayer2
.get(), m_layerTreeHost
->hudLayer()->parent());
88 // Change directly back to the last root layer/
89 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
92 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
98 virtual void afterTest() OVERRIDE
103 scoped_refptr
<DrawsContentLayer
> m_rootLayer1
;
104 scoped_refptr
<DrawsContentLayer
> m_rootLayer2
;
108 TEST_F(HudWithRootLayerChange
, runMultiThread
)
113 } // anonymous namespace