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/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 8 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
7 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" |
8 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "components/app_modal/app_modal_dialog.h" |
| 17 #include "content/public/browser/render_frame_host.h" |
12 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
13 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
14 #include "ui/base/test/ui_controls.h" | 20 #include "ui/base/test/ui_controls.h" |
15 | 21 |
16 namespace { | 22 namespace { |
17 | 23 |
18 class MouseLeaveTest : public InProcessBrowserTest { | 24 class MouseLeaveTest : public InProcessBrowserTest { |
19 public: | 25 public: |
20 MouseLeaveTest() {} | 26 MouseLeaveTest() {} |
21 | 27 |
22 void MouseLeaveTestCommon() { | 28 void LoadTestPageAndWaitForMouseOver(content::WebContents* tab) { |
| 29 gfx::Rect tab_view_bounds = tab->GetContainerBounds(); |
23 GURL test_url = ui_test_utils::GetTestUrl( | 30 GURL test_url = ui_test_utils::GetTestUrl( |
24 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); | 31 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); |
25 | 32 |
26 content::WebContents* tab = | 33 gfx::Point in_content(tab_view_bounds.x() + tab_view_bounds.width() / 2, |
27 browser()->tab_strip_model()->GetActiveWebContents(); | 34 tab_view_bounds.y() + 10); |
28 gfx::Rect tab_view_bounds = tab->GetContainerBounds(); | 35 out_of_content_ = |
29 | 36 gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2, |
30 gfx::Point in_content_point( | 37 tab_view_bounds.y() - 2); |
31 tab_view_bounds.x() + tab_view_bounds.width() / 2, | |
32 tab_view_bounds.y() + 10); | |
33 gfx::Point above_content_point( | |
34 tab_view_bounds.x() + tab_view_bounds.width() / 2, | |
35 tab_view_bounds.y() - 2); | |
36 | 38 |
37 // Start by moving the point just above the content. | 39 // Start by moving the point just above the content. |
38 ui_controls::SendMouseMove(above_content_point.x(), | 40 ui_controls::SendMouseMove(out_of_content_.x(), out_of_content_.y()); |
39 above_content_point.y()); | |
40 | 41 |
41 // Navigate to the test html page. | 42 // Navigate to the test html page. |
42 base::string16 load_expected_title(base::ASCIIToUTF16("onload")); | 43 base::string16 load_expected_title(base::ASCIIToUTF16("onload")); |
43 content::TitleWatcher load_title_watcher(tab, load_expected_title); | 44 content::TitleWatcher load_title_watcher(tab, load_expected_title); |
44 ui_test_utils::NavigateToURL(browser(), test_url); | 45 ui_test_utils::NavigateToURL(browser(), test_url); |
45 // Wait for the onload() handler to complete so we can do the | 46 // Wait for the onload() handler to complete so we can do the |
46 // next part of the test. | 47 // next part of the test. |
47 EXPECT_EQ(load_expected_title, load_title_watcher.WaitAndGetTitle()); | 48 EXPECT_EQ(load_expected_title, load_title_watcher.WaitAndGetTitle()); |
48 | 49 |
49 // Move the cursor to the top-center of the content, which will trigger | 50 // Move the cursor to the top-center of the content which will trigger |
50 // a javascript onMouseOver event. | 51 // a javascript onMouseOver event. |
51 ui_controls::SendMouseMove(in_content_point.x(), in_content_point.y()); | 52 ui_controls::SendMouseMove(in_content.x(), in_content.y()); |
52 | 53 |
53 // Wait on the correct intermediate title. | 54 // Wait on the correct intermediate title. |
54 base::string16 entered_expected_title(base::ASCIIToUTF16("entered")); | 55 base::string16 entered_expected_title(base::ASCIIToUTF16("entered")); |
55 content::TitleWatcher entered_title_watcher(tab, entered_expected_title); | 56 content::TitleWatcher entered_title_watcher(tab, entered_expected_title); |
56 EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle()); | 57 EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle()); |
| 58 } |
| 59 |
| 60 void MouseLeaveTestCommon() { |
| 61 content::WebContents* tab = |
| 62 browser()->tab_strip_model()->GetActiveWebContents(); |
| 63 |
| 64 EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab)); |
57 | 65 |
58 // Move the cursor above the content again, which should trigger | 66 // Move the cursor above the content again, which should trigger |
59 // a javascript onMouseOut event. | 67 // a javascript onMouseOut event. |
60 ui_controls::SendMouseMove(above_content_point.x(), | 68 ui_controls::SendMouseMove(out_of_content_.x(), out_of_content_.y()); |
61 above_content_point.y()); | |
62 | 69 |
63 // Wait on the correct final value of the cookie. | 70 // Wait on the correct final value of the cookie. |
64 base::string16 left_expected_title(base::ASCIIToUTF16("left")); | 71 base::string16 left_expected_title(base::ASCIIToUTF16("left")); |
65 content::TitleWatcher left_title_watcher(tab, left_expected_title); | 72 content::TitleWatcher left_title_watcher(tab, left_expected_title); |
66 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); | 73 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); |
67 } | 74 } |
68 | 75 |
| 76 // The coordinates out of the content to move the mouse point |
| 77 gfx::Point out_of_content_; |
| 78 |
69 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest); | 79 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest); |
70 }; | 80 }; |
71 | 81 |
72 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_WIN) | 82 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_WIN) |
73 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. | 83 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. |
74 // OS_LINUX: http://crbug.com/133361. | 84 // OS_LINUX: http://crbug.com/133361. |
75 // OS_WIN: http://crbug.com/419468 | 85 // OS_WIN: http://crbug.com/419468 |
76 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut | 86 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut |
77 #else | 87 #else |
78 #define MAYBE_TestOnMouseOut TestOnMouseOut | 88 #define MAYBE_TestOnMouseOut TestOnMouseOut |
79 #endif | 89 #endif |
80 | 90 |
81 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) { | 91 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) { |
82 MouseLeaveTestCommon(); | 92 MouseLeaveTestCommon(); |
83 } | 93 } |
84 | 94 |
85 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
86 // For MAC: Missing automation provider support: http://crbug.com/45892 | 96 // For MAC: Missing automation provider support: http://crbug.com/45892 |
87 // For linux : http://crbug.com/133361. interactive mouse tests are flaky. | 97 // For linux : http://crbug.com/133361. interactive mouse tests are flaky. |
88 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) { | 98 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) { |
89 gfx::Rect browser_bounds = browser()->window()->GetBounds(); | 99 gfx::Rect browser_bounds = browser()->window()->GetBounds(); |
90 ui_controls::SendMouseMove(browser_bounds.x() + 200, | 100 ui_controls::SendMouseMove(browser_bounds.x() + 200, |
91 browser_bounds.y() + 10); | 101 browser_bounds.y() + 10); |
92 ui_controls::SendMouseClick(ui_controls::LEFT); | 102 ui_controls::SendMouseClick(ui_controls::LEFT); |
93 | 103 |
94 MouseLeaveTestCommon(); | 104 MouseLeaveTestCommon(); |
95 } | 105 } |
96 #endif | 106 #endif |
97 | 107 |
| 108 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 109 // Test that a mouseleave is not triggered when showing the context menu. |
| 110 // If the test is failed, it means that Blink gets the mouseleave event |
| 111 // when showing the context menu and it could make the unexpecting |
| 112 // content behavior such as clearing the hover status. |
| 113 // Please refer to the below issue for understanding what happens . |
| 114 // TODO: Make test pass on OS_WIN and OS_MACOSX |
| 115 // OS_WIN: http://crbug.com/450138 |
| 116 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. |
| 117 #define MAYBE_ContextMenu DISABLED_ContextMenu |
| 118 #else |
| 119 #define MAYBE_ContextMenu ContextMenu |
| 120 #endif |
| 121 |
| 122 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) { |
| 123 content::WebContents* tab = |
| 124 browser()->tab_strip_model()->GetActiveWebContents(); |
| 125 |
| 126 EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab)); |
| 127 |
| 128 ContextMenuWaiter menu_observer(content::NotificationService::AllSources()); |
| 129 ui_controls::SendMouseClick(ui_controls::RIGHT); |
| 130 // Wait until the context menu is opened and closed. |
| 131 menu_observer.WaitForMenuOpenAndClose(); |
| 132 |
| 133 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); |
| 134 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); |
| 135 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); |
| 136 content::TitleWatcher done_title_watcher(tab, success_title); |
| 137 done_title_watcher.AlsoWaitForTitle(failure_title); |
| 138 |
| 139 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); |
| 140 } |
| 141 |
| 142 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 143 // Test that a mouseleave is not triggered when showing a modal dialog. |
| 144 // Sample regression: crbug.com/394672 |
| 145 // TODO: Make test pass on OS_WIN and OS_MACOSX |
| 146 // OS_WIN: http://crbug.com/450138 |
| 147 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. |
| 148 #define MAYBE_ModalDialog DISABLED_ModalDialog |
| 149 #else |
| 150 #define MAYBE_ModalDialog ModalDialog |
| 151 #endif |
| 152 |
| 153 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) { |
| 154 content::WebContents* tab = |
| 155 browser()->tab_strip_model()->GetActiveWebContents(); |
| 156 |
| 157 EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab)); |
| 158 |
| 159 tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()")); |
| 160 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 161 // Cancel the dialog. |
| 162 alert->CloseModalDialog(); |
| 163 |
| 164 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); |
| 165 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); |
| 166 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); |
| 167 content::TitleWatcher done_title_watcher(tab, success_title); |
| 168 done_title_watcher.AlsoWaitForTitle(failure_title); |
| 169 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); |
| 170 } |
| 171 |
98 } // namespace | 172 } // namespace |
OLD | NEW |