| 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/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/constrained_window_tab_helper.h" | 9 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // showing. | 143 // showing. |
| 144 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); | 144 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); |
| 145 ConstrainedWindowViews* window2 = new ConstrainedWindowViews( | 145 ConstrainedWindowViews* window2 = new ConstrainedWindowViews( |
| 146 web_contents, test_dialog2.get()); | 146 web_contents, test_dialog2.get()); |
| 147 // Should be the same focus_manager. | 147 // Should be the same focus_manager. |
| 148 ASSERT_EQ(focus_manager, window2->GetFocusManager()); | 148 ASSERT_EQ(focus_manager, window2->GetFocusManager()); |
| 149 | 149 |
| 150 // test_dialog1's text field should still be the view that has focus. | 150 // test_dialog1's text field should still be the view that has focus. |
| 151 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 151 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
| 152 focus_manager->GetFocusedView()); | 152 focus_manager->GetFocusedView()); |
| 153 ASSERT_EQ(2u, constrained_window_helper->constrained_window_count()); | 153 ASSERT_EQ(2u, constrained_window_helper->dialog_count()); |
| 154 | 154 |
| 155 // Now send a VKEY_RETURN to the browser. This should result in closing | 155 // Now send a VKEY_RETURN to the browser. This should result in closing |
| 156 // test_dialog1. | 156 // test_dialog1. |
| 157 EXPECT_TRUE(focus_manager->ProcessAccelerator( | 157 EXPECT_TRUE(focus_manager->ProcessAccelerator( |
| 158 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE))); | 158 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE))); |
| 159 content::RunAllPendingInMessageLoop(); | 159 content::RunAllPendingInMessageLoop(); |
| 160 | 160 |
| 161 EXPECT_TRUE(test_dialog1->done()); | 161 EXPECT_TRUE(test_dialog1->done()); |
| 162 EXPECT_FALSE(test_dialog2->done()); | 162 EXPECT_FALSE(test_dialog2->done()); |
| 163 EXPECT_EQ(1u, constrained_window_helper->constrained_window_count()); | 163 EXPECT_EQ(1u, constrained_window_helper->dialog_count()); |
| 164 | 164 |
| 165 // test_dialog2 will be shown. Focus should be on test_dialog2's text field. | 165 // test_dialog2 will be shown. Focus should be on test_dialog2's text field. |
| 166 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), | 166 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), |
| 167 focus_manager->GetFocusedView()); | 167 focus_manager->GetFocusedView()); |
| 168 | 168 |
| 169 int tab_with_constrained_window = browser()->active_index(); | 169 int tab_with_constrained_window = browser()->active_index(); |
| 170 | 170 |
| 171 // Create a new tab. | 171 // Create a new tab. |
| 172 chrome::NewTab(browser()); | 172 chrome::NewTab(browser()); |
| 173 | 173 |
| 174 // The constrained dialog should no longer be selected. | 174 // The constrained dialog should no longer be selected. |
| 175 EXPECT_NE(test_dialog2->GetInitiallyFocusedView(), | 175 EXPECT_NE(test_dialog2->GetInitiallyFocusedView(), |
| 176 focus_manager->GetFocusedView()); | 176 focus_manager->GetFocusedView()); |
| 177 | 177 |
| 178 browser()->tab_strip_model()->ActivateTabAt(tab_with_constrained_window, | 178 browser()->tab_strip_model()->ActivateTabAt(tab_with_constrained_window, |
| 179 false); | 179 false); |
| 180 | 180 |
| 181 // Activating the previous tab should bring focus to the constrained window. | 181 // Activating the previous tab should bring focus to the constrained window. |
| 182 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), | 182 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), |
| 183 focus_manager->GetFocusedView()); | 183 focus_manager->GetFocusedView()); |
| 184 | 184 |
| 185 // Send another VKEY_RETURN, closing test_dialog2 | 185 // Send another VKEY_RETURN, closing test_dialog2 |
| 186 EXPECT_TRUE(focus_manager->ProcessAccelerator( | 186 EXPECT_TRUE(focus_manager->ProcessAccelerator( |
| 187 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE))); | 187 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE))); |
| 188 content::RunAllPendingInMessageLoop(); | 188 content::RunAllPendingInMessageLoop(); |
| 189 EXPECT_TRUE(test_dialog2->done()); | 189 EXPECT_TRUE(test_dialog2->done()); |
| 190 EXPECT_EQ(0u, constrained_window_helper->constrained_window_count()); | 190 EXPECT_EQ(0u, constrained_window_helper->dialog_count()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 // Tests that the constrained window is closed properly when its tab is | 193 // Tests that the constrained window is closed properly when its tab is |
| 194 // closed. | 194 // closed. |
| 195 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabCloseTest) { | 195 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabCloseTest) { |
| 196 content::WebContents* web_contents = | 196 content::WebContents* web_contents = |
| 197 browser()->tab_strip_model()->GetActiveWebContents(); | 197 browser()->tab_strip_model()->GetActiveWebContents(); |
| 198 ASSERT_TRUE(web_contents != NULL); | 198 ASSERT_TRUE(web_contents != NULL); |
| 199 ConstrainedWindowTabHelper* constrained_window_helper = | 199 ConstrainedWindowTabHelper* constrained_window_helper = |
| 200 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 200 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 ui_test_utils::NavigateToURL(browser(), url); | 265 ui_test_utils::NavigateToURL(browser(), url); |
| 266 | 266 |
| 267 ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog( | 267 ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog( |
| 268 browser()->profile(), | 268 browser()->profile(), |
| 269 new ui::test::TestWebDialogDelegate(url), | 269 new ui::test::TestWebDialogDelegate(url), |
| 270 NULL, | 270 NULL, |
| 271 web_contents); | 271 web_contents); |
| 272 | 272 |
| 273 ConstrainedWindowViews* cwv = | 273 ConstrainedWindowViews* cwv = |
| 274 static_cast<ConstrainedWindowViews*>(cwdd->GetWindow()); | 274 static_cast<ConstrainedWindowViews*>(cwdd->GetWindow()); |
| 275 cwv->FocusConstrainedWindow(); | 275 cwv->FocusWebContentsModalDialog(); |
| 276 | 276 |
| 277 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); | 277 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
| 278 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, | 278 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, |
| 279 ui::VKEY_BACK, | 279 ui::VKEY_BACK, |
| 280 ui::EF_NONE, | 280 ui::EF_NONE, |
| 281 false); | 281 false); |
| 282 bool not_consumed = browser_view->GetFocusManager()->OnKeyEvent(key_event); | 282 bool not_consumed = browser_view->GetFocusManager()->OnKeyEvent(key_event); |
| 283 EXPECT_TRUE(not_consumed); | 283 EXPECT_TRUE(not_consumed); |
| 284 } | 284 } |
| 285 #endif // defined(OS_WIN) && !defined(USE_AURA) | 285 #endif // defined(OS_WIN) && !defined(USE_AURA) |
| OLD | NEW |