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