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/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/run_loop.h" | |
10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
15 #include "chrome/browser/ui/browser_tabstrip.h" | 16 #include "chrome/browser/ui/browser_tabstrip.h" |
16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
17 #include "chrome/browser/ui/chrome_pages.h" | 18 #include "chrome/browser/ui/chrome_pages.h" |
18 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h" | 19 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h" |
19 #include "chrome/browser/ui/location_bar/location_bar.h" | 20 #include "chrome/browser/ui/location_bar/location_bar.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/browser/ui/view_ids.h" | 22 #include "chrome/browser/ui/view_ids.h" |
22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
24 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
25 #include "chrome/test/base/interactive_test_utils.h" | 26 #include "chrome/test/base/interactive_test_utils.h" |
26 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
27 #include "components/omnibox/browser/omnibox_edit_controller.h" | 28 #include "components/omnibox/browser/omnibox_edit_controller.h" |
28 #include "components/omnibox/browser/omnibox_edit_model.h" | 29 #include "components/omnibox/browser/omnibox_edit_model.h" |
29 #include "components/omnibox/browser/omnibox_view.h" | 30 #include "components/omnibox/browser/omnibox_view.h" |
30 #include "content/public/browser/interstitial_page.h" | 31 #include "content/public/browser/interstitial_page.h" |
31 #include "content/public/browser/interstitial_page_delegate.h" | 32 #include "content/public/browser/interstitial_page_delegate.h" |
32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/render_frame_host.h" | 34 #include "content/public/browser/render_frame_host.h" |
34 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
35 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
36 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
37 #include "content/public/test/browser_test_utils.h" | 38 #include "content/public/test/browser_test_utils.h" |
38 #include "net/test/embedded_test_server/embedded_test_server.h" | 39 #include "net/test/embedded_test_server/embedded_test_server.h" |
40 #include "ui/views/widget/widget.h" | |
msw
2015/09/14 16:56:16
c/b/ui/ can't always depend on views code; move th
msw
2015/09/14 18:15:27
Ping; I'm not sure if you saw this comment.
joone
2015/09/14 18:23:39
Okay, I will move this test to browser_view_focus_
joone
2015/09/14 19:15:30
Done.
| |
41 #include "ui/views/widget/widget_observer.h" | |
39 | 42 |
40 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
41 #include "base/win/windows_version.h" | 44 #include "base/win/windows_version.h" |
42 #endif | 45 #endif |
43 | 46 |
44 using content::RenderViewHost; | 47 using content::RenderViewHost; |
45 using content::WebContents; | 48 using content::WebContents; |
46 | 49 |
47 #if defined(OS_LINUX) || defined(OS_MACOSX) | 50 #if defined(OS_LINUX) || defined(OS_MACOSX) |
48 // TODO(jcampan): http://crbug.com/23683 for linux. | 51 // TODO(jcampan): http://crbug.com/23683 for linux. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 void DontProceed() { interstitial_page_->DontProceed(); } | 184 void DontProceed() { interstitial_page_->DontProceed(); } |
182 | 185 |
183 bool HasFocus() { return render_view_host()->GetView()->HasFocus(); } | 186 bool HasFocus() { return render_view_host()->GetView()->HasFocus(); } |
184 | 187 |
185 private: | 188 private: |
186 std::string html_contents_; | 189 std::string html_contents_; |
187 content::InterstitialPage* interstitial_page_; // Owns this. | 190 content::InterstitialPage* interstitial_page_; // Owns this. |
188 DISALLOW_COPY_AND_ASSIGN(TestInterstitialPage); | 191 DISALLOW_COPY_AND_ASSIGN(TestInterstitialPage); |
189 }; | 192 }; |
190 | 193 |
194 // Spins a run loop until a Widget becomes inactive. | |
195 class WidgetActivationWaiter : public views::WidgetObserver { | |
joone
2015/09/11 23:41:50
The WidgetActivationWaiter class was copied from u
| |
196 public: | |
197 explicit WidgetActivationWaiter(views::Widget* widget) : observed_(false) { | |
198 widget->AddObserver(this); | |
199 } | |
200 | |
201 void Wait() { | |
202 if (!observed_) | |
203 run_loop_.Run(); | |
204 } | |
205 | |
206 void OnWidgetActivationChanged(views::Widget* widget, bool active) override { | |
207 EXPECT_FALSE(active); | |
208 observed_ = true; | |
209 widget->RemoveObserver(this); | |
210 if (run_loop_.running()) | |
211 run_loop_.Quit(); | |
212 } | |
213 | |
214 private: | |
215 base::RunLoop run_loop_; | |
216 bool observed_; | |
217 | |
218 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); | |
219 }; | |
220 | |
191 // Flaky on Mac (http://crbug.com/67301) and Windows | 221 // Flaky on Mac (http://crbug.com/67301) and Windows |
192 // (http://crbug.com/523255). | 222 // (http://crbug.com/523255). |
193 #if defined(OS_MACOSX) || defined(OS_WIN) | 223 #if defined(OS_MACOSX) || defined(OS_WIN) |
194 #define MAYBE_ClickingMovesFocus DISABLED_ClickingMovesFocus | 224 #define MAYBE_ClickingMovesFocus DISABLED_ClickingMovesFocus |
195 #else | 225 #else |
196 #define MAYBE_ClickingMovesFocus ClickingMovesFocus | 226 #define MAYBE_ClickingMovesFocus ClickingMovesFocus |
197 #endif | 227 #endif |
198 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_ClickingMovesFocus) { | 228 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_ClickingMovesFocus) { |
199 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 229 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
200 #if defined(OS_POSIX) | 230 #if defined(OS_POSIX) |
(...skipping 30 matching lines...) Expand all Loading... | |
231 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 261 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
232 | 262 |
233 chrome::FocusLocationBar(browser()); | 263 chrome::FocusLocationBar(browser()); |
234 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 264 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
235 // Hide the window, show it again, the focus should not have changed. | 265 // Hide the window, show it again, the focus should not have changed. |
236 ui_test_utils::HideNativeWindow(window); | 266 ui_test_utils::HideNativeWindow(window); |
237 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); | 267 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); |
238 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 268 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
239 } | 269 } |
240 | 270 |
271 // This test is only for Linux Desktop. | |
272 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
273 #define MAYBE_BrowserDialogModalTest BrowserDialogModalTest | |
274 #else | |
275 #define MAYBE_BrowserDialogModalTest DISABLED_BrowserDialogModalTest | |
276 #endif | |
277 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_BrowserDialogModalTest) { | |
278 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
279 const GURL url = embedded_test_server()->GetURL(kSimplePage); | |
280 ui_test_utils::NavigateToURL(browser(), url); | |
281 ASSERT_TRUE(browser()->window()->IsActive()); | |
282 | |
283 browser()->OpenFile(); | |
284 | |
285 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | |
286 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | |
287 ASSERT_NE(nullptr, widget); | |
288 | |
289 // Insert a delay to wait until the browser window becomes inactive. | |
msw
2015/09/14 16:56:16
Update this comment.
joone
2015/09/14 18:14:17
Done.
| |
290 WidgetActivationWaiter waiter(widget); | |
291 waiter.Wait(); | |
292 EXPECT_FALSE(browser()->window()->IsActive()); | |
293 | |
294 ClickOnView(VIEW_ID_TAB_CONTAINER); | |
295 // The window should not get focus due to modal dialog. | |
296 EXPECT_FALSE(browser()->window()->IsActive()); | |
297 | |
298 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
299 EXPECT_FALSE(browser()->window()->IsActive()); | |
300 | |
301 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); | |
302 EXPECT_FALSE(browser()->window()->IsActive()); | |
303 | |
304 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
305 browser(), ui::VKEY_TAB, false, false, true, false)); | |
306 EXPECT_FALSE(browser()->window()->IsActive()); | |
307 } | |
308 | |
241 // Tabs remember focus. | 309 // Tabs remember focus. |
242 // Disabled, http://crbug.com/62542. | 310 // Disabled, http://crbug.com/62542. |
243 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { | 311 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { |
244 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 312 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
245 const GURL url = embedded_test_server()->GetURL(kSimplePage); | 313 const GURL url = embedded_test_server()->GetURL(kSimplePage); |
246 ui_test_utils::NavigateToURL(browser(), url); | 314 ui_test_utils::NavigateToURL(browser(), url); |
247 | 315 |
248 // Create several tabs. | 316 // Create several tabs. |
249 for (int i = 0; i < 4; ++i) { | 317 for (int i = 0; i < 4; ++i) { |
250 chrome::AddSelectedTabWithURL(browser(), url, | 318 chrome::AddSelectedTabWithURL(browser(), url, |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 771 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
704 content::NotificationService::AllSources()); | 772 content::NotificationService::AllSources()); |
705 chrome::GoForward(browser(), CURRENT_TAB); | 773 chrome::GoForward(browser(), CURRENT_TAB); |
706 forward_nav_observer.Wait(); | 774 forward_nav_observer.Wait(); |
707 } | 775 } |
708 | 776 |
709 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 777 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
710 } | 778 } |
711 | 779 |
712 } // namespace | 780 } // namespace |
OLD | NEW |