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

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

Issue 8653005: Make Aura and compositor stacking methods more intuitive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 if (diff_pixels_count != 0) { 85 if (diff_pixels_count != 0) {
86 LOG(ERROR) << "Images differ by pixel count: " << diff_pixels_count; 86 LOG(ERROR) << "Images differ by pixel count: " << diff_pixels_count;
87 return false; 87 return false;
88 } 88 }
89 89
90 return true; 90 return true;
91 } 91 }
92 92
93 // Returns a comma-separated list of the names of |layer|'s children in
94 // bottom-to-top stacking order.
95 std::string GetLayerChildrenNames(const Layer& layer) {
96 std::string names;
97 for (std::vector<Layer*>::const_iterator it = layer.children().begin();
98 it != layer.children().end(); ++it) {
99 if (!names.empty())
100 names += ",";
101 names += (*it)->name();
102 }
103 return names;
104 }
105
93 106
94 // There are three test classes in here that configure the Compositor and 107 // There are three test classes in here that configure the Compositor and
95 // Layer's slightly differently: 108 // Layer's slightly differently:
96 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the 109 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the
97 // LayerDelegate. This is typically the base class you want to use. 110 // LayerDelegate. This is typically the base class you want to use.
98 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate 111 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate
99 // on the delegates. 112 // on the delegates.
100 // - LayerWithRealCompositorTest when a real compositor is required for testing. 113 // - LayerWithRealCompositorTest when a real compositor is required for testing.
101 // - Slow because they bring up a window and run the real compositor. This 114 // - Slow because they bring up a window and run the real compositor. This
102 // is typically not what you want. 115 // is typically not what you want.
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 1053
1041 l1->SetVisible(true); 1054 l1->SetVisible(true);
1042 EXPECT_TRUE(l1->IsDrawn()); 1055 EXPECT_TRUE(l1->IsDrawn());
1043 EXPECT_TRUE(l2->IsDrawn()); 1056 EXPECT_TRUE(l2->IsDrawn());
1044 EXPECT_FALSE(l3->IsDrawn()); 1057 EXPECT_FALSE(l3->IsDrawn());
1045 #if defined(USE_WEBKIT_COMPOSITOR) 1058 #if defined(USE_WEBKIT_COMPOSITOR)
1046 EXPECT_EQ(1.f, l1->web_layer().opacity()); 1059 EXPECT_EQ(1.f, l1->web_layer().opacity());
1047 #endif 1060 #endif
1048 } 1061 }
1049 1062
1063 // Checks that stacking-related methods behave as advertised.
1064 TEST_F(LayerWithNullDelegateTest, Stacking) {
1065 scoped_ptr<Layer> root(new Layer(Layer::LAYER_HAS_NO_TEXTURE));
1066 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE));
1067 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE));
1068 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE));
1069 l1->set_name("1");
1070 l2->set_name("2");
1071 l3->set_name("3");
1072 root->Add(l3.get());
1073 root->Add(l2.get());
1074 root->Add(l1.get());
1075
1076 // Layers' children are stored in bottom-to-top order.
1077 EXPECT_EQ("3,2,1", GetLayerChildrenNames(*root.get()));
1078
1079 root->StackAtTop(l3.get());
1080 EXPECT_EQ("2,1,3", GetLayerChildrenNames(*root.get()));
1081
1082 root->StackAtTop(l1.get());
1083 EXPECT_EQ("2,3,1", GetLayerChildrenNames(*root.get()));
1084
1085 root->StackAtTop(l1.get());
1086 EXPECT_EQ("2,3,1", GetLayerChildrenNames(*root.get()));
1087
1088 root->StackAbove(l2.get(), l3.get());
1089 EXPECT_EQ("3,2,1", GetLayerChildrenNames(*root.get()));
1090
1091 root->StackAbove(l1.get(), l3.get());
1092 EXPECT_EQ("3,1,2", GetLayerChildrenNames(*root.get()));
1093
1094 root->StackAbove(l2.get(), l1.get());
1095 EXPECT_EQ("3,1,2", GetLayerChildrenNames(*root.get()));
1096 }
1097
1050 // Checks that the invalid rect assumes correct values when setting bounds. 1098 // Checks that the invalid rect assumes correct values when setting bounds.
1051 // TODO(vollick): for USE_WEBKIT_COMPOSITOR, use WebKit's dirty rect. 1099 // TODO(vollick): for USE_WEBKIT_COMPOSITOR, use WebKit's dirty rect.
1052 TEST_F(LayerWithNullDelegateTest, 1100 TEST_F(LayerWithNullDelegateTest,
1053 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(SetBoundsInvalidRect)) { 1101 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(SetBoundsInvalidRect)) {
1054 scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200))); 1102 scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200)));
1055 compositor()->SetRootLayer(l1.get()); 1103 compositor()->SetRootLayer(l1.get());
1056 1104
1057 // After a draw the invalid rect should be empty. 1105 // After a draw the invalid rect should be empty.
1058 Draw(); 1106 Draw();
1059 EXPECT_TRUE(l1->invalid_rect().IsEmpty()); 1107 EXPECT_TRUE(l1->invalid_rect().IsEmpty());
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 l0->Add(l11.get()); 1338 l0->Add(l11.get());
1291 DrawTree(l0.get()); 1339 DrawTree(l0.get());
1292 SkBitmap bitmap; 1340 SkBitmap bitmap;
1293 ASSERT_TRUE(ReadPixels(&bitmap)); 1341 ASSERT_TRUE(ReadPixels(&bitmap));
1294 ASSERT_FALSE(bitmap.empty()); 1342 ASSERT_FALSE(bitmap.empty());
1295 // WritePNGFile(bitmap, ref_img); 1343 // WritePNGFile(bitmap, ref_img);
1296 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img)); 1344 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img));
1297 } 1345 }
1298 1346
1299 } // namespace ui 1347 } // namespace ui
OLDNEW
« ui/aura_shell/shadow_controller_unittest.cc ('K') | « ui/gfx/compositor/layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698