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

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

Issue 15114002: Reorder the NativeViews attached to a view via kViewHostKey according to the position of the view (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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_constants_aura.cc ('k') | ui/views/views.gyp » ('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 3349 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « ui/views/view_constants_aura.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698