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..25e134482d55d2cc0e175e84cb363a3615e4be35 100644 |
| --- a/chrome/browser/mouseleave_browsertest.cc |
| +++ b/chrome/browser/mouseleave_browsertest.cc |
| @@ -4,13 +4,24 @@ |
| #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 "content/public/test/test_utils.h" |
| #include "ui/base/test/ui_controls.h" |
| namespace { |
| @@ -19,24 +30,20 @@ class MouseLeaveTest : public InProcessBrowserTest { |
| public: |
| MouseLeaveTest() {} |
| - void MouseLeaveTestCommon() { |
| + void LoadTestPageAndWaitForMouseOver(content::WebContents* tab) { |
| + gfx::Rect tab_view_bounds = tab->GetContainerBounds(); |
| GURL test_url = ui_test_utils::GetTestUrl( |
| base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html"))); |
| - content::WebContents* tab = |
| - browser()->tab_strip_model()->GetActiveWebContents(); |
| - 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); |
| + gfx::Point 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")); |
| @@ -46,19 +53,25 @@ class MouseLeaveTest : public InProcessBrowserTest { |
| // 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 |
| + // 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()); |
| + 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(); |
| + |
| + LoadTestPageAndWaitForMouseOver(tab); |
| // 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()); |
|
pkotwicz
2015/02/12 16:42:03
Nit: Can you access |above_content_| directly?
(An
Miyoung Shin
2015/02/13 07:48:40
Done.
|
| // Wait on the correct final value of the cookie. |
| base::string16 left_expected_title(base::ASCIIToUTF16("left")); |
| @@ -66,6 +79,11 @@ class MouseLeaveTest : public InProcessBrowserTest { |
| EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); |
| } |
| + gfx::Point above_content() { return above_content_; } |
| + |
| + private: |
| + gfx::Point above_content_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest); |
| }; |
| @@ -95,4 +113,154 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) { |
| } |
| #endif |
| +class ContextMenuWaiter : public content::NotificationObserver { |
| + public: |
| + // Wait until showing a context menu and closing one |
| + ContextMenuWaiter(const content::NotificationSource& source) |
| + : menu_visible_(false) { |
| + registrar_.Add(this, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, |
| + content::NotificationService::AllSources()); |
| + } |
| + ~ContextMenuWaiter() override {} |
| + |
| + content::ContextMenuParams params() { return params_; } |
| + // Wait for the context menu to be visible and closing. |
| + void WaitForMenuOpenAndClose() { |
| + content::WindowedNotificationObserver menu_observer( |
| + chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, |
| + content::NotificationService::AllSources()); |
| + if (!menu_visible_) |
| + menu_observer.Wait(); |
| + menu_visible_ = false; |
| + } |
| + |
| + private: |
| + void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) override { |
| + switch (type) { |
| + case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { |
| + menu_visible_ = true; |
| + RenderViewContextMenu* context_menu = |
| + content::Source<RenderViewContextMenu>(source).ptr(); |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, base::Bind(&ContextMenuWaiter::Cancel, |
| + base::Unretained(this), context_menu)); |
| + break; |
| + } |
| + |
| + default: |
| + NOTREACHED(); |
| + } |
| + } |
| + |
| + void Cancel(RenderViewContextMenu* context_menu) { |
| + params_ = context_menu->params(); |
| + context_menu->Cancel(); |
| + } |
| + |
| + bool menu_visible_; |
| + content::ContextMenuParams params_; |
| + content::NotificationRegistrar registrar_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ContextMenuWaiter); |
| +}; |
| + |
| +#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 |
| +// Others except OS_WIN do not send the mouseleave when opening the new window |
| +#define MAYBE_NewWindow DISABLED_NewWindow |
| +#endif |
| + |
| +IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_NewWindow) { |
| + content::WebContents* tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + |
| + LoadTestPageAndWaitForMouseOver(tab); |
| + |
| + // Create an new window. |
| + ui_test_utils::BrowserAddedObserver browser_added_observer; |
| + chrome::NewWindow(browser()); |
| + browser_added_observer.WaitForSingleNewBrowser(); |
| + |
| + ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
| + |
| + content::RunAllPendingInMessageLoop(); |
| + |
| + tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); |
| + const base::string16 success_title = base::ASCIIToUTF16("with mouseleave"); |
| + const base::string16 failure_title = base::ASCIIToUTF16("without mouseleave"); |
| + content::TitleWatcher done_title_watcher(tab, success_title); |
| + done_title_watcher.AlsoWaitForTitle(failure_title); |
| + |
| + EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); |
| +} |
| + |
| +#if defined(OS_WIN) || defined(OS_MACOSX) |
| +// Test that a mouseleave is not triggered when showing the context menu. |
| +// TODO:Make test pass on OS_WIN and OS_MACOSX |
| +// 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(); |
| + |
| + LoadTestPageAndWaitForMouseOver(tab); |
| + |
| + ContextMenuWaiter menu_observer(content::NotificationService::AllSources()); |
| + ui_controls::SendMouseClick(ui_controls::RIGHT); |
| + // Wait until opening context menu and closing one. |
| + menu_observer.WaitForMenuOpenAndClose(); |
| + |
| + content::RunAllPendingInMessageLoop(); |
| + |
| + tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); |
| + const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); |
| + const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); |
| + content::TitleWatcher done_title_watcher(tab, success_title); |
| + done_title_watcher.AlsoWaitForTitle(failure_title); |
| + |
| + EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); |
| +} |
| + |
| +#if defined(OS_WIN) || defined(OS_MACOSX) |
| +// Test that a mouseleave is not triggered when showing a modal dialog. |
| +// Sample regression: crbug.com/394672 |
| +// 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.
|
| +// 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(); |
| + |
| + LoadTestPageAndWaitForMouseOver(tab); |
| + |
| + tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()")); |
| + // Cancel the dialog. |
| + app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| + alert->CloseModalDialog(); |
| + |
| + content::RunAllPendingInMessageLoop(); |
| + |
| + tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()")); |
| + const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); |
| + const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); |
| + content::TitleWatcher done_title_watcher(tab, success_title); |
| + done_title_watcher.AlsoWaitForTitle(failure_title); |
| + EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); |
| +} |
| + |
| } // namespace |