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

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 831643004: MacViews: Fix child window z-order and SetBounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ShowInactive for a more compelling test Created 5 years, 11 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
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 <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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // parent is shown. 307 // parent is shown.
308 child->Hide(); 308 child->Hide();
309 toplevel->Show(); 309 toplevel->Show();
310 EXPECT_TRUE(toplevel->IsVisible()); 310 EXPECT_TRUE(toplevel->IsVisible());
311 EXPECT_FALSE(child->IsVisible()); 311 EXPECT_FALSE(child->IsVisible());
312 312
313 toplevel->CloseNow(); 313 toplevel->CloseNow();
314 // |child| should be automatically destroyed with |toplevel|. 314 // |child| should be automatically destroyed with |toplevel|.
315 } 315 }
316 316
317 // Test that child widgets are positioned relative to their parent.
318 TEST_F(WidgetTest, ChildBoundsRelativeToParent) {
319 Widget* toplevel = CreateTopLevelPlatformWidget();
320 Widget* child = CreateChildPlatformWidget(toplevel->GetNativeView());
321
322 toplevel->SetBounds(gfx::Rect(160, 100, 320, 200));
323 child->SetBounds(gfx::Rect(0, 0, 320, 200));
324
325 child->Show();
326 toplevel->Show();
327
328 gfx::Rect toplevel_bounds = toplevel->GetWindowBoundsInScreen();
329
330 // Check the parent origin. If it was (0, 0) the test wouldn't be interesting.
331 EXPECT_NE(gfx::Vector2d(0, 0), toplevel_bounds.OffsetFromOrigin());
332
333 // The child's origin is at (0, 0), but the same size, so bounds should match.
334 EXPECT_EQ(toplevel_bounds, child->GetWindowBoundsInScreen());
335
336 toplevel->CloseNow();
337 }
338
339 // Test z-order of child widgets relative to their parent.
340 TEST_F(WidgetTest, ChildStackedRelativeToParent) {
341 Widget* parent = CreateTopLevelPlatformWidget();
342 Widget* child = CreateChildPlatformWidget(parent->GetNativeView());
343
344 parent->SetBounds(gfx::Rect(160, 100, 320, 200));
345 child->SetBounds(gfx::Rect(50, 50, 30, 20));
346
347 // Child shown first. Initially not visible, but on top of parent when shown.
348 // Use ShowInactive whenever showing the child, otherwise the usual activation
349 // logic will just put it on top anyway. Here, we want to ensure it is on top
350 // of its parent regardless.
351 child->ShowInactive();
352 EXPECT_FALSE(child->IsVisible());
353
354 parent->Show();
355 EXPECT_TRUE(child->IsVisible());
356 EXPECT_TRUE(IsWindowStackedAbove(child, parent));
357 EXPECT_FALSE(IsWindowStackedAbove(parent, child)); // Sanity check.
358
359 Widget* popover = CreateTopLevelPlatformWidget();
360 popover->SetBounds(gfx::Rect(150, 90, 340, 240));
361 popover->Show();
362
363 EXPECT_TRUE(IsWindowStackedAbove(popover, child));
364 EXPECT_TRUE(IsWindowStackedAbove(child, parent));
365
366 // Showing the parent again should raise it and its child above the popover.
367 parent->Show();
368 EXPECT_TRUE(IsWindowStackedAbove(child, parent));
369 EXPECT_TRUE(IsWindowStackedAbove(parent, popover));
370
371 // Test grandchildren.
372 Widget* grandchild = CreateChildPlatformWidget(child->GetNativeView());
373 grandchild->SetBounds(gfx::Rect(5, 5, 15, 10));
374 grandchild->ShowInactive();
375 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child));
376 EXPECT_TRUE(IsWindowStackedAbove(child, parent));
377 EXPECT_TRUE(IsWindowStackedAbove(parent, popover));
378
379 popover->Show();
380 EXPECT_TRUE(IsWindowStackedAbove(popover, grandchild));
381 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child));
382
383 parent->Show();
384 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child));
385 EXPECT_TRUE(IsWindowStackedAbove(child, popover));
386
387 // Test hiding and reshowing.
388 parent->Hide();
389 EXPECT_FALSE(grandchild->IsVisible());
390 parent->Show();
391
392 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child));
393 EXPECT_TRUE(IsWindowStackedAbove(child, parent));
394 EXPECT_TRUE(IsWindowStackedAbove(parent, popover));
395
396 grandchild->Hide();
397 EXPECT_FALSE(grandchild->IsVisible());
398 grandchild->ShowInactive();
399
400 EXPECT_TRUE(IsWindowStackedAbove(grandchild, child));
401 EXPECT_TRUE(IsWindowStackedAbove(child, parent));
402 EXPECT_TRUE(IsWindowStackedAbove(parent, popover));
403
404 popover->CloseNow();
405 parent->CloseNow();
406 }
407
317 //////////////////////////////////////////////////////////////////////////////// 408 ////////////////////////////////////////////////////////////////////////////////
318 // Widget ownership tests. 409 // Widget ownership tests.
319 // 410 //
320 // Tests various permutations of Widget ownership specified in the 411 // Tests various permutations of Widget ownership specified in the
321 // InitParams::Ownership param. 412 // InitParams::Ownership param.
322 413
323 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. 414 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to.
324 class WidgetOwnershipTest : public WidgetTest { 415 class WidgetOwnershipTest : public WidgetTest {
325 public: 416 public:
326 WidgetOwnershipTest() {} 417 WidgetOwnershipTest() {}
(...skipping 3067 matching lines...) Expand 10 before | Expand all | Expand 10 after
3394 3485
3395 EXPECT_EQ(test_rect, root_view->bounds()); 3486 EXPECT_EQ(test_rect, root_view->bounds());
3396 widget->ReorderNativeViews(); 3487 widget->ReorderNativeViews();
3397 EXPECT_EQ(test_rect, root_view->bounds()); 3488 EXPECT_EQ(test_rect, root_view->bounds());
3398 3489
3399 widget->CloseNow(); 3490 widget->CloseNow();
3400 } 3491 }
3401 3492
3402 } // namespace test 3493 } // namespace test
3403 } // namespace views 3494 } // namespace views
OLDNEW
« ui/views/test/widget_test_aura.cc ('K') | « ui/views/test/widget_test_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698