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

Unified Diff: chrome/browser/ui/views/constrained_window_views_unittest.cc

Issue 22903022: Limit constrained windows to the size of the parent view. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comments Created 7 years, 4 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
Index: chrome/browser/ui/views/constrained_window_views_unittest.cc
diff --git a/chrome/browser/ui/views/constrained_window_views_unittest.cc b/chrome/browser/ui/views/constrained_window_views_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2a7c5f33a0154351f0b2bdbb578e432f7146bb46
--- /dev/null
+++ b/chrome/browser/ui/views/constrained_window_views_unittest.cc
@@ -0,0 +1,134 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/constrained_window_views.h"
+
+#include "components/web_modal/web_contents_modal_dialog_host.h"
+#include "ui/gfx/native_widget_types.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
+#include "ui/views/test/views_test_base.h"
+#include "ui/views/widget/widget.h"
+#include "ui/views/window/dialog_delegate.h"
+
+namespace web_modal {
+class WebContentsModalDialogHostObserver;
+}
+
+namespace views {
+
+class DialogContents : public DialogDelegateView {
+ public:
+ DialogContents() : preferred_size_() {}
sky 2013/09/05 23:39:14 nit: no need to explicitly initialize preferred_si
Rune Fevang 2013/09/06 00:04:26 Done.
+ virtual ~DialogContents() {}
+
+ void set_preferred_size(const gfx::Size& preferred_size) {
+ preferred_size_ = preferred_size;
+ }
+
+ // Overriden from DialogDelegateView:
+ virtual View* GetContentsView() OVERRIDE { return this; }
+ virtual gfx::Size GetPreferredSize() OVERRIDE { return preferred_size_; }
+ virtual gfx::Size GetMinimumSize() OVERRIDE { return gfx::Size(); }
+
+ private:
+ gfx::Size preferred_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(DialogContents);
+};
+
+class DialogHost : public web_modal::WebContentsModalDialogHost {
+ public:
+ explicit DialogHost(gfx::NativeView host_view)
+ : host_view_(host_view),
+ max_dialog_size_(5000, 5000) {
+ }
+
+ virtual ~DialogHost() {}
+
+ void set_max_dialog_size(const gfx::Size& max_dialog_size) {
+ max_dialog_size_ = max_dialog_size;
+ }
+
+ // Overridden from WebContentsModalDialogHost:
+ virtual gfx::NativeView GetHostView() const OVERRIDE { return host_view_; }
+ virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE {
+ return gfx::Point();
+ }
+ virtual gfx::Size GetMaximumDialogSize() OVERRIDE { return max_dialog_size_; }
+ virtual void AddObserver(
+ web_modal::WebContentsModalDialogHostObserver* observer) OVERRIDE {};
+ virtual void RemoveObserver(
+ web_modal::WebContentsModalDialogHostObserver* observer) OVERRIDE {};
+
+ private:
+ gfx::NativeView host_view_;
+ gfx::Size max_dialog_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(DialogHost);
+};
+
+typedef ViewsTestBase ConstrainedWindowViewsTest;
+
+TEST_F(ConstrainedWindowViewsTest, UpdateDialogPosition) {
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ Widget parent;
+ parent.Init(params);
+
+ DialogContents* contents = new DialogContents;
+ Widget* dialog =
+ CreateBrowserModalDialogViews(contents, parent.GetNativeWindow());
+ DialogHost dialog_host(parent.GetNativeView());
+ UpdateWebContentsModalDialogPosition(dialog, &dialog_host);
+
+ // Set the preferred size to something larger than the size of a dialog with
+ // no content.
+ gfx::Size preferred_size = dialog->GetClientAreaBoundsInScreen().size();
+ preferred_size.Enlarge(50, 50);
+ contents->set_preferred_size(preferred_size);
+ UpdateWebContentsModalDialogPosition(dialog, &dialog_host);
+
+ // Now increase the preferred content area and make sure the dialog grows by
+ // the same amount after the position is updated.
+ gfx::Size expected_size = dialog->GetClientAreaBoundsInScreen().size();
+ expected_size.Enlarge(200, 200);
+ preferred_size.Enlarge(200, 200);
+ contents->set_preferred_size(preferred_size);
+ UpdateWebContentsModalDialogPosition(dialog, &dialog_host);
+ EXPECT_EQ(expected_size, dialog->GetClientAreaBoundsInScreen().size());
+
+ // Make sure the dialog shrinks when the preferred content area shrinks.
+ expected_size.Enlarge(-200, -200);
+ preferred_size.Enlarge(-200, -200);
+ contents->set_preferred_size(preferred_size);
+ UpdateWebContentsModalDialogPosition(dialog, &dialog_host);
+ EXPECT_EQ(expected_size, dialog->GetClientAreaBoundsInScreen().size());
+
+ // Make sure the dialog is never larger than the max dialog size the dialog
+ // host can handle.
+ gfx::Size full_dialog_size = dialog->GetClientAreaBoundsInScreen().size();
+ gfx::Size max_dialog_size = full_dialog_size;
+ max_dialog_size.Enlarge(-100, -100);
+ dialog_host.set_max_dialog_size(max_dialog_size);
+ UpdateWebContentsModalDialogPosition(dialog, &dialog_host);
+ // The top border of the dialog is intentionally drawn outside the area
+ // specified by the dialog host, so add it to the size the dialog is expected
+ // to occupy.
+ expected_size = max_dialog_size;
+ Border* border = dialog->non_client_view()->frame_view()->border();
+ if (border)
+ expected_size.Enlarge(0, border->GetInsets().top());
+ EXPECT_EQ(expected_size,
+ dialog->non_client_view()->GetBoundsInScreen().size());
+
+ // Enlarge the max area again and make sure the dialog again uses its
+ // preferred size.
+ dialog_host.set_max_dialog_size(gfx::Size(5000, 5000));
+ UpdateWebContentsModalDialogPosition(dialog, &dialog_host);
+ EXPECT_EQ(full_dialog_size, dialog->GetClientAreaBoundsInScreen().size());
+}
+
+} // namespace views
« no previous file with comments | « chrome/browser/ui/views/constrained_window_views.cc ('k') | chrome/browser/ui/views/frame/browser_view_layout.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698