This source file includes following definitions.
- set_preferred_size
- GetContentsView
- GetPreferredSize
- GetMinimumSize
- SetUp
- TearDown
- GetDialogSize
- contents
- dialog_host
- dialog
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/views/constrained_window_views.h"
#include "components/web_modal/test_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/border.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
namespace views {
class DialogContents : public DialogDelegateView {
public:
DialogContents() {}
virtual ~DialogContents() {}
void set_preferred_size(const gfx::Size& preferred_size) {
preferred_size_ = preferred_size;
}
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 ConstrainedWindowViewsTest : public ViewsTestBase {
public:
ConstrainedWindowViewsTest() : contents_(NULL) {}
virtual ~ConstrainedWindowViewsTest() {}
virtual void SetUp() OVERRIDE {
ViewsTestBase::SetUp();
contents_ = new DialogContents;
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.delegate = contents_;
dialog_.reset(new Widget);
dialog_->Init(params);
dialog_host_.reset(new web_modal::TestWebContentsModalDialogHost(
dialog_->GetNativeView()));
dialog_host_->set_max_dialog_size(gfx::Size(5000, 5000));
gfx::Size preferred_size = dialog()->GetRootView()->GetPreferredSize();
preferred_size.Enlarge(500, 500);
contents()->set_preferred_size(preferred_size);
}
virtual void TearDown() OVERRIDE {
ViewsTestBase::TearDown();
contents_ = NULL;
dialog_host_.reset();
dialog_.reset();
}
gfx::Size GetDialogSize() {
return dialog()->GetRootView()->GetBoundsInScreen().size();
}
DialogContents* contents() { return contents_; }
web_modal::TestWebContentsModalDialogHost* dialog_host() {
return dialog_host_.get();
}
Widget* dialog() { return dialog_.get(); }
private:
DialogContents* contents_;
scoped_ptr<web_modal::TestWebContentsModalDialogHost> dialog_host_;
scoped_ptr<Widget> dialog_;
DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowViewsTest);
};
TEST_F(ConstrainedWindowViewsTest, GrowModalDialogSize) {
UpdateBrowserModalDialogPosition(dialog(), dialog_host());
gfx::Size expected_size = GetDialogSize();
gfx::Size preferred_size = contents()->GetPreferredSize();
expected_size.Enlarge(50, 50);
preferred_size.Enlarge(50, 50);
contents()->set_preferred_size(preferred_size);
UpdateBrowserModalDialogPosition(dialog(), dialog_host());
EXPECT_EQ(expected_size.ToString(), GetDialogSize().ToString());
}
TEST_F(ConstrainedWindowViewsTest, ShrinkModalDialogSize) {
UpdateBrowserModalDialogPosition(dialog(), dialog_host());
gfx::Size expected_size = GetDialogSize();
gfx::Size preferred_size = contents()->GetPreferredSize();
expected_size.Enlarge(-50, -50);
preferred_size.Enlarge(-50, -50);
contents()->set_preferred_size(preferred_size);
UpdateBrowserModalDialogPosition(dialog(), dialog_host());
EXPECT_EQ(expected_size.ToString(), GetDialogSize().ToString());
}
TEST_F(ConstrainedWindowViewsTest, MaximumBrowserDialogSize) {
UpdateBrowserModalDialogPosition(dialog(), dialog_host());
gfx::Size dialog_size = GetDialogSize();
gfx::Size max_dialog_size = dialog_size;
max_dialog_size.Enlarge(-50, -50);
dialog_host()->set_max_dialog_size(max_dialog_size);
UpdateBrowserModalDialogPosition(dialog(), dialog_host());
EXPECT_EQ(dialog_size.ToString(), GetDialogSize().ToString());
}
TEST_F(ConstrainedWindowViewsTest, MaximumWebContentsDialogSize) {
UpdateWebContentsModalDialogPosition(dialog(), dialog_host());
gfx::Size full_dialog_size = GetDialogSize();
gfx::Size max_dialog_size = full_dialog_size;
max_dialog_size.Enlarge(-50, -50);
dialog_host()->set_max_dialog_size(max_dialog_size);
UpdateWebContentsModalDialogPosition(dialog(), dialog_host());
gfx::Size 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.ToString(), GetDialogSize().ToString());
max_dialog_size.Enlarge(100, 100);
dialog_host()->set_max_dialog_size(max_dialog_size);
UpdateWebContentsModalDialogPosition(dialog(), dialog_host());
EXPECT_EQ(full_dialog_size.ToString(), GetDialogSize().ToString());
}
}