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