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

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

Issue 2712383002: Only perform dialog Layout() once during Widget::Init(). (Closed)
Patch Set: selfnits Created 3 years, 9 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
« no previous file with comments | « ui/views/widget/root_view.cc ('k') | ui/views/widget/widget.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/views/context_menu_controller.h" 10 #include "ui/views/context_menu_controller.h"
11 #include "ui/views/test/views_test_base.h" 11 #include "ui/views/test/views_test_base.h"
12 #include "ui/views/view_targeter.h" 12 #include "ui/views/view_targeter.h"
13 #include "ui/views/widget/root_view.h" 13 #include "ui/views/widget/root_view.h"
14 #include "ui/views/widget/widget_deletion_observer.h" 14 #include "ui/views/widget/widget_deletion_observer.h"
15 #include "ui/views/window/dialog_delegate.h"
15 16
16 namespace views { 17 namespace views {
17 namespace test { 18 namespace test {
18 19
19 typedef ViewsTestBase RootViewTest; 20 typedef ViewsTestBase RootViewTest;
20 21
21 class DeleteOnKeyEventView : public View { 22 class DeleteOnKeyEventView : public View {
22 public: 23 public:
23 explicit DeleteOnKeyEventView(bool* set_on_key) : set_on_key_(set_on_key) {} 24 explicit DeleteOnKeyEventView(bool* set_on_key) : set_on_key_(set_on_key) {}
24 ~DeleteOnKeyEventView() override {} 25 ~DeleteOnKeyEventView() override {}
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 534
534 // Move the mouse outside of |subchild| and |child| which should dispatch a 535 // Move the mouse outside of |subchild| and |child| which should dispatch a
535 // mouse exit event to |subchild| and destroy the widget. This should not 536 // mouse exit event to |subchild| and destroy the widget. This should not
536 // crash when the mouse exit handler returns from |subchild|. 537 // crash when the mouse exit handler returns from |subchild|.
537 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), 538 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::Point(15, 15),
538 gfx::Point(15, 15), ui::EventTimeForNow(), 0, 0); 539 gfx::Point(15, 15), ui::EventTimeForNow(), 0, 0);
539 root_view->OnMouseMoved(move_event2); 540 root_view->OnMouseMoved(move_event2);
540 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive()); 541 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive());
541 } 542 }
542 543
544 namespace {
545 class RootViewTestDialogDelegate : public DialogDelegateView {
546 public:
547 RootViewTestDialogDelegate() {}
548
549 int layout_count() const { return layout_count_; }
550
551 // DialogDelegateView:
552 gfx::Size GetPreferredSize() const override { return preferred_size_; }
553 void Layout() override {
554 EXPECT_EQ(size(), preferred_size_);
555 ++layout_count_;
556 }
557 int GetDialogButtons() const override {
558 return ui::DIALOG_BUTTON_NONE; // Ensure buttons do not influence size.
559 }
560
561 private:
562 const gfx::Size preferred_size_ = gfx::Size(111, 111);
563
564 int layout_count_ = 0;
565
566 DISALLOW_COPY_AND_ASSIGN(RootViewTestDialogDelegate);
567 };
568 } // namespace
569
570 // Ensure only one call to Layout() happens during Widget initialization, and
571 // ensure it happens at the ContentView's preferred size.
572 TEST_F(RootViewTest, SingleLayoutDuringInit) {
573 RootViewTestDialogDelegate* delegate = new RootViewTestDialogDelegate();
574 Widget* widget =
575 DialogDelegate::CreateDialogWidget(delegate, GetContext(), nullptr);
576 EXPECT_EQ(1, delegate->layout_count());
577 widget->CloseNow();
578
579 // Also test Aura desktop Widget codepaths.
580 views_delegate()->set_use_desktop_native_widgets(true);
581 delegate = new RootViewTestDialogDelegate();
582 widget = DialogDelegate::CreateDialogWidget(delegate, GetContext(), nullptr);
583 EXPECT_EQ(1, delegate->layout_count());
584 widget->CloseNow();
585 }
586
543 } // namespace test 587 } // namespace test
544 } // namespace views 588 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.cc ('k') | ui/views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698