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