OLD | NEW |
| (Empty) |
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. | |
4 | |
5 | |
6 #include "chrome/browser/view_ids.h" | |
7 #include "chrome/test/automation/browser_proxy.h" | |
8 #include "chrome/test/automation/window_proxy.h" | |
9 #include "chrome/test/automation/tab_proxy.h" | |
10 #include "chrome/test/ui/ui_test.h" | |
11 #include "net/url_request/url_request_unittest.h" | |
12 #include "views/view.h" | |
13 | |
14 namespace { | |
15 | |
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"; | |
20 | |
21 class FindInPageTest : public UITest { | |
22 public: | |
23 FindInPageTest() { | |
24 show_window_ = true; | |
25 dom_automation_enabled_ = true; | |
26 } | |
27 }; | |
28 | |
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 | |
31 // has been changed). | |
32 bool ActivateTabByClick(AutomationProxy* automation, | |
33 WindowProxy* browser_window, | |
34 int tab_index) { | |
35 // Click on the tab. | |
36 gfx::Rect bounds; | |
37 | |
38 if (!browser_window->GetViewBounds(VIEW_ID_TAB_0 + tab_index, &bounds, true)) | |
39 return false; | |
40 | |
41 if (!browser_window->SimulateOSClick(bounds.CenterPoint(), | |
42 views::Event::EF_LEFT_BUTTON_DOWN)) | |
43 return false; | |
44 | |
45 // Wait a bit to let the click be processed. | |
46 ::Sleep(kActionDelayMs); | |
47 | |
48 return true; | |
49 } | |
50 | |
51 } // namespace | |
52 | |
53 TEST_F(FindInPageTest, CrashEscHandlers) { | |
54 scoped_refptr<HTTPTestServer> server = | |
55 HTTPTestServer::CreateServer(kDocRoot, NULL); | |
56 ASSERT_TRUE(NULL != server.get()); | |
57 | |
58 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
59 ASSERT_TRUE(browser.get() != NULL); | |
60 scoped_refptr<WindowProxy> window(browser->GetWindow()); | |
61 ASSERT_TRUE(window.get() != NULL); | |
62 | |
63 // First we navigate to our test page (tab A). | |
64 GURL url = server->TestServerPageW(kSimplePage); | |
65 scoped_refptr<TabProxy> tabA(GetActiveTab()); | |
66 EXPECT_NE(AUTOMATION_MSG_NAVIGATION_ERROR, tabA->NavigateToURL(url)); | |
67 | |
68 EXPECT_TRUE(browser->OpenFindInPage()); | |
69 | |
70 // Open another tab (tab B). | |
71 EXPECT_TRUE(browser->AppendTab(url)); | |
72 scoped_refptr<TabProxy> tabB(GetActiveTab()); | |
73 | |
74 EXPECT_TRUE(browser->OpenFindInPage()); | |
75 | |
76 // Select tab A. | |
77 EXPECT_TRUE(ActivateTabByClick(automation(), window.get(), 0)); | |
78 | |
79 // Close tab B. | |
80 EXPECT_TRUE(tabB->Close(true)); | |
81 | |
82 // Click on the location bar so that Find box loses focus. | |
83 gfx::Rect bounds; | |
84 EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, false)); | |
85 EXPECT_TRUE(window->SimulateOSClick(bounds.CenterPoint(), | |
86 views::Event::EF_LEFT_BUTTON_DOWN)); | |
87 ::Sleep(kActionDelayMs); | |
88 int focused_view_id; | |
89 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); | |
90 EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); | |
91 | |
92 // This used to crash until bug 1303709 was fixed. | |
93 EXPECT_TRUE(window->SimulateOSKeyPress(VK_ESCAPE, 0)); | |
94 ::Sleep(kActionDelayMs); | |
95 } | |
OLD | NEW |