Chromium Code Reviews| 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" | |
| 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()); |
|
pkotwicz
2015/02/12 16:42:03
Nit: Can you access |above_content_| directly?
(An
Miyoung Shin
2015/02/13 07:48:40
Done.
| |
| 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() { return above_content_; } | |
| 83 | |
| 84 private: | |
| 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 class ContextMenuWaiter : public content::NotificationObserver { | |
| 117 public: | |
| 118 // Wait until showing a context menu and closing one | |
| 119 ContextMenuWaiter(const content::NotificationSource& source) | |
| 120 : menu_visible_(false) { | |
| 121 registrar_.Add(this, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, | |
| 122 content::NotificationService::AllSources()); | |
| 123 } | |
| 124 ~ContextMenuWaiter() override {} | |
| 125 | |
| 126 content::ContextMenuParams params() { return params_; } | |
| 127 // Wait for the context menu to be visible and closing. | |
| 128 void WaitForMenuOpenAndClose() { | |
| 129 content::WindowedNotificationObserver menu_observer( | |
| 130 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, | |
| 131 content::NotificationService::AllSources()); | |
| 132 if (!menu_visible_) | |
| 133 menu_observer.Wait(); | |
| 134 menu_visible_ = false; | |
| 135 } | |
| 136 | |
| 137 private: | |
| 138 void Observe(int type, | |
| 139 const content::NotificationSource& source, | |
| 140 const content::NotificationDetails& details) override { | |
| 141 switch (type) { | |
| 142 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { | |
| 143 menu_visible_ = true; | |
| 144 RenderViewContextMenu* context_menu = | |
| 145 content::Source<RenderViewContextMenu>(source).ptr(); | |
| 146 base::MessageLoop::current()->PostTask( | |
| 147 FROM_HERE, base::Bind(&ContextMenuWaiter::Cancel, | |
| 148 base::Unretained(this), context_menu)); | |
| 149 break; | |
| 150 } | |
| 151 | |
| 152 default: | |
| 153 NOTREACHED(); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 void Cancel(RenderViewContextMenu* context_menu) { | |
| 158 params_ = context_menu->params(); | |
| 159 context_menu->Cancel(); | |
| 160 } | |
| 161 | |
| 162 bool menu_visible_; | |
| 163 content::ContextMenuParams params_; | |
| 164 content::NotificationRegistrar registrar_; | |
| 165 | |
| 166 DISALLOW_COPY_AND_ASSIGN(ContextMenuWaiter); | |
| 167 }; | |
| 168 | |
| 169 #if defined(OS_WIN) | |
| 170 // This test is for preventing a regression that the mouseleave is triggered | |
| 171 // on Window when opening the new window. | |
| 172 #define MAYBE_NewWindow NewWindow | |
| 173 #else | |
| 174 // Others except OS_WIN do not send the mouseleave when opening the new window | |
| 175 #define MAYBE_NewWindow DISABLED_NewWindow | |
| 176 #endif | |
| 177 | |
| 178 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_NewWindow) { | |
| 179 content::WebContents* tab = | |
| 180 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 181 | |
| 182 LoadTestPageAndWaitForMouseOver(tab); | |
| 183 | |
| 184 // Create an new window. | |
| 185 ui_test_utils::BrowserAddedObserver browser_added_observer; | |
| 186 chrome::NewWindow(browser()); | |
| 187 browser_added_observer.WaitForSingleNewBrowser(); | |
| 188 | |
| 189 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); | |
| 190 | |
| 191 content::RunAllPendingInMessageLoop(); | |
| 192 | |
| 193 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
| 194 const base::string16 success_title = base::ASCIIToUTF16("with mouseleave"); | |
| 195 const base::string16 failure_title = base::ASCIIToUTF16("without mouseleave"); | |
| 196 content::TitleWatcher done_title_watcher(tab, success_title); | |
| 197 done_title_watcher.AlsoWaitForTitle(failure_title); | |
| 198 | |
| 199 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
| 200 } | |
| 201 | |
| 202 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 203 // Test that a mouseleave is not triggered when showing the context menu. | |
| 204 // TODO:Make test pass on OS_WIN and OS_MACOSX | |
| 205 // OS_WIN: http://crbug.com/450138 | |
| 206 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. | |
| 207 #define MAYBE_ContextMenu DISABLED_ContextMenu | |
| 208 #else | |
| 209 #define MAYBE_ContextMenu ContextMenu | |
| 210 #endif | |
| 211 | |
| 212 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) { | |
| 213 content::WebContents* tab = | |
| 214 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 215 | |
| 216 LoadTestPageAndWaitForMouseOver(tab); | |
| 217 | |
| 218 ContextMenuWaiter menu_observer(content::NotificationService::AllSources()); | |
| 219 ui_controls::SendMouseClick(ui_controls::RIGHT); | |
| 220 // Wait until opening context menu and closing one. | |
| 221 menu_observer.WaitForMenuOpenAndClose(); | |
| 222 | |
| 223 content::RunAllPendingInMessageLoop(); | |
| 224 | |
| 225 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
| 226 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); | |
| 227 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); | |
| 228 content::TitleWatcher done_title_watcher(tab, success_title); | |
| 229 done_title_watcher.AlsoWaitForTitle(failure_title); | |
| 230 | |
| 231 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
| 232 } | |
| 233 | |
| 234 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 235 // Test that a mouseleave is not triggered when showing a modal dialog. | |
| 236 // Sample regression: crbug.com/394672 | |
| 237 // TODO:Make test pass on OS_WIN and OS_MACOSX | |
|
pkotwicz
2015/02/12 16:42:03
Nit: "space" after "TODO:"
Miyoung Shin
2015/02/13 07:48:41
Done.
| |
| 238 // OS_WIN: http://crbug.com/450138 | |
| 239 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. | |
| 240 #define MAYBE_ModalDialog DISABLED_ModalDialog | |
| 241 #else | |
| 242 #define MAYBE_ModalDialog ModalDialog | |
| 243 #endif | |
| 244 | |
| 245 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) { | |
| 246 content::WebContents* tab = | |
| 247 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 248 | |
| 249 LoadTestPageAndWaitForMouseOver(tab); | |
| 250 | |
| 251 tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()")); | |
| 252 // Cancel the dialog. | |
| 253 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | |
| 254 alert->CloseModalDialog(); | |
| 255 | |
| 256 content::RunAllPendingInMessageLoop(); | |
| 257 | |
| 258 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
| 259 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); | |
| 260 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); | |
| 261 content::TitleWatcher done_title_watcher(tab, success_title); | |
| 262 done_title_watcher.AlsoWaitForTitle(failure_title); | |
| 263 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
| 264 } | |
| 265 | |
| 98 } // namespace | 266 } // namespace |
| OLD | NEW |