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

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) {
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());
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.
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_; }
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
pkotwicz 2015/02/04 19:43:31 Can you add comments as to why the test is disable
Miyoung Shin 2015/02/08 14:29:04 I've added the comment at patchset3
121 #define MAYBE_NewWindow DISABLED_NewWindow
122 #endif
123
124 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_NewWindow) {
125 content::WebContents* tab =
126 browser()->tab_strip_model()->GetActiveWebContents();
127 GURL test_url = ui_test_utils::GetTestUrl(
128 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
129
130 NavigateAndLoadContent(tab, test_url);
131
132 // Create an new window.
133 ui_test_utils::BrowserAddedObserver browser_added_observer;
134 chrome::NewWindow(browser());
135 Browser* new_browser = browser_added_observer.WaitForSingleNewBrowser();
136
137 ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
138
139 // Close the second window.
pkotwicz 2015/02/04 19:43:31 Is there a reason that you are closing the browser
Miyoung Shin 2015/02/08 14:29:04 I removed it. I thought that I should close the br
140 content::WindowedNotificationObserver browser_closed_observer(
141 chrome::NOTIFICATION_BROWSER_CLOSED,
142 content::NotificationService::AllSources());
143 chrome::CloseWindow(new_browser);
144 browser_closed_observer.Wait();
145
146 ASSERT_EQ(1u, chrome::GetTotalBrowserCount());
147
148 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
149 base::string16 done_expected_title(base::ASCIIToUTF16("with mouseleave"));
150 content::TitleWatcher done_title_watcher(tab, done_expected_title);
151 EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle());
152 }
153
154 #if defined(OS_WIN) || defined(OS_MACOSX)
155 // This test is for preventing a regression that a mouseleave is triggered
156 // when showing the context menu.
pkotwicz 2015/02/04 19:43:31 Can you please link to crbug.com/450138 for an exa
Miyoung Shin 2015/02/08 14:29:04 Done
157 // OS_WIN : http://crbug.com/450138
158 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
159 #define MAYBE_ContextMenu DISABLED_ContextMenu
160 #else
161 #define MAYBE_ContextMenu ContextMenu
162 #endif
163
164 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) {
165 content::WebContents* tab =
166 browser()->tab_strip_model()->GetActiveWebContents();
167 GURL test_url = ui_test_utils::GetTestUrl(
168 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
169
170 NavigateAndLoadContent(tab, test_url);
171
172 // Wait until guest sees a context menu, select an arbitrary item (copy).
173 ContextMenuNotificationObserver context_menu_observer(
174 IDC_CONTENT_CONTEXT_COPYLINKLOCATION);
pkotwicz 2015/02/04 19:43:31 I think that if you use SaveLinkAsContextMenuObser
Miyoung Shin 2015/02/08 14:29:04 thank you for your suggestion. I changed to use Sa
175
176 ui_controls::SendMouseClick(ui_controls::RIGHT);
177 base::string16 show_expected_title(base::ASCIIToUTF16("showed"));
178 content::TitleWatcher show_title_watcher(tab, show_expected_title);
179 EXPECT_EQ(show_expected_title, show_title_watcher.WaitAndGetTitle());
180
181 ui_controls::SendMouseClick(ui_controls::LEFT);
182 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
183 base::string16 done_expected_title(base::ASCIIToUTF16("without mouseleave"));
184 content::TitleWatcher done_title_watcher(tab, done_expected_title);
pkotwicz 2015/02/04 19:43:31 Will the test timeout if a ET_MOUSE_EXITED event i
Miyoung Shin 2015/02/08 14:29:04 Yes, the test is timeout.
pkotwicz 2015/02/10 22:50:14 It is hard to tell for a sheriff whether a test ti
Miyoung Shin 2015/02/12 14:23:26 Thank your for your good information. I added Also
185 EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle());
186 }
187
188 #if defined(OS_WIN) || defined(OS_MACOSX)
pkotwicz 2015/02/04 19:43:31 Can you reference crbug.com/394672 for an example
Miyoung Shin 2015/02/08 14:29:04 I changed it. If I didn't catch your point from th
pkotwicz 2015/02/10 22:50:14 I was suggesting changing the comment to something
Miyoung Shin 2015/02/12 14:23:26 Done
189 // This test is for preventing a regression that a mouseleave is triggered
190 // when showing the modal dialog.
191 // OS_WIN : http://crbug.com/450138
192 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
193 #define MAYBE_ModalDialog DISABLED_ModalDialog
194 #else
195 #define MAYBE_ModalDialog ModalDialog
196 #endif
197
198 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) {
199 content::WebContents* tab =
200 browser()->tab_strip_model()->GetActiveWebContents();
201 GURL test_url = ui_test_utils::GetTestUrl(
202 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
203
204 NavigateAndLoadContent(tab, test_url);
205
206 tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()"));
207 // Cancel the dialog.
208 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
209 alert->CloseModalDialog();
pkotwicz 2015/02/04 19:43:31 Can you call content::RunAllPendingInMessageLoop()
Miyoung Shin 2015/02/08 14:29:04 Done
210
211 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
212 base::string16 done_expected_title(base::ASCIIToUTF16("without mouseleave"));
213 content::TitleWatcher done_title_watcher(tab, done_expected_title);
214 EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle());
215 }
216
98 } // namespace 217 } // 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