1 // Copyright (c) 2006-2008 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.
6 #include "chrome/browser/view_ids.h"
7 #include "chrome/views/view.h"
8 #include "chrome/test/automation/browser_proxy.h"
9 #include "chrome/test/automation/window_proxy.h"
10 #include "chrome/test/automation/tab_proxy.h"
11 #include "chrome/test/ui/ui_test.h"
12 #include "net/url_request/url_request_unittest.h"
16 // The delay waited after sending an OS simulated event.
17 static const int kActionDelayMs
= 500;
18 static const wchar_t kDocRoot
[] = L
"chrome/test/data";
19 static const wchar_t kSimplePage
[] = L
"404_is_enough_for_us.html";
21 class FindInPageTest
: public UITest
{
25 dom_automation_enabled_
= true;
29 // Activate a tab by clicking on it. Returns true if the call was successful
30 // (meaning the messages were correctly sent, but does not guarantee the tab
32 bool ActivateTabByClick(AutomationProxy
* automation
,
33 WindowProxy
* browser_window
,
38 if (!browser_window
->GetViewBounds(VIEW_ID_TAB_0
+ tab_index
, &bounds
, true))
41 POINT
click(bounds
.CenterPoint().ToPOINT());
42 if (!browser_window
->SimulateOSClick(click
,
43 ChromeViews::Event::EF_LEFT_BUTTON_DOWN
))
46 // Wait a bit to let the click be processed.
47 ::Sleep(kActionDelayMs
);
54 TEST_F(FindInPageTest
, CrashEscHandlers
) {
55 TestServer
server(kDocRoot
);
57 scoped_ptr
<BrowserProxy
> browser(automation()->GetLastActiveBrowserWindow());
58 ASSERT_TRUE(browser
.get() != NULL
);
59 scoped_ptr
<WindowProxy
> window(
60 automation()->GetWindowForBrowser(browser
.get()));
61 ASSERT_TRUE(window
.get() != NULL
);
63 // First we navigate to our test page (tab A).
64 GURL url
= server
.TestServerPageW(kSimplePage
);
65 scoped_ptr
<TabProxy
> tabA(GetActiveTab());
66 EXPECT_NE(AUTOMATION_MSG_NAVIGATION_ERROR
, tabA
->NavigateToURL(url
));
68 EXPECT_TRUE(tabA
->OpenFindInPage());
70 // Open another tab (tab B).
71 EXPECT_TRUE(browser
->AppendTab(url
));
72 scoped_ptr
<TabProxy
> tabB(GetActiveTab());
74 EXPECT_TRUE(tabB
->OpenFindInPage());
77 EXPECT_TRUE(ActivateTabByClick(automation(), window
.get(), 0));
80 EXPECT_TRUE(tabB
->Close(true));
82 // Click on the location bar so that Find box loses focus.
84 EXPECT_TRUE(window
->GetViewBounds(VIEW_ID_LOCATION_BAR
, &bounds
, false));
85 POINT
click(bounds
.CenterPoint().ToPOINT());
86 EXPECT_TRUE(window
->SimulateOSClick(click
,
87 ChromeViews::Event::EF_LEFT_BUTTON_DOWN
));
88 ::Sleep(kActionDelayMs
);
90 EXPECT_TRUE(window
->GetFocusedViewID(&focused_view_id
));
91 EXPECT_EQ(VIEW_ID_LOCATION_BAR
, focused_view_id
);
93 // This used to crash until bug 1303709 was fixed.
94 EXPECT_TRUE(window
->SimulateOSKeyPress(VK_ESCAPE
, 0));
95 ::Sleep(kActionDelayMs
);