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()); |
| 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 // This test is for preventing a regression that the mouseleave is triggered | |
| 115 // on Window when opening the new window. | |
|
pkotwicz
2015/02/13 20:52:13
How about: "Test that a mouse leave event is trigg
Miyoung Shin
2015/02/14 15:32:01
Done. Thank you for correcting it.
| |
| 116 #define MAYBE_NewWindow NewWindow | |
| 117 #else | |
| 118 // Others except OS_WIN do not send the mouseleave when opening the new window | |
| 119 // TODO: Make test pass on the other OSes | |
| 120 // See http://crbug.com/458492 | |
| 121 #define MAYBE_NewWindow DISABLED_NewWindow | |
| 122 #endif | |
| 123 | |
|
pkotwicz
2015/02/13 20:52:13
I suspect that a mouse leave is sent only when the
Miyoung Shin
2015/02/14 15:32:01
The mouse leave is sent when the mouse position is
pkotwicz
2015/02/17 19:59:29
It sounds like this test will pass / fail based on
Miyoung Shin
2015/02/18 12:10:33
Yes, right.
| |
| 124 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_NewWindow) { | |
| 125 content::WebContents* tab = | |
| 126 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 127 | |
| 128 LoadTestPageAndWaitForMouseOver(tab); | |
| 129 | |
| 130 // Create an new window. | |
| 131 ui_test_utils::BrowserAddedObserver browser_added_observer; | |
| 132 chrome::NewWindow(browser()); | |
| 133 browser_added_observer.WaitForSingleNewBrowser(); | |
| 134 | |
| 135 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); | |
| 136 | |
| 137 content::RunAllPendingInMessageLoop(); | |
| 138 | |
| 139 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
| 140 const base::string16 success_title = base::ASCIIToUTF16("with mouseleave"); | |
| 141 const base::string16 failure_title = base::ASCIIToUTF16("without mouseleave"); | |
| 142 content::TitleWatcher done_title_watcher(tab, success_title); | |
| 143 done_title_watcher.AlsoWaitForTitle(failure_title); | |
| 144 | |
| 145 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
| 146 } | |
| 147 | |
| 148 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 149 // Test that a mouseleave is not triggered when showing the context menu. | |
| 150 // TODO: Make test pass on OS_WIN and OS_MACOSX | |
| 151 // OS_WIN: http://crbug.com/450138 | |
| 152 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. | |
| 153 #define MAYBE_ContextMenu DISABLED_ContextMenu | |
| 154 #else | |
| 155 #define MAYBE_ContextMenu ContextMenu | |
| 156 #endif | |
| 157 | |
| 158 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) { | |
| 159 content::WebContents* tab = | |
| 160 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 161 | |
| 162 LoadTestPageAndWaitForMouseOver(tab); | |
| 163 | |
| 164 SaveLinkAsContextMenuObserver menu_observer( | |
| 165 content::NotificationService::AllSources()); | |
| 166 ui_controls::SendMouseClick(ui_controls::RIGHT); | |
| 167 // Wait until opening context menu and closing one. | |
| 168 menu_observer.WaitForMenuOpenAndClose(); | |
| 169 | |
| 170 content::RunAllPendingInMessageLoop(); | |
| 171 | |
| 172 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
| 173 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); | |
| 174 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); | |
| 175 content::TitleWatcher done_title_watcher(tab, success_title); | |
| 176 done_title_watcher.AlsoWaitForTitle(failure_title); | |
| 177 | |
| 178 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
| 179 } | |
| 180 | |
| 181 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 182 // Test that a mouseleave is not triggered when showing a modal dialog. | |
| 183 // Sample regression: crbug.com/394672 | |
| 184 // TODO: Make test pass on OS_WIN and OS_MACOSX | |
| 185 // OS_WIN: http://crbug.com/450138 | |
| 186 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892. | |
| 187 #define MAYBE_ModalDialog DISABLED_ModalDialog | |
| 188 #else | |
| 189 #define MAYBE_ModalDialog ModalDialog | |
| 190 #endif | |
| 191 | |
| 192 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) { | |
| 193 content::WebContents* tab = | |
| 194 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 195 | |
| 196 LoadTestPageAndWaitForMouseOver(tab); | |
| 197 | |
| 198 tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()")); | |
| 199 // Cancel the dialog. | |
| 200 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | |
| 201 alert->CloseModalDialog(); | |
| 202 | |
| 203 content::RunAllPendingInMessageLoop(); | |
| 204 | |
| 205 tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); | |
| 206 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); | |
| 207 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); | |
| 208 content::TitleWatcher done_title_watcher(tab, success_title); | |
| 209 done_title_watcher.AlsoWaitForTitle(failure_title); | |
| 210 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | |
| 211 } | |
| 212 | |
| 98 } // namespace | 213 } // namespace |
| OLD | NEW |