| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/command_line.h" | |
| 6 #include "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/browser_tabstrip.h" | 6 #include "chrome/browser/ui/browser_tabstrip.h" |
| 8 #include "chrome/browser/ui/search/search.h" | 7 #include "chrome/browser/ui/search/search.h" |
| 9 #include "chrome/browser/ui/search/search_model.h" | 8 #include "chrome/browser/ui/search/search_model.h" |
| 10 #include "chrome/browser/ui/search/search_tab_helper.h" | 9 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 11 #include "chrome/common/chrome_switches.h" | |
| 12 #include "chrome/test/base/browser_with_test_window_test.h" | 10 #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 | 11 |
| 14 namespace chrome { | 12 namespace chrome { |
| 15 namespace search { | 13 namespace search { |
| 16 | 14 |
| 17 typedef BrowserWithTestWindowTest SearchDelegateTest; | 15 typedef BrowserWithTestWindowTest SearchDelegateTest; |
| 18 | 16 |
| 19 // Test the propagation of search "mode" changes from the tab's search model to | 17 // Test the propagation of search "mode" changes from the tab's search model to |
| 20 // the browser's search model. | 18 // the browser's search model. |
| 21 TEST_F(SearchDelegateTest, SearchModel) { | 19 TEST_F(SearchDelegateTest, SearchModel) { |
| 22 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 20 chrome::search::SetForceInstantExtendedAPIEnabledForTesting(true); |
| 23 command_line->AppendSwitch(switches::kEnableInstantExtendedAPI); | |
| 24 | |
| 25 // Avoid these tests on branded Chrome where channel is set to CHANNEL_STABLE. | |
| 26 if (!chrome::search::IsInstantExtendedAPIEnabled(profile())) | |
| 27 return; | |
| 28 | 21 |
| 29 // Initial state. | 22 // Initial state. |
| 30 EXPECT_TRUE(browser()->search_model()->mode().is_default()); | 23 EXPECT_TRUE(browser()->search_model()->mode().is_default()); |
| 31 | 24 |
| 32 // Propagate change from tab's search model to browser's search model. | 25 // Propagate change from tab's search model to browser's search model. |
| 33 AddTab(browser(), GURL("http://foo/0")); | 26 AddTab(browser(), GURL("http://foo/0")); |
| 34 content::WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0); | 27 content::WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0); |
| 35 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> | 28 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> |
| 36 SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP, false)); | 29 SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP, false)); |
| 37 EXPECT_TRUE(browser()->search_model()->mode().is_ntp()); | 30 EXPECT_TRUE(browser()->search_model()->mode().is_ntp()); |
| 38 | 31 |
| 39 // Add second tab, make it active, and make sure its mode changes | 32 // Add second tab, make it active, and make sure its mode changes |
| 40 // propagate to the browser's search model. | 33 // propagate to the browser's search model. |
| 41 AddTab(browser(), GURL("http://foo/1")); | 34 AddTab(browser(), GURL("http://foo/1")); |
| 42 chrome::ActivateTabAt(browser(), 1, true); | 35 chrome::ActivateTabAt(browser(), 1, true); |
| 43 web_contents = chrome::GetWebContentsAt(browser(), 1); | 36 web_contents = chrome::GetWebContentsAt(browser(), 1); |
| 44 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> | 37 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> |
| 45 SetMode(Mode(Mode::MODE_SEARCH_RESULTS, Mode::ORIGIN_DEFAULT, false)); | 38 SetMode(Mode(Mode::MODE_SEARCH_RESULTS, Mode::ORIGIN_DEFAULT, false)); |
| 46 EXPECT_TRUE(browser()->search_model()->mode().is_search()); | 39 EXPECT_TRUE(browser()->search_model()->mode().is_search()); |
| 47 | 40 |
| 48 // The first tab is not active so changes should not propagate. | 41 // The first tab is not active so changes should not propagate. |
| 49 web_contents = chrome::GetWebContentsAt(browser(), 0); | 42 web_contents = chrome::GetWebContentsAt(browser(), 0); |
| 50 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> | 43 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> |
| 51 SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP, false)); | 44 SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP, false)); |
| 52 EXPECT_TRUE(browser()->search_model()->mode().is_search()); | 45 EXPECT_TRUE(browser()->search_model()->mode().is_search()); |
| 46 |
| 47 chrome::search::SetForceInstantExtendedAPIEnabledForTesting(false); |
| 53 } | 48 } |
| 54 | 49 |
| 55 } // namespace search | 50 } // namespace search |
| 56 } // namespace chrome | 51 } // namespace chrome |
| OLD | NEW |