omnibox_view_views_browsertest.cc revision 116680a4aac90f2aa7413d9095a592090648e557
1a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 3a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// found in the LICENSE file. 4a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 5a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 6a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/command_line.h" 8a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/search_engines/template_url_service_factory.h" 9a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/ui/browser.h" 10a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/ui/browser_commands.h" 11a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/ui/browser_window.h" 12a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/ui/browser_window_testing_views.h" 13a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/ui/location_bar/location_bar.h" 14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 15a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/ui/view_ids.h" 16a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/ui/views/frame/browser_view.h" 17e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "chrome/browser/ui/views/location_bar/location_bar_view.h" 18e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "chrome/test/base/in_process_browser_test.h" 19c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/test/base/interactive_test_utils.h" 20c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "grit/generated_resources.h" 21c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/aura/test/event_generator.h" 22e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/aura/window.h" 23e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/aura/window_tree_host.h" 245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ui/base/clipboard/clipboard.h" 255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ui/base/clipboard/scoped_clipboard_writer.h" 26e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/base/ime/text_input_focus_manager.h" 27e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/base/test/ui_controls.h" 28e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/base/ui_base_switches.h" 29e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/events/event_processor.h" 30e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/events/event_utils.h" 31e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "ui/views/controls/textfield/textfield_test_api.h" 32e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 33e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass OmniboxViewViewsTest : public InProcessBrowserTest { 34e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch protected: 35e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch OmniboxViewViewsTest() {} 36e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 37e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch static void GetOmniboxViewForBrowser(const Browser* browser, 38e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch OmniboxView** omnibox_view) { 39a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch BrowserWindow* window = browser->window(); 40a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ASSERT_TRUE(window); 41c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch LocationBar* location_bar = window->GetLocationBar(); 42c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ASSERT_TRUE(location_bar); 43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch *omnibox_view = location_bar->GetOmniboxView(); 44e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ASSERT_TRUE(*omnibox_view); 45c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } 46e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 47e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // Move the mouse to the center of the browser window and left-click. 48e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch void ClickBrowserWindowCenter() { 49c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( 50e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch BrowserView::GetBrowserViewForBrowser( 51e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch browser())->GetBoundsInScreen().CenterPoint())); 52c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, 53e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui_controls::DOWN)); 54e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ASSERT_TRUE( 55e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); 565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Press and release the mouse at the specified locations. If 595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |release_offset| differs from |press_offset|, the mouse will be moved 605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // between the press and release. 61c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch void Click(ui_controls::MouseButton button, 625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const gfx::Point& press_location, 63e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const gfx::Point& release_location) { 64e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_location)); 65e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); 66e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 67e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch if (press_location != release_location) 68e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_location)); 69e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); 70e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch } 71c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Tap the center of the browser window. 73e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch void TapBrowserWindowCenter() { 74e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch gfx::Point center = BrowserView::GetBrowserViewForBrowser( 75e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch browser())->GetBoundsInScreen().CenterPoint(); 76e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch aura::test::EventGenerator generator(browser()->window()-> 77e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch GetNativeWindow()->GetRootWindow()); 78e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch generator.GestureTapAt(center); 79e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch } 80e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 81e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // Touch down and release at the specified locations. 82e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch void Tap(const gfx::Point& press_location, 83a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch const gfx::Point& release_location) { 84a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::EventProcessor* dispatcher = 85a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch browser()->window()->GetNativeWindow()->GetHost()->event_processor(); 86a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 87a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch base::TimeDelta timestamp = ui::EventTimeForNow(); 88a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::TouchEvent press( 89a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::ET_TOUCH_PRESSED, press_location, 5, timestamp); 90a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); 91a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ASSERT_FALSE(details.dispatcher_destroyed); 92a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 93a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch if (press_location != release_location) { 94a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch timestamp += base::TimeDelta::FromMilliseconds(10); 95a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::TouchEvent move( 96a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::ET_TOUCH_MOVED, release_location, 5, timestamp); 97a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch details = dispatcher->OnEventFromSource(&move); 98a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch } 99a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 100a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch timestamp += base::TimeDelta::FromMilliseconds(50); 101a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::TouchEvent release( 102a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::ET_TOUCH_RELEASED, release_location, 5, timestamp); 103a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch details = dispatcher->OnEventFromSource(&release); 104a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ASSERT_FALSE(details.dispatcher_destroyed); 105a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch } 106a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 107a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch private: 108a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // InProcessBrowserTest: 109a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch virtual void SetUpOnMainThread() OVERRIDE { 110a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 111a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch chrome::FocusLocationBar(browser()); 112a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 113a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch } 114a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 115a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); 116a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch}; 117a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 118a3f7b4e666c476898878fa745f637129375cd889Ben MurdochIN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) { 119a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch OmniboxView* view = NULL; 120a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view)); 121a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); 122a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 123a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // Put an URL on the clipboard. 124a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch { 125a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::ScopedClipboardWriter clipboard_writer( 126a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ui::Clipboard::GetForCurrentThread(), ui::CLIPBOARD_TYPE_COPY_PASTE); 127a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch clipboard_writer.WriteURL(base::ASCIIToUTF16("http://www.example.com/")); 128e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch } 129e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 130e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // Paste and go. 131e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch omnibox_view_views->ExecuteCommand(IDS_PASTE_AND_GO, ui::EF_NONE); 132a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 133a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // The popup should not be open. 1342385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch EXPECT_FALSE(view->model()->popup_model()->IsOpen()); 135e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 136 137IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnClick) { 138 OmniboxView* omnibox_view = NULL; 139 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); 140 omnibox_view->SetUserText(base::ASCIIToUTF16("http://www.google.com/")); 141 142 // Take the focus away from the omnibox. 143 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); 144 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 145 EXPECT_FALSE(omnibox_view->IsSelectAll()); 146 147 // Clicking in the omnibox should take focus and select all text. 148 const gfx::Rect omnibox_bounds = BrowserView::GetBrowserViewForBrowser( 149 browser())->GetViewByID(VIEW_ID_OMNIBOX)->GetBoundsInScreen(); 150 const gfx::Point click_location = omnibox_bounds.CenterPoint(); 151 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::LEFT, 152 click_location, click_location)); 153 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 154 EXPECT_TRUE(omnibox_view->IsSelectAll()); 155 156 // Clicking in another view should clear focus and the selection. 157 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); 158 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 159 EXPECT_FALSE(omnibox_view->IsSelectAll()); 160 161 // Clicking in the omnibox again should take focus and select all text again. 162 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::LEFT, 163 click_location, click_location)); 164 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 165 EXPECT_TRUE(omnibox_view->IsSelectAll()); 166 167 // Clicking another omnibox spot should keep focus but clear the selection. 168 omnibox_view->SelectAll(false); 169 const gfx::Point click2_location = omnibox_bounds.origin() + 170 gfx::Vector2d(omnibox_bounds.width() / 4, omnibox_bounds.height() / 4); 171 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::LEFT, 172 click2_location, click2_location)); 173 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 174 EXPECT_FALSE(omnibox_view->IsSelectAll()); 175 176 // Take the focus away and click in the omnibox again, but drag a bit before 177 // releasing. We should focus the omnibox but not select all of its text. 178 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); 179 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::LEFT, 180 click_location, click2_location)); 181 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 182 EXPECT_FALSE(omnibox_view->IsSelectAll()); 183 184 // Middle-clicking should not be handled by the omnibox. 185 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); 186 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::MIDDLE, 187 click_location, click_location)); 188 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 189 EXPECT_FALSE(omnibox_view->IsSelectAll()); 190} 191 192IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTap) { 193 OmniboxView* omnibox_view = NULL; 194 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); 195 omnibox_view->SetUserText(base::ASCIIToUTF16("http://www.google.com/")); 196 197 // Take the focus away from the omnibox. 198 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); 199 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 200 EXPECT_FALSE(omnibox_view->IsSelectAll()); 201 202 // Tapping in the omnibox should take focus and select all text. 203 const gfx::Rect omnibox_bounds = BrowserView::GetBrowserViewForBrowser( 204 browser())->GetViewByID(VIEW_ID_OMNIBOX)->GetBoundsInScreen(); 205 const gfx::Point tap_location = omnibox_bounds.CenterPoint(); 206 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap_location)); 207 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 208 EXPECT_TRUE(omnibox_view->IsSelectAll()); 209 210 // Tapping in another view should clear focus and the selection. 211 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); 212 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 213 EXPECT_FALSE(omnibox_view->IsSelectAll()); 214 215 // Tapping in the omnibox again should take focus and select all text again. 216 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap_location)); 217 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 218 EXPECT_TRUE(omnibox_view->IsSelectAll()); 219 220 // Tapping another omnibox spot should keep focus and selection. 221 omnibox_view->SelectAll(false); 222 const gfx::Point tap2_location = omnibox_bounds.origin() + 223 gfx::Vector2d(omnibox_bounds.width() / 4, omnibox_bounds.height() / 4); 224 ASSERT_NO_FATAL_FAILURE(Tap(tap2_location, tap2_location)); 225 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 226 // We don't test if the all text is selected because it depends on whether or 227 // not there was text under the tap, which appears to be flaky. 228 229 // Take the focus away and tap in the omnibox again, but drag a bit before 230 // releasing. We should focus the omnibox but not select all of its text. 231 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); 232 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap2_location)); 233 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 234 EXPECT_FALSE(omnibox_view->IsSelectAll()); 235} 236 237IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTabToFocus) { 238 OmniboxView* omnibox_view = NULL; 239 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); 240 ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com/")); 241 // RevertAll after navigation to invalidate the selection range saved on blur. 242 omnibox_view->RevertAll(); 243 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 244 EXPECT_FALSE(omnibox_view->IsSelectAll()); 245 246 // Pressing tab to focus the omnibox should select all text. 247 while (!ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)) { 248 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, 249 false, false, false, false)); 250 } 251 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 252 EXPECT_TRUE(omnibox_view->IsSelectAll()); 253} 254 255IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag) { 256 OmniboxView* omnibox_view = NULL; 257 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); 258 OmniboxViewViews* omnibox_view_views = 259 static_cast<OmniboxViewViews*>(omnibox_view); 260 261 // Populate suggestions for the omnibox popup. 262 AutocompleteController* autocomplete_controller = 263 omnibox_view->model()->popup_model()->autocomplete_controller(); 264 AutocompleteResult& results = autocomplete_controller->result_; 265 ACMatches matches; 266 AutocompleteMatch match; 267 match.destination_url = GURL("http://autocomplete-result/"); 268 match.allowed_to_be_default_match = true; 269 match.type = AutocompleteMatchType::HISTORY_TITLE; 270 match.relevance = 500; 271 matches.push_back(match); 272 match.destination_url = GURL("http://autocomplete-result2/"); 273 matches.push_back(match); 274 results.AppendMatches(matches); 275 results.SortAndCull( 276 AutocompleteInput(), 277 TemplateURLServiceFactory::GetForProfile(browser()->profile())); 278 279 // The omnibox popup should open with suggestions displayed. 280 omnibox_view->model()->popup_model()->OnResultChanged(); 281 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); 282 283 // The omnibox text should be selected. 284 EXPECT_TRUE(omnibox_view->IsSelectAll()); 285 286 // Simulate a mouse click before dragging the mouse. 287 gfx::Point point(omnibox_view_views->x(), omnibox_view_views->y()); 288 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point, 289 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 290 omnibox_view_views->OnMousePressed(pressed); 291 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); 292 293 // Simulate a mouse drag of the omnibox text, and the omnibox should close. 294 ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, point, point, 295 ui::EF_LEFT_MOUSE_BUTTON, 0); 296 omnibox_view_views->OnMouseDragged(dragged); 297 298 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen()); 299} 300 301IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, BackgroundIsOpaque) { 302 // The omnibox text should be rendered on an opaque background. Otherwise, we 303 // can't use subpixel rendering. 304 BrowserWindowTesting* window = browser()->window()->GetBrowserWindowTesting(); 305 ASSERT_TRUE(window); 306 OmniboxViewViews* view = window->GetLocationBarView()->omnibox_view(); 307 ASSERT_TRUE(view); 308 EXPECT_FALSE(view->GetRenderText()->background_is_transparent()); 309} 310 311// Tests if executing a command hides touch editing handles. 312IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, 313 DeactivateTouchEditingOnExecuteCommand) { 314 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); 315 316 OmniboxView* view = NULL; 317 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view)); 318 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); 319 views::TextfieldTestApi textfield_test_api(omnibox_view_views); 320 321 // Put a URL on the clipboard. It is written to the clipboard upon destruction 322 // of the writer. 323 { 324 ui::ScopedClipboardWriter clipboard_writer( 325 ui::Clipboard::GetForCurrentThread(), 326 ui::CLIPBOARD_TYPE_COPY_PASTE); 327 clipboard_writer.WriteURL(base::ASCIIToUTF16("http://www.example.com/")); 328 } 329 330 // Tap to activate touch editing. 331 gfx::Point omnibox_center = 332 omnibox_view_views->GetBoundsInScreen().CenterPoint(); 333 Tap(omnibox_center, omnibox_center); 334 EXPECT_TRUE(textfield_test_api.touch_selection_controller()); 335 336 // Execute a command and check if it deactivate touch editing. Paste & Go is 337 // chosen since it is specific to Omnibox and its execution wouldn't be 338 // delgated to the base Textfield class. 339 omnibox_view_views->ExecuteCommand(IDS_PASTE_AND_GO, ui::EF_NONE); 340 EXPECT_FALSE(textfield_test_api.touch_selection_controller()); 341} 342 343IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, FocusedTextInputClient) { 344 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 345 cmd_line->AppendSwitch(switches::kEnableTextInputFocusManager); 346 347 // TODO(yukishiino): The following call to FocusLocationBar is not necessary 348 // if the flag is enabled by default. Remove the call once the transition to 349 // TextInputFocusManager completes. 350 chrome::FocusLocationBar(browser()); 351 OmniboxView* view = NULL; 352 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view)); 353 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); 354 ui::TextInputFocusManager* text_input_focus_manager = 355 ui::TextInputFocusManager::GetInstance(); 356 EXPECT_EQ(omnibox_view_views->GetTextInputClient(), 357 text_input_focus_manager->GetFocusedTextInputClient()); 358} 359