OLD | NEW |
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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 2815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2826 | 2826 |
2827 View* parent_view = new View; | 2827 View* parent_view = new View; |
2828 content_view->AddChildView(parent_view); | 2828 content_view->AddChildView(parent_view); |
2829 parent_view->SetPaintToLayer(true); | 2829 parent_view->SetPaintToLayer(true); |
2830 parent_view->SetBounds(0, 0, 400, 400); | 2830 parent_view->SetBounds(0, 0, 400, 400); |
2831 | 2831 |
2832 View* child_view = new View; | 2832 View* child_view = new View; |
2833 child_view->SetBounds(50, 50, 100, 100); | 2833 child_view->SetBounds(50, 50, 100, 100); |
2834 parent_view->AddChildView(child_view); | 2834 parent_view->AddChildView(child_view); |
2835 | 2835 |
| 2836 widget()->GetCompositor()->Draw(false); |
| 2837 |
2836 ASSERT_TRUE(child_view->layer() == NULL); | 2838 ASSERT_TRUE(child_view->layer() == NULL); |
2837 child_view->SetPaintToLayer(true); | 2839 child_view->SetPaintToLayer(true); |
2838 child_view->SetFillsBoundsOpaquely(true); | 2840 child_view->SetFillsBoundsOpaquely(true); |
| 2841 widget()->GetCompositor()->Draw(false); |
2839 ASSERT_TRUE(child_view->layer()); | 2842 ASSERT_TRUE(child_view->layer()); |
2840 EXPECT_EQ( | 2843 EXPECT_EQ( |
2841 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); | 2844 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); |
2842 | 2845 |
2843 child_view->SetFillsBoundsOpaquely(false); | 2846 child_view->SetFillsBoundsOpaquely(false); |
| 2847 widget()->GetCompositor()->Draw(false); |
2844 EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty()); | 2848 EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty()); |
2845 } | 2849 } |
2846 | 2850 |
2847 // Test that a hole in a layer always corresponds to the bounds of opaque | 2851 // Test that a hole in a layer always corresponds to the bounds of opaque |
2848 // layers. | 2852 // layers. |
2849 TEST_F(ViewLayerTest, MultipleOpaqueLayers) { | 2853 TEST_F(ViewLayerTest, MultipleOpaqueLayers) { |
2850 View* content_view = new View; | 2854 View* content_view = new View; |
2851 widget()->SetContentsView(content_view); | 2855 widget()->SetContentsView(content_view); |
2852 | 2856 |
2853 View* parent_view = new View; | 2857 View* parent_view = new View; |
2854 parent_view->SetPaintToLayer(true); | 2858 parent_view->SetPaintToLayer(true); |
2855 parent_view->SetBounds(0, 0, 400, 400); | 2859 parent_view->SetBounds(0, 0, 400, 400); |
2856 content_view->AddChildView(parent_view); | 2860 content_view->AddChildView(parent_view); |
2857 | 2861 |
2858 View* child_view1 = new View; | 2862 View* child_view1 = new View; |
2859 child_view1->SetPaintToLayer(true); | 2863 child_view1->SetPaintToLayer(true); |
2860 child_view1->SetFillsBoundsOpaquely(true); | 2864 child_view1->SetFillsBoundsOpaquely(true); |
2861 child_view1->SetBounds(50, 50, 100, 100); | 2865 child_view1->SetBounds(50, 50, 100, 100); |
2862 parent_view->AddChildView(child_view1); | 2866 parent_view->AddChildView(child_view1); |
2863 | 2867 |
2864 View* child_view2 = new View; | 2868 View* child_view2 = new View; |
2865 child_view2->SetPaintToLayer(true); | 2869 child_view2->SetPaintToLayer(true); |
2866 child_view2->SetFillsBoundsOpaquely(false); | 2870 child_view2->SetFillsBoundsOpaquely(false); |
2867 child_view2->SetBounds(150, 150, 200, 200); | 2871 child_view2->SetBounds(150, 150, 200, 200); |
2868 parent_view->AddChildView(child_view2); | 2872 parent_view->AddChildView(child_view2); |
2869 | 2873 |
| 2874 widget()->GetCompositor()->Draw(false); |
| 2875 |
2870 // Only child_view1 is opaque | 2876 // Only child_view1 is opaque |
2871 EXPECT_EQ( | 2877 EXPECT_EQ( |
2872 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); | 2878 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); |
2873 | 2879 |
2874 // Both child views are opaque | 2880 // Both child views are opaque |
2875 child_view2->SetFillsBoundsOpaquely(true); | 2881 child_view2->SetFillsBoundsOpaquely(true); |
| 2882 widget()->GetCompositor()->Draw(false); |
2876 EXPECT_TRUE( | 2883 EXPECT_TRUE( |
2877 gfx::Rect(50, 50, 100, 100) == parent_view->layer()->hole_rect() || | 2884 gfx::Rect(50, 50, 100, 100) == parent_view->layer()->hole_rect() || |
2878 gfx::Rect(150, 150, 200, 200) == parent_view->layer()->hole_rect()); | 2885 gfx::Rect(150, 150, 200, 200) == parent_view->layer()->hole_rect()); |
2879 | 2886 |
2880 // Only child_view2 is opaque | 2887 // Only child_view2 is opaque |
2881 delete child_view1; | 2888 delete child_view1; |
2882 EXPECT_EQ( | 2889 EXPECT_EQ( |
2883 gfx::Rect(150, 150, 200, 200), parent_view->layer()->hole_rect()); | 2890 gfx::Rect(150, 150, 200, 200), parent_view->layer()->hole_rect()); |
2884 } | 2891 } |
2885 | 2892 |
2886 // Makes sure that opacity of layer persists after toggling visibilty. | 2893 // Makes sure that opacity of layer persists after toggling visibilty. |
2887 TEST_F(ViewLayerTest, ToggleVisibilityWithOpaqueLayer) { | 2894 TEST_F(ViewLayerTest, ToggleVisibilityWithOpaqueLayer) { |
2888 View* content_view = new View; | 2895 View* content_view = new View; |
2889 widget()->SetContentsView(content_view); | 2896 widget()->SetContentsView(content_view); |
2890 | 2897 |
2891 View* parent_view = new View; | 2898 View* parent_view = new View; |
2892 parent_view->SetPaintToLayer(true); | 2899 parent_view->SetPaintToLayer(true); |
2893 parent_view->SetBounds(0, 0, 400, 400); | 2900 parent_view->SetBounds(0, 0, 400, 400); |
2894 content_view->AddChildView(parent_view); | 2901 content_view->AddChildView(parent_view); |
2895 | 2902 |
2896 parent_view->SetPaintToLayer(true); | 2903 parent_view->SetPaintToLayer(true); |
2897 parent_view->SetBounds(0, 0, 400, 400); | 2904 parent_view->SetBounds(0, 0, 400, 400); |
2898 | 2905 |
2899 View* child_view = new View; | 2906 View* child_view = new View; |
2900 child_view->SetBounds(50, 50, 100, 100); | 2907 child_view->SetBounds(50, 50, 100, 100); |
2901 child_view->SetPaintToLayer(true); | 2908 child_view->SetPaintToLayer(true); |
2902 child_view->SetFillsBoundsOpaquely(true); | 2909 child_view->SetFillsBoundsOpaquely(true); |
2903 parent_view->AddChildView(child_view); | 2910 parent_view->AddChildView(child_view); |
| 2911 widget()->GetCompositor()->Draw(false); |
2904 EXPECT_EQ( | 2912 EXPECT_EQ( |
2905 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); | 2913 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); |
2906 | 2914 |
2907 child_view->SetVisible(false); | 2915 child_view->SetVisible(false); |
| 2916 widget()->GetCompositor()->Draw(false); |
2908 EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty()); | 2917 EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty()); |
2909 | 2918 |
2910 child_view->SetVisible(true); | 2919 child_view->SetVisible(true); |
| 2920 widget()->GetCompositor()->Draw(false); |
2911 EXPECT_EQ( | 2921 EXPECT_EQ( |
2912 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); | 2922 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); |
2913 } | 2923 } |
2914 | 2924 |
2915 // Tests that the layers in the subtree are orphaned after a View is removed | 2925 // Tests that the layers in the subtree are orphaned after a View is removed |
2916 // from the parent. | 2926 // from the parent. |
2917 TEST_F(ViewLayerTest, OrphanLayerAfterViewRemove) { | 2927 TEST_F(ViewLayerTest, OrphanLayerAfterViewRemove) { |
2918 View* content_view = new View; | 2928 View* content_view = new View; |
2919 widget()->SetContentsView(content_view); | 2929 widget()->SetContentsView(content_view); |
2920 | 2930 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3097 ScrambleTree(content); | 3107 ScrambleTree(content); |
3098 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3108 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
3099 | 3109 |
3100 ScrambleTree(content); | 3110 ScrambleTree(content); |
3101 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3111 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
3102 } | 3112 } |
3103 | 3113 |
3104 #endif // VIEWS_COMPOSITOR | 3114 #endif // VIEWS_COMPOSITOR |
3105 | 3115 |
3106 } // namespace views | 3116 } // namespace views |
OLD | NEW |