summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/search/search_delegate_unittest.cc
blob: 4e4354cc8b9baabf8159c89cbcd64e2b69b41141 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/instant/search.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/browser_with_test_window_test.h"

namespace chrome {
namespace search {

typedef BrowserWithTestWindowTest SearchDelegateTest;

// Test the propagation of search "mode" changes from the tab's search model to
// the browser's search model.
TEST_F(SearchDelegateTest, SearchModel) {
  chrome::search::EnableInstantExtendedAPIForTesting();

  // Initial state.
  EXPECT_TRUE(browser()->search_model()->mode().is_default());

  // Propagate change from tab's search model to browser's search model.
  AddTab(browser(), GURL("http://foo/0"));
  content::WebContents* web_contents =
      browser()->tab_strip_model()->GetWebContentsAt(0);
  chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()->
      SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP));
  EXPECT_TRUE(browser()->search_model()->mode().is_ntp());

  // Add second tab, make it active, and make sure its mode changes
  // propagate to the browser's search model.
  AddTab(browser(), GURL("http://foo/1"));
  browser()->tab_strip_model()->ActivateTabAt(1, true);
  web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
  chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()->
      SetMode(Mode(Mode::MODE_SEARCH_RESULTS, Mode::ORIGIN_DEFAULT));
  EXPECT_TRUE(browser()->search_model()->mode().is_search());

  // The first tab is not active so changes should not propagate.
  web_contents = browser()->tab_strip_model()->GetWebContentsAt(0);
  chrome::search::SearchTabHelper::FromWebContents(web_contents)->model()->
      SetMode(Mode(Mode::MODE_NTP, Mode::ORIGIN_NTP));
  EXPECT_TRUE(browser()->search_model()->mode().is_search());
}

}  // namespace search
}  // namespace chrome