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/ui/browser.h"
8 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_view.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "ui/base/test/ui_controls.h"
19 class MouseLeaveTest
: public InProcessBrowserTest
{
23 void MouseLeaveTestCommon() {
24 GURL test_url
= ui_test_utils::GetTestUrl(
25 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
27 content::WebContents
* tab
=
28 browser()->tab_strip_model()->GetActiveWebContents();
29 gfx::Rect tab_view_bounds
;
30 tab
->GetView()->GetContainerBounds(&tab_view_bounds
);
32 gfx::Point
in_content_point(
33 tab_view_bounds
.x() + tab_view_bounds
.width() / 2,
34 tab_view_bounds
.y() + 10);
35 gfx::Point
above_content_point(
36 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(above_content_point
.x(),
41 above_content_point
.y());
43 // Navigate to the test html page.
44 base::string16
load_expected_title(base::ASCIIToUTF16("onload"));
45 content::TitleWatcher
load_title_watcher(tab
, load_expected_title
);
46 ui_test_utils::NavigateToURL(browser(), test_url
);
47 // Wait for the onload() handler to complete so we can do the
48 // next part of the test.
49 EXPECT_EQ(load_expected_title
, load_title_watcher
.WaitAndGetTitle());
51 // Move the cursor to the top-center of the content, which will trigger
52 // a javascript onMouseOver event.
53 ui_controls::SendMouseMove(in_content_point
.x(), in_content_point
.y());
55 // Wait on the correct intermediate title.
56 base::string16
entered_expected_title(base::ASCIIToUTF16("entered"));
57 content::TitleWatcher
entered_title_watcher(tab
, entered_expected_title
);
58 EXPECT_EQ(entered_expected_title
, entered_title_watcher
.WaitAndGetTitle());
60 // Move the cursor above the content again, which should trigger
61 // a javascript onMouseOut event.
62 ui_controls::SendMouseMove(above_content_point
.x(),
63 above_content_point
.y());
65 // Wait on the correct final value of the cookie.
66 base::string16
left_expected_title(base::ASCIIToUTF16("left"));
67 content::TitleWatcher
left_title_watcher(tab
, left_expected_title
);
68 EXPECT_EQ(left_expected_title
, left_title_watcher
.WaitAndGetTitle());
71 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest
);
74 #if defined(OS_MACOSX)
75 // Missing automation provider support: http://crbug.com/45892
76 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut
77 #elif defined(OS_LINUX)
78 // http://crbug.com/133361
79 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut
81 #define MAYBE_TestOnMouseOut TestOnMouseOut
84 IN_PROC_BROWSER_TEST_F(MouseLeaveTest
, MAYBE_TestOnMouseOut
) {
85 MouseLeaveTestCommon();
89 // For MAC: Missing automation provider support: http://crbug.com/45892
90 // For linux : http://crbug.com/133361. interactive mouse tests are flaky.
91 IN_PROC_BROWSER_TEST_F(MouseLeaveTest
, MouseDownOnBrowserCaption
) {
92 gfx::Rect browser_bounds
= browser()->window()->GetBounds();
93 ui_controls::SendMouseMove(browser_bounds
.x() + 200,
94 browser_bounds
.y() + 10);
95 ui_controls::SendMouseClick(ui_controls::LEFT
);
97 MouseLeaveTestCommon();