Chromium Code Reviews| Index: chrome/browser/mouseleave_browsertest.cc |
| diff --git a/chrome/browser/mouseleave_browsertest.cc b/chrome/browser/mouseleave_browsertest.cc |
| index 416b081f112b51b7f0acaec195cefb78fef5393a..3e358f684fa2cadc1d52371b811d7c639426789d 100644 |
| --- a/chrome/browser/mouseleave_browsertest.cc |
| +++ b/chrome/browser/mouseleave_browsertest.cc |
| @@ -4,13 +4,23 @@ |
| #include "base/files/file_path.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| +#include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_commands.h" |
| +#include "chrome/browser/ui/browser_finder.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| +#include "components/app_modal/app_modal_dialog.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/test_navigation_observer.h" |
| #include "ui/base/test/ui_controls.h" |
| namespace { |
| @@ -19,46 +29,46 @@ class MouseLeaveTest : public InProcessBrowserTest { |
| public: |
| MouseLeaveTest() {} |
| - void MouseLeaveTestCommon() { |
| - GURL test_url = ui_test_utils::GetTestUrl( |
| - base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); |
| - |
| - content::WebContents* tab = |
| - browser()->tab_strip_model()->GetActiveWebContents(); |
| + void NavigateAndLoadContent(content::WebContents* tab, GURL& url) { |
| gfx::Rect tab_view_bounds = tab->GetContainerBounds(); |
| - gfx::Point in_content_point( |
| - tab_view_bounds.x() + tab_view_bounds.width() / 2, |
| - tab_view_bounds.y() + 10); |
| - gfx::Point above_content_point( |
| - tab_view_bounds.x() + tab_view_bounds.width() / 2, |
| - tab_view_bounds.y() - 2); |
| + in_content_ = gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2, |
| + tab_view_bounds.y() + 10); |
| + above_content_ = |
| + gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2, |
| + tab_view_bounds.y() - 2); |
| - // Start by moving the point just above the content. |
| - ui_controls::SendMouseMove(above_content_point.x(), |
| - above_content_point.y()); |
| + ui_controls::SendMouseMove(above_content_.x(), above_content_.y()); |
| // Navigate to the test html page. |
| base::string16 load_expected_title(base::ASCIIToUTF16("onload")); |
| content::TitleWatcher load_title_watcher(tab, load_expected_title); |
| - ui_test_utils::NavigateToURL(browser(), test_url); |
| + ui_test_utils::NavigateToURL(browser(), url); |
| // Wait for the onload() handler to complete so we can do the |
| // next part of the test. |
| EXPECT_EQ(load_expected_title, load_title_watcher.WaitAndGetTitle()); |
| - // Move the cursor to the top-center of the content, which will trigger |
| - // a javascript onMouseOver event. |
| - ui_controls::SendMouseMove(in_content_point.x(), in_content_point.y()); |
| + // Move the cursor to the top-center of the content which will trigger |
| + // a javascript event. |
| + ui_controls::SendMouseMove(in_content_.x(), in_content_.y()); |
| // Wait on the correct intermediate title. |
| base::string16 entered_expected_title(base::ASCIIToUTF16("entered")); |
| content::TitleWatcher entered_title_watcher(tab, entered_expected_title); |
| EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle()); |
| + } |
| + |
| + void MouseLeaveTestCommon() { |
| + content::WebContents* tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + GURL test_url = ui_test_utils::GetTestUrl( |
| + base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); |
| + |
| + NavigateAndLoadContent(tab, test_url); |
| // Move the cursor above the content again, which should trigger |
| // a javascript onMouseOut event. |
| - ui_controls::SendMouseMove(above_content_point.x(), |
| - above_content_point.y()); |
| + ui_controls::SendMouseMove(above_content().x(), above_content().y()); |
| // Wait on the correct final value of the cookie. |
| base::string16 left_expected_title(base::ASCIIToUTF16("left")); |
| @@ -66,6 +76,14 @@ class MouseLeaveTest : public InProcessBrowserTest { |
| EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); |
| } |
| + gfx::Point in_content() { return in_content_; } |
| + |
| + gfx::Point above_content() { return above_content_; } |
| + |
| + private: |
| + gfx::Point in_content_; |
| + gfx::Point above_content_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest); |
| }; |
| @@ -95,4 +113,105 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) { |
| } |
| #endif |
| +#if defined(OS_WIN) |
| +// This test is for preventing a regression that the mouseleave is triggered |
| +// on Window when opening the new window. |
| +#define MAYBE_NewWindow NewWindow |
| +#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
|
| +#define MAYBE_NewWindow DISABLED_NewWindow |
| +#endif |
| + |
| +IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_NewWindow) { |
| + content::WebContents* tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + GURL test_url = ui_test_utils::GetTestUrl( |
| + base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); |
| + |
| + NavigateAndLoadContent(tab, test_url); |
| + |
| + // Create an new window. |
| + ui_test_utils::BrowserAddedObserver browser_added_observer; |
| + chrome::NewWindow(browser()); |
| + Browser* new_browser = browser_added_observer.WaitForSingleNewBrowser(); |
| + |
| + ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
| + |
| + // 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
|
| + content::WindowedNotificationObserver browser_closed_observer( |
| + chrome::NOTIFICATION_BROWSER_CLOSED, |
| + content::NotificationService::AllSources()); |
| + chrome::CloseWindow(new_browser); |
| + browser_closed_observer.Wait(); |
| + |
| + ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); |
| + |
| + tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); |
| + base::string16 done_expected_title(base::ASCIIToUTF16("with mouseleave")); |
| + content::TitleWatcher done_title_watcher(tab, done_expected_title); |
| + EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle()); |
| +} |
| + |
| +#if defined(OS_WIN) || defined(OS_MACOSX) |
| +// This test is for preventing a regression that a mouseleave is triggered |
| +// 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
|
| +// OS_WIN : http://crbug.com/450138 |
| +// OS_MACOSX: Missing automation provider support: http://crbug.com/45892. |
| +#define MAYBE_ContextMenu DISABLED_ContextMenu |
| +#else |
| +#define MAYBE_ContextMenu ContextMenu |
| +#endif |
| + |
| +IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) { |
| + content::WebContents* tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + GURL test_url = ui_test_utils::GetTestUrl( |
| + base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); |
| + |
| + NavigateAndLoadContent(tab, test_url); |
| + |
| + // Wait until guest sees a context menu, select an arbitrary item (copy). |
| + ContextMenuNotificationObserver context_menu_observer( |
| + 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
|
| + |
| + ui_controls::SendMouseClick(ui_controls::RIGHT); |
| + base::string16 show_expected_title(base::ASCIIToUTF16("showed")); |
| + content::TitleWatcher show_title_watcher(tab, show_expected_title); |
| + EXPECT_EQ(show_expected_title, show_title_watcher.WaitAndGetTitle()); |
| + |
| + ui_controls::SendMouseClick(ui_controls::LEFT); |
| + tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); |
| + base::string16 done_expected_title(base::ASCIIToUTF16("without mouseleave")); |
| + 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
|
| + EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle()); |
| +} |
| + |
| +#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
|
| +// This test is for preventing a regression that a mouseleave is triggered |
| +// when showing the modal dialog. |
| +// OS_WIN : http://crbug.com/450138 |
| +// OS_MACOSX: Missing automation provider support: http://crbug.com/45892. |
| +#define MAYBE_ModalDialog DISABLED_ModalDialog |
| +#else |
| +#define MAYBE_ModalDialog ModalDialog |
| +#endif |
| + |
| +IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) { |
| + content::WebContents* tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + GURL test_url = ui_test_utils::GetTestUrl( |
| + base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); |
| + |
| + NavigateAndLoadContent(tab, test_url); |
| + |
| + tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()")); |
| + // Cancel the dialog. |
| + app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| + alert->CloseModalDialog(); |
|
pkotwicz
2015/02/04 19:43:31
Can you call content::RunAllPendingInMessageLoop()
Miyoung Shin
2015/02/08 14:29:04
Done
|
| + |
| + tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); |
| + base::string16 done_expected_title(base::ASCIIToUTF16("without mouseleave")); |
| + content::TitleWatcher done_title_watcher(tab, done_expected_title); |
| + EXPECT_EQ(done_expected_title, done_title_watcher.WaitAndGetTitle()); |
| +} |
| + |
| } // namespace |