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