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

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, 9 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/browser/renderer_context_menu/render_view_context_menu_browsertest.cc » ('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/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) {
sky 2015/03/12 15:37:37 This should either return a boolean that it's succ
Miyoung Shin 2015/03/18 16:16:51 Done.
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 =
27 browser()->tab_strip_model()->GetActiveWebContents(); 34 gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2,
sky 2015/03/12 15:37:37 nit: use constructor that takes x,y.
Miyoung Shin 2015/03/18 16:16:51 Done.
28 gfx::Rect tab_view_bounds = tab->GetContainerBounds(); 35 tab_view_bounds.y() + 10);
29 36 above_content_ =
30 gfx::Point in_content_point( 37 gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2,
31 tab_view_bounds.x() + tab_view_bounds.width() / 2, 38 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 39
37 // Start by moving the point just above the content. 40 // Start by moving the point just above the content.
38 ui_controls::SendMouseMove(above_content_point.x(), 41 ui_controls::SendMouseMove(above_content_.x(), above_content_.y());
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(), test_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 onMouseOver 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
65 LoadTestPageAndWaitForMouseOver(tab);
57 66
58 // Move the cursor above the content again, which should trigger 67 // Move the cursor above the content again, which should trigger
59 // a javascript onMouseOut event. 68 // a javascript onMouseOut event.
60 ui_controls::SendMouseMove(above_content_point.x(), 69 ui_controls::SendMouseMove(above_content_.x(), above_content_.y());
61 above_content_point.y());
62 70
63 // Wait on the correct final value of the cookie. 71 // Wait on the correct final value of the cookie.
64 base::string16 left_expected_title(base::ASCIIToUTF16("left")); 72 base::string16 left_expected_title(base::ASCIIToUTF16("left"));
65 content::TitleWatcher left_title_watcher(tab, left_expected_title); 73 content::TitleWatcher left_title_watcher(tab, left_expected_title);
66 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); 74 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle());
67 } 75 }
68 76
77 gfx::Point above_content_;
sky 2015/03/12 15:37:37 Add a description.
Miyoung Shin 2015/03/18 16:16:51 Done.
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)
pkotwicz 2015/03/12 16:51:57 I think the MouseLeaveTest.NewWindow should be rem
Miyoung Shin 2015/03/18 16:16:51 Done.
109 // Test that a mouse leave event is triggered when opening a new window.
110 #define MAYBE_NewWindow NewWindow
111 #else
112 // Others except OS_WIN do not send the mouseleave when opening the new window
113 // TODO: Make test pass on the other OSes
114 // See http://crbug.com/458492
115 #define MAYBE_NewWindow DISABLED_NewWindow
116 #endif
117
118 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_NewWindow) {
119 content::WebContents* tab =
120 browser()->tab_strip_model()->GetActiveWebContents();
121
122 LoadTestPageAndWaitForMouseOver(tab);
123
124 // Create an new window.
sky 2015/03/12 15:37:37 an->a
Miyoung Shin 2015/03/18 16:16:51 Done. I removed this TC.
125 ui_test_utils::BrowserAddedObserver browser_added_observer;
126 chrome::NewWindow(browser());
127 browser_added_observer.WaitForSingleNewBrowser();
sky 2015/03/12 15:37:37 Seems like you're assuming the new window is opene
Miyoung Shin 2015/03/18 16:16:51 Done. I removed this TC.
128
129 ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
130
131 content::RunAllPendingInMessageLoop();
sky 2015/03/12 15:37:37 Why do you need the run all pending?
Miyoung Shin 2015/03/18 16:16:51 Done. I removed this TC.
132
133 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
134 const base::string16 success_title = base::ASCIIToUTF16("with mouseleave");
135 const base::string16 failure_title = base::ASCIIToUTF16("without 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 the context menu.
144 // TODO: Make test pass on OS_WIN and OS_MACOSX
145 // OS_WIN: http://crbug.com/450138
146 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
147 #define MAYBE_ContextMenu DISABLED_ContextMenu
148 #else
149 #define MAYBE_ContextMenu ContextMenu
150 #endif
151
152 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) {
153 content::WebContents* tab =
154 browser()->tab_strip_model()->GetActiveWebContents();
155
156 LoadTestPageAndWaitForMouseOver(tab);
157
158 ContextMenuWaiter menu_observer(content::NotificationService::AllSources());
159 ui_controls::SendMouseClick(ui_controls::RIGHT);
160 // Wait until the context menu is opened and closed.
161 menu_observer.WaitForMenuOpenAndClose();
162
163 content::RunAllPendingInMessageLoop();
sky 2015/03/12 15:37:37 Same comment about position of context menu and wh
pkotwicz 2015/03/12 16:51:57 I suggested adding content::RunAllPendingInMessage
sky 2015/03/12 19:54:12 Isn't the WaitAndGetTitle below effectively doing
pkotwicz 2015/03/12 21:44:14 I checked and on ChromeOS there aren't any delayed
sky 2015/03/12 22:34:06 Certainly, but aren't those set based on mouse eve
Miyoung Shin 2015/03/16 04:34:26 sky@, pkotwicz@, RunAll is called in WaitForMenuOp
Miyoung Shin 2015/03/18 16:16:51 Done. I removed to call content::RunAllPendingInMe
164
165 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
166 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
167 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave");
168 content::TitleWatcher done_title_watcher(tab, success_title);
169 done_title_watcher.AlsoWaitForTitle(failure_title);
170
171 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle());
172 }
173
174 #if defined(OS_WIN) || defined(OS_MACOSX)
175 // Test that a mouseleave is not triggered when showing a modal dialog.
176 // Sample regression: crbug.com/394672
177 // TODO: Make test pass on OS_WIN and OS_MACOSX
178 // OS_WIN: http://crbug.com/450138
179 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
180 #define MAYBE_ModalDialog DISABLED_ModalDialog
181 #else
182 #define MAYBE_ModalDialog ModalDialog
183 #endif
184
185 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) {
186 content::WebContents* tab =
187 browser()->tab_strip_model()->GetActiveWebContents();
188
189 LoadTestPageAndWaitForMouseOver(tab);
190
191 tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()"));
192 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
193 // Cancel the dialog.
194 alert->CloseModalDialog();
195
196 content::RunAllPendingInMessageLoop();
sky 2015/03/12 15:37:37 And same comment here.
Miyoung Shin 2015/03/16 04:34:26 This is not set based on mouse events, so I think
Miyoung Shin 2015/03/18 16:16:51 Done. I removed to call content::RunAllPendingInMe
197
198 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
199 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
200 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave");
201 content::TitleWatcher done_title_watcher(tab, success_title);
202 done_title_watcher.AlsoWaitForTitle(failure_title);
203 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle());
204 }
205
98 } // namespace 206 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698