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

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

Issue 2885853002: Instant: remove InstantSupportState (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/ui/search/search_model.h" 5 #include "chrome/browser/ui/search/search_model.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "chrome/browser/ui/search/search_model_observer.h" 9 #include "chrome/browser/ui/search/search_model_observer.h"
10 #include "chrome/browser/ui/search/search_tab_helper.h" 10 #include "chrome/browser/ui/search/search_tab_helper.h"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/search/search_types.h" 12 #include "chrome/common/search/search_types.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 14
15 namespace { 15 namespace {
16 16
17 class MockSearchModelObserver : public SearchModelObserver { 17 class MockSearchModelObserver : public SearchModelObserver {
18 public: 18 public:
19 MockSearchModelObserver(); 19 MockSearchModelObserver();
20 ~MockSearchModelObserver() override; 20 ~MockSearchModelObserver() override;
21 21
22 void ModelChanged(const SearchModel::State& old_state, 22 void ModelChanged(const SearchMode& old_mode,
23 const SearchModel::State& new_state) override; 23 const SearchMode& new_mode) override;
24 24
25 void VerifySearchModelStates(const SearchModel::State& expected_old_state, 25 void VerifySearchModelStates(const SearchMode& expected_old_mode,
26 const SearchModel::State& expected_new_state); 26 const SearchMode& expected_new_mode);
27 27
28 void VerifyNotificationCount(int expected_count); 28 void VerifyNotificationCount(int expected_count);
29 29
30 private: 30 private:
31 // How many times we've seen search model changed notifications. 31 // How many times we've seen search model changed notifications.
32 int modelchanged_notification_count_; 32 int modelchanged_notification_count_;
33 33
34 SearchModel::State actual_old_state_; 34 SearchMode actual_old_mode_;
35 SearchModel::State actual_new_state_; 35 SearchMode actual_new_mode_;
36 36
37 DISALLOW_COPY_AND_ASSIGN(MockSearchModelObserver); 37 DISALLOW_COPY_AND_ASSIGN(MockSearchModelObserver);
38 }; 38 };
39 39
40 MockSearchModelObserver::MockSearchModelObserver() 40 MockSearchModelObserver::MockSearchModelObserver()
41 : modelchanged_notification_count_(0) { 41 : modelchanged_notification_count_(0) {
42 } 42 }
43 43
44 MockSearchModelObserver::~MockSearchModelObserver() { 44 MockSearchModelObserver::~MockSearchModelObserver() {
45 } 45 }
46 46
47 void MockSearchModelObserver::ModelChanged( 47 void MockSearchModelObserver::ModelChanged(const SearchMode& old_mode,
48 const SearchModel::State& old_state, 48 const SearchMode& new_mode) {
49 const SearchModel::State& new_state) { 49 actual_old_mode_ = old_mode;
50 actual_old_state_ = old_state; 50 actual_new_mode_ = new_mode;
51 actual_new_state_ = new_state;
52 modelchanged_notification_count_++; 51 modelchanged_notification_count_++;
53 } 52 }
54 53
55 void MockSearchModelObserver::VerifySearchModelStates( 54 void MockSearchModelObserver::VerifySearchModelStates(
56 const SearchModel::State& expected_old_state, 55 const SearchMode& expected_old_mode,
57 const SearchModel::State& expected_new_state) { 56 const SearchMode& expected_new_mode) {
58 EXPECT_TRUE(actual_old_state_ == expected_old_state); 57 EXPECT_TRUE(actual_old_mode_ == expected_old_mode);
59 EXPECT_TRUE(actual_new_state_ == expected_new_state); 58 EXPECT_TRUE(actual_new_mode_ == expected_new_mode);
60 } 59 }
61 60
62 void MockSearchModelObserver::VerifyNotificationCount(int expected_count) { 61 void MockSearchModelObserver::VerifyNotificationCount(int expected_count) {
63 EXPECT_EQ(modelchanged_notification_count_, expected_count); 62 EXPECT_EQ(modelchanged_notification_count_, expected_count);
64 } 63 }
65 64
66 } // namespace 65 } // namespace
67 66
68 class SearchModelTest : public ChromeRenderViewHostTestHarness { 67 class SearchModelTest : public ChromeRenderViewHostTestHarness {
69 public: 68 public:
(...skipping 12 matching lines...) Expand all
82 ASSERT_TRUE(search_tab_helper != NULL); 81 ASSERT_TRUE(search_tab_helper != NULL);
83 model = search_tab_helper->model(); 82 model = search_tab_helper->model();
84 model->AddObserver(&mock_observer); 83 model->AddObserver(&mock_observer);
85 } 84 }
86 85
87 void SearchModelTest::TearDown() { 86 void SearchModelTest::TearDown() {
88 model->RemoveObserver(&mock_observer); 87 model->RemoveObserver(&mock_observer);
89 ChromeRenderViewHostTestHarness::TearDown(); 88 ChromeRenderViewHostTestHarness::TearDown();
90 } 89 }
91 90
92 TEST_F(SearchModelTest, UpdateSearchModelInstantSupport) {
93 mock_observer.VerifyNotificationCount(0);
94 EXPECT_TRUE(model->instant_support() == INSTANT_SUPPORT_NO);
95 SearchModel::State expected_old_state = model->state();
96 SearchModel::State expected_new_state(model->state());
97 expected_new_state.instant_support = INSTANT_SUPPORT_YES;
98
99 model->SetInstantSupportState(INSTANT_SUPPORT_YES);
100 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state);
101 mock_observer.VerifyNotificationCount(1);
102 EXPECT_TRUE(model->instant_support() == INSTANT_SUPPORT_YES);
103
104 expected_old_state = expected_new_state;
105 expected_new_state.instant_support = INSTANT_SUPPORT_NO;
106 model->SetInstantSupportState(INSTANT_SUPPORT_NO);
107 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state);
108 mock_observer.VerifyNotificationCount(2);
109
110 // Notify the observer only if the search model state is changed.
111 model->SetInstantSupportState(INSTANT_SUPPORT_NO);
112 EXPECT_TRUE(model->state() == expected_new_state);
113 EXPECT_TRUE(model->instant_support() == INSTANT_SUPPORT_NO);
114 mock_observer.VerifyNotificationCount(2);
115 }
116
117 TEST_F(SearchModelTest, UpdateSearchModelMode) { 91 TEST_F(SearchModelTest, UpdateSearchModelMode) {
118 mock_observer.VerifyNotificationCount(0); 92 mock_observer.VerifyNotificationCount(0);
119 SearchMode search_mode(SearchMode::MODE_NTP, SearchMode::ORIGIN_NTP); 93 SearchMode search_mode(SearchMode::MODE_NTP, SearchMode::ORIGIN_NTP);
120 SearchModel::State expected_old_state = model->state(); 94 SearchMode expected_old_mode = model->mode();
121 SearchModel::State expected_new_state(model->state()); 95 SearchMode expected_new_mode = search_mode;
122 expected_new_state.mode = search_mode;
123
124 model->SetMode(search_mode); 96 model->SetMode(search_mode);
125 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state); 97 mock_observer.VerifySearchModelStates(expected_old_mode, expected_new_mode);
126 mock_observer.VerifyNotificationCount(1); 98 mock_observer.VerifyNotificationCount(1);
127 99
128 search_mode.mode = SearchMode::MODE_SEARCH_SUGGESTIONS; 100 search_mode.mode = SearchMode::MODE_SEARCH_SUGGESTIONS;
129 expected_old_state = expected_new_state; 101 expected_old_mode = expected_new_mode;
130 expected_new_state.mode = search_mode; 102 expected_new_mode = search_mode;
131 model->SetMode(search_mode); 103 model->SetMode(search_mode);
132 mock_observer.VerifySearchModelStates(expected_old_state, expected_new_state); 104 mock_observer.VerifySearchModelStates(expected_old_mode, expected_new_mode);
133 mock_observer.VerifyNotificationCount(2); 105 mock_observer.VerifyNotificationCount(2);
134 EXPECT_TRUE(model->state() == expected_new_state); 106 EXPECT_TRUE(model->mode() == expected_new_mode);
135 } 107 }
136
137 TEST_F(SearchModelTest, UpdateSearchModelState) {
138 SearchModel::State expected_new_state(model->state());
139 expected_new_state.instant_support = INSTANT_SUPPORT_YES;
140 EXPECT_FALSE(model->state() == expected_new_state);
141 model->SetState(expected_new_state);
142 mock_observer.VerifyNotificationCount(1);
143 EXPECT_TRUE(model->state() == expected_new_state);
144 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_model_observer.h ('k') | chrome/browser/ui/search/search_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698