| 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 2800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2811 v1->SetVisible(true); | 2811 v1->SetVisible(true); |
| 2812 EXPECT_TRUE(v1->layer()->IsDrawn()); | 2812 EXPECT_TRUE(v1->layer()->IsDrawn()); |
| 2813 | 2813 |
| 2814 widget()->Hide(); | 2814 widget()->Hide(); |
| 2815 EXPECT_FALSE(v1->layer()->IsDrawn()); | 2815 EXPECT_FALSE(v1->layer()->IsDrawn()); |
| 2816 | 2816 |
| 2817 widget()->Show(); | 2817 widget()->Show(); |
| 2818 EXPECT_TRUE(v1->layer()->IsDrawn()); | 2818 EXPECT_TRUE(v1->layer()->IsDrawn()); |
| 2819 } | 2819 } |
| 2820 | 2820 |
| 2821 // We don't set the hole in the webkit compositor, so disable tests that rely on | |
| 2822 // it. | |
| 2823 #if defined(USE_WEBKIT_COMPOSITOR) | |
| 2824 #define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) DISABLED_ ## X | |
| 2825 #else | |
| 2826 #define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) X | |
| 2827 #endif | |
| 2828 | |
| 2829 // Test that a hole in a layer is correctly created regardless of whether | 2821 // Test that a hole in a layer is correctly created regardless of whether |
| 2830 // the opacity attribute is set before or after the layer is created. | 2822 // the opacity attribute is set before or after the layer is created. |
| 2831 TEST_F(ViewLayerTest, | 2823 TEST_F(ViewLayerTest, ToggleOpacityWithLayer) { |
| 2832 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(ToggleOpacityWithLayer)) { | |
| 2833 View* content_view = new View; | 2824 View* content_view = new View; |
| 2834 widget()->SetContentsView(content_view); | 2825 widget()->SetContentsView(content_view); |
| 2835 | 2826 |
| 2836 View* parent_view = new View; | 2827 View* parent_view = new View; |
| 2837 content_view->AddChildView(parent_view); | 2828 content_view->AddChildView(parent_view); |
| 2838 parent_view->SetPaintToLayer(true); | 2829 parent_view->SetPaintToLayer(true); |
| 2839 parent_view->SetBounds(0, 0, 400, 400); | 2830 parent_view->SetBounds(0, 0, 400, 400); |
| 2840 | 2831 |
| 2841 View* child_view = new View; | 2832 View* child_view = new View; |
| 2842 child_view->SetBounds(50, 50, 100, 100); | 2833 child_view->SetBounds(50, 50, 100, 100); |
| 2843 parent_view->AddChildView(child_view); | 2834 parent_view->AddChildView(child_view); |
| 2844 | 2835 |
| 2845 widget()->GetCompositor()->Draw(false); | 2836 widget()->GetCompositor()->Draw(false); |
| 2846 | 2837 |
| 2847 ASSERT_TRUE(child_view->layer() == NULL); | 2838 ASSERT_TRUE(child_view->layer() == NULL); |
| 2848 child_view->SetPaintToLayer(true); | 2839 child_view->SetPaintToLayer(true); |
| 2849 child_view->SetFillsBoundsOpaquely(true); | 2840 child_view->SetFillsBoundsOpaquely(true); |
| 2850 widget()->GetCompositor()->Draw(false); | 2841 widget()->GetCompositor()->Draw(false); |
| 2851 ASSERT_TRUE(child_view->layer()); | 2842 ASSERT_TRUE(child_view->layer()); |
| 2852 EXPECT_EQ( | 2843 EXPECT_EQ( |
| 2853 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); | 2844 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect()); |
| 2854 | 2845 |
| 2855 child_view->SetFillsBoundsOpaquely(false); | 2846 child_view->SetFillsBoundsOpaquely(false); |
| 2856 widget()->GetCompositor()->Draw(false); | 2847 widget()->GetCompositor()->Draw(false); |
| 2857 EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty()); | 2848 EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty()); |
| 2858 } | 2849 } |
| 2859 | 2850 |
| 2860 // 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 |
| 2861 // layers. | 2852 // layers. |
| 2862 TEST_F(ViewLayerTest, | 2853 TEST_F(ViewLayerTest, MultipleOpaqueLayers) { |
| 2863 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(MultipleOpaqueLayers)) { | |
| 2864 View* content_view = new View; | 2854 View* content_view = new View; |
| 2865 widget()->SetContentsView(content_view); | 2855 widget()->SetContentsView(content_view); |
| 2866 | 2856 |
| 2867 View* parent_view = new View; | 2857 View* parent_view = new View; |
| 2868 parent_view->SetPaintToLayer(true); | 2858 parent_view->SetPaintToLayer(true); |
| 2869 parent_view->SetBounds(0, 0, 400, 400); | 2859 parent_view->SetBounds(0, 0, 400, 400); |
| 2870 content_view->AddChildView(parent_view); | 2860 content_view->AddChildView(parent_view); |
| 2871 | 2861 |
| 2872 View* child_view1 = new View; | 2862 View* child_view1 = new View; |
| 2873 child_view1->SetPaintToLayer(true); | 2863 child_view1->SetPaintToLayer(true); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2894 gfx::Rect(50, 50, 100, 100) == parent_view->layer()->hole_rect() || | 2884 gfx::Rect(50, 50, 100, 100) == parent_view->layer()->hole_rect() || |
| 2895 gfx::Rect(150, 150, 200, 200) == parent_view->layer()->hole_rect()); | 2885 gfx::Rect(150, 150, 200, 200) == parent_view->layer()->hole_rect()); |
| 2896 | 2886 |
| 2897 // Only child_view2 is opaque | 2887 // Only child_view2 is opaque |
| 2898 delete child_view1; | 2888 delete child_view1; |
| 2899 EXPECT_EQ( | 2889 EXPECT_EQ( |
| 2900 gfx::Rect(150, 150, 200, 200), parent_view->layer()->hole_rect()); | 2890 gfx::Rect(150, 150, 200, 200), parent_view->layer()->hole_rect()); |
| 2901 } | 2891 } |
| 2902 | 2892 |
| 2903 // Makes sure that opacity of layer persists after toggling visibilty. | 2893 // Makes sure that opacity of layer persists after toggling visibilty. |
| 2904 TEST_F(ViewLayerTest, | 2894 TEST_F(ViewLayerTest, ToggleVisibilityWithOpaqueLayer) { |
| 2905 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(ToggleVisibilityWithOpaqueLayer)) { | |
| 2906 View* content_view = new View; | 2895 View* content_view = new View; |
| 2907 widget()->SetContentsView(content_view); | 2896 widget()->SetContentsView(content_view); |
| 2908 | 2897 |
| 2909 View* parent_view = new View; | 2898 View* parent_view = new View; |
| 2910 parent_view->SetPaintToLayer(true); | 2899 parent_view->SetPaintToLayer(true); |
| 2911 parent_view->SetBounds(0, 0, 400, 400); | 2900 parent_view->SetBounds(0, 0, 400, 400); |
| 2912 content_view->AddChildView(parent_view); | 2901 content_view->AddChildView(parent_view); |
| 2913 | 2902 |
| 2914 parent_view->SetPaintToLayer(true); | 2903 parent_view->SetPaintToLayer(true); |
| 2915 parent_view->SetBounds(0, 0, 400, 400); | 2904 parent_view->SetBounds(0, 0, 400, 400); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3070 ScrambleTree(content); | 3059 ScrambleTree(content); |
| 3071 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3060 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3072 | 3061 |
| 3073 ScrambleTree(content); | 3062 ScrambleTree(content); |
| 3074 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3063 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3075 } | 3064 } |
| 3076 | 3065 |
| 3077 #endif // VIEWS_COMPOSITOR | 3066 #endif // VIEWS_COMPOSITOR |
| 3078 | 3067 |
| 3079 } // namespace views | 3068 } // namespace views |
| OLD | NEW |