Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: chrome/browser/mouseleave_browsertest.cc

Issue 891213002: Add a test for the mouseleave event on window. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/mouseleave.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
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"
14 #include "ui/base/test/ui_controls.h" 24 #include "ui/base/test/ui_controls.h"
15 25
16 namespace { 26 namespace {
17 27
18 class MouseLeaveTest : public InProcessBrowserTest { 28 class MouseLeaveTest : public InProcessBrowserTest {
19 public: 29 public:
20 MouseLeaveTest() {} 30 MouseLeaveTest() {}
21 31
22 void MouseLeaveTestCommon() { 32 void NavigateAndLoadContent(content::WebContents* tab, GURL& url) {
pkotwicz 2015/02/10 22:50:15 Would LoadTestPageAndWaitForMouseOver() be a more
Miyoung Shin 2015/02/12 14:23:27 Done.
23 GURL test_url = ui_test_utils::GetTestUrl(
24 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
25
26 content::WebContents* tab =
27 browser()->tab_strip_model()->GetActiveWebContents();
28 gfx::Rect tab_view_bounds = tab->GetContainerBounds(); 33 gfx::Rect tab_view_bounds = tab->GetContainerBounds();
29 34
30 gfx::Point in_content_point( 35 in_content_ = gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2,
31 tab_view_bounds.x() + tab_view_bounds.width() / 2, 36 tab_view_bounds.y() + 10);
32 tab_view_bounds.y() + 10); 37 above_content_ =
33 gfx::Point above_content_point( 38 gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2,
34 tab_view_bounds.x() + tab_view_bounds.width() / 2, 39 tab_view_bounds.y() - 2);
35 tab_view_bounds.y() - 2);
36 40
37 // Start by moving the point just above the content. 41 ui_controls::SendMouseMove(above_content_.x(), above_content_.y());
pkotwicz 2015/02/10 22:50:15 Isn't this comment still accurate?
Miyoung Shin 2015/02/12 14:23:27 Done.
38 ui_controls::SendMouseMove(above_content_point.x(),
39 above_content_point.y());
40 42
41 // Navigate to the test html page. 43 // Navigate to the test html page.
42 base::string16 load_expected_title(base::ASCIIToUTF16("onload")); 44 base::string16 load_expected_title(base::ASCIIToUTF16("onload"));
43 content::TitleWatcher load_title_watcher(tab, load_expected_title); 45 content::TitleWatcher load_title_watcher(tab, load_expected_title);
44 ui_test_utils::NavigateToURL(browser(), test_url); 46 ui_test_utils::NavigateToURL(browser(), url);
45 // Wait for the onload() handler to complete so we can do the 47 // Wait for the onload() handler to complete so we can do the
46 // next part of the test. 48 // next part of the test.
47 EXPECT_EQ(load_expected_title, load_title_watcher.WaitAndGetTitle()); 49 EXPECT_EQ(load_expected_title, load_title_watcher.WaitAndGetTitle());
48 50
49 // Move the cursor to the top-center of the content, which will trigger 51 // Move the cursor to the top-center of the content which will trigger
50 // a javascript onMouseOver event. 52 // a javascript event.
pkotwicz 2015/02/10 22:50:15 Isn't this comment still accurate?
Miyoung Shin 2015/02/12 14:23:27 Done.
51 ui_controls::SendMouseMove(in_content_point.x(), in_content_point.y()); 53 ui_controls::SendMouseMove(in_content_.x(), in_content_.y());
52 54
53 // Wait on the correct intermediate title. 55 // Wait on the correct intermediate title.
54 base::string16 entered_expected_title(base::ASCIIToUTF16("entered")); 56 base::string16 entered_expected_title(base::ASCIIToUTF16("entered"));
55 content::TitleWatcher entered_title_watcher(tab, entered_expected_title); 57 content::TitleWatcher entered_title_watcher(tab, entered_expected_title);
56 EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle()); 58 EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle());
59 }
60
61 void MouseLeaveTestCommon() {
62 content::WebContents* tab =
63 browser()->tab_strip_model()->GetActiveWebContents();
64 GURL test_url = ui_test_utils::GetTestUrl(
65 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
66
67 NavigateAndLoadContent(tab, test_url);
57 68
58 // Move the cursor above the content again, which should trigger 69 // Move the cursor above the content again, which should trigger
59 // a javascript onMouseOut event. 70 // a javascript onMouseOut event.
60 ui_controls::SendMouseMove(above_content_point.x(), 71 ui_controls::SendMouseMove(above_content().x(), above_content().y());
61 above_content_point.y());
62 72
63 // Wait on the correct final value of the cookie. 73 // Wait on the correct final value of the cookie.
64 base::string16 left_expected_title(base::ASCIIToUTF16("left")); 74 base::string16 left_expected_title(base::ASCIIToUTF16("left"));
65 content::TitleWatcher left_title_watcher(tab, left_expected_title); 75 content::TitleWatcher left_title_watcher(tab, left_expected_title);
66 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); 76 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle());
67 } 77 }
68 78
79 gfx::Point in_content() { return in_content_; }
80
81 gfx::Point above_content() { return above_content_; }
pkotwicz 2015/02/10 22:50:15 Can these two methods be removed? in_content() doe
Miyoung Shin 2015/02/12 14:23:27 I removed in_content() but I keep to use above_con
82
83 private:
84 gfx::Point in_content_;
85 gfx::Point above_content_;
86
69 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest); 87 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest);
70 }; 88 };
71 89
72 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_WIN) 90 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_WIN)
73 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. 91 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
74 // OS_LINUX: http://crbug.com/133361. 92 // OS_LINUX: http://crbug.com/133361.
75 // OS_WIN: http://crbug.com/419468 93 // OS_WIN: http://crbug.com/419468
76 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut 94 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut
77 #else 95 #else
78 #define MAYBE_TestOnMouseOut TestOnMouseOut 96 #define MAYBE_TestOnMouseOut TestOnMouseOut
79 #endif 97 #endif
80 98
81 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) { 99 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) {
82 MouseLeaveTestCommon(); 100 MouseLeaveTestCommon();
83 } 101 }
84 102
85 #if defined(OS_WIN) 103 #if defined(OS_WIN)
86 // For MAC: Missing automation provider support: http://crbug.com/45892 104 // For MAC: Missing automation provider support: http://crbug.com/45892
87 // For linux : http://crbug.com/133361. interactive mouse tests are flaky. 105 // For linux : http://crbug.com/133361. interactive mouse tests are flaky.
88 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) { 106 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) {
89 gfx::Rect browser_bounds = browser()->window()->GetBounds(); 107 gfx::Rect browser_bounds = browser()->window()->GetBounds();
90 ui_controls::SendMouseMove(browser_bounds.x() + 200, 108 ui_controls::SendMouseMove(browser_bounds.x() + 200,
91 browser_bounds.y() + 10); 109 browser_bounds.y() + 10);
92 ui_controls::SendMouseClick(ui_controls::LEFT); 110 ui_controls::SendMouseClick(ui_controls::LEFT);
93 111
94 MouseLeaveTestCommon(); 112 MouseLeaveTestCommon();
95 } 113 }
96 #endif 114 #endif
97 115
116 #if defined(OS_WIN)
117 // This test is for preventing a regression that the mouseleave is triggered
118 // on Window when opening the new window.
119 #define MAYBE_NewWindow NewWindow
120 #else
121 // Others except OS_WIN do not send the mouseleave when opening the new window
pkotwicz 2015/02/10 22:50:14 I think it is definitely worth enabling the test o
Miyoung Shin 2015/02/12 14:23:27 Um.. I can see the different result with yours. As
pkotwicz 2015/02/12 16:42:03 Sorry. Yes, you are right. (And without the change
Miyoung Shin 2015/02/13 07:48:40 I think so it looks like a bug but I'd like to che
Rick Byers 2015/02/13 08:59:43 All platforms should be sending a mouseleave when
Miyoung Shin 2015/02/13 12:16:57 Thanks rick, I will feel free to report the bug if
122 #define MAYBE_NewWindow DISABLED_NewWindow
123 #endif
124
125 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_NewWindow) {
126 content::WebContents* tab =
127 browser()->tab_strip_model()->GetActiveWebContents();
128 GURL test_url = ui_test_utils::GetTestUrl(
129 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
130
131 NavigateAndLoadContent(tab, test_url);
132
133 // Create an new window.
134 ui_test_utils::BrowserAddedObserver browser_added_observer;
135 chrome::NewWindow(browser());
136 browser_added_observer.WaitForSingleNewBrowser();
137
138 ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
139
140 content::RunAllPendingInMessageLoop();
141
142 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
143 base::string16 done_expected_title(base::ASCIIToUTF16("with mouseleave"));
144 content::TitleWatcher done_title_watcher(tab, done_expected_title);
145 EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle());
146 }
147
148
149 #if !defined(OS_WIN) && !defined(OS_MACOSX)
150 // This test is for preventing a regression that a mouseleave is triggered
151 // when showing the context menu.
152 // TODO:Make test pass on OS_WIN and OS_MACOSX
153 // OS_WIN : http://crbug.com/450138
154 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
pkotwicz 2015/02/10 22:50:15 Nits: - Rename the test to MAYBE_ContextMenu and d
Miyoung Shin 2015/02/12 14:23:27 Done.
155 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, ContextMenu) {
156 content::WebContents* tab =
157 browser()->tab_strip_model()->GetActiveWebContents();
158 GURL test_url = ui_test_utils::GetTestUrl(
159 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
160
161 NavigateAndLoadContent(tab, test_url);
162
163 SaveLinkAsContextMenuObserver menu_observer(
164 content::NotificationService::AllSources());
pkotwicz 2015/02/10 22:50:14 I think that SaveLinkAsContextMenuObserver is a ba
Miyoung Shin 2015/02/12 14:23:27 Done. Thank you for your kindly comments.
pkotwicz 2015/02/12 16:42:03 Sorry I should have been clearer. I meant renaming
Miyoung Shin 2015/02/13 07:48:40 Ah, I got it. I had not catched your point. I rena
165 ui_controls::SendMouseClick(ui_controls::RIGHT);
166 // Wait for context menu to be visible.
167 menu_observer.WaitForMenu();
168
169 base::string16 show_expected_title(base::ASCIIToUTF16("showed"));
170 content::TitleWatcher show_title_watcher(tab, show_expected_title);
171 EXPECT_EQ(show_expected_title, show_title_watcher.WaitAndGetTitle());
pkotwicz 2015/02/10 22:50:14 show_title_watcher.WaitAndGetTitle() seems to retu
Miyoung Shin 2015/02/12 14:23:27 Done. I think so it's not neccessary. I removed it
172
173 content::RunAllPendingInMessageLoop();
174
175 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
176 base::string16 done_expected_title(base::ASCIIToUTF16("without mouseleave"));
177 content::TitleWatcher done_title_watcher(tab, done_expected_title);
178 EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle());
179 }
180
181 // This test is for preventing a regression that a mouseleave is triggered
182 // when showing the modal dialog.
183 // TODO:Make test pass on OS_WIN and OS_MACOSX
184 // OS_WIN : http://crbug.com/450138
185 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
186 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, ModalDialog) {
187 content::WebContents* tab =
188 browser()->tab_strip_model()->GetActiveWebContents();
189 GURL test_url = ui_test_utils::GetTestUrl(
190 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
191
192 NavigateAndLoadContent(tab, test_url);
193
194 tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()"));
195 // Cancel the dialog.
196 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
197 alert->CloseModalDialog();
198
199 content::RunAllPendingInMessageLoop();
200
201 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
202 base::string16 done_expected_title(base::ASCIIToUTF16("without mouseleave"));
203 content::TitleWatcher done_title_watcher(tab, done_expected_title);
204 EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle());
205 }
206 #endif
207
98 } // namespace 208 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/mouseleave.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698