OLD | NEW |
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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 3525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3536 v->AddChildView(v2); | 3536 v->AddChildView(v2); |
3537 | 3537 |
3538 // Test the initial z-order. | 3538 // Test the initial z-order. |
3539 const std::vector<ui::Layer*>& child_layers_pre = v->layer()->children(); | 3539 const std::vector<ui::Layer*>& child_layers_pre = v->layer()->children(); |
3540 ASSERT_EQ(2u, child_layers_pre.size()); | 3540 ASSERT_EQ(2u, child_layers_pre.size()); |
3541 EXPECT_EQ(v1->layer(), child_layers_pre[0]); | 3541 EXPECT_EQ(v1->layer(), child_layers_pre[0]); |
3542 EXPECT_EQ(v2->layer(), child_layers_pre[1]); | 3542 EXPECT_EQ(v2->layer(), child_layers_pre[1]); |
3543 | 3543 |
3544 scoped_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); | 3544 scoped_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); |
3545 | 3545 |
3546 // Test the new layer order. |v1_old_layer| should be above the layers | 3546 // Test the new layer order. We expect: |v1| |v1_old_layer| |v2|. |
3547 // for |v1| and |v2|. | 3547 // for |v1| and |v2|. |
3548 const std::vector<ui::Layer*>& child_layers_post = v->layer()->children(); | 3548 const std::vector<ui::Layer*>& child_layers_post = v->layer()->children(); |
3549 ASSERT_EQ(3u, child_layers_post.size()); | 3549 ASSERT_EQ(3u, child_layers_post.size()); |
3550 EXPECT_EQ(v1->layer(), child_layers_post[0]); | 3550 EXPECT_EQ(v1->layer(), child_layers_post[0]); |
3551 EXPECT_EQ(v2->layer(), child_layers_post[1]); | 3551 EXPECT_EQ(v1_old_layer, child_layers_post[1]); |
3552 EXPECT_EQ(v1_old_layer, child_layers_post[2]); | 3552 EXPECT_EQ(v2->layer(), child_layers_post[2]); |
3553 } | 3553 } |
3554 | 3554 |
3555 // Verify the z-order of the layers as a result of calling RecreateLayer when | 3555 // Verify the z-order of the layers as a result of calling RecreateLayer when |
3556 // the widget is the parent with the layer. | 3556 // the widget is the parent with the layer. |
3557 TEST_F(ViewLayerTest, RecreateLayerZOrderWidgetParent) { | 3557 TEST_F(ViewLayerTest, RecreateLayerZOrderWidgetParent) { |
3558 View* v = new View(); | 3558 View* v = new View(); |
3559 widget()->SetContentsView(v); | 3559 widget()->SetContentsView(v); |
3560 | 3560 |
3561 View* v1 = new View(); | 3561 View* v1 = new View(); |
3562 v1->SetPaintToLayer(true); | 3562 v1->SetPaintToLayer(true); |
3563 v->AddChildView(v1); | 3563 v->AddChildView(v1); |
3564 View* v2 = new View(); | 3564 View* v2 = new View(); |
3565 v2->SetPaintToLayer(true); | 3565 v2->SetPaintToLayer(true); |
3566 v->AddChildView(v2); | 3566 v->AddChildView(v2); |
3567 | 3567 |
3568 ui::Layer* root_layer = GetRootLayer(); | 3568 ui::Layer* root_layer = GetRootLayer(); |
3569 | 3569 |
3570 // Test the initial z-order. | 3570 // Test the initial z-order. |
3571 const std::vector<ui::Layer*>& child_layers_pre = root_layer->children(); | 3571 const std::vector<ui::Layer*>& child_layers_pre = root_layer->children(); |
3572 ASSERT_EQ(2u, child_layers_pre.size()); | 3572 ASSERT_EQ(2u, child_layers_pre.size()); |
3573 EXPECT_EQ(v1->layer(), child_layers_pre[0]); | 3573 EXPECT_EQ(v1->layer(), child_layers_pre[0]); |
3574 EXPECT_EQ(v2->layer(), child_layers_pre[1]); | 3574 EXPECT_EQ(v2->layer(), child_layers_pre[1]); |
3575 | 3575 |
3576 scoped_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); | 3576 scoped_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); |
3577 | 3577 |
3578 // Test the new layer order. |v1_old_layer| should be above the layers | 3578 // Test the new layer order. We expect: |v1| |v1_old_layer| |v2|. |
3579 // for |v1| and |v2|. | |
3580 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); | 3579 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); |
3581 ASSERT_EQ(3u, child_layers_post.size()); | 3580 ASSERT_EQ(3u, child_layers_post.size()); |
3582 EXPECT_EQ(v1->layer(), child_layers_post[0]); | 3581 EXPECT_EQ(v1->layer(), child_layers_post[0]); |
3583 EXPECT_EQ(v2->layer(), child_layers_post[1]); | 3582 EXPECT_EQ(v1_old_layer, child_layers_post[1]); |
3584 EXPECT_EQ(v1_old_layer, child_layers_post[2]); | 3583 EXPECT_EQ(v2->layer(), child_layers_post[2]); |
| 3584 } |
| 3585 |
| 3586 // Verifies RecreateLayer() moves all Layers over, even those that don't have |
| 3587 // a View. |
| 3588 TEST_F(ViewLayerTest, RecreateLayerMovesNonViewChildren) { |
| 3589 View v; |
| 3590 v.SetPaintToLayer(true); |
| 3591 View child; |
| 3592 child.SetPaintToLayer(true); |
| 3593 v.AddChildView(&child); |
| 3594 ASSERT_TRUE(v.layer() != NULL); |
| 3595 ASSERT_EQ(1u, v.layer()->children().size()); |
| 3596 EXPECT_EQ(v.layer()->children()[0], child.layer()); |
| 3597 |
| 3598 ui::Layer layer(ui::LAYER_NOT_DRAWN); |
| 3599 v.layer()->Add(&layer); |
| 3600 v.layer()->StackAtBottom(&layer); |
| 3601 |
| 3602 scoped_ptr<ui::Layer> old_layer(v.RecreateLayer()); |
| 3603 |
| 3604 // All children should be moved from old layer to new layer. |
| 3605 ASSERT_TRUE(old_layer.get() != NULL); |
| 3606 EXPECT_TRUE(old_layer->children().empty()); |
| 3607 |
| 3608 // And new layer should have the two children. |
| 3609 ASSERT_TRUE(v.layer() != NULL); |
| 3610 ASSERT_EQ(2u, v.layer()->children().size()); |
| 3611 EXPECT_EQ(v.layer()->children()[0], &layer); |
| 3612 EXPECT_EQ(v.layer()->children()[1], child.layer()); |
3585 } | 3613 } |
3586 | 3614 |
3587 TEST_F(ViewTest, FocusableAssertions) { | 3615 TEST_F(ViewTest, FocusableAssertions) { |
3588 // View subclasses may change insets based on whether they are focusable, | 3616 // View subclasses may change insets based on whether they are focusable, |
3589 // which effects the preferred size. To avoid preferred size changing around | 3617 // which effects the preferred size. To avoid preferred size changing around |
3590 // these Views need to key off the last value set to SetFocusable(), not | 3618 // these Views need to key off the last value set to SetFocusable(), not |
3591 // whether the View is focusable right now. For this reason it's important | 3619 // whether the View is focusable right now. For this reason it's important |
3592 // that focusable() return the last value passed to SetFocusable and not | 3620 // that focusable() return the last value passed to SetFocusable and not |
3593 // whether the View is focusable right now. | 3621 // whether the View is focusable right now. |
3594 TestView view; | 3622 TestView view; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3690 ASSERT_EQ("v5", ui::test::ChildLayerNamesAsString(*w2_layer)); | 3718 ASSERT_EQ("v5", ui::test::ChildLayerNamesAsString(*w2_layer)); |
3691 v5_layer = w2_layer->children()[0]; | 3719 v5_layer = w2_layer->children()[0]; |
3692 ASSERT_EQ("v6", ui::test::ChildLayerNamesAsString(*v5_layer)); | 3720 ASSERT_EQ("v6", ui::test::ChildLayerNamesAsString(*v5_layer)); |
3693 | 3721 |
3694 } | 3722 } |
3695 // The views and the widgets are destroyed when AuraTestHelper::TearDown() | 3723 // The views and the widgets are destroyed when AuraTestHelper::TearDown() |
3696 // destroys root_window(). | 3724 // destroys root_window(). |
3697 } | 3725 } |
3698 | 3726 |
3699 } // namespace views | 3727 } // namespace views |
OLD | NEW |