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

Side by Side Diff: ui/gfx/compositor/layer_unittest.cc

Issue 8510076: Fix stale compositor references from ui::Layer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux_touch build Created 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/layer.cc ('k') | views/view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 16 matching lines...) Expand all
27 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the 27 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the
28 // LayerDelegate. This is typically the base class you want to use. 28 // LayerDelegate. This is typically the base class you want to use.
29 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate 29 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate
30 // on the delegates. 30 // on the delegates.
31 // - LayerWithRealCompositorTest when a real compositor is required for testing. 31 // - LayerWithRealCompositorTest when a real compositor is required for testing.
32 // - Slow because they bring up a window and run the real compositor. This 32 // - Slow because they bring up a window and run the real compositor. This
33 // is typically not what you want. 33 // is typically not what you want.
34 34
35 class ColoredLayer : public Layer, public LayerDelegate { 35 class ColoredLayer : public Layer, public LayerDelegate {
36 public: 36 public:
37 ColoredLayer(Compositor* compositor, SkColor color) 37 explicit ColoredLayer(SkColor color)
38 : Layer(compositor, Layer::LAYER_HAS_TEXTURE), 38 : Layer(Layer::LAYER_HAS_TEXTURE),
39 color_(color) { 39 color_(color) {
40 set_delegate(this); 40 set_delegate(this);
41 } 41 }
42 42
43 virtual ~ColoredLayer() { } 43 virtual ~ColoredLayer() { }
44 44
45 // Overridden from LayerDelegate: 45 // Overridden from LayerDelegate:
46 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 46 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
47 canvas->GetSkCanvas()->drawColor(color_); 47 canvas->GetSkCanvas()->drawColor(color_);
48 } 48 }
(...skipping 15 matching lines...) Expand all
64 } 64 }
65 65
66 virtual void TearDown() OVERRIDE { 66 virtual void TearDown() OVERRIDE {
67 } 67 }
68 68
69 Compositor* GetCompositor() { 69 Compositor* GetCompositor() {
70 return window_->GetCompositor(); 70 return window_->GetCompositor();
71 } 71 }
72 72
73 Layer* CreateLayer(Layer::LayerType type) { 73 Layer* CreateLayer(Layer::LayerType type) {
74 return new Layer(GetCompositor(), type); 74 return new Layer(type);
75 } 75 }
76 76
77 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 77 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
78 Layer* layer = new ColoredLayer(GetCompositor(), color); 78 Layer* layer = new ColoredLayer(color);
79 layer->SetBounds(bounds); 79 layer->SetBounds(bounds);
80 return layer; 80 return layer;
81 } 81 }
82 82
83 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 83 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
84 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 84 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE);
85 layer->SetBounds(bounds); 85 layer->SetBounds(bounds);
86 return layer; 86 return layer;
87 } 87 }
88 88
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 #if defined(OS_WIN) 197 #if defined(OS_WIN)
198 // These are disabled on windows as they don't run correctly on the buildbot. 198 // These are disabled on windows as they don't run correctly on the buildbot.
199 // Reenable once we move to the real compositor. 199 // Reenable once we move to the real compositor.
200 #define MAYBE_Delegate DISABLED_Delegate 200 #define MAYBE_Delegate DISABLED_Delegate
201 #define MAYBE_Draw DISABLED_Draw 201 #define MAYBE_Draw DISABLED_Draw
202 #define MAYBE_DrawTree DISABLED_DrawTree 202 #define MAYBE_DrawTree DISABLED_DrawTree
203 #define MAYBE_Hierarchy DISABLED_Hierarchy 203 #define MAYBE_Hierarchy DISABLED_Hierarchy
204 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture 204 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture
205 #define MAYBE_DrawPixels DISABLED_DrawPixels 205 #define MAYBE_DrawPixels DISABLED_DrawPixels
206 #define MAYBE_SetRootLayer DISABLED_SetRootLayer
206 #else 207 #else
207 #define MAYBE_Delegate Delegate 208 #define MAYBE_Delegate Delegate
208 #define MAYBE_Draw Draw 209 #define MAYBE_Draw Draw
209 #define MAYBE_DrawTree DrawTree 210 #define MAYBE_DrawTree DrawTree
210 #define MAYBE_Hierarchy Hierarchy 211 #define MAYBE_Hierarchy Hierarchy
211 #define MAYBE_HierarchyNoTexture HierarchyNoTexture 212 #define MAYBE_HierarchyNoTexture HierarchyNoTexture
212 #define MAYBE_DrawPixels DrawPixels 213 #define MAYBE_DrawPixels DrawPixels
214 #define MAYBE_SetRootLayer SetRootLayer
213 #endif 215 #endif
214 216
215 TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) { 217 TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) {
216 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, 218 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED,
217 gfx::Rect(20, 20, 50, 50))); 219 gfx::Rect(20, 20, 50, 50)));
218 DrawTree(layer.get()); 220 DrawTree(layer.get());
219 } 221 }
220 222
221 // Create this hierarchy: 223 // Create this hierarchy:
222 // L1 - red 224 // L1 - red
(...skipping 27 matching lines...) Expand all
250 virtual void SetUp() OVERRIDE { 252 virtual void SetUp() OVERRIDE {
251 compositor_ = new TestCompositor(this); 253 compositor_ = new TestCompositor(this);
252 } 254 }
253 255
254 virtual void TearDown() OVERRIDE { 256 virtual void TearDown() OVERRIDE {
255 } 257 }
256 258
257 Compositor* compositor() { return compositor_.get(); } 259 Compositor* compositor() { return compositor_.get(); }
258 260
259 virtual Layer* CreateLayer(Layer::LayerType type) { 261 virtual Layer* CreateLayer(Layer::LayerType type) {
260 return new Layer(compositor(), type); 262 return new Layer(type);
261 } 263 }
262 264
263 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 265 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
264 Layer* layer = new ColoredLayer(compositor(), color); 266 Layer* layer = new ColoredLayer(color);
265 layer->SetBounds(bounds); 267 layer->SetBounds(bounds);
266 return layer; 268 return layer;
267 } 269 }
268 270
269 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 271 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
270 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 272 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE);
271 layer->SetBounds(bounds); 273 layer->SetBounds(bounds);
272 return layer; 274 return layer;
273 } 275 }
274 276
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // Overridden from testing::Test: 456 // Overridden from testing::Test:
455 virtual void SetUp() OVERRIDE { 457 virtual void SetUp() OVERRIDE {
456 LayerWithDelegateTest::SetUp(); 458 LayerWithDelegateTest::SetUp();
457 default_layer_delegate_.reset(new NullLayerDelegate()); 459 default_layer_delegate_.reset(new NullLayerDelegate());
458 } 460 }
459 461
460 virtual void TearDown() OVERRIDE { 462 virtual void TearDown() OVERRIDE {
461 } 463 }
462 464
463 Layer* CreateLayer(Layer::LayerType type) OVERRIDE { 465 Layer* CreateLayer(Layer::LayerType type) OVERRIDE {
464 Layer* layer = new Layer(compositor(), type); 466 Layer* layer = new Layer(type);
465 layer->set_delegate(default_layer_delegate_.get()); 467 layer->set_delegate(default_layer_delegate_.get());
466 return layer; 468 return layer;
467 } 469 }
468 470
469 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { 471 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) {
470 Layer* layer = CreateTextureLayer(bounds); 472 Layer* layer = CreateTextureLayer(bounds);
471 compositor()->SetRootLayer(layer); 473 compositor()->SetRootLayer(layer);
472 return layer; 474 return layer;
473 } 475 }
474 476
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 883
882 // Toggling l2's visibility should drop all sub-layer textures. 884 // Toggling l2's visibility should drop all sub-layer textures.
883 l12->SetVisible(false); 885 l12->SetVisible(false);
884 EXPECT_EQ(NULL, l12->texture()); 886 EXPECT_EQ(NULL, l12->texture());
885 EXPECT_EQ(NULL, l121->texture()); 887 EXPECT_EQ(NULL, l121->texture());
886 EXPECT_EQ(NULL, l122->texture()); 888 EXPECT_EQ(NULL, l122->texture());
887 } 889 }
888 890
889 // Various visibile/drawn assertions. 891 // Various visibile/drawn assertions.
890 TEST_F(LayerWithNullDelegateTest, Visibility) { 892 TEST_F(LayerWithNullDelegateTest, Visibility) {
891 scoped_ptr<Layer> l1(new Layer(NULL, Layer::LAYER_HAS_TEXTURE)); 893 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE));
892 scoped_ptr<Layer> l2(new Layer(NULL, Layer::LAYER_HAS_TEXTURE)); 894 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE));
893 scoped_ptr<Layer> l3(new Layer(NULL, Layer::LAYER_HAS_TEXTURE)); 895 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE));
894 l1->Add(l2.get()); 896 l1->Add(l2.get());
895 l2->Add(l3.get()); 897 l2->Add(l3.get());
896 898
897 NullLayerDelegate delegate; 899 NullLayerDelegate delegate;
898 l1->set_delegate(&delegate); 900 l1->set_delegate(&delegate);
899 l2->set_delegate(&delegate); 901 l2->set_delegate(&delegate);
900 l3->set_delegate(&delegate); 902 l3->set_delegate(&delegate);
901 903
902 // Layers should initially be drawn. 904 // Layers should initially be drawn.
903 EXPECT_TRUE(l1->IsDrawn()); 905 EXPECT_TRUE(l1->IsDrawn());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 994
993 SkAutoLockPixels lock(bitmap); 995 SkAutoLockPixels lock(bitmap);
994 bool is_all_red = true; 996 bool is_all_red = true;
995 for (int x = 0; is_all_red && x < 500; x++) 997 for (int x = 0; is_all_red && x < 500; x++)
996 for (int y = 0; is_all_red && y < 500; y++) 998 for (int y = 0; is_all_red && y < 500; y++)
997 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); 999 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED);
998 1000
999 EXPECT_TRUE(is_all_red); 1001 EXPECT_TRUE(is_all_red);
1000 } 1002 }
1001 1003
1004 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor.
1005 TEST_F(LayerWithRealCompositorTest, MAYBE_SetRootLayer) {
1006 Compositor* compositor = GetCompositor();
1007 Layer l1;
1008 EXPECT_EQ(NULL, l1.GetCompositor());
1009
1010 Layer l2;
1011 EXPECT_EQ(NULL, l2.GetCompositor());
1012
1013 compositor->SetRootLayer(&l1);
1014 EXPECT_EQ(compositor, l1.GetCompositor());
1015
1016 l1.Add(&l2);
1017 EXPECT_EQ(compositor, l2.GetCompositor());
1018
1019 l1.Remove(&l2);
1020 EXPECT_EQ(NULL, l2.GetCompositor());
1021
1022 l1.Add(&l2);
1023 EXPECT_EQ(compositor, l2.GetCompositor());
1024
1025 compositor->SetRootLayer(NULL);
1026 EXPECT_EQ(NULL, l1.GetCompositor());
1027 EXPECT_EQ(NULL, l2.GetCompositor());
1028 }
1029
1002 } // namespace ui 1030 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer.cc ('k') | views/view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698