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

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

Issue 12045037: Refactor modality-specific behavior from ConstrainedWindowViews to WebContentsModalDialogManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Android link error Created 7 years, 10 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
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/memory/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 #include "chrome/browser/profiles/profile.h" 6 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/views/constrained_window_views.h" 10 #include "chrome/browser/ui/views/constrained_window_views.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, FocusTest) { 129 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, FocusTest) {
130 content::WebContents* web_contents = 130 content::WebContents* web_contents =
131 browser()->tab_strip_model()->GetActiveWebContents(); 131 browser()->tab_strip_model()->GetActiveWebContents();
132 ASSERT_TRUE(web_contents != NULL); 132 ASSERT_TRUE(web_contents != NULL);
133 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 133 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
134 WebContentsModalDialogManager::FromWebContents(web_contents); 134 WebContentsModalDialogManager::FromWebContents(web_contents);
135 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL); 135 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL);
136 136
137 // Create a constrained dialog. It will attach itself to web_contents. 137 // Create a constrained dialog. It will attach itself to web_contents.
138 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); 138 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog);
139 ConstrainedWindowViews* window1 = new ConstrainedWindowViews( 139 ConstrainedWindowViews* window1 = ConstrainedWindowViews::Create(
140 web_contents, test_dialog1.get()); 140 web_contents, test_dialog1.get());
141 141
142 views::FocusManager* focus_manager = window1->GetFocusManager(); 142 views::FocusManager* focus_manager = window1->GetFocusManager();
143 ASSERT_TRUE(focus_manager); 143 ASSERT_TRUE(focus_manager);
144 144
145 // test_dialog1's text field should be focused. 145 // test_dialog1's text field should be focused.
146 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), 146 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(),
147 focus_manager->GetFocusedView()); 147 focus_manager->GetFocusedView());
148 148
149 // Now create a second constrained dialog. This will also be attached to 149 // Now create a second constrained dialog. This will also be attached to
150 // web_contents, but will remain hidden since the test_dialog1 is still 150 // web_contents, but will remain hidden since the test_dialog1 is still
151 // showing. 151 // showing.
152 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); 152 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog);
153 ConstrainedWindowViews* window2 = new ConstrainedWindowViews( 153 ConstrainedWindowViews* window2 = ConstrainedWindowViews::Create(
154 web_contents, test_dialog2.get()); 154 web_contents, test_dialog2.get());
155 // Should be the same focus_manager. 155 // Should be the same focus_manager.
156 ASSERT_EQ(focus_manager, window2->GetFocusManager()); 156 ASSERT_EQ(focus_manager, window2->GetFocusManager());
157 157
158 // test_dialog1's text field should still be the view that has focus. 158 // test_dialog1's text field should still be the view that has focus.
159 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), 159 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(),
160 focus_manager->GetFocusedView()); 160 focus_manager->GetFocusedView());
161 ASSERT_TRUE(web_contents_modal_dialog_manager->IsShowingDialog()); 161 ASSERT_TRUE(web_contents_modal_dialog_manager->IsShowingDialog());
162 162
163 // Now send a VKEY_RETURN to the browser. This should result in closing 163 // Now send a VKEY_RETURN to the browser. This should result in closing
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabCloseTest) { 204 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabCloseTest) {
205 content::WebContents* web_contents = 205 content::WebContents* web_contents =
206 browser()->tab_strip_model()->GetActiveWebContents(); 206 browser()->tab_strip_model()->GetActiveWebContents();
207 ASSERT_TRUE(web_contents != NULL); 207 ASSERT_TRUE(web_contents != NULL);
208 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 208 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
209 WebContentsModalDialogManager::FromWebContents(web_contents); 209 WebContentsModalDialogManager::FromWebContents(web_contents);
210 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL); 210 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL);
211 211
212 // Create a constrained dialog. It will attach itself to web_contents. 212 // Create a constrained dialog. It will attach itself to web_contents.
213 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); 213 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog);
214 new ConstrainedWindowViews( 214 ConstrainedWindowViews::Create(
215 web_contents, test_dialog.get()); 215 web_contents, test_dialog.get());
216 216
217 bool closed = 217 bool closed =
218 browser()->tab_strip_model()->CloseWebContentsAt( 218 browser()->tab_strip_model()->CloseWebContentsAt(
219 browser()->tab_strip_model()->active_index(), 219 browser()->tab_strip_model()->active_index(),
220 TabStripModel::CLOSE_NONE); 220 TabStripModel::CLOSE_NONE);
221 EXPECT_TRUE(closed); 221 EXPECT_TRUE(closed);
222 content::RunAllPendingInMessageLoop(); 222 content::RunAllPendingInMessageLoop();
223 EXPECT_TRUE(test_dialog->done()); 223 EXPECT_TRUE(test_dialog->done());
224 } 224 }
225 225
226 // Tests that the constrained window is hidden when an other tab is selected and 226 // Tests that the constrained window is hidden when an other tab is selected and
227 // shown when its tab is selected again. 227 // shown when its tab is selected again.
228 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabSwitchTest) { 228 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabSwitchTest) {
229 content::WebContents* web_contents = 229 content::WebContents* web_contents =
230 browser()->tab_strip_model()->GetActiveWebContents(); 230 browser()->tab_strip_model()->GetActiveWebContents();
231 ASSERT_TRUE(web_contents != NULL); 231 ASSERT_TRUE(web_contents != NULL);
232 232
233 // Create a constrained dialog. It will attach itself to web_contents. 233 // Create a constrained dialog. It will attach itself to web_contents.
234 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); 234 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog);
235 ConstrainedWindowViews* window = new ConstrainedWindowViews( 235 ConstrainedWindowViews* window = ConstrainedWindowViews::Create(
236 web_contents, test_dialog.get()); 236 web_contents, test_dialog.get());
237 EXPECT_TRUE(window->IsVisible()); 237 EXPECT_TRUE(window->IsVisible());
238 238
239 // Open a new tab. The constrained window should hide itself. 239 // Open a new tab. The constrained window should hide itself.
240 browser()->tab_strip_model()->AppendWebContents( 240 browser()->tab_strip_model()->AppendWebContents(
241 content::WebContents::Create( 241 content::WebContents::Create(
242 content::WebContents::CreateParams(browser()->profile())), 242 content::WebContents::CreateParams(browser()->profile())),
243 true); 243 true);
244 EXPECT_FALSE(window->IsVisible()); 244 EXPECT_FALSE(window->IsVisible());
245 245
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Escape is not processed as accelerator before it's sent to web contents. 347 // Escape is not processed as accelerator before it's sent to web contents.
348 EXPECT_FALSE(observer.widget_closed()); 348 EXPECT_FALSE(observer.widget_closed());
349 349
350 content::RunAllPendingInMessageLoop(); 350 content::RunAllPendingInMessageLoop();
351 351
352 // Escape is processed as accelerator after it's sent to web contents. 352 // Escape is processed as accelerator after it's sent to web contents.
353 EXPECT_TRUE(observer.widget_closed()); 353 EXPECT_TRUE(observer.widget_closed());
354 } 354 }
355 355
356 #endif // defined(OS_WIN) || (defined(USE_AURA) && defined(USE_X11)) 356 #endif // defined(OS_WIN) || (defined(USE_AURA) && defined(USE_X11))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698