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/app/chrome_command_ids.h" | |
pkotwicz
2015/03/11 00:47:39
Can you please remove the new includes that you do
Miyoung Shin
2015/03/11 05:42:26
Done. I got rid of the unnecessary include.
| |
8 #include "chrome/browser/chrome_notification_types.h" | |
9 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | |
10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" | |
7 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_commands.h" | |
13 #include "chrome/browser/ui/browser_finder.h" | |
8 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "components/app_modal/app_modal_dialog.h" | |
19 #include "content/public/browser/render_frame_host.h" | |
20 #include "content/public/browser/render_view_host.h" | |
12 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
13 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
23 #include "content/public/test/test_navigation_observer.h" | |
24 #include "content/public/test/test_utils.h" | |
14 #include "ui/base/test/ui_controls.h" | 25 #include "ui/base/test/ui_controls.h" |
15 | 26 |
16 namespace { | 27 namespace { |
17 | 28 |
18 class MouseLeaveTest : public InProcessBrowserTest { | 29 class MouseLeaveTest : public InProcessBrowserTest { |
19 public: | 30 public: |
20 MouseLeaveTest() {} | 31 MouseLeaveTest() {} |
21 | 32 |
22 void MouseLeaveTestCommon() { | 33 void LoadTestPageAndWaitForMouseOver(content::WebContents* tab) { |
34 gfx::Rect tab_view_bounds = tab->GetContainerBounds(); | |
23 GURL test_url = ui_test_utils::GetTestUrl( | 35 GURL test_url = ui_test_utils::GetTestUrl( |
24 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); | 36 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); |
25 | 37 |
26 content::WebContents* tab = | 38 gfx::Point in_content = |
27 browser()->tab_strip_model()->GetActiveWebContents(); | 39 gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2, |
28 gfx::Rect tab_view_bounds = tab->GetContainerBounds(); | 40 tab_view_bounds.y() + 10); |
29 | 41 above_content_ = |
30 gfx::Point in_content_point( | 42 gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2, |
31 tab_view_bounds.x() + tab_view_bounds.width() / 2, | 43 tab_view_bounds.y() - 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 | 44 |
37 // Start by moving the point just above the content. | 45 // Start by moving the point just above the content. |
38 ui_controls::SendMouseMove(above_content_point.x(), | 46 ui_controls::SendMouseMove(above_content_.x(), above_content_.y()); |
39 above_content_point.y()); | |
40 | 47 |
41 // Navigate to the test html page. | 48 // Navigate to the test html page. |
42 base::string16 load_expected_title(base::ASCIIToUTF16("onload")); | 49 base::string16 load_expected_title(base::ASCIIToUTF16("onload")); |
43 content::TitleWatcher load_title_watcher(tab, load_expected_title); | 50 content::TitleWatcher load_title_watcher(tab, load_expected_title); |
44 ui_test_utils::NavigateToURL(browser(), test_url); | 51 ui_test_utils::NavigateToURL(browser(), test_url); |
45 // Wait for the onload() handler to complete so we can do the | 52 // Wait for the onload() handler to complete so we can do the |
46 // next part of the test. | 53 // next part of the test. |
47 EXPECT_EQ(load_expected_title, load_title_watcher.WaitAndGetTitle()); | 54 EXPECT_EQ(load_expected_title, load_title_watcher.WaitAndGetTitle()); |
48 | 55 |
49 // Move the cursor to the top-center of the content, which will trigger | 56 // Move the cursor to the top-center of the content which will trigger |
50 // a javascript onMouseOver event. | 57 // a javascript onMouseOver event. |
51 ui_controls::SendMouseMove(in_content_point.x(), in_content_point.y()); | 58 ui_controls::SendMouseMove(in_content.x(), in_content.y()); |
52 | 59 |
53 // Wait on the correct intermediate title. | 60 // Wait on the correct intermediate title. |
54 base::string16 entered_expected_title(base::ASCIIToUTF16("entered")); | 61 base::string16 entered_expected_title(base::ASCIIToUTF16("entered")); |
55 content::TitleWatcher entered_title_watcher(tab, entered_expected_title); | 62 content::TitleWatcher entered_title_watcher(tab, entered_expected_title); |
56 EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle()); | 63 EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle()); |
64 } | |
65 | |
66 void MouseLeaveTestCommon() { | |
67 content::WebContents* tab = | |
68 browser()->tab_strip_model()->GetActiveWebContents(); | |
69 | |
70 LoadTestPageAndWaitForMouseOver(tab); | |
57 | 71 |
58 // Move the cursor above the content again, which should trigger | 72 // Move the cursor above the content again, which should trigger |
59 // a javascript onMouseOut event. | 73 // a javascript onMouseOut event. |
60 ui_controls::SendMouseMove(above_content_point.x(), | 74 ui_controls::SendMouseMove(above_content_.x(), above_content_.y()); |
61 above_content_point.y()); | |
62 | 75 |
63 // Wait on the correct final value of the cookie. | 76 // Wait on the correct final value of the cookie. |
64 base::string16 left_expected_title(base::ASCIIToUTF16("left")); | 77 base::string16 left_expected_title(base::ASCIIToUTF16("left")); |
65 content::TitleWatcher left_title_watcher(tab, left_expected_title); | 78 content::TitleWatcher left_title_watcher(tab, left_expected_title); |
66 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); | 79 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); |
67 } | 80 } |
68 | 81 |
82 gfx::Point above_content_; | |
83 | |
69 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest); | 84 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest); |
70 }; | 85 }; |
71 | 86 |
72 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_WIN) | 87 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_WIN) |
73 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. | 88 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. |
74 // OS_LINUX: http://crbug.com/133361. | 89 // OS_LINUX: http://crbug.com/133361. |
75 // OS_WIN: http://crbug.com/419468 | 90 // OS_WIN: http://crbug.com/419468 |
76 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut | 91 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut |
77 #else | 92 #else |
78 #define MAYBE_TestOnMouseOut TestOnMouseOut | 93 #define MAYBE_TestOnMouseOut TestOnMouseOut |
79 #endif | 94 #endif |
80 | 95 |
81 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) { | 96 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) { |
82 MouseLeaveTestCommon(); | 97 MouseLeaveTestCommon(); |
83 } | 98 } |
84 | 99 |
85 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
86 // For MAC: Missing automation provider support: http://crbug.com/45892 | 101 // For MAC: Missing automation provider support: http://crbug.com/45892 |
87 // For linux : http://crbug.com/133361. interactive mouse tests are flaky. | 102 // For linux : http://crbug.com/133361. interactive mouse tests are flaky. |
88 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) { | 103 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) { |
89 gfx::Rect browser_bounds = browser()->window()->GetBounds(); | 104 gfx::Rect browser_bounds = browser()->window()->GetBounds(); |
90 ui_controls::SendMouseMove(browser_bounds.x() + 200, | 105 ui_controls::SendMouseMove(browser_bounds.x() + 200, |
91 browser_bounds.y() + 10); | 106 browser_bounds.y() + 10); |
92 ui_controls::SendMouseClick(ui_controls::LEFT); | 107 ui_controls::SendMouseClick(ui_controls::LEFT); |
93 | 108 |
94 MouseLeaveTestCommon(); | 109 MouseLeaveTestCommon(); |
95 } | 110 } |
96 #endif | 111 #endif |
97 | 112 |
113 #if defined(OS_WIN) | |
114 // Test that a mouse leave event is triggered when opening a new window. | |
115 #define MAYBE_NewWindow NewWindow | |
116 #else | |
117 // Others except OS_WIN do not send the mouseleave when opening the new window | |
118 // TODO: Make test pass on the other OSes | |
119 // See http://crbug.com/458492 | |
120 #define MAYBE_NewWindow DISABLED_NewWindow | |
121 #endif | |
122 | |
123 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_NewWindow) { | |
124 content::WebContents* tab = | |
125 browser()->tab_strip_model()->GetActiveWebContents(); | |
126 | |
127 LoadTestPageAndWaitForMouseOver(tab); | |
128 | |
129 // Create an new window. | |
130 ui_test_utils::BrowserAddedObserver browser_added_observer; | |
131 chrome::NewWindow(browser()); | |
132 browser_added_observer.WaitForSingleNewBrowser(); | |
133 | |
134 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); | |
135 | |
136 content::RunAllPendingInMessageLoop(); | |
137 | |
138 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
139 const base::string16 success_title = base::ASCIIToUTF16("with mouseleave"); | |
140 const base::string16 failure_title = base::ASCIIToUTF16("without mouseleave"); | |
141 content::TitleWatcher done_title_watcher(tab, success_title); | |
142 done_title_watcher.AlsoWaitForTitle(failure_title); | |
143 | |
144 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
145 } | |
146 | |
147 #if defined(OS_WIN) || defined(OS_MACOSX) | |
148 // Test that a mouseleave is not triggered when showing the context menu. | |
149 // TODO: Make test pass on OS_WIN and OS_MACOSX | |
150 // OS_WIN: http://crbug.com/450138 | |
151 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. | |
152 #define MAYBE_ContextMenu DISABLED_ContextMenu | |
153 #else | |
154 #define MAYBE_ContextMenu ContextMenu | |
155 #endif | |
156 | |
157 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) { | |
158 content::WebContents* tab = | |
159 browser()->tab_strip_model()->GetActiveWebContents(); | |
160 | |
161 LoadTestPageAndWaitForMouseOver(tab); | |
162 | |
163 ContextMenuWaiter menu_observer(content::NotificationService::AllSources()); | |
164 ui_controls::SendMouseClick(ui_controls::RIGHT); | |
165 // Wait until the context menu is opened and closed. | |
166 menu_observer.WaitForMenuOpenAndClose(); | |
167 | |
168 content::RunAllPendingInMessageLoop(); | |
169 | |
170 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
171 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); | |
172 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); | |
173 content::TitleWatcher done_title_watcher(tab, success_title); | |
174 done_title_watcher.AlsoWaitForTitle(failure_title); | |
175 | |
176 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
177 } | |
178 | |
179 #if defined(OS_WIN) || defined(OS_MACOSX) | |
180 // Test that a mouseleave is not triggered when showing a modal dialog. | |
181 // Sample regression: crbug.com/394672 | |
182 // TODO: Make test pass on OS_WIN and OS_MACOSX | |
183 // OS_WIN: http://crbug.com/450138 | |
184 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. | |
185 #define MAYBE_ModalDialog DISABLED_ModalDialog | |
186 #else | |
187 #define MAYBE_ModalDialog ModalDialog | |
188 #endif | |
189 | |
190 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) { | |
191 content::WebContents* tab = | |
192 browser()->tab_strip_model()->GetActiveWebContents(); | |
193 | |
194 LoadTestPageAndWaitForMouseOver(tab); | |
195 | |
196 tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()")); | |
197 // Cancel the dialog. | |
pkotwicz
2015/03/11 00:47:40
Nit: Move the comment between lines 198 and 199.
Miyoung Shin
2015/03/11 05:42:26
Done.
| |
198 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | |
199 alert->CloseModalDialog(); | |
200 | |
201 content::RunAllPendingInMessageLoop(); | |
202 | |
203 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
204 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); | |
205 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); | |
206 content::TitleWatcher done_title_watcher(tab, success_title); | |
207 done_title_watcher.AlsoWaitForTitle(failure_title); | |
208 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
209 } | |
210 | |
98 } // namespace | 211 } // namespace |
OLD | NEW |