summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_commands_unittest.cc27
-rw-r--r--chrome/browser/ui/browser.cc19
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() {