| 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" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "ui/base/accelerators/accelerator.h" | 12 #include "ui/base/accelerators/accelerator.h" |
| 13 #include "ui/base/clipboard/clipboard.h" | 13 #include "ui/base/clipboard/clipboard.h" |
| 14 #include "ui/base/keycodes/keyboard_codes.h" | 14 #include "ui/base/keycodes/keyboard_codes.h" |
| 15 #include "ui/base/models/simple_menu_model.h" | 15 #include "ui/base/models/simple_menu_model.h" |
| 16 #include "ui/gfx/canvas_skia.h" | 16 #include "ui/gfx/canvas_skia.h" |
| 17 #include "ui/gfx/compositor/compositor.h" | 17 #include "ui/gfx/compositor/compositor.h" |
| 18 #include "ui/gfx/compositor/layer.h" | 18 #include "ui/gfx/compositor/layer.h" |
| 19 #include "ui/gfx/compositor/layer_animator.h" | 19 #include "ui/gfx/compositor/layer_animator.h" |
| 20 #include "ui/gfx/compositor/test/test_compositor.h" | |
| 21 #include "ui/gfx/compositor/test/test_texture.h" | |
| 22 #include "ui/gfx/path.h" | 20 #include "ui/gfx/path.h" |
| 23 #include "ui/gfx/transform.h" | 21 #include "ui/gfx/transform.h" |
| 24 #include "ui/views/background.h" | 22 #include "ui/views/background.h" |
| 25 #include "ui/views/controls/button/button_dropdown.h" | 23 #include "ui/views/controls/button/button_dropdown.h" |
| 26 #include "ui/views/controls/button/checkbox.h" | 24 #include "ui/views/controls/button/checkbox.h" |
| 27 #include "ui/views/controls/native/native_view_host.h" | 25 #include "ui/views/controls/native/native_view_host.h" |
| 28 #include "ui/views/controls/scroll_view.h" | 26 #include "ui/views/controls/scroll_view.h" |
| 29 #include "ui/views/controls/textfield/textfield.h" | 27 #include "ui/views/controls/textfield/textfield.h" |
| 30 #include "ui/views/events/event.h" | 28 #include "ui/views/events/event.h" |
| 31 #include "ui/views/focus/accelerator_handler.h" | 29 #include "ui/views/focus/accelerator_handler.h" |
| (...skipping 2492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2524 #else | 2522 #else |
| 2525 return widget()->GetRootView()->layer(); | 2523 return widget()->GetRootView()->layer(); |
| 2526 #endif | 2524 #endif |
| 2527 } | 2525 } |
| 2528 | 2526 |
| 2529 virtual void SetUp() OVERRIDE { | 2527 virtual void SetUp() OVERRIDE { |
| 2530 ViewTest::SetUp(); | 2528 ViewTest::SetUp(); |
| 2531 old_use_acceleration_ = View::get_use_acceleration_when_possible(); | 2529 old_use_acceleration_ = View::get_use_acceleration_when_possible(); |
| 2532 View::set_use_acceleration_when_possible(true); | 2530 View::set_use_acceleration_when_possible(true); |
| 2533 | 2531 |
| 2534 ui::TestTexture::reset_live_count(); | |
| 2535 | |
| 2536 widget_ = new Widget; | 2532 widget_ = new Widget; |
| 2537 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 2533 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
| 2538 params.bounds = gfx::Rect(50, 50, 200, 200); | 2534 params.bounds = gfx::Rect(50, 50, 200, 200); |
| 2539 widget_->Init(params); | 2535 widget_->Init(params); |
| 2540 widget_->Show(); | 2536 widget_->Show(); |
| 2541 widget_->GetRootView()->SetBounds(0, 0, 200, 200); | 2537 widget_->GetRootView()->SetBounds(0, 0, 200, 200); |
| 2542 } | 2538 } |
| 2543 | 2539 |
| 2544 virtual void TearDown() OVERRIDE { | 2540 virtual void TearDown() OVERRIDE { |
| 2545 View::set_use_acceleration_when_possible(old_use_acceleration_); | 2541 View::set_use_acceleration_when_possible(old_use_acceleration_); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2590 #if defined(USE_AURA) | 2586 #if defined(USE_AURA) |
| 2591 ui::Layer* root_layer = NULL; | 2587 ui::Layer* root_layer = NULL; |
| 2592 gfx::Point origin; | 2588 gfx::Point origin; |
| 2593 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer); | 2589 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer); |
| 2594 #else | 2590 #else |
| 2595 ui::Layer* root_layer = widget()->GetRootView()->layer(); | 2591 ui::Layer* root_layer = widget()->GetRootView()->layer(); |
| 2596 #endif | 2592 #endif |
| 2597 View* content_view = new View; | 2593 View* content_view = new View; |
| 2598 widget()->SetContentsView(content_view); | 2594 widget()->SetContentsView(content_view); |
| 2599 | 2595 |
| 2600 #if !defined(USE_WEBKIT_COMPOSITOR) | |
| 2601 // TODO(piman): with the webkit compositor, we don't create Textures on | |
| 2602 // Layers. We're not supposed to be calling Layer::DrawTree. This test needs | |
| 2603 // refactoring to fully work in that case. | |
| 2604 root_layer->DrawTree(); | |
| 2605 ui::TestTexture::reset_live_count(); | |
| 2606 #endif | |
| 2607 | |
| 2608 // Create v1, give it a bounds and verify everything is set up correctly. | 2596 // Create v1, give it a bounds and verify everything is set up correctly. |
| 2609 View* v1 = new View; | 2597 View* v1 = new View; |
| 2610 v1->SetPaintToLayer(true); | 2598 v1->SetPaintToLayer(true); |
| 2611 #if !defined(USE_WEBKIT_COMPOSITOR) | |
| 2612 root_layer->DrawTree(); | |
| 2613 EXPECT_EQ(0, ui::TestTexture::live_count()); | |
| 2614 #endif | |
| 2615 EXPECT_TRUE(v1->layer() != NULL); | 2599 EXPECT_TRUE(v1->layer() != NULL); |
| 2616 v1->SetBounds(20, 30, 140, 150); | 2600 v1->SetBounds(20, 30, 140, 150); |
| 2617 content_view->AddChildView(v1); | 2601 content_view->AddChildView(v1); |
| 2618 #if !defined(USE_WEBKIT_COMPOSITOR) | |
| 2619 root_layer->DrawTree(); | |
| 2620 EXPECT_EQ(1, ui::TestTexture::live_count()); | |
| 2621 #endif | |
| 2622 ASSERT_TRUE(v1->layer() != NULL); | 2602 ASSERT_TRUE(v1->layer() != NULL); |
| 2623 EXPECT_EQ(root_layer, v1->layer()->parent()); | 2603 EXPECT_EQ(root_layer, v1->layer()->parent()); |
| 2624 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds()); | 2604 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds()); |
| 2625 | 2605 |
| 2626 // Create v2 as a child of v1 and do basic assertion testing. | 2606 // Create v2 as a child of v1 and do basic assertion testing. |
| 2627 View* v2 = new View; | 2607 View* v2 = new View; |
| 2628 v1->AddChildView(v2); | 2608 v1->AddChildView(v2); |
| 2629 EXPECT_TRUE(v2->layer() == NULL); | 2609 EXPECT_TRUE(v2->layer() == NULL); |
| 2630 v2->SetBounds(10, 20, 30, 40); | 2610 v2->SetBounds(10, 20, 30, 40); |
| 2631 v2->SetPaintToLayer(true); | 2611 v2->SetPaintToLayer(true); |
| 2632 #if !defined(USE_WEBKIT_COMPOSITOR) | |
| 2633 root_layer->DrawTree(); | |
| 2634 EXPECT_EQ(2, ui::TestTexture::live_count()); | |
| 2635 #endif | |
| 2636 ASSERT_TRUE(v2->layer() != NULL); | 2612 ASSERT_TRUE(v2->layer() != NULL); |
| 2637 EXPECT_EQ(v1->layer(), v2->layer()->parent()); | 2613 EXPECT_EQ(v1->layer(), v2->layer()->parent()); |
| 2638 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); | 2614 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); |
| 2639 | 2615 |
| 2640 // Turn off v1s layer. v2 should still have a layer but its parent should have | 2616 // Turn off v1s layer. v2 should still have a layer but its parent should have |
| 2641 // changed. | 2617 // changed. |
| 2642 v1->SetPaintToLayer(false); | 2618 v1->SetPaintToLayer(false); |
| 2643 #if !defined(USE_WEBKIT_COMPOSITOR) | |
| 2644 root_layer->DrawTree(); | |
| 2645 EXPECT_EQ(1, ui::TestTexture::live_count()); | |
| 2646 #endif | |
| 2647 EXPECT_TRUE(v1->layer() == NULL); | 2619 EXPECT_TRUE(v1->layer() == NULL); |
| 2648 EXPECT_TRUE(v2->layer() != NULL); | 2620 EXPECT_TRUE(v2->layer() != NULL); |
| 2649 EXPECT_EQ(root_layer, v2->layer()->parent()); | 2621 EXPECT_EQ(root_layer, v2->layer()->parent()); |
| 2650 ASSERT_EQ(1u, root_layer->children().size()); | 2622 ASSERT_EQ(1u, root_layer->children().size()); |
| 2651 EXPECT_EQ(root_layer->children()[0], v2->layer()); | 2623 EXPECT_EQ(root_layer->children()[0], v2->layer()); |
| 2652 // The bounds of the layer should have changed to be relative to the root view | 2624 // The bounds of the layer should have changed to be relative to the root view |
| 2653 // now. | 2625 // now. |
| 2654 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds()); | 2626 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds()); |
| 2655 | 2627 |
| 2656 // Make v1 have a layer again and verify v2s layer is wired up correctly. | 2628 // Make v1 have a layer again and verify v2s layer is wired up correctly. |
| 2657 ui::Transform transform; | 2629 ui::Transform transform; |
| 2658 transform.SetScale(2.0f, 2.0f); | 2630 transform.SetScale(2.0f, 2.0f); |
| 2659 v1->SetTransform(transform); | 2631 v1->SetTransform(transform); |
| 2660 #if !defined(USE_WEBKIT_COMPOSITOR) | |
| 2661 root_layer->DrawTree(); | |
| 2662 EXPECT_EQ(2, ui::TestTexture::live_count()); | |
| 2663 #endif | |
| 2664 EXPECT_TRUE(v1->layer() != NULL); | 2632 EXPECT_TRUE(v1->layer() != NULL); |
| 2665 EXPECT_TRUE(v2->layer() != NULL); | 2633 EXPECT_TRUE(v2->layer() != NULL); |
| 2666 EXPECT_EQ(root_layer, v1->layer()->parent()); | 2634 EXPECT_EQ(root_layer, v1->layer()->parent()); |
| 2667 EXPECT_EQ(v1->layer(), v2->layer()->parent()); | 2635 EXPECT_EQ(v1->layer(), v2->layer()->parent()); |
| 2668 ASSERT_EQ(1u, root_layer->children().size()); | 2636 ASSERT_EQ(1u, root_layer->children().size()); |
| 2669 EXPECT_EQ(root_layer->children()[0], v1->layer()); | 2637 EXPECT_EQ(root_layer->children()[0], v1->layer()); |
| 2670 ASSERT_EQ(1u, v1->layer()->children().size()); | 2638 ASSERT_EQ(1u, v1->layer()->children().size()); |
| 2671 EXPECT_EQ(v1->layer()->children()[0], v2->layer()); | 2639 EXPECT_EQ(v1->layer()->children()[0], v2->layer()); |
| 2672 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); | 2640 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); |
| 2673 } | 2641 } |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3059 ScrambleTree(content); | 3027 ScrambleTree(content); |
| 3060 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3028 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3061 | 3029 |
| 3062 ScrambleTree(content); | 3030 ScrambleTree(content); |
| 3063 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3031 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3064 } | 3032 } |
| 3065 | 3033 |
| 3066 #endif // VIEWS_COMPOSITOR | 3034 #endif // VIEWS_COMPOSITOR |
| 3067 | 3035 |
| 3068 } // namespace views | 3036 } // namespace views |
| OLD | NEW |