Extensions: Remove the old permission message interface
[chromium-blink-merge.git] / chrome / browser / mouseleave_browsertest.cc
blob6719b9394d356debca9bf729e14055af6450ef6d
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
3 // found in the LICENSE file.
5 #include "base/files/file_path.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_browsertest_util.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/test/base/in_process_browser_test.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"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/browser_test_utils.h"
20 #include "ui/base/test/ui_controls.h"
22 namespace {
24 class MouseLeaveTest : public InProcessBrowserTest {
25 public:
26 MouseLeaveTest() {}
28 void LoadTestPageAndWaitForMouseOver(content::WebContents* tab) {
29 gfx::Rect tab_view_bounds = tab->GetContainerBounds();
30 GURL test_url = ui_test_utils::GetTestUrl(
31 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
33 gfx::Point in_content(tab_view_bounds.x() + tab_view_bounds.width() / 2,
34 tab_view_bounds.y() + 10);
35 out_of_content_ =
36 gfx::Point(tab_view_bounds.x() + tab_view_bounds.width() / 2,
37 tab_view_bounds.y() - 2);
39 // Start by moving the point just above the content.
40 ui_controls::SendMouseMove(out_of_content_.x(), out_of_content_.y());
42 // Navigate to the test html page.
43 base::string16 load_expected_title(base::ASCIIToUTF16("onload"));
44 content::TitleWatcher load_title_watcher(tab, load_expected_title);
45 ui_test_utils::NavigateToURL(browser(), test_url);
46 // Wait for the onload() handler to complete so we can do the
47 // next part of the test.
48 EXPECT_EQ(load_expected_title, load_title_watcher.WaitAndGetTitle());
50 // Move the cursor to the top-center of the content which will trigger
51 // a javascript onMouseOver event.
52 ui_controls::SendMouseMove(in_content.x(), in_content.y());
54 // Wait on the correct intermediate title.
55 base::string16 entered_expected_title(base::ASCIIToUTF16("entered"));
56 content::TitleWatcher entered_title_watcher(tab, entered_expected_title);
57 EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle());
60 void MouseLeaveTestCommon() {
61 content::WebContents* tab =
62 browser()->tab_strip_model()->GetActiveWebContents();
64 EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab));
66 // Move the cursor above the content again, which should trigger
67 // a javascript onMouseOut event.
68 ui_controls::SendMouseMove(out_of_content_.x(), out_of_content_.y());
70 // Wait on the correct final value of the cookie.
71 base::string16 left_expected_title(base::ASCIIToUTF16("left"));
72 content::TitleWatcher left_title_watcher(tab, left_expected_title);
73 EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle());
76 // The coordinates out of the content to move the mouse point
77 gfx::Point out_of_content_;
79 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest);
82 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_WIN)
83 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
84 // OS_LINUX: http://crbug.com/133361.
85 // OS_WIN: http://crbug.com/419468
86 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut
87 #else
88 #define MAYBE_TestOnMouseOut TestOnMouseOut
89 #endif
91 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) {
92 MouseLeaveTestCommon();
95 #if defined(OS_WIN)
96 // For MAC: Missing automation provider support: http://crbug.com/45892
97 // For linux : http://crbug.com/133361. interactive mouse tests are flaky.
98 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MouseDownOnBrowserCaption) {
99 gfx::Rect browser_bounds = browser()->window()->GetBounds();
100 ui_controls::SendMouseMove(browser_bounds.x() + 200,
101 browser_bounds.y() + 10);
102 ui_controls::SendMouseClick(ui_controls::LEFT);
104 MouseLeaveTestCommon();
106 #endif
108 #if defined(OS_WIN) || defined(OS_MACOSX)
109 // Test that a mouseleave is not triggered when showing the context menu.
110 // If the test is failed, it means that Blink gets the mouseleave event
111 // when showing the context menu and it could make the unexpecting
112 // content behavior such as clearing the hover status.
113 // Please refer to the below issue for understanding what happens .
114 // TODO: Make test pass on OS_WIN and OS_MACOSX
115 // OS_WIN: http://crbug.com/450138
116 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
117 #define MAYBE_ContextMenu DISABLED_ContextMenu
118 #else
119 #define MAYBE_ContextMenu ContextMenu
120 #endif
122 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) {
123 content::WebContents* tab =
124 browser()->tab_strip_model()->GetActiveWebContents();
126 EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab));
128 ContextMenuWaiter menu_observer(content::NotificationService::AllSources());
129 ui_controls::SendMouseClick(ui_controls::RIGHT);
130 // Wait until the context menu is opened and closed.
131 menu_observer.WaitForMenuOpenAndClose();
133 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16("done()"));
134 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
135 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave");
136 content::TitleWatcher done_title_watcher(tab, success_title);
137 done_title_watcher.AlsoWaitForTitle(failure_title);
139 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle());
142 #if defined(OS_WIN) || defined(OS_MACOSX)
143 // Test that a mouseleave is not triggered when showing a modal dialog.
144 // Sample regression: crbug.com/394672
145 // TODO: Make test pass on OS_WIN and OS_MACOSX
146 // OS_WIN: http://crbug.com/450138
147 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
148 #define MAYBE_ModalDialog DISABLED_ModalDialog
149 #else
150 #define MAYBE_ModalDialog ModalDialog
151 #endif
153 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) {
154 content::WebContents* tab =
155 browser()->tab_strip_model()->GetActiveWebContents();
157 EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab));
159 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
160 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
161 // Cancel the dialog.
162 alert->CloseModalDialog();
164 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16("done()"));
165 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
166 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave");
167 content::TitleWatcher done_title_watcher(tab, success_title);
168 done_title_watcher.AlsoWaitForTitle(failure_title);
169 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle());
172 } // namespace