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

Side by Side Diff: chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc

Issue 1412963003: Plugin Power Saver: Implement pixel tests for plugin placeholders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl formatted Created 5 years, 2 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
OLDNEW
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/callback.h" 5 #include "base/callback.h"
6 #include "base/location.h" 6 #include "base/location.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager.h" 16 #include "components/web_modal/web_contents_modal_dialog_manager.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/test/browser_test_utils.h" 19 #include "content/public/test/browser_test_utils.h"
19 #include "content/public/test/test_navigation_observer.h" 20 #include "content/public/test/test_navigation_observer.h"
20 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" 21 #include "ui/web_dialogs/test/test_web_dialog_delegate.h"
21 22
22 using content::WebContents; 23 using content::WebContents;
23 using ui::WebDialogDelegate; 24 using ui::WebDialogDelegate;
24 using web_modal::WebContentsModalDialogManager; 25 using web_modal::WebContentsModalDialogManager;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 60
60 bool contents_destroyed_; 61 bool contents_destroyed_;
61 }; 62 };
62 63
63 } // namespace 64 } // namespace
64 65
65 class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest { 66 class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest {
66 public: 67 public:
67 ConstrainedWebDialogBrowserTest() {} 68 ConstrainedWebDialogBrowserTest() {}
68 69
69 // Runs the current MessageLoop until |condition| is true or timeout.
70 bool RunLoopUntil(const base::Callback<bool()>& condition) {
71 const base::TimeTicks start_time = base::TimeTicks::Now();
72 while (!condition.Run()) {
73 const base::TimeTicks current_time = base::TimeTicks::Now();
74 if (current_time - start_time > base::TimeDelta::FromSeconds(5)) {
75 ADD_FAILURE() << "Condition not met within five seconds.";
76 return false;
77 }
78
79 base::MessageLoop::current()->task_runner()->PostDelayedTask(
80 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
81 base::TimeDelta::FromMilliseconds(20));
82 content::RunMessageLoop();
83 }
84 return true;
85 }
86
87 protected: 70 protected:
88 bool IsShowingWebContentsModalDialog(WebContents* web_contents) const { 71 bool IsShowingWebContentsModalDialog(WebContents* web_contents) const {
89 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 72 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
90 WebContentsModalDialogManager::FromWebContents(web_contents); 73 WebContentsModalDialogManager::FromWebContents(web_contents);
91 return web_contents_modal_dialog_manager->IsDialogActive(); 74 return web_contents_modal_dialog_manager->IsDialogActive();
92 } 75 }
93 }; 76 };
94 77
95 // Tests that opening/closing the constrained window won't crash it. 78 // Tests that opening/closing the constrained window won't crash it.
96 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) { 79 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); 161 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize());
179 162
180 observer.Wait(); 163 observer.Wait();
181 164
182 // Wait until the entire WebContents has loaded. 165 // Wait until the entire WebContents has loaded.
183 WaitForLoadStop(dialog_delegate->GetWebContents()); 166 WaitForLoadStop(dialog_delegate->GetWebContents());
184 167
185 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents)); 168 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents));
186 169
187 // Resize to content's originally set dimensions. 170 // Resize to content's originally set dimensions.
188 ASSERT_TRUE(RunLoopUntil(base::Bind( 171 ASSERT_TRUE(ui_test_utils::RunLoopUntil(base::Bind(
189 &IsEqualSizes, 172 &IsEqualSizes, gfx::Size(initial_size, initial_size), dialog_delegate)));
190 gfx::Size(initial_size, initial_size),
191 dialog_delegate)));
192 173
193 // Resize to dimensions within expected bounds. 174 // Resize to dimensions within expected bounds.
194 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 175 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
195 GetChangeDimensionsScript(175))); 176 GetChangeDimensionsScript(175)));
196 ASSERT_TRUE(RunLoopUntil(base::Bind( 177 ASSERT_TRUE(ui_test_utils::RunLoopUntil(base::Bind(
197 &IsEqualSizes, 178 &IsEqualSizes, gfx::Size(new_size, new_size), dialog_delegate)));
198 gfx::Size(new_size, new_size),
199 dialog_delegate)));
200 179
201 // Resize to dimensions smaller than the minimum bounds. 180 // Resize to dimensions smaller than the minimum bounds.
202 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 181 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
203 GetChangeDimensionsScript(50))); 182 GetChangeDimensionsScript(50)));
204 ASSERT_TRUE(RunLoopUntil(base::Bind( 183 ASSERT_TRUE(ui_test_utils::RunLoopUntil(
205 &IsEqualSizes, 184 base::Bind(&IsEqualSizes, min_size, dialog_delegate)));
206 min_size,
207 dialog_delegate)));
208 185
209 // Resize to dimensions greater than the maximum bounds. 186 // Resize to dimensions greater than the maximum bounds.
210 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 187 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
211 GetChangeDimensionsScript(250))); 188 GetChangeDimensionsScript(250)));
212 ASSERT_TRUE(RunLoopUntil(base::Bind( 189 ASSERT_TRUE(ui_test_utils::RunLoopUntil(
213 &IsEqualSizes, 190 base::Bind(&IsEqualSizes, max_size, dialog_delegate)));
214 max_size,
215 dialog_delegate)));
216 } 191 }
217 192
218 // Tests that dialog does not autoresize when autoresizing is not enabled. 193 // Tests that dialog does not autoresize when autoresizing is not enabled.
219 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, 194 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest,
220 ContentResizeInNonAutoResizingDialog) { 195 ContentResizeInNonAutoResizingDialog) {
221 // The delegate deletes itself. 196 // The delegate deletes itself.
222 WebDialogDelegate* delegate = 197 WebDialogDelegate* delegate =
223 new ui::test::TestWebDialogDelegate(GURL(kTestDataURL)); 198 new ui::test::TestWebDialogDelegate(GURL(kTestDataURL));
224 WebContents* web_contents = 199 WebContents* web_contents =
225 browser()->tab_strip_model()->GetActiveWebContents(); 200 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 11 matching lines...) Expand all
237 gfx::Size initial_dialog_size; 212 gfx::Size initial_dialog_size;
238 delegate->GetDialogSize(&initial_dialog_size); 213 delegate->GetDialogSize(&initial_dialog_size);
239 214
240 // Check for initial sizing. Dialog was created as a 400x400 dialog. 215 // Check for initial sizing. Dialog was created as a 400x400 dialog.
241 EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize()); 216 EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize());
242 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); 217 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize());
243 218
244 // Resize <body> to dimension smaller than dialog. 219 // Resize <body> to dimension smaller than dialog.
245 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 220 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
246 GetChangeDimensionsScript(100))); 221 GetChangeDimensionsScript(100)));
247 ASSERT_TRUE(RunLoopUntil(base::Bind( 222 ASSERT_TRUE(ui_test_utils::RunLoopUntil(
248 &IsEqualSizes, 223 base::Bind(&IsEqualSizes, initial_dialog_size, dialog_delegate)));
249 initial_dialog_size,
250 dialog_delegate)));
251 224
252 // Resize <body> to dimension larger than dialog. 225 // Resize <body> to dimension larger than dialog.
253 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 226 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
254 GetChangeDimensionsScript(500))); 227 GetChangeDimensionsScript(500)));
255 ASSERT_TRUE(RunLoopUntil(base::Bind( 228 ASSERT_TRUE(ui_test_utils::RunLoopUntil(
256 &IsEqualSizes, 229 base::Bind(&IsEqualSizes, initial_dialog_size, dialog_delegate)));
257 initial_dialog_size,
258 dialog_delegate)));
259 } 230 }
260 #endif // !OS_MACOSX 231 #endif // !OS_MACOSX
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698