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