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/test/browser_test_utils.h"
14 #include "ui/base/test/ui_controls.h"
18 class MouseLeaveTest
: public InProcessBrowserTest
{
22 void MouseLeaveTestCommon() {
23 GURL test_url
= ui_test_utils::GetTestUrl(
24 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("mouseleave.html")));
26 content::WebContents
* tab
=
27 browser()->tab_strip_model()->GetActiveWebContents();
28 gfx::Rect tab_view_bounds
= tab
->GetContainerBounds();
30 gfx::Point
in_content_point(
31 tab_view_bounds
.x() + tab_view_bounds
.width() / 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);
37 // Start by moving the point just above the content.
38 ui_controls::SendMouseMove(above_content_point
.x(),
39 above_content_point
.y());
41 // Navigate to the test html page.
42 base::string16
load_expected_title(base::ASCIIToUTF16("onload"));
43 content::TitleWatcher
load_title_watcher(tab
, load_expected_title
);
44 ui_test_utils::NavigateToURL(browser(), test_url
);
45 // Wait for the onload() handler to complete so we can do the
46 // next part of the test.
47 EXPECT_EQ(load_expected_title
, load_title_watcher
.WaitAndGetTitle());
49 // Move the cursor to the top-center of the content, which will trigger
50 // a javascript onMouseOver event.
51 ui_controls::SendMouseMove(in_content_point
.x(), in_content_point
.y());
53 // Wait on the correct intermediate title.
54 base::string16
entered_expected_title(base::ASCIIToUTF16("entered"));
55 content::TitleWatcher
entered_title_watcher(tab
, entered_expected_title
);
56 EXPECT_EQ(entered_expected_title
, entered_title_watcher
.WaitAndGetTitle());
58 // Move the cursor above the content again, which should trigger
59 // a javascript onMouseOut event.
60 ui_controls::SendMouseMove(above_content_point
.x(),
61 above_content_point
.y());
63 // Wait on the correct final value of the cookie.
64 base::string16
left_expected_title(base::ASCIIToUTF16("left"));
65 content::TitleWatcher
left_title_watcher(tab
, left_expected_title
);
66 EXPECT_EQ(left_expected_title
, left_title_watcher
.WaitAndGetTitle());
69 DISALLOW_COPY_AND_ASSIGN(MouseLeaveTest
);
72 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_WIN)
73 // OS_MACOSX: Missing automation provider support: http://crbug.com/45892.
74 // OS_LINUX: http://crbug.com/133361.
75 // OS_WIN: http://crbug.com/419468
76 #define MAYBE_TestOnMouseOut DISABLED_TestOnMouseOut
78 #define MAYBE_TestOnMouseOut TestOnMouseOut
81 IN_PROC_BROWSER_TEST_F(MouseLeaveTest
, MAYBE_TestOnMouseOut
) {
82 MouseLeaveTestCommon();
86 // For MAC: Missing automation provider support: http://crbug.com/45892
87 // For linux : http://crbug.com/133361. interactive mouse tests are flaky.
88 IN_PROC_BROWSER_TEST_F(MouseLeaveTest
, MouseDownOnBrowserCaption
) {
89 gfx::Rect browser_bounds
= browser()->window()->GetBounds();
90 ui_controls::SendMouseMove(browser_bounds
.x() + 200,
91 browser_bounds
.y() + 10);
92 ui_controls::SendMouseClick(ui_controls::LEFT
);
94 MouseLeaveTestCommon();