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

Side by Side Diff: chrome/browser/views/html_dialog_view_browsertest.cc

Issue 2768006: Test + Fix for GTK window resizing when using toolkit views. (Closed)
Patch Set: Return a gfx::Size instead. Created 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/views/tab_contents/tab_contents_view_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/test/ui/ui_test.h"
6
7 #include "base/file_path.h"
8 #include "base/message_loop.h"
9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/dom_ui/html_dialog_ui.h"
11 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "chrome/browser/renderer_host/render_widget_host_view.h"
13 #include "chrome/browser/views/html_dialog_view.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/in_process_browser_test.h"
16 #include "chrome/test/ui_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "views/widget/widget.h"
20 #include "views/window/window.h"
21
22 using testing::Eq;
23
24 namespace {
25
26 // Window non-client-area means that the minimum size for the window
27 // won't be the actual minimum size - our layout and resizing code
28 // makes sure the chrome is always visible.
29 const int kMinimumWidthToTestFor = 20;
30 const int kMinimumHeightToTestFor = 30;
31
32 class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate {
33 public:
34 TestHtmlDialogUIDelegate() {}
35 virtual ~TestHtmlDialogUIDelegate() {}
36
37 // HTMLDialogUIDelegate implementation:
38 virtual bool IsDialogModal() const {
39 return true;
40 }
41 virtual std::wstring GetDialogTitle() const {
42 return std::wstring(L"Test");
43 }
44 virtual GURL GetDialogContentURL() const {
45 return GURL(chrome::kAboutBlankURL);
46 }
47 virtual void GetDOMMessageHandlers(
48 std::vector<DOMMessageHandler*>* handlers) const { }
49 virtual void GetDialogSize(gfx::Size* size) const {
50 size->set_width(40);
51 size->set_height(40);
52 }
53 virtual std::string GetDialogArgs() const {
54 return std::string();
55 }
56 virtual void OnDialogClosed(const std::string& json_retval) { }
57 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) {
58 if (out_close_dialog)
59 *out_close_dialog = true;
60 }
61 };
62
63 } // namespace
64
65 class HtmlDialogBrowserTest : public InProcessBrowserTest {
66 public:
67 HtmlDialogBrowserTest() {}
68
69 #if defined(OS_WIN)
70 class WindowChangedObserver : public base::MessagePumpForUI::Observer {
71 public:
72 WindowChangedObserver() {}
73
74 static WindowChangedObserver* Get() {
75 return Singleton<WindowChangedObserver>::get();
76 }
77
78 // This method is called before processing a message.
79 virtual void WillProcessMessage(const MSG& msg) {}
80
81 // This method is called after processing a message.
82 virtual void DidProcessMessage(const MSG& msg) {
83 // Either WM_PAINT or WM_TIMER indicates the actual work of
84 // pushing through the window resizing messages is done since
85 // they are lower priority (we don't get to see the
86 // WM_WINDOWPOSCHANGED message here).
87 if (msg.message == WM_PAINT || msg.message == WM_TIMER)
88 MessageLoop::current()->Quit();
89 }
90 };
91 #elif !defined(OS_MACOSX)
92 class WindowChangedObserver : public base::MessagePumpForUI::Observer {
93 public:
94 WindowChangedObserver() {}
95
96 static WindowChangedObserver* Get() {
97 return Singleton<WindowChangedObserver>::get();
98 }
99
100 // This method is called before processing a message.
101 virtual void WillProcessEvent(GdkEvent* event) {}
102
103 // This method is called after processing a message.
104 virtual void DidProcessEvent(GdkEvent* event) {
105 // Quit once the GDK_CONFIGURE event has been processed - seeing
106 // this means the window sizing request that was made actually
107 // happened.
108 if (event->type == GDK_CONFIGURE)
109 MessageLoop::current()->Quit();
110 }
111 };
112 #endif
113 };
114
115 #if defined(OS_LINUX)
116 #define MAYBE_SizeWindow SizeWindow
117 #else
118 // http://code.google.com/p/chromium/issues/detail?id=52602
119 // Windows has some issues resizing windows- an off by one problem,
120 // and a minimum size that seems too big. This file isn't included in
121 // Mac builds yet.
122 #define MAYBE_SizeWindow DISABLED_SizeWindow
123 #endif
124
125 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) {
126 HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate();
127
128 HtmlDialogView* html_view =
129 new HtmlDialogView(browser()->profile(), delegate);
130 TabContents* tab_contents = browser()->GetSelectedTabContents();
131 ASSERT_TRUE(tab_contents != NULL);
132 views::Window::CreateChromeWindow(tab_contents->GetMessageBoxRootWindow(),
133 gfx::Rect(), html_view);
134 html_view->InitDialog();
135 html_view->window()->Show();
136
137 MessageLoopForUI::current()->AddObserver(WindowChangedObserver::Get());
138
139 gfx::Rect bounds;
140 html_view->GetWidget()->GetBounds(&bounds, false);
141
142 gfx::Rect set_bounds = bounds;
143 gfx::Rect actual_bounds, rwhv_bounds;
144
145 // Bigger than the default in both dimensions.
146 set_bounds.set_width(400);
147 set_bounds.set_height(300);
148
149 html_view->MoveContents(tab_contents, set_bounds);
150 ui_test_utils::RunMessageLoop();
151 html_view->GetWidget()->GetBounds(&actual_bounds, false);
152 EXPECT_EQ(set_bounds, actual_bounds);
153
154 rwhv_bounds =
155 html_view->tab_contents()->GetRenderWidgetHostView()->GetViewBounds();
156 EXPECT_LT(0, rwhv_bounds.width());
157 EXPECT_LT(0, rwhv_bounds.height());
158 EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
159 EXPECT_GE(set_bounds.height(), rwhv_bounds.height());
160
161 // Larger in one dimension and smaller in the other.
162 set_bounds.set_width(550);
163 set_bounds.set_height(250);
164
165 html_view->MoveContents(tab_contents, set_bounds);
166 ui_test_utils::RunMessageLoop();
167 html_view->GetWidget()->GetBounds(&actual_bounds, false);
168 EXPECT_EQ(set_bounds, actual_bounds);
169
170 rwhv_bounds =
171 html_view->tab_contents()->GetRenderWidgetHostView()->GetViewBounds();
172 EXPECT_LT(0, rwhv_bounds.width());
173 EXPECT_LT(0, rwhv_bounds.height());
174 EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
175 EXPECT_GE(set_bounds.height(), rwhv_bounds.height());
176
177 // Get very small.
178 set_bounds.set_width(kMinimumWidthToTestFor);
179 set_bounds.set_height(kMinimumHeightToTestFor);
180
181 html_view->MoveContents(tab_contents, set_bounds);
182 ui_test_utils::RunMessageLoop();
183 html_view->GetWidget()->GetBounds(&actual_bounds, false);
184 EXPECT_EQ(set_bounds, actual_bounds);
185
186 rwhv_bounds =
187 html_view->tab_contents()->GetRenderWidgetHostView()->GetViewBounds();
188 EXPECT_LT(0, rwhv_bounds.width());
189 EXPECT_LT(0, rwhv_bounds.height());
190 EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
191 EXPECT_GE(set_bounds.height(), rwhv_bounds.height());
192
193 // Check to make sure we can't get to 0x0
194 set_bounds.set_width(0);
195 set_bounds.set_height(0);
196
197 html_view->MoveContents(tab_contents, set_bounds);
198 ui_test_utils::RunMessageLoop();
199 html_view->GetWidget()->GetBounds(&actual_bounds, false);
200 EXPECT_LT(0, actual_bounds.width());
201 EXPECT_LT(0, actual_bounds.height());
202
203 MessageLoopForUI::current()->RemoveObserver(WindowChangedObserver::Get());
204 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/views/tab_contents/tab_contents_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698