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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 chrome::CloseWindow(browser()); | 161 chrome::CloseWindow(browser()); |
162 content::RunAllPendingInMessageLoop(); | 162 content::RunAllPendingInMessageLoop(); |
163 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); | 163 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); |
164 | 164 |
165 // Close the dialog's browser window. | 165 // Close the dialog's browser window. |
166 chrome::CloseTab(browser2); | 166 chrome::CloseTab(browser2); |
167 content::RunAllPendingInMessageLoop(); | 167 content::RunAllPendingInMessageLoop(); |
168 EXPECT_EQ(NULL, dialog->GetWidget()); | 168 EXPECT_EQ(NULL, dialog->GetWidget()); |
169 } | 169 } |
170 | 170 |
| 171 // Tests that the web contents navigates when backspace is pressed. |
| 172 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, NavigationOnBackspace) { |
| 173 content::WebContents* web_contents = |
| 174 browser()->tab_strip_model()->GetActiveWebContents(); |
| 175 content::WaitForLoadStop(web_contents); |
| 176 const GURL original_url = web_contents->GetURL(); |
| 177 EXPECT_NE(GURL(chrome::kChromeUIVersionURL), original_url); |
| 178 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIVersionURL)); |
| 179 content::WaitForLoadStop(web_contents); |
| 180 EXPECT_EQ(GURL(chrome::kChromeUIVersionURL), web_contents->GetURL()); |
| 181 |
| 182 std::unique_ptr<TestDialog> dialog = ShowModalDialog(web_contents); |
| 183 |
| 184 views::Widget* widget = dialog->GetWidget(); |
| 185 |
| 186 EXPECT_TRUE(widget->IsVisible()); |
| 187 EXPECT_EQ(dialog->GetContentsView(), |
| 188 widget->GetFocusManager()->GetFocusedView()); |
| 189 |
| 190 // Pressing backspace should not navigate back and close the dialog |
| 191 // with the Finch flag disabled. |
| 192 EXPECT_TRUE(chrome::CanGoBack(browser())); |
| 193 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_BACK, |
| 194 false, false, false, false)); |
| 195 content::RunAllPendingInMessageLoop(); |
| 196 content::WaitForLoadStop(web_contents); |
| 197 |
| 198 EXPECT_EQ(widget, dialog->GetWidget()); |
| 199 EXPECT_EQ(GURL(chrome::kChromeUIVersionURL), web_contents->GetURL()); |
| 200 |
| 201 // Pressing backspace should navigate back and close the dialog with the |
| 202 // Finch flag enabled. |
| 203 base::FeatureList::ClearInstanceForTesting(); |
| 204 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 205 feature_list->InitializeFromCommandLine("BackspaceGoesBack", std::string()); |
| 206 base::FeatureList::SetInstance(std::move(feature_list)); |
| 207 |
| 208 EXPECT_TRUE(chrome::CanGoBack(browser())); |
| 209 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_BACK, |
| 210 false, false, false, false)); |
| 211 content::RunAllPendingInMessageLoop(); |
| 212 content::WaitForLoadStop(web_contents); |
| 213 |
| 214 EXPECT_EQ(nullptr, dialog->GetWidget()); |
| 215 EXPECT_EQ(original_url, web_contents->GetURL()); |
| 216 } |
| 217 |
171 // Tests that the dialog closes when the escape key is pressed. | 218 // Tests that the dialog closes when the escape key is pressed. |
172 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, ClosesOnEscape) { | 219 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, ClosesOnEscape) { |
173 #if defined(OS_WIN) | 220 #if defined(OS_WIN) |
174 // TODO(msw): The widget is not made NULL on XP. http://crbug.com/177482 | 221 // TODO(msw): The widget is not made NULL on XP. http://crbug.com/177482 |
175 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 222 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
176 return; | 223 return; |
177 #endif | 224 #endif |
178 | 225 |
179 std::unique_ptr<TestDialog> dialog = | 226 std::unique_ptr<TestDialog> dialog = |
180 ShowModalDialog(browser()->tab_strip_model()->GetActiveWebContents()); | 227 ShowModalDialog(browser()->tab_strip_model()->GetActiveWebContents()); |
181 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); | 228 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); |
182 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_ESCAPE, | 229 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_ESCAPE, |
183 false, false, false, false)); | 230 false, false, false, false)); |
184 content::RunAllPendingInMessageLoop(); | 231 content::RunAllPendingInMessageLoop(); |
185 EXPECT_EQ(NULL, dialog->GetWidget()); | 232 EXPECT_EQ(NULL, dialog->GetWidget()); |
186 } | 233 } |
OLD | NEW |