Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: trunk/src/chrome/browser/ui/search/search_model_unittest.cc

Issue 16124009: Revert 204709 "Move instant support to SearchTabHelper." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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/search/search_model.h"
6
7 #include "base/command_line.h"
8 #include "chrome/browser/ui/search/search_model_observer.h"
9 #include "chrome/browser/ui/search/search_tab_helper.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/search_types.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13
14 namespace {
15
16 class MockSearchModelObserver : public SearchModelObserver {
17 public:
18 MockSearchModelObserver();
19 virtual ~MockSearchModelObserver();
20
21 virtual void ModelChanged(const SearchModel::State& old_state,
22 const SearchModel::State& new_state) OVERRIDE;
23
24 void VerifySearchModelStates(const SearchModel::State& expected_old_state,
25 const SearchModel::State& expected_new_state);
26
27 void VerifyNotificationCount(int expected_count);
28
29 private:
30 // How many times we've seen search model changed notifications.
31 int modelchanged_notification_count_;
32
33 SearchModel::State actual_old_state_;
34 SearchModel::State actual_new_state_;
35
36 DISALLOW_COPY_AND_ASSIGN(MockSearchModelObserver);
37 };
38
39 MockSearchModelObserver::MockSearchModelObserver()
40 : modelchanged_notification_count_(0) {
41 }
42
43 MockSearchModelObserver::~MockSearchModelObserver() {
44 }
45
46 void MockSearchModelObserver::ModelChanged(
47 const SearchModel::State& old_state,
48 const SearchModel::State& new_state) {
49 actual_old_state_ = old_state;
50 actual_new_state_ = new_state;
51 modelchanged_notification_count_++;
52 }
53
54 void MockSearchModelObserver::VerifySearchModelStates(
55 const SearchModel::State& expected_old_state,
56 const SearchModel::State& expected_new_state) {
57 EXPECT_TRUE(actual_old_state_ == expected_old_state);
58 EXPECT_TRUE(actual_new_state_ == expected_new_state);
59 }
60
61 void MockSearchModelObserver::VerifyNotificationCount(int expected_count) {
62 EXPECT_EQ(modelchanged_notification_count_, expected_count);
63 }
64
65 } // namespace
66
67 class SearchModelTest : public ChromeRenderViewHostTestHarness {
68 public:
69 virtual void SetUp() OVERRIDE;
70 virtual void TearDown() OVERRIDE;
71
72 MockSearchModelObserver mock_observer;
73 SearchModel* model;
74 };
75
76 void SearchModelTest::SetUp() {
77 CommandLine::ForCurrentProcess()->AppendSwitch(
78 switches::kEnableInstantExtendedAPI);
79 ChromeRenderViewHostTestHarness::SetUp();
80 SearchTabHelper::CreateForWebContents(web_contents());
81 SearchTabHelper* search_tab_helper =
82 SearchTabHelper::FromWebContents(web_contents());
83 ASSERT_TRUE(search_tab_helper != NULL);
84 model = search_tab_helper->model();
85 model->AddObserver(&mock_observer);
86 }
87
88 void SearchModelTest::TearDown() {
89 model->RemoveObserver(&mock_observer);
90 ChromeRenderViewHostTestHarness::TearDown();
91 }
92
93 TEST_F(SearchModelTest, UpdateSearchModelInstantSupport) {
94 mock_observer.VerifyNotificationCount(0);
95 EXPECT_TRUE(model->instant_support() == INSTANT_SUPPORT_UNKNOWN);
96 SearchModel::State expected_old_state = model->state();
97 SearchModel::State expected_new_state(model->state());
98 expected_new_state.instant_support = INSTANT_SUPPORT_YES;
99
100 model->SetSupportsInstant(true);
101 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state);
102 mock_observer.VerifyNotificationCount(1);
103 EXPECT_TRUE(model->instant_support() == INSTANT_SUPPORT_YES);
104
105 expected_old_state = expected_new_state;
106 expected_new_state.instant_support = INSTANT_SUPPORT_NO;
107 model->SetSupportsInstant(false);
108 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state);
109 mock_observer.VerifyNotificationCount(2);
110
111 // Notify the observer only if the search model state is changed.
112 model->SetSupportsInstant(false);
113 EXPECT_TRUE(model->state() == expected_new_state);
114 EXPECT_TRUE(model->instant_support() == INSTANT_SUPPORT_NO);
115 mock_observer.VerifyNotificationCount(2);
116 }
117
118 TEST_F(SearchModelTest, UpdateSearchModelMode) {
119 mock_observer.VerifyNotificationCount(0);
120 SearchMode search_mode(SearchMode::MODE_NTP, SearchMode::ORIGIN_NTP);
121 SearchModel::State expected_old_state = model->state();
122 SearchModel::State expected_new_state(model->state());
123 expected_new_state.mode = search_mode;
124
125 model->SetMode(search_mode);
126 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state);
127 mock_observer.VerifyNotificationCount(1);
128
129 search_mode.mode = SearchMode::MODE_SEARCH_RESULTS;
130 expected_old_state = expected_new_state;
131 expected_new_state.mode = search_mode;
132 model->SetMode(search_mode);
133 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state);
134 mock_observer.VerifyNotificationCount(2);
135 EXPECT_TRUE(model->state() == expected_new_state);
136 }
137
138 TEST_F(SearchModelTest, UpdateTopBarVisibility) {
139 mock_observer.VerifyNotificationCount(0);
140 EXPECT_TRUE(model->top_bars_visible());
141
142 SearchModel::State expected_old_state = model->state();
143 SearchModel::State expected_new_state(model->state());
144 expected_new_state.top_bars_visible = false;
145
146 model->SetTopBarsVisible(false);
147 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state);
148 mock_observer.VerifyNotificationCount(1);
149 EXPECT_FALSE(model->top_bars_visible());
150 }
151
152 TEST_F(SearchModelTest, UpdateSearchModelState) {
153 SearchModel::State expected_new_state(model->state());
154 expected_new_state.top_bars_visible = false;
155 expected_new_state.instant_support = INSTANT_SUPPORT_NO;
156 EXPECT_FALSE(model->state() == expected_new_state);
157 model->SetState(expected_new_state);
158 mock_observer.VerifyNotificationCount(1);
159 EXPECT_TRUE(model->state() == expected_new_state);
160 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/search/search_model.cc ('k') | trunk/src/chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698