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

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

Issue 8538018: Added a unittest for compositor observers. (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
« no previous file with comments | « no previous file | 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 (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/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/canvas_skia.h" 9 #include "ui/gfx/canvas_skia.h"
10 #include "ui/gfx/compositor/compositor_observer.h" 10 #include "ui/gfx/compositor/compositor_observer.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 virtual ~NullLayerDelegate() {} 166 virtual ~NullLayerDelegate() {}
167 167
168 private: 168 private:
169 // Overridden from LayerDelegate: 169 // Overridden from LayerDelegate:
170 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 170 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
171 } 171 }
172 172
173 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); 173 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate);
174 }; 174 };
175 175
176 // Remembers if it has been notified.
177 class TestCompositorObserver : public CompositorObserver {
178 public:
179 TestCompositorObserver() : notified_(false) {}
180
181 bool notified() const { return notified_; }
182
183 void Reset() { notified_ = false; }
184
185 private:
186 virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE {
187 notified_ = true;
188 }
189
190 bool notified_;
jonathan.backer 2011/11/11 20:17:16 DISALLOW_COPY_AND_ASSIGN
191 };
192
176 } 193 }
177 194
178 #if defined(OS_WIN) 195 #if defined(OS_WIN)
179 // These are disabled on windows as they don't run correctly on the buildbot. 196 // These are disabled on windows as they don't run correctly on the buildbot.
180 // Reenable once we move to the real compositor. 197 // Reenable once we move to the real compositor.
181 #define MAYBE_Delegate DISABLED_Delegate 198 #define MAYBE_Delegate DISABLED_Delegate
182 #define MAYBE_Draw DISABLED_Draw 199 #define MAYBE_Draw DISABLED_Draw
183 #define MAYBE_DrawTree DISABLED_DrawTree 200 #define MAYBE_DrawTree DISABLED_DrawTree
184 #define MAYBE_Hierarchy DISABLED_Hierarchy 201 #define MAYBE_Hierarchy DISABLED_Hierarchy
185 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture 202 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 814
798 SkAutoLockPixels lock(bitmap); 815 SkAutoLockPixels lock(bitmap);
799 bool is_all_red = true; 816 bool is_all_red = true;
800 for (int x = 0; is_all_red && x < 500; x++) 817 for (int x = 0; is_all_red && x < 500; x++)
801 for (int y = 0; is_all_red && y < 500; y++) 818 for (int y = 0; is_all_red && y < 500; y++)
802 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); 819 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED);
803 820
804 EXPECT_TRUE(is_all_red); 821 EXPECT_TRUE(is_all_red);
805 } 822 }
806 823
824 // Checks that compositor observers are notified when:
825 // - DrawTree is called,
826 // - After ScheduleDraw is called, or
827 // - Whenever SetBounds, SetOpacity or SetTransform are called.
828 TEST_F(LayerWithRealCompositorTest, CompositorObservers) {
829 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
830 gfx::Rect(20, 20, 400, 400)));
831 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
832 gfx::Rect(10, 10, 350, 350)));
833 l1->Add(l2.get());
834 TestCompositorObserver observer;
835 GetCompositor()->AddObserver(&observer);
836
837 // Explicitly called DrawTree should cause the observers to be notified.
838 DrawTree(l1.get());
839 RunPendingMessages();
840 EXPECT_TRUE(observer.notified());
841
842 // As should scheduling a draw and waiting.
843 observer.Reset();
844 l1->ScheduleDraw();
845 RunPendingMessages();
846 EXPECT_TRUE(observer.notified());
847
848 // Moving, but not resizing, a layer should alert the observers.
849 observer.Reset();
850 l2->SetBounds(gfx::Rect(0, 0, 350, 350));
851 RunPendingMessages();
852 EXPECT_TRUE(observer.notified());
853
854 // So should resizing a layer.
855 observer.Reset();
856 l2->SetBounds(gfx::Rect(0, 0, 400, 400));
857 RunPendingMessages();
858 EXPECT_TRUE(observer.notified());
859
860 // Opacity changes should alert the observers.
861 observer.Reset();
862 l2->SetOpacity(0.5f);
863 RunPendingMessages();
864 EXPECT_TRUE(observer.notified());
865
866 // So should setting the opacity back.
867 observer.Reset();
868 l2->SetOpacity(1.0f);
869 RunPendingMessages();
870 EXPECT_TRUE(observer.notified());
871
872 // Setting the transform of a layer should alert the observers.
873 observer.Reset();
874 Transform transform;
875 transform.ConcatTranslate(-200, -200);
876 transform.ConcatRotate(90.0f);
877 transform.ConcatTranslate(200, 200);
878 l2->SetTransform(transform);
879 RunPendingMessages();
880 EXPECT_TRUE(observer.notified());
881
882 GetCompositor()->RemoveObserver(&observer);
jonathan.backer 2011/11/11 20:17:16 Test this?
883 }
884
807 } // namespace ui 885 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698