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 "CCLayerTreeHost.h"
8 #include "CCThreadedTest.h"
9 #include "HeadsUpDisplayLayerChromium.h"
10 #include "LayerChromium.h"
13 using namespace WebKitTests
;
17 class CCHeadsUpDisplayTest
: public CCThreadedTest
{
19 virtual void initializeSettings(CCLayerTreeSettings
& settings
) OVERRIDE
21 // Enable the HUD without requiring text.
22 settings
.showPropertyChangedRects
= true;
26 class DrawsContentLayerChromium
: public LayerChromium
{
28 static PassRefPtr
<DrawsContentLayerChromium
> create() { return adoptRef(new DrawsContentLayerChromium()); }
29 virtual bool drawsContent() const OVERRIDE
{ return true; }
32 DrawsContentLayerChromium() : LayerChromium() { }
35 class CCHudWithRootLayerChange
: public CCHeadsUpDisplayTest
{
37 CCHudWithRootLayerChange()
38 : m_rootLayer1(DrawsContentLayerChromium::create())
39 , m_rootLayer2(DrawsContentLayerChromium::create())
44 virtual void beginTest() OVERRIDE
46 m_rootLayer1
->setBounds(IntSize(30, 30));
47 m_rootLayer2
->setBounds(IntSize(30, 30));
49 postSetNeedsCommitToMainThread();
52 virtual void didCommit() OVERRIDE
56 ASSERT_TRUE(m_layerTreeHost
->hudLayer());
58 switch (m_numCommits
) {
60 // Change directly to a new root layer.
61 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
64 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
65 // Unset the root layer.
66 m_layerTreeHost
->setRootLayer(0);
69 EXPECT_EQ(0, m_layerTreeHost
->hudLayer()->parent());
70 // Change back to the previous root layer.
71 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
74 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
75 // Unset the root layer.
76 m_layerTreeHost
->setRootLayer(0);
79 EXPECT_EQ(0, m_layerTreeHost
->hudLayer()->parent());
80 // Change to a new root layer from a null root.
81 m_layerTreeHost
->setRootLayer(m_rootLayer2
);
84 EXPECT_EQ(m_rootLayer2
.get(), m_layerTreeHost
->hudLayer()->parent());
85 // Change directly back to the last root layer/
86 m_layerTreeHost
->setRootLayer(m_rootLayer1
);
89 EXPECT_EQ(m_rootLayer1
.get(), m_layerTreeHost
->hudLayer()->parent());
95 virtual void afterTest() OVERRIDE
100 RefPtr
<DrawsContentLayerChromium
> m_rootLayer1
;
101 RefPtr
<DrawsContentLayerChromium
> m_rootLayer2
;
105 TEST_F(CCHudWithRootLayerChange
, runMultiThread
)