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/layers/nine_patch_layer.h"
7 #include "cc/debug/overdraw_metrics.h"
8 #include "cc/resources/prioritized_resource_manager.h"
9 #include "cc/resources/resource_provider.h"
10 #include "cc/resources/resource_update_queue.h"
11 #include "cc/resources/scoped_ui_resource.h"
12 #include "cc/scheduler/texture_uploader.h"
13 #include "cc/test/fake_layer_tree_host_client.h"
14 #include "cc/test/fake_output_surface.h"
15 #include "cc/test/fake_output_surface_client.h"
16 #include "cc/test/geometry_test_utils.h"
17 #include "cc/trees/layer_tree_host.h"
18 #include "cc/trees/occlusion_tracker.h"
19 #include "cc/trees/single_thread_proxy.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/skia/include/core/SkBitmap.h"
24 using ::testing::Mock
;
26 using ::testing::AtLeast
;
27 using ::testing::AnyNumber
;
32 class MockLayerTreeHost
: public LayerTreeHost
{
34 explicit MockLayerTreeHost(LayerTreeHostClient
* client
)
35 : LayerTreeHost(client
, LayerTreeSettings()) {
40 class NinePatchLayerTest
: public testing::Test
{
42 NinePatchLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D
) {}
44 cc::Proxy
* Proxy() const { return layer_tree_host_
->proxy(); }
47 virtual void SetUp() {
48 layer_tree_host_
.reset(new MockLayerTreeHost(&fake_client_
));
51 virtual void TearDown() {
52 Mock::VerifyAndClearExpectations(layer_tree_host_
.get());
55 scoped_ptr
<MockLayerTreeHost
> layer_tree_host_
;
56 FakeLayerTreeHostClient fake_client_
;
59 TEST_F(NinePatchLayerTest
, SetLayerProperties
) {
60 scoped_refptr
<NinePatchLayer
> test_layer
= NinePatchLayer::Create();
61 ASSERT_TRUE(test_layer
.get());
62 test_layer
->SetIsDrawable(true);
63 test_layer
->SetBounds(gfx::Size(100, 100));
65 layer_tree_host_
->SetRootLayer(test_layer
);
66 Mock::VerifyAndClearExpectations(layer_tree_host_
.get());
67 EXPECT_EQ(test_layer
->layer_tree_host(), layer_tree_host_
.get());
69 layer_tree_host_
->InitializeOutputSurfaceIfNeeded();
71 ResourceUpdateQueue queue
;
72 OcclusionTracker
occlusion_tracker(gfx::Rect(), false);
73 test_layer
->SavePaintProperties();
74 test_layer
->Update(&queue
, &occlusion_tracker
);
76 EXPECT_FALSE(test_layer
->DrawsContent());
79 bitmap
.setConfig(SkBitmap::kARGB_8888_Config
, 10, 10);
81 bitmap
.setImmutable();
83 scoped_ptr
<ScopedUIResource
> resource
= ScopedUIResource::Create(
84 layer_tree_host_
.get(), UIResourceBitmap(bitmap
));
85 gfx::Rect
aperture(5, 5, 1, 1);
86 bool fill_center
= true;
87 test_layer
->SetAperture(aperture
);
88 test_layer
->SetUIResourceId(resource
->id());
89 test_layer
->SetFillCenter(fill_center
);
90 test_layer
->Update(&queue
, &occlusion_tracker
);
92 EXPECT_TRUE(test_layer
->DrawsContent());