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

Unified 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, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/root_view_unittest.cc
diff --git a/ui/views/widget/root_view_unittest.cc b/ui/views/widget/root_view_unittest.cc
index b4d712e8c7b365ee2488df884c21511a0040c481..54eeee2164465677ba5b43a9869d72fb1d715e13 100644
--- a/ui/views/widget/root_view_unittest.cc
+++ b/ui/views/widget/root_view_unittest.cc
@@ -12,6 +12,7 @@
#include "ui/views/view_targeter.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget_deletion_observer.h"
+#include "ui/views/window/dialog_delegate.h"
namespace views {
namespace test {
@@ -540,5 +541,48 @@ TEST_F(RootViewTest, DeleteWidgetOnMouseExitDispatchFromChild) {
EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive());
}
+namespace {
+class RootViewTestDialogDelegate : public DialogDelegateView {
+ public:
+ RootViewTestDialogDelegate() {}
+
+ int layout_count() const { return layout_count_; }
+
+ // DialogDelegateView:
+ gfx::Size GetPreferredSize() const override { return preferred_size_; }
+ void Layout() override {
+ EXPECT_EQ(size(), preferred_size_);
+ ++layout_count_;
+ }
+ int GetDialogButtons() const override {
+ return ui::DIALOG_BUTTON_NONE; // Ensure buttons do not influence size.
+ }
+
+ private:
+ const gfx::Size preferred_size_ = gfx::Size(111, 111);
+
+ int layout_count_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(RootViewTestDialogDelegate);
+};
+} // namespace
+
+// Ensure only one call to Layout() happens during Widget initialization, and
+// ensure it happens at the ContentView's preferred size.
+TEST_F(RootViewTest, SingleLayoutDuringInit) {
+ RootViewTestDialogDelegate* delegate = new RootViewTestDialogDelegate();
+ Widget* widget =
+ DialogDelegate::CreateDialogWidget(delegate, GetContext(), nullptr);
+ EXPECT_EQ(1, delegate->layout_count());
+ widget->CloseNow();
+
+ // Also test Aura desktop Widget codepaths.
+ views_delegate()->set_use_desktop_native_widgets(true);
+ delegate = new RootViewTestDialogDelegate();
+ widget = DialogDelegate::CreateDialogWidget(delegate, GetContext(), nullptr);
+ EXPECT_EQ(1, delegate->layout_count());
+ widget->CloseNow();
+}
+
} // namespace test
} // namespace views
« 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