Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(895)

Side by Side Diff: chrome/browser/views/find_bar_host_interactive_uitest.cc

Issue 251064: Fix focus restore bug in find-in-bar (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/find_bar_host_browsertest.cc ('k') | chrome/test/ui_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5
6 #include "base/keyboard_codes.h" 5 #include "base/keyboard_codes.h"
6 #include "base/message_loop.h"
7 #include "chrome/browser/automation/ui_controls.h"
8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/browser_window.h"
10 #include "chrome/browser/find_bar_controller.h"
11 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "chrome/browser/views/find_bar_host.h"
13 #include "chrome/browser/views/frame/browser_view.h"
7 #include "chrome/browser/view_ids.h" 14 #include "chrome/browser/view_ids.h"
8 #include "chrome/test/automation/browser_proxy.h" 15 #include "chrome/test/in_process_browser_test.h"
9 #include "chrome/test/automation/window_proxy.h" 16 #include "chrome/test/ui_test_utils.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" 17 #include "net/url_request/url_request_unittest.h"
18 #include "views/focus/focus_manager.h"
13 #include "views/view.h" 19 #include "views/view.h"
14 20
15 namespace { 21 namespace {
16 22
17 // The delay waited after sending an OS simulated event. 23 // The delay waited after sending an OS simulated event.
18 static const int kActionDelayMs = 500; 24 static const int kActionDelayMs = 500;
19 static const wchar_t kDocRoot[] = L"chrome/test/data"; 25 static const wchar_t kDocRoot[] = L"chrome/test/data";
20 static const wchar_t kSimplePage[] = L"404_is_enough_for_us.html"; 26 static const wchar_t kSimplePage[] = L"404_is_enough_for_us.html";
21 27
22 class FindInPageTest : public UITest { 28 class FindInPageTest : public InProcessBrowserTest {
23 public: 29 public:
24 FindInPageTest() { 30 FindInPageTest() {
25 show_window_ = true; 31 set_show_window(true);
26 dom_automation_enabled_ = true; 32 FindBarHost::disable_animations_during_testing_ = true;
33 }
34
35 void ClickOnView(ViewID view_id) {
36 BrowserWindow* browser_window = browser()->window();
37 ASSERT_TRUE(browser_window);
38 #if defined(TOOLKIT_VIEWS)
39 views::View* view =
40 reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(view_id);
41 #elif defined(OS_LINUX)
42 gfx::NativeWindow window = browser_window->GetNativeHandle();
43 ASSERT_TRUE(window);
44 GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), view_id);
45 #endif
46 ASSERT_TRUE(view);
47 ui_controls::MoveMouseToCenterAndPress(view,
48 ui_controls::LEFT,
49 ui_controls::DOWN | ui_controls::UP,
50 new MessageLoop::QuitTask());
51 ui_test_utils::RunMessageLoop();
52 }
53
54 int GetFocusedViewID() {
55 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN)
56 views::FocusManager* focus_manager =
57 views::FocusManager::GetFocusManagerForNativeView(
58 browser()->window()->GetNativeHandle());
59 if (!focus_manager) {
60 NOTREACHED();
61 return -1;
62 }
63 views::View* focused_view = focus_manager->GetFocusedView();
64 if (!focused_view)
65 return -1;
66 return focused_view->GetID();
67 #else
68 return -1;
69 #endif
27 } 70 }
28 }; 71 };
29 72
30 // Activate a tab by clicking on it. Returns true if the call was successful
31 // (meaning the messages were correctly sent, but does not guarantee the tab
32 // has been changed).
33 bool ActivateTabByClick(AutomationProxy* automation,
34 WindowProxy* browser_window,
35 int tab_index) {
36 // Click on the tab.
37 gfx::Rect bounds;
38
39 if (!browser_window->GetViewBounds(VIEW_ID_TAB_0 + tab_index, &bounds, true))
40 return false;
41
42 if (!browser_window->SimulateOSClick(bounds.CenterPoint(),
43 views::Event::EF_LEFT_BUTTON_DOWN))
44 return false;
45
46 // Wait a bit to let the click be processed.
47 ::Sleep(kActionDelayMs);
48
49 return true;
50 }
51
52 } // namespace 73 } // namespace
53 74
54 TEST_F(FindInPageTest, CrashEscHandlers) { 75 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) {
55 scoped_refptr<HTTPTestServer> server = 76 scoped_refptr<HTTPTestServer> server =
56 HTTPTestServer::CreateServer(kDocRoot, NULL); 77 HTTPTestServer::CreateServer(kDocRoot, NULL);
57 ASSERT_TRUE(NULL != server.get()); 78 ASSERT_TRUE(NULL != server.get());
58 79
59 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
60 ASSERT_TRUE(browser.get() != NULL);
61 scoped_refptr<WindowProxy> window(browser->GetWindow());
62 ASSERT_TRUE(window.get() != NULL);
63
64 // First we navigate to our test page (tab A). 80 // First we navigate to our test page (tab A).
65 GURL url = server->TestServerPageW(kSimplePage); 81 GURL url = server->TestServerPageW(kSimplePage);
66 scoped_refptr<TabProxy> tabA(GetActiveTab()); 82 ui_test_utils::NavigateToURL(browser(), url);
67 EXPECT_NE(AUTOMATION_MSG_NAVIGATION_ERROR, tabA->NavigateToURL(url));
68 83
69 EXPECT_TRUE(browser->OpenFindInPage()); 84 browser()->Find();
70 85
71 // Open another tab (tab B). 86 // Open another tab (tab B).
72 EXPECT_TRUE(browser->AppendTab(url)); 87 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1,
73 scoped_refptr<TabProxy> tabB(GetActiveTab()); 88 false, NULL);
74 89
75 EXPECT_TRUE(browser->OpenFindInPage()); 90 browser()->Find();
91 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
76 92
77 // Select tab A. 93 // Select tab A.
78 EXPECT_TRUE(ActivateTabByClick(automation(), window.get(), 0)); 94 browser()->SelectTabContentsAt(0, true);
79 95
80 // Close tab B. 96 // Close tab B.
81 EXPECT_TRUE(tabB->Close(true)); 97 browser()->CloseTabContents(browser()->GetTabContentsAt(1));
82 98
83 // Click on the location bar so that Find box loses focus. 99 // Click on the location bar so that Find box loses focus.
84 gfx::Rect bounds; 100 ClickOnView(VIEW_ID_LOCATION_BAR);
85 EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, false)); 101 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN)
86 EXPECT_TRUE(window->SimulateOSClick(bounds.CenterPoint(), 102 // Check the location bar is focused.
87 views::Event::EF_LEFT_BUTTON_DOWN)); 103 EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
88 ::Sleep(kActionDelayMs); 104 #endif
89 int focused_view_id;
90 EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id));
91 EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id);
92 105
93 // This used to crash until bug 1303709 was fixed. 106 // This used to crash until bug 1303709 was fixed.
94 EXPECT_TRUE(window->SimulateOSKeyPress(base::VKEY_ESCAPE, 0)); 107 ui_controls::SendKeyPressNotifyWhenDone(
95 ::Sleep(kActionDelayMs); 108 browser()->window()->GetNativeHandle(), base::VKEY_ESCAPE,
109 true, false, false, new MessageLoop::QuitTask());
110 ui_test_utils::RunMessageLoop();
96 } 111 }
112
113 IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) {
114 scoped_refptr<HTTPTestServer> server =
115 HTTPTestServer::CreateServer(kDocRoot, NULL);
116 ASSERT_TRUE(NULL != server.get());
117
118 GURL url = server->TestServerPageW(L"title1.html");
119 ui_test_utils::NavigateToURL(browser(), url);
120
121 // Focus the location bar, open and close the find-in-page, focus should
122 // return to the location bar.
123 browser()->FocusLocationBar();
124 EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
125 browser()->find_bar()->Show();
126 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
127 browser()->find_bar()->EndFindSession();
128 EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
129
130 // Focus the location bar, find something on the page, close the find box,
131 // focus should go to the page.
132 browser()->FocusLocationBar();
133 browser()->Find();
134 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
135 ui_test_utils::FindInPage(browser()->GetSelectedTabContents(),
136 L"a", true, false, NULL);
137 browser()->find_bar()->EndFindSession();
138 EXPECT_EQ(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW, GetFocusedViewID());
139
140 // Focus the location bar, open and close the find box, focus should return to
141 // the location bar (same as before, just checking that http://crbug.com/23599
142 // is fixed).
143 browser()->FocusLocationBar();
144 EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
145 browser()->find_bar()->Show();
146 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
147 browser()->find_bar()->EndFindSession();
148 EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
149 }
OLDNEW
« no previous file with comments | « chrome/browser/views/find_bar_host_browsertest.cc ('k') | chrome/test/ui_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698