Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: cc/layers/ui_resource_layer_unittest.cc

Issue 664173002: Prevent recreation of UI resource holder when created with resource ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed NeedsRecreation Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/ui_resource_layer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/ui_resource_layer.h" 5 #include "cc/layers/ui_resource_layer.h"
6 6
7 #include "cc/resources/prioritized_resource_manager.h" 7 #include "cc/resources/prioritized_resource_manager.h"
8 #include "cc/resources/resource_provider.h" 8 #include "cc/resources/resource_provider.h"
9 #include "cc/resources/resource_update_queue.h" 9 #include "cc/resources/resource_update_queue.h"
10 #include "cc/resources/scoped_ui_resource.h" 10 #include "cc/resources/scoped_ui_resource.h"
(...skipping 10 matching lines...) Expand all
21 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
22 22
23 using ::testing::Mock; 23 using ::testing::Mock;
24 using ::testing::_; 24 using ::testing::_;
25 using ::testing::AtLeast; 25 using ::testing::AtLeast;
26 using ::testing::AnyNumber; 26 using ::testing::AnyNumber;
27 27
28 namespace cc { 28 namespace cc {
29 namespace { 29 namespace {
30 30
31 class TestUIResourceLayer : public UIResourceLayer {
32 public:
33 static scoped_refptr<TestUIResourceLayer> Create() {
34 return make_scoped_refptr(new TestUIResourceLayer());
35 }
36
37 UIResourceId GetUIResourceId() {
38 if (ui_resource_holder_)
39 return ui_resource_holder_->id();
40 return 0;
41 }
42
43 protected:
44 ~TestUIResourceLayer() override {}
45 };
46
31 class UIResourceLayerTest : public testing::Test { 47 class UIResourceLayerTest : public testing::Test {
32 public: 48 public:
33 UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 49 UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
34 50
35 protected: 51 protected:
36 virtual void SetUp() { 52 virtual void SetUp() {
37 layer_tree_host_ = FakeLayerTreeHost::Create(&fake_client_); 53 layer_tree_host_ = FakeLayerTreeHost::Create(&fake_client_);
38 layer_tree_host_->InitializeSingleThreaded( 54 layer_tree_host_->InitializeSingleThreaded(
39 &fake_client_, 55 &fake_client_,
40 base::MessageLoopProxy::current(), 56 base::MessageLoopProxy::current(),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 89
74 test_layer->SetBitmap(bitmap); 90 test_layer->SetBitmap(bitmap);
75 test_layer->Update(&queue, &occlusion_tracker); 91 test_layer->Update(&queue, &occlusion_tracker);
76 92
77 EXPECT_TRUE(test_layer->DrawsContent()); 93 EXPECT_TRUE(test_layer->DrawsContent());
78 } 94 }
79 95
80 TEST_F(UIResourceLayerTest, SetUIResourceId) { 96 TEST_F(UIResourceLayerTest, SetUIResourceId) {
81 scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create(); 97 scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create();
82 ASSERT_TRUE(test_layer.get()); 98 ASSERT_TRUE(test_layer.get());
83 test_layer->SetIsDrawable(true); 99 test_layer->SetIsDrawable(true);
danakj 2014/11/20 21:48:46 You could make this test_layer your new type, so y
Changwan Ryu 2014/11/20 21:58:24 Done.
84 test_layer->SetBounds(gfx::Size(100, 100)); 100 test_layer->SetBounds(gfx::Size(100, 100));
85 101
86 layer_tree_host_->SetRootLayer(test_layer); 102 layer_tree_host_->SetRootLayer(test_layer);
87 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 103 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
88 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); 104 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
89 105
90 ResourceUpdateQueue queue; 106 ResourceUpdateQueue queue;
91 gfx::Rect screen_space_clip_rect; 107 gfx::Rect screen_space_clip_rect;
92 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect); 108 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
93 test_layer->SavePaintProperties(); 109 test_layer->SavePaintProperties();
94 test_layer->Update(&queue, &occlusion_tracker); 110 test_layer->Update(&queue, &occlusion_tracker);
95 111
96 EXPECT_FALSE(test_layer->DrawsContent()); 112 EXPECT_FALSE(test_layer->DrawsContent());
97 113
98 bool is_opaque = false; 114 bool is_opaque = false;
99 scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create( 115 scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create(
100 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(10, 10), is_opaque)); 116 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(10, 10), is_opaque));
101 test_layer->SetUIResourceId(resource->id()); 117 test_layer->SetUIResourceId(resource->id());
102 test_layer->Update(&queue, &occlusion_tracker); 118 test_layer->Update(&queue, &occlusion_tracker);
103 119
104 EXPECT_TRUE(test_layer->DrawsContent()); 120 EXPECT_TRUE(test_layer->DrawsContent());
121
122 // ID is preserved even when you set ID first and attach it to the tree.
123 scoped_refptr<TestUIResourceLayer> new_test_layer =
124 TestUIResourceLayer::Create();
125 scoped_ptr<ScopedUIResource> new_resource = ScopedUIResource::Create(
126 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(5, 5), is_opaque));
127 new_test_layer->SetUIResourceId(new_resource->id());
128 test_layer->AddChild(new_test_layer);
129 EXPECT_EQ(new_resource->id(), new_test_layer->GetUIResourceId());
danakj 2014/11/20 21:32:48 can you verify DrawsContent() as well like in the
Changwan Ryu 2014/11/20 21:58:24 Done.
105 } 130 }
106 131
107 } // namespace 132 } // namespace
108 } // namespace cc 133 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/ui_resource_layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698