diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-03 21:56:37 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-03 21:56:37 +0000 |
commit | 0080c4fc83b66fb66706ec36023c04c379bb5cc5 (patch) | |
tree | 01333c72aba5dbd65295944efa6d3faf2a63f5ab /chrome | |
parent | 5db15a7c97ba8f9feee200df7f0ba090cb4e9485 (diff) | |
download | chromium_src-0080c4fc83b66fb66706ec36023c04c379bb5cc5.zip chromium_src-0080c4fc83b66fb66706ec36023c04c379bb5cc5.tar.gz chromium_src-0080c4fc83b66fb66706ec36023c04c379bb5cc5.tar.bz2 |
chromeos: Make Search key never close the NTP.
The Search key had complicated behavior: pressing it would
open the new tab page and focus its omnibox... unless the
NTP was already open, in which case the key would close it.
This was intended to provide an escape hatch for accidental
presses, but it prevents users from just mashing the key and
typing a URL whenever they want to load a page.
This change gets rid of the closing behavior -- if the NTP
is already open, we just focus the omnibox.
BUG=chromium-os:8742
TEST=added a simple unit test (which doesn't cover the focusing change); also did manual testing: opened NTP, unfocused omnibox, and checked that Search key re-focuses it
Review URL: http://codereview.chromium.org/8093012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_commands_unittest.cc | 27 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 19 |
2 files changed, 36 insertions, 10 deletions
diff --git a/chrome/browser/browser_commands_unittest.cc b/chrome/browser/browser_commands_unittest.cc index 60284b9..daaf106 100644 --- a/chrome/browser/browser_commands_unittest.cc +++ b/chrome/browser/browser_commands_unittest.cc @@ -166,3 +166,30 @@ TEST_F(BrowserCommandsTest, BackForwardInNewTab) { ASSERT_EQ(4, browser()->active_index()); ASSERT_EQ(url2, browser()->GetSelectedTabContents()->GetURL()); } + +// Tests IDC_SEARCH (the Search key on Chrome OS devices). +#if defined(OS_CHROMEOS) +TEST_F(BrowserCommandsTest, Search) { + // Load a non-NTP URL. + GURL non_ntp_url("http://foo/"); + AddTab(browser(), non_ntp_url); + ASSERT_EQ(1, browser()->tab_count()); + EXPECT_EQ(non_ntp_url, browser()->GetSelectedTabContents()->GetURL()); + + // Pressing the Search key should open a new tab containing the NTP. + browser()->Search(); + ASSERT_EQ(2, browser()->tab_count()); + ASSERT_EQ(1, browser()->active_index()); + GURL current_url = browser()->GetSelectedTabContents()->GetURL(); + EXPECT_TRUE(current_url.SchemeIs(chrome::kChromeUIScheme)); + EXPECT_EQ(chrome::kChromeUINewTabHost, current_url.host()); + + // Pressing it a second time while the NTP is open shouldn't change anything. + browser()->Search(); + ASSERT_EQ(2, browser()->tab_count()); + ASSERT_EQ(1, browser()->active_index()); + current_url = browser()->GetSelectedTabContents()->GetURL(); + EXPECT_TRUE(current_url.SchemeIs(chrome::kChromeUIScheme)); + EXPECT_EQ(chrome::kChromeUINewTabHost, current_url.host()); +} +#endif diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 7f8349c..6d0b435 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1706,14 +1706,6 @@ void Browser::TogglePresentationMode() { #if defined(OS_CHROMEOS) void Browser::Search() { - // If the NTP is showing, close it. - const GURL& url = GetSelectedTabContents()->GetURL(); - if (url.SchemeIs(chrome::kChromeUIScheme) && - url.host() == chrome::kChromeUINewTabHost) { - CloseTab(); - return; - } - // Exit fullscreen to show omnibox. if (window_->IsFullscreen()) { ToggleFullscreenMode(); @@ -1725,8 +1717,15 @@ void Browser::Search() { return; } - // Otherwise just open it. - NewTab(); + const GURL& url = GetSelectedTabContents()->GetURL(); + if (url.SchemeIs(chrome::kChromeUIScheme) && + url.host() == chrome::kChromeUINewTabHost) { + // If the NTP is showing, focus the omnibox. + window_->SetFocusToLocationBar(true); + } else { + // Otherwise, open the NTP. + NewTab(); + } } void Browser::ShowKeyboardOverlay() { |