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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 3349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3360 EXPECT_EQ(layer.get(), c1->layer()); | 3360 EXPECT_EQ(layer.get(), c1->layer()); |
3361 | 3361 |
3362 scoped_ptr<ui::Layer> layer2(c1->RecreateLayer()); | 3362 scoped_ptr<ui::Layer> layer2(c1->RecreateLayer()); |
3363 EXPECT_NE(c1->layer(), layer2.get()); | 3363 EXPECT_NE(c1->layer(), layer2.get()); |
3364 | 3364 |
3365 // Destroy view before destroying layer. | 3365 // Destroy view before destroying layer. |
3366 c1.reset(); | 3366 c1.reset(); |
3367 } | 3367 } |
3368 | 3368 |
3369 // Verify that new layer scales content only if the old layer does. | 3369 // Verify that new layer scales content only if the old layer does. |
3370 TEST_F(ViewLayerTest, RecreateLayer) { | 3370 TEST_F(ViewLayerTest, RecreateLayerScaling) { |
3371 scoped_ptr<View> v(new View()); | 3371 scoped_ptr<View> v(new View()); |
3372 v->SetPaintToLayer(true); | 3372 v->SetPaintToLayer(true); |
3373 // Set to non default value. | 3373 // Set to non default value. |
3374 v->layer()->set_scale_content(false); | 3374 v->layer()->set_scale_content(false); |
3375 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); | 3375 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); |
3376 ui::Layer* new_layer = v->layer(); | 3376 ui::Layer* new_layer = v->layer(); |
3377 EXPECT_FALSE(new_layer->scale_content()); | 3377 EXPECT_FALSE(new_layer->scale_content()); |
3378 } | 3378 } |
3379 | 3379 |
| 3380 // Verify the z-order of the layers as a result of calling RecreateLayer(). |
| 3381 TEST_F(ViewLayerTest, RecreateLayerZOrder) { |
| 3382 scoped_ptr<View> v(new View()); |
| 3383 v->SetPaintToLayer(true); |
| 3384 |
| 3385 View* v1 = new View(); |
| 3386 v1->SetPaintToLayer(true); |
| 3387 v->AddChildView(v1); |
| 3388 View* v2 = new View(); |
| 3389 v2->SetPaintToLayer(true); |
| 3390 v->AddChildView(v2); |
| 3391 |
| 3392 // Test the initial z-order. |
| 3393 const std::vector<ui::Layer*>& child_layers_pre = v->layer()->children(); |
| 3394 ASSERT_EQ(2u, child_layers_pre.size()); |
| 3395 EXPECT_EQ(v1->layer(), child_layers_pre[0]); |
| 3396 EXPECT_EQ(v2->layer(), child_layers_pre[1]); |
| 3397 |
| 3398 scoped_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); |
| 3399 |
| 3400 // Test the new layer order. |v1_old_layer| should be above the layers |
| 3401 // for |v1| and |v2|. |
| 3402 const std::vector<ui::Layer*>& child_layers_post = v->layer()->children(); |
| 3403 ASSERT_EQ(3u, child_layers_post.size()); |
| 3404 EXPECT_EQ(v1->layer(), child_layers_post[0]); |
| 3405 EXPECT_EQ(v2->layer(), child_layers_post[1]); |
| 3406 EXPECT_EQ(v1_old_layer, child_layers_post[2]); |
| 3407 } |
| 3408 |
| 3409 // Verify the z-order of the layers as a result of calling RecreateLayer when |
| 3410 // the widget is the parent with the layer. |
| 3411 TEST_F(ViewLayerTest, RecreateLayerZOrderWidgetParent) { |
| 3412 View* v = new View(); |
| 3413 widget()->SetContentsView(v); |
| 3414 |
| 3415 View* v1 = new View(); |
| 3416 v1->SetPaintToLayer(true); |
| 3417 v->AddChildView(v1); |
| 3418 View* v2 = new View(); |
| 3419 v2->SetPaintToLayer(true); |
| 3420 v->AddChildView(v2); |
| 3421 |
| 3422 ui::Layer* root_layer = GetRootLayer(); |
| 3423 |
| 3424 // Test the initial z-order. |
| 3425 const std::vector<ui::Layer*>& child_layers_pre = root_layer->children(); |
| 3426 ASSERT_EQ(2u, child_layers_pre.size()); |
| 3427 EXPECT_EQ(v1->layer(), child_layers_pre[0]); |
| 3428 EXPECT_EQ(v2->layer(), child_layers_pre[1]); |
| 3429 |
| 3430 scoped_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); |
| 3431 |
| 3432 // Test the new layer order. |v1_old_layer| should be above the layers |
| 3433 // for |v1| and |v2|. |
| 3434 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); |
| 3435 ASSERT_EQ(3u, child_layers_post.size()); |
| 3436 EXPECT_EQ(v1->layer(), child_layers_post[0]); |
| 3437 EXPECT_EQ(v2->layer(), child_layers_post[1]); |
| 3438 EXPECT_EQ(v1_old_layer, child_layers_post[2]); |
| 3439 } |
| 3440 |
3380 #endif // USE_AURA | 3441 #endif // USE_AURA |
3381 | 3442 |
3382 } // namespace views | 3443 } // namespace views |
OLD | NEW |