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

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

Issue 10214001: WebDialogs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "base/file_path.h"
8 #include "base/memory/singleton.h"
9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/views/html_dialog_view.h"
13 #include "chrome/browser/ui/webui/test_html_dialog_ui_delegate.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/render_widget_host_view.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_view.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/views/widget/widget.h"
23
24 using content::WebContents;
25 using testing::Eq;
26
27 namespace {
28
29 // Initial size of HTMLDialog for SizeWindow test case.
30 const int kInitialWidth = 40;
31 const int kInitialHeight = 40;
32
33 class TestHtmlDialogView: public HtmlDialogView {
34 public:
35 TestHtmlDialogView(Profile* profile,
36 Browser* browser,
37 HtmlDialogUIDelegate* delegate)
38 : HtmlDialogView(profile, browser, delegate),
39 painted_(false),
40 should_quit_on_size_change_(false) {
41 delegate->GetDialogSize(&last_size_);
42 }
43
44 bool painted() const {
45 return painted_;
46 }
47
48 void set_should_quit_on_size_change(bool should_quit) {
49 should_quit_on_size_change_ = should_quit;
50 }
51
52 private:
53 // TODO(xiyuan): Update this when WidgetDelegate has bounds change hook.
54 virtual void SaveWindowPlacement(const gfx::Rect& bounds,
55 ui::WindowShowState show_state) OVERRIDE {
56 if (should_quit_on_size_change_ && last_size_ != bounds.size()) {
57 // Schedule message loop quit because we could be called while
58 // the bounds change call is on the stack and not in the nested message
59 // loop.
60 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
61 &MessageLoop::Quit, base::Unretained(MessageLoop::current())));
62 }
63
64 last_size_ = bounds.size();
65 }
66
67 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE {
68 should_quit_on_size_change_ = false; // No quit when we are closing.
69 HtmlDialogView::OnDialogClosed(json_retval);
70 }
71
72 virtual void OnTabMainFrameRender() OVERRIDE {
73 HtmlDialogView::OnTabMainFrameRender();
74 painted_ = true;
75 MessageLoop::current()->Quit();
76 }
77
78 // Whether first rendered notification is received.
79 bool painted_;
80
81 // Whether we should quit message loop when size change is detected.
82 bool should_quit_on_size_change_;
83 gfx::Size last_size_;
84
85 DISALLOW_COPY_AND_ASSIGN(TestHtmlDialogView);
86 };
87
88 } // namespace
89
90 class HtmlDialogBrowserTest : public InProcessBrowserTest {
91 public:
92 HtmlDialogBrowserTest() {}
93 };
94
95 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
96 #define MAYBE_SizeWindow SizeWindow
97 #else
98 // http://code.google.com/p/chromium/issues/detail?id=52602
99 // Windows has some issues resizing windows- an off by one problem,
100 // and a minimum size that seems too big. This file isn't included in
101 // Mac builds yet. On Chrome OS, this test doesn't apply since ChromeOS
102 // doesn't allow resizing of windows.
103 #define MAYBE_SizeWindow DISABLED_SizeWindow
104 #endif
105
106 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) {
107 test::TestHtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate(
108 GURL(chrome::kChromeUIChromeURLsURL));
109 delegate->set_size(kInitialWidth, kInitialHeight);
110
111 TestHtmlDialogView* html_view =
112 new TestHtmlDialogView(browser()->profile(), browser(), delegate);
113 WebContents* web_contents = browser()->GetSelectedWebContents();
114 ASSERT_TRUE(web_contents != NULL);
115 views::Widget::CreateWindowWithParent(
116 html_view, web_contents->GetView()->GetTopLevelNativeWindow());
117 html_view->GetWidget()->Show();
118
119 // TestHtmlDialogView should quit current message loop on size change.
120 html_view->set_should_quit_on_size_change(true);
121
122 gfx::Rect bounds = html_view->GetWidget()->GetClientAreaScreenBounds();
123
124 gfx::Rect set_bounds = bounds;
125 gfx::Rect actual_bounds, rwhv_bounds;
126
127 // Bigger than the default in both dimensions.
128 set_bounds.set_width(400);
129 set_bounds.set_height(300);
130
131 html_view->MoveContents(web_contents, set_bounds);
132 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit.
133 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds();
134 EXPECT_EQ(set_bounds, actual_bounds);
135
136 rwhv_bounds =
137 html_view->web_contents()->GetRenderWidgetHostView()->GetViewBounds();
138 EXPECT_LT(0, rwhv_bounds.width());
139 EXPECT_LT(0, rwhv_bounds.height());
140 EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
141 EXPECT_GE(set_bounds.height(), rwhv_bounds.height());
142
143 // Larger in one dimension and smaller in the other.
144 set_bounds.set_width(550);
145 set_bounds.set_height(250);
146
147 html_view->MoveContents(web_contents, set_bounds);
148 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit.
149 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds();
150 EXPECT_EQ(set_bounds, actual_bounds);
151
152 rwhv_bounds =
153 html_view->web_contents()->GetRenderWidgetHostView()->GetViewBounds();
154 EXPECT_LT(0, rwhv_bounds.width());
155 EXPECT_LT(0, rwhv_bounds.height());
156 EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
157 EXPECT_GE(set_bounds.height(), rwhv_bounds.height());
158
159 // Get very small.
160 gfx::Size min_size = html_view->GetWidget()->GetMinimumSize();
161 set_bounds.set_size(min_size);
162
163 html_view->MoveContents(web_contents, set_bounds);
164 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit.
165 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds();
166 EXPECT_EQ(set_bounds, actual_bounds);
167
168 rwhv_bounds =
169 html_view->web_contents()->GetRenderWidgetHostView()->GetViewBounds();
170 EXPECT_LT(0, rwhv_bounds.width());
171 EXPECT_LT(0, rwhv_bounds.height());
172 EXPECT_GE(set_bounds.width(), rwhv_bounds.width());
173 EXPECT_GE(set_bounds.height(), rwhv_bounds.height());
174
175 // Check to make sure we can't get to 0x0
176 set_bounds.set_width(0);
177 set_bounds.set_height(0);
178
179 html_view->MoveContents(web_contents, set_bounds);
180 ui_test_utils::RunMessageLoop(); // TestHtmlDialogView will quit.
181 actual_bounds = html_view->GetWidget()->GetClientAreaScreenBounds();
182 EXPECT_LT(0, actual_bounds.width());
183 EXPECT_LT(0, actual_bounds.height());
184 }
185
186 // This is timing out about 5~10% of runs. See crbug.com/86059.
187 IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, DISABLED_WebContentRendered) {
188 HtmlDialogUIDelegate* delegate = new test::TestHtmlDialogUIDelegate(
189 GURL(chrome::kChromeUIChromeURLsURL));
190
191 TestHtmlDialogView* html_view =
192 new TestHtmlDialogView(browser()->profile(), browser(), delegate);
193 WebContents* web_contents = browser()->GetSelectedWebContents();
194 ASSERT_TRUE(web_contents != NULL);
195 views::Widget::CreateWindowWithParent(
196 html_view, web_contents->GetView()->GetTopLevelNativeWindow());
197 EXPECT_TRUE(html_view->initialized_);
198
199 html_view->InitDialog();
200 html_view->GetWidget()->Show();
201
202 // TestHtmlDialogView::OnTabMainFrameRender() will Quit().
203 MessageLoopForUI::current()->Run();
204
205 EXPECT_TRUE(html_view->painted());
206
207 html_view->GetWidget()->Close();
208 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/html_dialog_view.cc ('k') | chrome/browser/ui/views/keyboard_overlay_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698