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/search.h" | |
6 #include "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
7 #include "chrome/browser/ui/search/search_model.h" | 6 #include "chrome/browser/ui/search/search_model.h" |
8 #include "chrome/browser/ui/search/search_tab_helper.h" | 7 #include "chrome/browser/ui/search/search_tab_helper.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/test/base/browser_with_test_window_test.h" | 9 #include "chrome/test/base/browser_with_test_window_test.h" |
11 | 10 |
12 typedef BrowserWithTestWindowTest SearchDelegateTest; | 11 typedef BrowserWithTestWindowTest SearchDelegateTest; |
13 | 12 |
14 // Test the propagation of search "mode" changes from the tab's search model to | 13 // Test the propagation of search "mode" changes from the tab's search model to |
15 // the browser's search model. | 14 // the browser's search model. |
16 TEST_F(SearchDelegateTest, SearchModel) { | 15 TEST_F(SearchDelegateTest, SearchModel) { |
17 chrome::EnableInstantExtendedAPIForTesting(); | |
18 | |
19 // Initial state. | 16 // Initial state. |
20 EXPECT_TRUE(browser()->search_model()->mode().is_default()); | 17 EXPECT_TRUE(browser()->search_model()->mode().is_default()); |
21 | 18 |
22 // Propagate change from tab's search model to browser's search model. | 19 // Propagate change from tab's search model to browser's search model. |
23 AddTab(browser(), GURL("http://foo/0")); | 20 AddTab(browser(), GURL("http://foo/0")); |
24 content::WebContents* web_contents = | 21 content::WebContents* web_contents = |
25 browser()->tab_strip_model()->GetWebContentsAt(0); | 22 browser()->tab_strip_model()->GetWebContentsAt(0); |
26 SearchTabHelper::FromWebContents(web_contents)->model()-> | 23 SearchTabHelper::FromWebContents(web_contents)->model()-> |
27 SetMode(SearchMode(SearchMode::MODE_NTP, SearchMode::ORIGIN_NTP)); | 24 SetMode(SearchMode(SearchMode::MODE_NTP, SearchMode::ORIGIN_NTP)); |
28 EXPECT_TRUE(browser()->search_model()->mode().is_ntp()); | 25 EXPECT_TRUE(browser()->search_model()->mode().is_ntp()); |
29 | 26 |
30 // Add second tab, make it active, and make sure its mode changes | 27 // Add second tab, make it active, and make sure its mode changes |
31 // propagate to the browser's search model. | 28 // propagate to the browser's search model. |
32 AddTab(browser(), GURL("http://foo/1")); | 29 AddTab(browser(), GURL("http://foo/1")); |
33 browser()->tab_strip_model()->ActivateTabAt(1, true); | 30 browser()->tab_strip_model()->ActivateTabAt(1, true); |
34 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); | 31 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); |
35 SearchTabHelper::FromWebContents(web_contents)->model()-> | 32 SearchTabHelper::FromWebContents(web_contents)->model()-> |
36 SetMode(SearchMode(SearchMode::MODE_SEARCH_RESULTS, | 33 SetMode(SearchMode(SearchMode::MODE_SEARCH_RESULTS, |
37 SearchMode::ORIGIN_DEFAULT)); | 34 SearchMode::ORIGIN_DEFAULT)); |
38 EXPECT_TRUE(browser()->search_model()->mode().is_search()); | 35 EXPECT_TRUE(browser()->search_model()->mode().is_search()); |
39 | 36 |
40 // The first tab is not active so changes should not propagate. | 37 // The first tab is not active so changes should not propagate. |
41 web_contents = browser()->tab_strip_model()->GetWebContentsAt(0); | 38 web_contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
42 SearchTabHelper::FromWebContents(web_contents)->model()-> | 39 SearchTabHelper::FromWebContents(web_contents)->model()-> |
43 SetMode(SearchMode(SearchMode::MODE_NTP, SearchMode::ORIGIN_NTP)); | 40 SetMode(SearchMode(SearchMode::MODE_NTP, SearchMode::ORIGIN_NTP)); |
44 EXPECT_TRUE(browser()->search_model()->mode().is_search()); | 41 EXPECT_TRUE(browser()->search_model()->mode().is_search()); |
45 } | 42 } |
OLD | NEW |