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

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

Issue 9225038: Fold views_compositor=1 into use_aura=1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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/widget/native_widget_win.cc » ('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 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2529 EXPECT_EQ(1, v1.GetIndexOf(&v3)); 2529 EXPECT_EQ(1, v1.GetIndexOf(&v3));
2530 v1.AddChildView(&v3); 2530 v1.AddChildView(&v3);
2531 EXPECT_EQ(0, v1.GetIndexOf(&v2)); 2531 EXPECT_EQ(0, v1.GetIndexOf(&v2));
2532 EXPECT_EQ(1, v1.GetIndexOf(&v3)); 2532 EXPECT_EQ(1, v1.GetIndexOf(&v3));
2533 } 2533 }
2534 2534
2535 //////////////////////////////////////////////////////////////////////////////// 2535 ////////////////////////////////////////////////////////////////////////////////
2536 // Layers 2536 // Layers
2537 //////////////////////////////////////////////////////////////////////////////// 2537 ////////////////////////////////////////////////////////////////////////////////
2538 2538
2539 #if defined(VIEWS_COMPOSITOR) 2539 #if defined(USE_AURA)
2540 2540
2541 namespace { 2541 namespace {
2542 2542
2543 // Test implementation of LayerAnimator. 2543 // Test implementation of LayerAnimator.
2544 class TestLayerAnimator : public ui::LayerAnimator { 2544 class TestLayerAnimator : public ui::LayerAnimator {
2545 public: 2545 public:
2546 TestLayerAnimator(); 2546 TestLayerAnimator();
2547 2547
2548 const gfx::Rect& last_bounds() const { return last_bounds_; } 2548 const gfx::Rect& last_bounds() const { return last_bounds_; }
2549 2549
(...skipping 18 matching lines...) Expand all
2568 2568
2569 class ViewLayerTest : public ViewsTestBase { 2569 class ViewLayerTest : public ViewsTestBase {
2570 public: 2570 public:
2571 ViewLayerTest() : widget_(NULL), old_use_acceleration_(false) {} 2571 ViewLayerTest() : widget_(NULL), old_use_acceleration_(false) {}
2572 2572
2573 virtual ~ViewLayerTest() { 2573 virtual ~ViewLayerTest() {
2574 } 2574 }
2575 2575
2576 // Returns the Layer used by the RootView. 2576 // Returns the Layer used by the RootView.
2577 ui::Layer* GetRootLayer() { 2577 ui::Layer* GetRootLayer() {
2578 #if defined(USE_AURA)
2579 ui::Layer* root_layer = NULL; 2578 ui::Layer* root_layer = NULL;
2580 gfx::Point origin; 2579 gfx::Point origin;
2581 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer); 2580 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer);
2582 return root_layer; 2581 return root_layer;
2583 #else
2584 return widget()->GetRootView()->layer();
2585 #endif
2586 } 2582 }
2587 2583
2588 virtual void SetUp() OVERRIDE { 2584 virtual void SetUp() OVERRIDE {
2589 ViewTest::SetUp(); 2585 ViewTest::SetUp();
2590 old_use_acceleration_ = View::get_use_acceleration_when_possible(); 2586 old_use_acceleration_ = View::get_use_acceleration_when_possible();
2591 View::set_use_acceleration_when_possible(true); 2587 View::set_use_acceleration_when_possible(true);
2592 2588
2593 widget_ = new Widget; 2589 widget_ = new Widget;
2594 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 2590 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
2595 params.bounds = gfx::Rect(50, 50, 200, 200); 2591 params.bounds = gfx::Rect(50, 50, 200, 200);
2596 widget_->Init(params); 2592 widget_->Init(params);
2597 widget_->Show(); 2593 widget_->Show();
2598 widget_->GetRootView()->SetBounds(0, 0, 200, 200); 2594 widget_->GetRootView()->SetBounds(0, 0, 200, 200);
2599 } 2595 }
2600 2596
2601 virtual void TearDown() OVERRIDE { 2597 virtual void TearDown() OVERRIDE {
2602 View::set_use_acceleration_when_possible(old_use_acceleration_); 2598 View::set_use_acceleration_when_possible(old_use_acceleration_);
2603 widget_->CloseNow(); 2599 widget_->CloseNow();
2604 Widget::SetPureViews(false); 2600 Widget::SetPureViews(false);
2605 ViewsTestBase::TearDown(); 2601 ViewsTestBase::TearDown();
2606 } 2602 }
2607 2603
2608 Widget* widget() { return widget_; } 2604 Widget* widget() { return widget_; }
2609 2605
2610 private: 2606 private:
2611 Widget* widget_; 2607 Widget* widget_;
2612 bool old_use_acceleration_; 2608 bool old_use_acceleration_;
2613 }; 2609 };
2614 2610
2615 #if !defined(USE_AURA)
2616 // This test assumes a particular layer hierarchy that isn't valid for aura.
2617 // Ensures the RootView has a layer and its set up correctly.
2618 TEST_F(ViewLayerTest, RootState) {
2619 ui::Layer* layer = widget()->GetRootView()->layer();
2620 ASSERT_TRUE(layer);
2621 EXPECT_FALSE(layer->parent());
2622 EXPECT_EQ(0u, layer->children().size());
2623 EXPECT_FALSE(layer->transform().HasChange());
2624 EXPECT_EQ(widget()->GetRootView()->bounds(), layer->bounds());
2625 EXPECT_TRUE(layer->GetCompositor() != NULL);
2626 }
2627
2628 // Verifies that the complete bounds of a texture are updated if the texture
2629 // needs to be refreshed and paint with a clip is invoked.
2630 // This test invokes OnNativeWidgetPaintAccelerated, which is not used by aura.
2631 TEST_F(ViewLayerTest, PaintAll) {
2632 View* view = widget()->GetRootView();
2633 ui::Layer* layer = GetRootLayer();
2634 view->SetBounds(0, 0, 200, 200);
2635 widget()->OnNativeWidgetPaintAccelerated(gfx::Rect(0, 0, 1, 1));
2636 ASSERT_TRUE(layer != NULL);
2637 const ui::TestTexture* texture =
2638 static_cast<const ui::TestTexture*>(layer->texture());
2639 ASSERT_TRUE(texture != NULL);
2640 EXPECT_EQ(view->GetLocalBounds(), texture->bounds_of_last_paint());
2641 }
2642 #endif
2643 2611
2644 TEST_F(ViewLayerTest, LayerToggling) { 2612 TEST_F(ViewLayerTest, LayerToggling) {
2645 // Because we lazily create textures the calls to DrawTree are necessary to 2613 // Because we lazily create textures the calls to DrawTree are necessary to
2646 // ensure we trigger creation of textures. 2614 // ensure we trigger creation of textures.
2647 #if defined(USE_AURA)
2648 ui::Layer* root_layer = NULL; 2615 ui::Layer* root_layer = NULL;
2649 gfx::Point origin; 2616 gfx::Point origin;
2650 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer); 2617 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer);
2651 #else
2652 ui::Layer* root_layer = widget()->GetRootView()->layer();
2653 #endif
2654 View* content_view = new View; 2618 View* content_view = new View;
2655 widget()->SetContentsView(content_view); 2619 widget()->SetContentsView(content_view);
2656 2620
2657 // Create v1, give it a bounds and verify everything is set up correctly. 2621 // Create v1, give it a bounds and verify everything is set up correctly.
2658 View* v1 = new View; 2622 View* v1 = new View;
2659 v1->SetPaintToLayer(true); 2623 v1->SetPaintToLayer(true);
2660 EXPECT_TRUE(v1->layer() != NULL); 2624 EXPECT_TRUE(v1->layer() != NULL);
2661 v1->SetBounds(20, 30, 140, 150); 2625 v1->SetBounds(20, 30, 140, 150);
2662 content_view->AddChildView(v1); 2626 content_view->AddChildView(v1);
2663 ASSERT_TRUE(v1->layer() != NULL); 2627 ASSERT_TRUE(v1->layer() != NULL);
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2975 ScrambleTree(content); 2939 ScrambleTree(content);
2976 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); 2940 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer()));
2977 2941
2978 ScrambleTree(content); 2942 ScrambleTree(content);
2979 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); 2943 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer()));
2980 2944
2981 ScrambleTree(content); 2945 ScrambleTree(content);
2982 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); 2946 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer()));
2983 } 2947 }
2984 2948
2985 #if defined(USE_AURA)
2986 // Verifies when views are reordered the layer is also reordered. The widget is 2949 // Verifies when views are reordered the layer is also reordered. The widget is
2987 // providing the parent layer. 2950 // providing the parent layer.
2988 TEST_F(ViewLayerTest, ReorderUnderWidget) { 2951 TEST_F(ViewLayerTest, ReorderUnderWidget) {
2989 View* content = new View; 2952 View* content = new View;
2990 widget()->SetContentsView(content); 2953 widget()->SetContentsView(content);
2991 View* c1 = new View; 2954 View* c1 = new View;
2992 c1->SetPaintToLayer(true); 2955 c1->SetPaintToLayer(true);
2993 content->AddChildView(c1); 2956 content->AddChildView(c1);
2994 View* c2 = new View; 2957 View* c2 = new View;
2995 c2->SetPaintToLayer(true); 2958 c2->SetPaintToLayer(true);
2996 content->AddChildView(c2); 2959 content->AddChildView(c2);
2997 2960
2998 ui::Layer* parent_layer = c1->layer()->parent(); 2961 ui::Layer* parent_layer = c1->layer()->parent();
2999 ASSERT_TRUE(parent_layer); 2962 ASSERT_TRUE(parent_layer);
3000 ASSERT_EQ(2u, parent_layer->children().size()); 2963 ASSERT_EQ(2u, parent_layer->children().size());
3001 EXPECT_EQ(c1->layer(), parent_layer->children()[0]); 2964 EXPECT_EQ(c1->layer(), parent_layer->children()[0]);
3002 EXPECT_EQ(c2->layer(), parent_layer->children()[1]); 2965 EXPECT_EQ(c2->layer(), parent_layer->children()[1]);
3003 2966
3004 // Move c1 to the front. The layers should have moved too. 2967 // Move c1 to the front. The layers should have moved too.
3005 content->ReorderChildView(c1, -1); 2968 content->ReorderChildView(c1, -1);
3006 EXPECT_EQ(c1->layer(), parent_layer->children()[1]); 2969 EXPECT_EQ(c1->layer(), parent_layer->children()[1]);
3007 EXPECT_EQ(c2->layer(), parent_layer->children()[0]); 2970 EXPECT_EQ(c2->layer(), parent_layer->children()[0]);
3008 } 2971 }
3009 #endif
3010 2972
3011 #endif // VIEWS_COMPOSITOR 2973 #endif // USE_AURA
3012 2974
3013 } // namespace views 2975 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/widget/native_widget_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698