WebKit merge 128969:128981
[chromium-blink-merge.git] / cc / CCHeadsUpDisplayTest.cpp
blobce847ab2b8cec3865c1519793424747f654289cf
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 "config.h"
7 #include "CCLayerTreeHost.h"
8 #include "CCThreadedTest.h"
9 #include "HeadsUpDisplayLayerChromium.h"
10 #include "LayerChromium.h"
12 using namespace cc;
13 using namespace WebKitTests;
15 namespace {
17 class CCHeadsUpDisplayTest : public CCThreadedTest {
18 protected:
19 virtual void initializeSettings(CCLayerTreeSettings& settings) OVERRIDE
21 // Enable the HUD without requiring text.
22 settings.showPropertyChangedRects = true;
26 class DrawsContentLayerChromium : public LayerChromium {
27 public:
28 static PassRefPtr<DrawsContentLayerChromium> create() { return adoptRef(new DrawsContentLayerChromium()); }
29 virtual bool drawsContent() const OVERRIDE { return true; }
31 private:
32 DrawsContentLayerChromium() : LayerChromium() { }
35 class CCHudWithRootLayerChange : public CCHeadsUpDisplayTest {
36 public:
37 CCHudWithRootLayerChange()
38 : m_rootLayer1(DrawsContentLayerChromium::create())
39 , m_rootLayer2(DrawsContentLayerChromium::create())
40 , m_numCommits(0)
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
54 ++m_numCommits;
56 ASSERT_TRUE(m_layerTreeHost->hudLayer());
58 switch (m_numCommits) {
59 case 1:
60 // Change directly to a new root layer.
61 m_layerTreeHost->setRootLayer(m_rootLayer1);
62 break;
63 case 2:
64 EXPECT_EQ(m_rootLayer1.get(), m_layerTreeHost->hudLayer()->parent());
65 // Unset the root layer.
66 m_layerTreeHost->setRootLayer(0);
67 break;
68 case 3:
69 EXPECT_EQ(0, m_layerTreeHost->hudLayer()->parent());
70 // Change back to the previous root layer.
71 m_layerTreeHost->setRootLayer(m_rootLayer1);
72 break;
73 case 4:
74 EXPECT_EQ(m_rootLayer1.get(), m_layerTreeHost->hudLayer()->parent());
75 // Unset the root layer.
76 m_layerTreeHost->setRootLayer(0);
77 break;
78 case 5:
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);
82 break;
83 case 6:
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);
87 break;
88 case 7:
89 EXPECT_EQ(m_rootLayer1.get(), m_layerTreeHost->hudLayer()->parent());
90 endTest();
91 break;
95 virtual void afterTest() OVERRIDE
99 private:
100 RefPtr<DrawsContentLayerChromium> m_rootLayer1;
101 RefPtr<DrawsContentLayerChromium> m_rootLayer2;
102 int m_numCommits;
105 TEST_F(CCHudWithRootLayerChange, runMultiThread)
107 runTest(true);
110 } // namespace