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

Side by Side Diff: ui/views/view_unittest.cc

Issue 9288053: Remove old (pre-webkit) compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 8 years, 10 months 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/views/view.cc ('k') | ui/views/views.gyp » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 25 matching lines...) Expand all
36 #include "ui/views/window/dialog_delegate.h" 36 #include "ui/views/window/dialog_delegate.h"
37 37
38 #if defined(OS_WIN) 38 #if defined(OS_WIN)
39 #include "ui/views/test/test_views_delegate.h" 39 #include "ui/views/test/test_views_delegate.h"
40 #endif 40 #endif
41 #if defined(USE_AURA) 41 #if defined(USE_AURA)
42 #include "ui/aura/event.h" 42 #include "ui/aura/event.h"
43 #include "ui/aura/root_window.h" 43 #include "ui/aura/root_window.h"
44 #include "ui/aura/gestures/gesture_recognizer.h" 44 #include "ui/aura/gestures/gesture_recognizer.h"
45 #endif 45 #endif
46 #if !defined(USE_WEBKIT_COMPOSITOR)
47 #include "ui/gfx/compositor/test/test_texture.h"
48 #endif
49 46
50 using ::testing::_; 47 using ::testing::_;
51 48
52 namespace { 49 namespace {
53 50
54 // Returns true if |ancestor| is an ancestor of |layer|. 51 // Returns true if |ancestor| is an ancestor of |layer|.
55 bool LayerIsAncestor(const ui::Layer* ancestor, const ui::Layer* layer) { 52 bool LayerIsAncestor(const ui::Layer* ancestor, const ui::Layer* layer) {
56 while (layer && layer != ancestor) 53 while (layer && layer != ancestor)
57 layer = layer->parent(); 54 layer = layer->parent();
58 return layer == ancestor; 55 return layer == ancestor;
(...skipping 2494 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 #else 2550 #else
2554 return widget()->GetRootView()->layer(); 2551 return widget()->GetRootView()->layer();
2555 #endif 2552 #endif
2556 } 2553 }
2557 2554
2558 virtual void SetUp() OVERRIDE { 2555 virtual void SetUp() OVERRIDE {
2559 ViewTest::SetUp(); 2556 ViewTest::SetUp();
2560 old_use_acceleration_ = View::get_use_acceleration_when_possible(); 2557 old_use_acceleration_ = View::get_use_acceleration_when_possible();
2561 View::set_use_acceleration_when_possible(true); 2558 View::set_use_acceleration_when_possible(true);
2562 2559
2563 #if !defined(USE_WEBKIT_COMPOSITOR)
2564 ui::TestTexture::reset_live_count();
2565 #endif
2566
2567 widget_ = new Widget; 2560 widget_ = new Widget;
2568 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 2561 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
2569 params.bounds = gfx::Rect(50, 50, 200, 200); 2562 params.bounds = gfx::Rect(50, 50, 200, 200);
2570 widget_->Init(params); 2563 widget_->Init(params);
2571 widget_->Show(); 2564 widget_->Show();
2572 widget_->GetRootView()->SetBounds(0, 0, 200, 200); 2565 widget_->GetRootView()->SetBounds(0, 0, 200, 200);
2573 } 2566 }
2574 2567
2575 virtual void TearDown() OVERRIDE { 2568 virtual void TearDown() OVERRIDE {
2576 View::set_use_acceleration_when_possible(old_use_acceleration_); 2569 View::set_use_acceleration_when_possible(old_use_acceleration_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2621 #if defined(USE_AURA) 2614 #if defined(USE_AURA)
2622 ui::Layer* root_layer = NULL; 2615 ui::Layer* root_layer = NULL;
2623 gfx::Point origin; 2616 gfx::Point origin;
2624 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer); 2617 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer);
2625 #else 2618 #else
2626 ui::Layer* root_layer = widget()->GetRootView()->layer(); 2619 ui::Layer* root_layer = widget()->GetRootView()->layer();
2627 #endif 2620 #endif
2628 View* content_view = new View; 2621 View* content_view = new View;
2629 widget()->SetContentsView(content_view); 2622 widget()->SetContentsView(content_view);
2630 2623
2631 #if !defined(USE_WEBKIT_COMPOSITOR)
2632 // TODO(piman): with the webkit compositor, we don't create Textures on
2633 // Layers. We're not supposed to be calling Layer::DrawTree. This test needs
2634 // refactoring to fully work in that case.
2635 root_layer->DrawTree();
2636 ui::TestTexture::reset_live_count();
2637 #endif
2638
2639 // Create v1, give it a bounds and verify everything is set up correctly. 2624 // Create v1, give it a bounds and verify everything is set up correctly.
2640 View* v1 = new View; 2625 View* v1 = new View;
2641 v1->SetPaintToLayer(true); 2626 v1->SetPaintToLayer(true);
2642 #if !defined(USE_WEBKIT_COMPOSITOR)
2643 root_layer->DrawTree();
2644 EXPECT_EQ(0, ui::TestTexture::live_count());
2645 #endif
2646 EXPECT_TRUE(v1->layer() != NULL); 2627 EXPECT_TRUE(v1->layer() != NULL);
2647 v1->SetBounds(20, 30, 140, 150); 2628 v1->SetBounds(20, 30, 140, 150);
2648 content_view->AddChildView(v1); 2629 content_view->AddChildView(v1);
2649 #if !defined(USE_WEBKIT_COMPOSITOR)
2650 root_layer->DrawTree();
2651 EXPECT_EQ(1, ui::TestTexture::live_count());
2652 #endif
2653 ASSERT_TRUE(v1->layer() != NULL); 2630 ASSERT_TRUE(v1->layer() != NULL);
2654 EXPECT_EQ(root_layer, v1->layer()->parent()); 2631 EXPECT_EQ(root_layer, v1->layer()->parent());
2655 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds()); 2632 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds());
2656 2633
2657 // Create v2 as a child of v1 and do basic assertion testing. 2634 // Create v2 as a child of v1 and do basic assertion testing.
2658 View* v2 = new View; 2635 View* v2 = new View;
2659 v1->AddChildView(v2); 2636 v1->AddChildView(v2);
2660 EXPECT_TRUE(v2->layer() == NULL); 2637 EXPECT_TRUE(v2->layer() == NULL);
2661 v2->SetBounds(10, 20, 30, 40); 2638 v2->SetBounds(10, 20, 30, 40);
2662 v2->SetPaintToLayer(true); 2639 v2->SetPaintToLayer(true);
2663 #if !defined(USE_WEBKIT_COMPOSITOR)
2664 root_layer->DrawTree();
2665 EXPECT_EQ(2, ui::TestTexture::live_count());
2666 #endif
2667 ASSERT_TRUE(v2->layer() != NULL); 2640 ASSERT_TRUE(v2->layer() != NULL);
2668 EXPECT_EQ(v1->layer(), v2->layer()->parent()); 2641 EXPECT_EQ(v1->layer(), v2->layer()->parent());
2669 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); 2642 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
2670 2643
2671 // Turn off v1s layer. v2 should still have a layer but its parent should have 2644 // Turn off v1s layer. v2 should still have a layer but its parent should have
2672 // changed. 2645 // changed.
2673 v1->SetPaintToLayer(false); 2646 v1->SetPaintToLayer(false);
2674 #if !defined(USE_WEBKIT_COMPOSITOR)
2675 root_layer->DrawTree();
2676 EXPECT_EQ(1, ui::TestTexture::live_count());
2677 #endif
2678 EXPECT_TRUE(v1->layer() == NULL); 2647 EXPECT_TRUE(v1->layer() == NULL);
2679 EXPECT_TRUE(v2->layer() != NULL); 2648 EXPECT_TRUE(v2->layer() != NULL);
2680 EXPECT_EQ(root_layer, v2->layer()->parent()); 2649 EXPECT_EQ(root_layer, v2->layer()->parent());
2681 ASSERT_EQ(1u, root_layer->children().size()); 2650 ASSERT_EQ(1u, root_layer->children().size());
2682 EXPECT_EQ(root_layer->children()[0], v2->layer()); 2651 EXPECT_EQ(root_layer->children()[0], v2->layer());
2683 // The bounds of the layer should have changed to be relative to the root view 2652 // The bounds of the layer should have changed to be relative to the root view
2684 // now. 2653 // now.
2685 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds()); 2654 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds());
2686 2655
2687 // Make v1 have a layer again and verify v2s layer is wired up correctly. 2656 // Make v1 have a layer again and verify v2s layer is wired up correctly.
2688 ui::Transform transform; 2657 ui::Transform transform;
2689 transform.SetScale(2.0f, 2.0f); 2658 transform.SetScale(2.0f, 2.0f);
2690 v1->SetTransform(transform); 2659 v1->SetTransform(transform);
2691 #if !defined(USE_WEBKIT_COMPOSITOR)
2692 root_layer->DrawTree();
2693 EXPECT_EQ(2, ui::TestTexture::live_count());
2694 #endif
2695 EXPECT_TRUE(v1->layer() != NULL); 2660 EXPECT_TRUE(v1->layer() != NULL);
2696 EXPECT_TRUE(v2->layer() != NULL); 2661 EXPECT_TRUE(v2->layer() != NULL);
2697 EXPECT_EQ(root_layer, v1->layer()->parent()); 2662 EXPECT_EQ(root_layer, v1->layer()->parent());
2698 EXPECT_EQ(v1->layer(), v2->layer()->parent()); 2663 EXPECT_EQ(v1->layer(), v2->layer()->parent());
2699 ASSERT_EQ(1u, root_layer->children().size()); 2664 ASSERT_EQ(1u, root_layer->children().size());
2700 EXPECT_EQ(root_layer->children()[0], v1->layer()); 2665 EXPECT_EQ(root_layer->children()[0], v1->layer());
2701 ASSERT_EQ(1u, v1->layer()->children().size()); 2666 ASSERT_EQ(1u, v1->layer()->children().size());
2702 EXPECT_EQ(v1->layer()->children()[0], v2->layer()); 2667 EXPECT_EQ(v1->layer()->children()[0], v2->layer());
2703 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); 2668 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
2704 } 2669 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2842 v1->SetVisible(true); 2807 v1->SetVisible(true);
2843 EXPECT_TRUE(v1->layer()->IsDrawn()); 2808 EXPECT_TRUE(v1->layer()->IsDrawn());
2844 2809
2845 widget()->Hide(); 2810 widget()->Hide();
2846 EXPECT_FALSE(v1->layer()->IsDrawn()); 2811 EXPECT_FALSE(v1->layer()->IsDrawn());
2847 2812
2848 widget()->Show(); 2813 widget()->Show();
2849 EXPECT_TRUE(v1->layer()->IsDrawn()); 2814 EXPECT_TRUE(v1->layer()->IsDrawn());
2850 } 2815 }
2851 2816
2852 // We don't set the hole in the webkit compositor, so disable tests that rely on
2853 // it.
2854 #if defined(USE_WEBKIT_COMPOSITOR)
2855 #define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) DISABLED_ ## X
2856 #else
2857 #define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) X
2858 #endif
2859
2860 // Test that a hole in a layer is correctly created regardless of whether
2861 // the opacity attribute is set before or after the layer is created.
2862 TEST_F(ViewLayerTest,
2863 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(ToggleOpacityWithLayer)) {
2864 View* content_view = new View;
2865 widget()->SetContentsView(content_view);
2866
2867 View* parent_view = new View;
2868 content_view->AddChildView(parent_view);
2869 parent_view->SetPaintToLayer(true);
2870 parent_view->SetBounds(0, 0, 400, 400);
2871
2872 View* child_view = new View;
2873 child_view->SetBounds(50, 50, 100, 100);
2874 parent_view->AddChildView(child_view);
2875
2876 widget()->GetCompositor()->Draw(false);
2877
2878 ASSERT_TRUE(child_view->layer() == NULL);
2879 child_view->SetPaintToLayer(true);
2880 child_view->SetFillsBoundsOpaquely(true);
2881 widget()->GetCompositor()->Draw(false);
2882 ASSERT_TRUE(child_view->layer());
2883 EXPECT_EQ(
2884 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect());
2885
2886 child_view->SetFillsBoundsOpaquely(false);
2887 widget()->GetCompositor()->Draw(false);
2888 EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty());
2889 }
2890
2891 // Test that a hole in a layer always corresponds to the bounds of opaque
2892 // layers.
2893 TEST_F(ViewLayerTest,
2894 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(MultipleOpaqueLayers)) {
2895 View* content_view = new View;
2896 widget()->SetContentsView(content_view);
2897
2898 View* parent_view = new View;
2899 parent_view->SetPaintToLayer(true);
2900 parent_view->SetBounds(0, 0, 400, 400);
2901 content_view->AddChildView(parent_view);
2902
2903 View* child_view1 = new View;
2904 child_view1->SetPaintToLayer(true);
2905 child_view1->SetFillsBoundsOpaquely(true);
2906 child_view1->SetBounds(50, 50, 100, 100);
2907 parent_view->AddChildView(child_view1);
2908
2909 View* child_view2 = new View;
2910 child_view2->SetPaintToLayer(true);
2911 child_view2->SetFillsBoundsOpaquely(false);
2912 child_view2->SetBounds(150, 150, 200, 200);
2913 parent_view->AddChildView(child_view2);
2914
2915 widget()->GetCompositor()->Draw(false);
2916
2917 // Only child_view1 is opaque
2918 EXPECT_EQ(
2919 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect());
2920
2921 // Both child views are opaque
2922 child_view2->SetFillsBoundsOpaquely(true);
2923 widget()->GetCompositor()->Draw(false);
2924 EXPECT_TRUE(
2925 gfx::Rect(50, 50, 100, 100) == parent_view->layer()->hole_rect() ||
2926 gfx::Rect(150, 150, 200, 200) == parent_view->layer()->hole_rect());
2927
2928 // Only child_view2 is opaque
2929 delete child_view1;
2930 EXPECT_EQ(
2931 gfx::Rect(150, 150, 200, 200), parent_view->layer()->hole_rect());
2932 }
2933
2934 // Makes sure that opacity of layer persists after toggling visibilty.
2935 TEST_F(ViewLayerTest,
2936 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(ToggleVisibilityWithOpaqueLayer)) {
2937 View* content_view = new View;
2938 widget()->SetContentsView(content_view);
2939
2940 View* parent_view = new View;
2941 parent_view->SetPaintToLayer(true);
2942 parent_view->SetBounds(0, 0, 400, 400);
2943 content_view->AddChildView(parent_view);
2944
2945 parent_view->SetPaintToLayer(true);
2946 parent_view->SetBounds(0, 0, 400, 400);
2947
2948 View* child_view = new View;
2949 child_view->SetBounds(50, 50, 100, 100);
2950 child_view->SetPaintToLayer(true);
2951 child_view->SetFillsBoundsOpaquely(true);
2952 parent_view->AddChildView(child_view);
2953 widget()->GetCompositor()->Draw(false);
2954 EXPECT_EQ(
2955 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect());
2956
2957 child_view->SetVisible(false);
2958 widget()->GetCompositor()->Draw(false);
2959 EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty());
2960
2961 child_view->SetVisible(true);
2962 widget()->GetCompositor()->Draw(false);
2963 EXPECT_EQ(
2964 gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect());
2965 }
2966
2967 // Tests that the layers in the subtree are orphaned after a View is removed 2817 // Tests that the layers in the subtree are orphaned after a View is removed
2968 // from the parent. 2818 // from the parent.
2969 TEST_F(ViewLayerTest, OrphanLayerAfterViewRemove) { 2819 TEST_F(ViewLayerTest, OrphanLayerAfterViewRemove) {
2970 View* content_view = new View; 2820 View* content_view = new View;
2971 widget()->SetContentsView(content_view); 2821 widget()->SetContentsView(content_view);
2972 2822
2973 View* v1 = new View; 2823 View* v1 = new View;
2974 content_view->AddChildView(v1); 2824 content_view->AddChildView(v1);
2975 2825
2976 View* v2 = new View; 2826 View* v2 = new View;
(...skipping 25 matching lines...) Expand all
3002 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 2852 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
3003 painted_ = true; 2853 painted_ = true;
3004 } 2854 }
3005 2855
3006 private: 2856 private:
3007 bool painted_; 2857 bool painted_;
3008 2858
3009 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); 2859 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView);
3010 }; 2860 };
3011 2861
3012 #if !defined(USE_WEBKIT_COMPOSITOR)
3013 // TODO(piman): this test relies on the way the non-webkit compositor works.
3014 // Layer::DrawTree should not be called with the webkit compositor. In the
3015 // WebKit case, it needs to go through the "real" compositor (not the test one)
3016 // to do the paints on the layer/views.
3017
3018 // Makes sure child views with layers aren't painted when paint starts at an 2862 // Makes sure child views with layers aren't painted when paint starts at an
3019 // ancestor. 2863 // ancestor.
3020 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { 2864 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) {
3021 PaintTrackingView* content_view = new PaintTrackingView; 2865 PaintTrackingView* content_view = new PaintTrackingView;
3022 widget()->SetContentsView(content_view); 2866 widget()->SetContentsView(content_view);
3023 content_view->SetPaintToLayer(true); 2867 content_view->SetPaintToLayer(true);
3024 GetRootLayer()->DrawTree(); 2868 // TODO(piman): Compositor::Draw() won't work for the threaded compositor.
2869 GetRootLayer()->GetCompositor()->Draw(false);
3025 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); 2870 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10));
3026 content_view->set_painted(false); 2871 content_view->set_painted(false);
3027 // content_view no longer has a dirty rect. Paint from the root and make sure 2872 // content_view no longer has a dirty rect. Paint from the root and make sure
3028 // PaintTrackingView isn't painted. 2873 // PaintTrackingView isn't painted.
3029 GetRootLayer()->DrawTree(); 2874 GetRootLayer()->GetCompositor()->Draw(false);
3030 EXPECT_FALSE(content_view->painted()); 2875 EXPECT_FALSE(content_view->painted());
3031 2876
3032 // Make content_view have a dirty rect, paint the layers and make sure 2877 // Make content_view have a dirty rect, paint the layers and make sure
3033 // PaintTrackingView is painted. 2878 // PaintTrackingView is painted.
3034 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); 2879 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10));
3035 GetRootLayer()->DrawTree(); 2880 GetRootLayer()->GetCompositor()->Draw(false);
3036 EXPECT_TRUE(content_view->painted()); 2881 EXPECT_TRUE(content_view->painted());
3037 } 2882 }
3038 #endif
3039 2883
3040 // Tests that the visibility of child layers are updated correctly when a View's 2884 // Tests that the visibility of child layers are updated correctly when a View's
3041 // visibility changes. 2885 // visibility changes.
3042 TEST_F(ViewLayerTest, VisibilityChildLayers) { 2886 TEST_F(ViewLayerTest, VisibilityChildLayers) {
3043 View* v1 = new View; 2887 View* v1 = new View;
3044 v1->SetPaintToLayer(true); 2888 v1->SetPaintToLayer(true);
3045 widget()->SetContentsView(v1); 2889 widget()->SetContentsView(v1);
3046 2890
3047 View* v2 = new View; 2891 View* v2 = new View;
3048 v1->AddChildView(v2); 2892 v1->AddChildView(v2);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3127 // Move c1 to the front. The layers should have moved too. 2971 // Move c1 to the front. The layers should have moved too.
3128 content->ReorderChildView(c1, -1); 2972 content->ReorderChildView(c1, -1);
3129 EXPECT_EQ(c1->layer(), parent_layer->children()[1]); 2973 EXPECT_EQ(c1->layer(), parent_layer->children()[1]);
3130 EXPECT_EQ(c2->layer(), parent_layer->children()[0]); 2974 EXPECT_EQ(c2->layer(), parent_layer->children()[0]);
3131 } 2975 }
3132 #endif 2976 #endif
3133 2977
3134 #endif // VIEWS_COMPOSITOR 2978 #endif // VIEWS_COMPOSITOR
3135 2979
3136 } // namespace views 2980 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698