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 "chrome/browser/search_engines/template_url_service_factory.h" |
5 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
6 #include "chrome/browser/ui/search/search.h" | 7 #include "chrome/browser/ui/search/search.h" |
7 #include "chrome/browser/ui/search/search_model.h" | 8 #include "chrome/browser/ui/search/search_model.h" |
8 #include "chrome/browser/ui/search/search_tab_helper.h" | 9 #include "chrome/browser/ui/search/search_tab_helper.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/test/base/browser_with_test_window_test.h" | 11 #include "chrome/test/base/browser_with_test_window_test.h" |
11 | 12 |
12 namespace chrome { | 13 namespace chrome { |
13 namespace search { | 14 namespace search { |
14 | 15 |
15 typedef BrowserWithTestWindowTest SearchDelegateTest; | 16 typedef BrowserWithTestWindowTest SearchDelegateTest; |
16 | 17 |
17 // Test the propagation of search "mode" changes from the tab's search model to | 18 // Test the propagation of search "mode" changes from the tab's search model to |
18 // the browser's search model. | 19 // the browser's search model. |
19 TEST_F(SearchDelegateTest, SearchModel) { | 20 TEST_F(SearchDelegateTest, SearchModel) { |
20 chrome::search::EnableInstantExtendedAPIForTesting(); | 21 chrome::search::EnableInstantExtendedAPIForTesting(); |
21 | 22 |
22 // Initial state. | 23 // Initial state. |
23 EXPECT_TRUE(browser()->search_model()->mode().is_default()); | 24 EXPECT_TRUE(browser()->search_model()->mode().is_default()); |
24 | 25 |
| 26 // This must be created to make sure the SearchTabHelper has a non-NULL |
| 27 // TemplateURLService when navigations are committed. |
| 28 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 29 browser()->profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 30 |
25 // Propagate change from tab's search model to browser's search model. | 31 // Propagate change from tab's search model to browser's search model. |
26 AddTab(browser(), GURL("http://foo/0")); | 32 AddTab(browser(), GURL("http://foo/0")); |
27 content::WebContents* web_contents = | 33 content::WebContents* web_contents = |
28 browser()->tab_strip_model()->GetWebContentsAt(0); | 34 browser()->tab_strip_model()->GetWebContentsAt(0); |
29 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> | 35 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> |
30 SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP, false)); | 36 SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP, false)); |
31 EXPECT_TRUE(browser()->search_model()->mode().is_ntp()); | 37 EXPECT_TRUE(browser()->search_model()->mode().is_ntp()); |
32 | 38 |
33 // Add second tab, make it active, and make sure its mode changes | 39 // Add second tab, make it active, and make sure its mode changes |
34 // propagate to the browser's search model. | 40 // propagate to the browser's search model. |
35 AddTab(browser(), GURL("http://foo/1")); | 41 AddTab(browser(), GURL("http://foo/1")); |
36 browser()->tab_strip_model()->ActivateTabAt(1, true); | 42 browser()->tab_strip_model()->ActivateTabAt(1, true); |
37 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); | 43 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); |
38 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> | 44 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> |
39 SetMode(Mode(Mode::MODE_SEARCH_RESULTS, Mode::ORIGIN_DEFAULT, false)); | 45 SetMode(Mode(Mode::MODE_SEARCH_RESULTS, Mode::ORIGIN_DEFAULT, false)); |
40 EXPECT_TRUE(browser()->search_model()->mode().is_search()); | 46 EXPECT_TRUE(browser()->search_model()->mode().is_search()); |
41 | 47 |
42 // The first tab is not active so changes should not propagate. | 48 // The first tab is not active so changes should not propagate. |
43 web_contents = browser()->tab_strip_model()->GetWebContentsAt(0); | 49 web_contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
44 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> | 50 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()-> |
45 SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP, false)); | 51 SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP, false)); |
46 EXPECT_TRUE(browser()->search_model()->mode().is_search()); | 52 EXPECT_TRUE(browser()->search_model()->mode().is_search()); |
47 } | 53 } |
48 | 54 |
49 } // namespace search | 55 } // namespace search |
50 } // namespace chrome | 56 } // namespace chrome |
OLD | NEW |