| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // parent is shown. | 323 // parent is shown. |
| 324 child->Hide(); | 324 child->Hide(); |
| 325 toplevel->Show(); | 325 toplevel->Show(); |
| 326 EXPECT_TRUE(toplevel->IsVisible()); | 326 EXPECT_TRUE(toplevel->IsVisible()); |
| 327 EXPECT_FALSE(child->IsVisible()); | 327 EXPECT_FALSE(child->IsVisible()); |
| 328 | 328 |
| 329 toplevel->CloseNow(); | 329 toplevel->CloseNow(); |
| 330 // |child| should be automatically destroyed with |toplevel|. | 330 // |child| should be automatically destroyed with |toplevel|. |
| 331 } | 331 } |
| 332 | 332 |
| 333 // Test that child widgets are positioned relative to their parent. |
| 334 TEST_F(WidgetTest, ChildBoundsRelativeToParent) { |
| 335 Widget* toplevel = CreateTopLevelPlatformWidget(); |
| 336 Widget* child = CreateChildPlatformWidget(toplevel->GetNativeView()); |
| 337 |
| 338 toplevel->SetBounds(gfx::Rect(160, 100, 320, 200)); |
| 339 child->SetBounds(gfx::Rect(0, 0, 320, 200)); |
| 340 |
| 341 child->Show(); |
| 342 toplevel->Show(); |
| 343 |
| 344 gfx::Rect toplevel_bounds = toplevel->GetWindowBoundsInScreen(); |
| 345 |
| 346 // Check the parent origin. If it was (0, 0) the test wouldn't be interesting. |
| 347 EXPECT_NE(gfx::Vector2d(0, 0), toplevel_bounds.OffsetFromOrigin()); |
| 348 |
| 349 // The child's origin is at (0, 0), but the same size, so bounds should match. |
| 350 EXPECT_EQ(toplevel_bounds, child->GetWindowBoundsInScreen()); |
| 351 |
| 352 toplevel->CloseNow(); |
| 353 } |
| 354 |
| 355 // Test z-order of child widgets relative to their parent. |
| 356 TEST_F(WidgetTest, ChildStackedRelativeToParent) { |
| 357 Widget* parent = CreateTopLevelPlatformWidget(); |
| 358 Widget* child = CreateChildPlatformWidget(parent->GetNativeView()); |
| 359 |
| 360 parent->SetBounds(gfx::Rect(160, 100, 320, 200)); |
| 361 child->SetBounds(gfx::Rect(50, 50, 30, 20)); |
| 362 |
| 363 // Child shown first. Initially not visible, but on top of parent when shown. |
| 364 // Use ShowInactive whenever showing the child, otherwise the usual activation |
| 365 // logic will just put it on top anyway. Here, we want to ensure it is on top |
| 366 // of its parent regardless. |
| 367 child->ShowInactive(); |
| 368 EXPECT_FALSE(child->IsVisible()); |
| 369 |
| 370 parent->Show(); |
| 371 EXPECT_TRUE(child->IsVisible()); |
| 372 EXPECT_TRUE(IsWindowStackedAbove(child, parent)); |
| 373 EXPECT_FALSE(IsWindowStackedAbove(parent, child)); // Sanity check. |
| 374 |
| 375 Widget* popover = CreateTopLevelPlatformWidget(); |
| 376 popover->SetBounds(gfx::Rect(150, 90, 340, 240)); |
| 377 popover->Show(); |
| 378 |
| 379 EXPECT_TRUE(IsWindowStackedAbove(popover, child)); |
| 380 EXPECT_TRUE(IsWindowStackedAbove(child, parent)); |
| 381 |
| 382 // Showing the parent again should raise it and its child above the popover. |
| 383 parent->Show(); |
| 384 EXPECT_TRUE(IsWindowStackedAbove(child, parent)); |
| 385 EXPECT_TRUE(IsWindowStackedAbove(parent, popover)); |
| 386 |
| 387 // Test grandchildren. |
| 388 Widget* grandchild = CreateChildPlatformWidget(child->GetNativeView()); |
| 389 grandchild->SetBounds(gfx::Rect(5, 5, 15, 10)); |
| 390 grandchild->ShowInactive(); |
| 391 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child)); |
| 392 EXPECT_TRUE(IsWindowStackedAbove(child, parent)); |
| 393 EXPECT_TRUE(IsWindowStackedAbove(parent, popover)); |
| 394 |
| 395 popover->Show(); |
| 396 EXPECT_TRUE(IsWindowStackedAbove(popover, grandchild)); |
| 397 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child)); |
| 398 |
| 399 parent->Show(); |
| 400 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child)); |
| 401 EXPECT_TRUE(IsWindowStackedAbove(child, popover)); |
| 402 |
| 403 // Test hiding and reshowing. |
| 404 parent->Hide(); |
| 405 EXPECT_FALSE(grandchild->IsVisible()); |
| 406 parent->Show(); |
| 407 |
| 408 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child)); |
| 409 EXPECT_TRUE(IsWindowStackedAbove(child, parent)); |
| 410 EXPECT_TRUE(IsWindowStackedAbove(parent, popover)); |
| 411 |
| 412 grandchild->Hide(); |
| 413 EXPECT_FALSE(grandchild->IsVisible()); |
| 414 grandchild->ShowInactive(); |
| 415 |
| 416 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child)); |
| 417 EXPECT_TRUE(IsWindowStackedAbove(child, parent)); |
| 418 EXPECT_TRUE(IsWindowStackedAbove(parent, popover)); |
| 419 |
| 420 popover->CloseNow(); |
| 421 parent->CloseNow(); |
| 422 } |
| 423 |
| 333 //////////////////////////////////////////////////////////////////////////////// | 424 //////////////////////////////////////////////////////////////////////////////// |
| 334 // Widget ownership tests. | 425 // Widget ownership tests. |
| 335 // | 426 // |
| 336 // Tests various permutations of Widget ownership specified in the | 427 // Tests various permutations of Widget ownership specified in the |
| 337 // InitParams::Ownership param. | 428 // InitParams::Ownership param. |
| 338 | 429 |
| 339 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. | 430 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. |
| 340 class WidgetOwnershipTest : public WidgetTest { | 431 class WidgetOwnershipTest : public WidgetTest { |
| 341 public: | 432 public: |
| 342 WidgetOwnershipTest() {} | 433 WidgetOwnershipTest() {} |
| (...skipping 3067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3410 | 3501 |
| 3411 EXPECT_EQ(test_rect, root_view->bounds()); | 3502 EXPECT_EQ(test_rect, root_view->bounds()); |
| 3412 widget->ReorderNativeViews(); | 3503 widget->ReorderNativeViews(); |
| 3413 EXPECT_EQ(test_rect, root_view->bounds()); | 3504 EXPECT_EQ(test_rect, root_view->bounds()); |
| 3414 | 3505 |
| 3415 widget->CloseNow(); | 3506 widget->CloseNow(); |
| 3416 } | 3507 } |
| 3417 | 3508 |
| 3418 } // namespace test | 3509 } // namespace test |
| 3419 } // namespace views | 3510 } // namespace views |
| OLD | NEW |