summaryrefslogtreecommitdiffstats
path: root/cc/CCSolidColorLayerImplTest.cpp
blob: a6807b2f3b032e38908d7f4d929ea13d8b8fcfd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#include "CCSolidColorLayerImpl.h"

#include "CCAppendQuadsData.h"
#include "CCLayerTestCommon.h"
#include "CCSingleThreadProxy.h"
#include "CCSolidColorDrawQuad.h"
#include "MockCCQuadCuller.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>

using namespace WebCore;
using namespace CCLayerTestCommon;

namespace {

TEST(CCSolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap)
{
    DebugScopedSetImplThread scopedImplThread;

    MockCCQuadCuller quadCuller;
    IntSize layerSize = IntSize(800, 600);
    IntRect visibleContentRect = IntRect(IntPoint(), layerSize);

    OwnPtr<CCSolidColorLayerImpl> layer = CCSolidColorLayerImpl::create(1);
    layer->setVisibleContentRect(visibleContentRect);
    layer->setBounds(layerSize);
    layer->setContentBounds(layerSize);
    layer->createRenderSurface();
    layer->setRenderTarget(layer.get());

    CCAppendQuadsData data;
    layer->appendQuads(quadCuller, data);

    verifyQuadsExactlyCoverRect(quadCuller.quadList(), visibleContentRect);
}

TEST(CCSolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad)
{
    DebugScopedSetImplThread scopedImplThread;

    SkColor testColor = 0xFFA55AFF;

    MockCCQuadCuller quadCuller;
    IntSize layerSize = IntSize(100, 100);
    IntRect visibleContentRect = IntRect(IntPoint(), layerSize);

    OwnPtr<CCSolidColorLayerImpl> layer = CCSolidColorLayerImpl::create(1);
    layer->setVisibleContentRect(visibleContentRect);
    layer->setBounds(layerSize);
    layer->setContentBounds(layerSize);
    layer->setBackgroundColor(testColor);
    layer->createRenderSurface();
    layer->setRenderTarget(layer.get());

    CCAppendQuadsData data;
    layer->appendQuads(quadCuller, data);

    ASSERT_EQ(quadCuller.quadList().size(), 1U);
    EXPECT_EQ(CCSolidColorDrawQuad::materialCast(quadCuller.quadList()[0].get())->color(), testColor);
}

TEST(CCSolidColorLayerImplTest, verifyCorrectOpacityInQuad)
{
    DebugScopedSetImplThread scopedImplThread;

    const float opacity = 0.5f;

    MockCCQuadCuller quadCuller;
    IntSize layerSize = IntSize(100, 100);
    IntRect visibleContentRect = IntRect(IntPoint(), layerSize);

    OwnPtr<CCSolidColorLayerImpl> layer = CCSolidColorLayerImpl::create(1);
    layer->setVisibleContentRect(visibleContentRect);
    layer->setBounds(layerSize);
    layer->setContentBounds(layerSize);
    layer->setDrawOpacity(opacity);
    layer->createRenderSurface();
    layer->setRenderTarget(layer.get());

    CCAppendQuadsData data;
    layer->appendQuads(quadCuller, data);

    ASSERT_EQ(quadCuller.quadList().size(), 1U);
    EXPECT_EQ(opacity, CCSolidColorDrawQuad::materialCast(quadCuller.quadList()[0].get())->opacity());
}

} // namespace