Changes to RenderFrameProxy:
[chromium-blink-merge.git] / cc / layers / ui_resource_layer_unittest.cc
blob25cc2c74332d6ebd438daee42963efd05e3dd865
1 // Copyright 2013 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/ui_resource_layer.h"
7 #include "cc/resources/prioritized_resource_manager.h"
8 #include "cc/resources/resource_provider.h"
9 #include "cc/resources/resource_update_queue.h"
10 #include "cc/resources/scoped_ui_resource.h"
11 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/fake_layer_tree_host_client.h"
13 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/fake_output_surface_client.h"
15 #include "cc/test/geometry_test_utils.h"
16 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/occlusion_tracker.h"
18 #include "cc/trees/single_thread_proxy.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkBitmap.h"
23 using ::testing::Mock;
24 using ::testing::_;
25 using ::testing::AtLeast;
26 using ::testing::AnyNumber;
28 namespace cc {
29 namespace {
31 class UIResourceLayerTest : public testing::Test {
32 public:
33 UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
35 protected:
36 virtual void SetUp() {
37 layer_tree_host_ = FakeLayerTreeHost::Create();
38 layer_tree_host_->InitializeSingleThreaded(&fake_client_);
41 virtual void TearDown() {
42 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
45 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
46 FakeLayerTreeHostClient fake_client_;
49 TEST_F(UIResourceLayerTest, SetBitmap) {
50 scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create();
51 ASSERT_TRUE(test_layer.get());
52 test_layer->SetIsDrawable(true);
53 test_layer->SetBounds(gfx::Size(100, 100));
55 layer_tree_host_->SetRootLayer(test_layer);
56 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
57 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
59 ResourceUpdateQueue queue;
60 gfx::Rect screen_space_clip_rect;
61 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
62 test_layer->SavePaintProperties();
63 test_layer->Update(&queue, &occlusion_tracker);
65 EXPECT_FALSE(test_layer->DrawsContent());
67 SkBitmap bitmap;
68 bitmap.allocN32Pixels(10, 10);
69 bitmap.setImmutable();
71 test_layer->SetBitmap(bitmap);
72 test_layer->Update(&queue, &occlusion_tracker);
74 EXPECT_TRUE(test_layer->DrawsContent());
77 TEST_F(UIResourceLayerTest, SetUIResourceId) {
78 scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create();
79 ASSERT_TRUE(test_layer.get());
80 test_layer->SetIsDrawable(true);
81 test_layer->SetBounds(gfx::Size(100, 100));
83 layer_tree_host_->SetRootLayer(test_layer);
84 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
85 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
87 ResourceUpdateQueue queue;
88 gfx::Rect screen_space_clip_rect;
89 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
90 test_layer->SavePaintProperties();
91 test_layer->Update(&queue, &occlusion_tracker);
93 EXPECT_FALSE(test_layer->DrawsContent());
95 bool is_opaque = false;
96 scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create(
97 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(10, 10), is_opaque));
98 test_layer->SetUIResourceId(resource->id());
99 test_layer->Update(&queue, &occlusion_tracker);
101 EXPECT_TRUE(test_layer->DrawsContent());
104 } // namespace
105 } // namespace cc