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

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

Issue 24940002: Send ChromeViewMsg_SearchBoxSetSuggestionToPrefetch IPC message from SearchIPCRouter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comment Created 7 years, 2 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
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_ipc_router.h" 5 #include "chrome/browser/ui/search/search_ipc_router.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 23 matching lines...) Expand all
34 MOCK_METHOD1(OnInstantSupportDetermined, void(bool supports_instant)); 34 MOCK_METHOD1(OnInstantSupportDetermined, void(bool supports_instant));
35 MOCK_METHOD1(OnSetVoiceSearchSupport, void(bool supports_voice_search)); 35 MOCK_METHOD1(OnSetVoiceSearchSupport, void(bool supports_voice_search));
36 }; 36 };
37 37
38 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { 38 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy {
39 public: 39 public:
40 virtual ~MockSearchIPCRouterPolicy() {} 40 virtual ~MockSearchIPCRouterPolicy() {}
41 41
42 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool()); 42 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool());
43 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool()); 43 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool());
44 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool());
44 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); 45 MOCK_METHOD0(ShouldSendMostVisitedItems, bool());
45 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); 46 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool());
46 }; 47 };
47 48
48 } // namespace 49 } // namespace
49 50
50 class SearchIPCRouterTest : public ChromeRenderViewHostTestHarness { 51 class SearchIPCRouterTest : public ChromeRenderViewHostTestHarness {
51 public: 52 public:
52 virtual void SetUp() { 53 virtual void SetUp() {
53 CommandLine::ForCurrentProcess()->AppendSwitch( 54 CommandLine::ForCurrentProcess()->AppendSwitch(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 NavigateAndCommit(GURL("chrome-search://foo/bar")); 136 NavigateAndCommit(GURL("chrome-search://foo/bar"));
136 process()->sink().ClearMessages(); 137 process()->sink().ClearMessages();
137 138
138 SetupMockDelegateAndPolicy(web_contents()); 139 SetupMockDelegateAndPolicy(web_contents());
139 MockSearchIPCRouterPolicy* policy = 140 MockSearchIPCRouterPolicy* policy =
140 GetSearchIPCRouterPolicy(web_contents()); 141 GetSearchIPCRouterPolicy(web_contents());
141 EXPECT_CALL(*policy, ShouldSendSetDisplayInstantResults()).Times(1) 142 EXPECT_CALL(*policy, ShouldSendSetDisplayInstantResults()).Times(1)
142 .WillOnce(testing::Return(true)); 143 .WillOnce(testing::Return(true));
143 144
144 GetSearchTabHelper(web_contents())->ipc_router().SetDisplayInstantResults(); 145 GetSearchTabHelper(web_contents())->ipc_router().SetDisplayInstantResults();
145 ASSERT_TRUE(MessageWasSent( 146 EXPECT_TRUE(MessageWasSent(
146 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID)); 147 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID));
147 } 148 }
148 149
149 TEST_F(SearchIPCRouterTest, DoNotSendSetDisplayInstantResultsMsg) { 150 TEST_F(SearchIPCRouterTest, DoNotSendSetDisplayInstantResultsMsg) {
150 NavigateAndCommit(GURL("chrome-search://foo/bar")); 151 NavigateAndCommit(GURL("chrome-search://foo/bar"));
151 process()->sink().ClearMessages(); 152 process()->sink().ClearMessages();
152 153
153 SetupMockDelegateAndPolicy(web_contents()); 154 SetupMockDelegateAndPolicy(web_contents());
154 MockSearchIPCRouterPolicy* policy = 155 MockSearchIPCRouterPolicy* policy =
155 GetSearchIPCRouterPolicy(web_contents()); 156 GetSearchIPCRouterPolicy(web_contents());
156 EXPECT_CALL(*policy, ShouldSendSetDisplayInstantResults()).Times(1) 157 EXPECT_CALL(*policy, ShouldSendSetDisplayInstantResults()).Times(1)
157 .WillOnce(testing::Return(false)); 158 .WillOnce(testing::Return(false));
158 159
159 GetSearchTabHelper(web_contents())->ipc_router().SetDisplayInstantResults(); 160 GetSearchTabHelper(web_contents())->ipc_router().SetDisplayInstantResults();
160 ASSERT_FALSE(MessageWasSent( 161 EXPECT_FALSE(MessageWasSent(
161 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID)); 162 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID));
162 } 163 }
163 164
165 TEST_F(SearchIPCRouterTest, SendSetSuggestionToPrefetch) {
166 NavigateAndCommit(GURL("chrome-search://foo/bar"));
167 process()->sink().ClearMessages();
168
169 SetupMockDelegateAndPolicy(web_contents());
170 MockSearchIPCRouterPolicy* policy =
171 GetSearchIPCRouterPolicy(web_contents());
172 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1)
173 .WillOnce(testing::Return(true));
174
175 GetSearchTabHelper(web_contents())->SetSuggestionToPrefetch(
176 InstantSuggestion());
177 EXPECT_TRUE(MessageWasSent(
178 ChromeViewMsg_SearchBoxSetSuggestionToPrefetch::ID));
179 }
180
181 TEST_F(SearchIPCRouterTest, DoNotSendSetSuggestionToPrefetch) {
182 NavigateAndCommit(GURL("chrome-search://foo/bar"));
183 process()->sink().ClearMessages();
184
185 SetupMockDelegateAndPolicy(web_contents());
186 MockSearchIPCRouterPolicy* policy =
187 GetSearchIPCRouterPolicy(web_contents());
188 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1)
189 .WillOnce(testing::Return(false));
190
191 GetSearchTabHelper(web_contents())->SetSuggestionToPrefetch(
192 InstantSuggestion());
193 EXPECT_FALSE(MessageWasSent(
194 ChromeViewMsg_SearchBoxSetSuggestionToPrefetch::ID));
195 }
196
164 TEST_F(SearchIPCRouterTest, SendMostVisitedItemsMsg) { 197 TEST_F(SearchIPCRouterTest, SendMostVisitedItemsMsg) {
165 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 198 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
166 process()->sink().ClearMessages(); 199 process()->sink().ClearMessages();
167 200
168 SetupMockDelegateAndPolicy(web_contents()); 201 SetupMockDelegateAndPolicy(web_contents());
169 MockSearchIPCRouterPolicy* policy = 202 MockSearchIPCRouterPolicy* policy =
170 GetSearchIPCRouterPolicy(web_contents()); 203 GetSearchIPCRouterPolicy(web_contents());
171 EXPECT_CALL(*policy, ShouldSendMostVisitedItems()).Times(1) 204 EXPECT_CALL(*policy, ShouldSendMostVisitedItems()).Times(1)
172 .WillOnce(testing::Return(true)); 205 .WillOnce(testing::Return(true));
173 206
174 GetSearchTabHelper(web_contents())->ipc_router().SendMostVisitedItems( 207 GetSearchTabHelper(web_contents())->ipc_router().SendMostVisitedItems(
175 std::vector<InstantMostVisitedItem>()); 208 std::vector<InstantMostVisitedItem>());
176 ASSERT_TRUE(MessageWasSent( 209 EXPECT_TRUE(MessageWasSent(
177 ChromeViewMsg_SearchBoxMostVisitedItemsChanged::ID)); 210 ChromeViewMsg_SearchBoxMostVisitedItemsChanged::ID));
178 } 211 }
179 212
180 TEST_F(SearchIPCRouterTest, DoNotSendMostVisitedItemsMsg) { 213 TEST_F(SearchIPCRouterTest, DoNotSendMostVisitedItemsMsg) {
181 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 214 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
182 process()->sink().ClearMessages(); 215 process()->sink().ClearMessages();
183 216
184 SetupMockDelegateAndPolicy(web_contents()); 217 SetupMockDelegateAndPolicy(web_contents());
185 MockSearchIPCRouterPolicy* policy = 218 MockSearchIPCRouterPolicy* policy =
186 GetSearchIPCRouterPolicy(web_contents()); 219 GetSearchIPCRouterPolicy(web_contents());
187 EXPECT_CALL(*policy, ShouldSendMostVisitedItems()).Times(1) 220 EXPECT_CALL(*policy, ShouldSendMostVisitedItems()).Times(1)
188 .WillOnce(testing::Return(false)); 221 .WillOnce(testing::Return(false));
189 222
190 GetSearchTabHelper(web_contents())->ipc_router().SendMostVisitedItems( 223 GetSearchTabHelper(web_contents())->ipc_router().SendMostVisitedItems(
191 std::vector<InstantMostVisitedItem>()); 224 std::vector<InstantMostVisitedItem>());
192 ASSERT_FALSE(MessageWasSent( 225 EXPECT_FALSE(MessageWasSent(
193 ChromeViewMsg_SearchBoxMostVisitedItemsChanged::ID)); 226 ChromeViewMsg_SearchBoxMostVisitedItemsChanged::ID));
194 } 227 }
195 228
196 TEST_F(SearchIPCRouterTest, SendThemeBackgroundInfoMsg) { 229 TEST_F(SearchIPCRouterTest, SendThemeBackgroundInfoMsg) {
197 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 230 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
198 process()->sink().ClearMessages(); 231 process()->sink().ClearMessages();
199 232
200 SetupMockDelegateAndPolicy(web_contents()); 233 SetupMockDelegateAndPolicy(web_contents());
201 MockSearchIPCRouterPolicy* policy = 234 MockSearchIPCRouterPolicy* policy =
202 GetSearchIPCRouterPolicy(web_contents()); 235 GetSearchIPCRouterPolicy(web_contents());
203 EXPECT_CALL(*policy, ShouldSendThemeBackgroundInfo()).Times(1) 236 EXPECT_CALL(*policy, ShouldSendThemeBackgroundInfo()).Times(1)
204 .WillOnce(testing::Return(true)); 237 .WillOnce(testing::Return(true));
205 238
206 GetSearchTabHelper(web_contents())->ipc_router().SendThemeBackgroundInfo( 239 GetSearchTabHelper(web_contents())->ipc_router().SendThemeBackgroundInfo(
207 ThemeBackgroundInfo()); 240 ThemeBackgroundInfo());
208 ASSERT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxThemeChanged::ID)); 241 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxThemeChanged::ID));
209 } 242 }
210 243
211 TEST_F(SearchIPCRouterTest, DoNotSendThemeBackgroundInfoMsg) { 244 TEST_F(SearchIPCRouterTest, DoNotSendThemeBackgroundInfoMsg) {
212 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 245 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
213 process()->sink().ClearMessages(); 246 process()->sink().ClearMessages();
214 247
215 SetupMockDelegateAndPolicy(web_contents()); 248 SetupMockDelegateAndPolicy(web_contents());
216 MockSearchIPCRouterPolicy* policy = 249 MockSearchIPCRouterPolicy* policy =
217 GetSearchIPCRouterPolicy(web_contents()); 250 GetSearchIPCRouterPolicy(web_contents());
218 EXPECT_CALL(*policy, ShouldSendThemeBackgroundInfo()).Times(1) 251 EXPECT_CALL(*policy, ShouldSendThemeBackgroundInfo()).Times(1)
219 .WillOnce(testing::Return(false)); 252 .WillOnce(testing::Return(false));
220 253
221 GetSearchTabHelper(web_contents())->ipc_router().SendThemeBackgroundInfo( 254 GetSearchTabHelper(web_contents())->ipc_router().SendThemeBackgroundInfo(
222 ThemeBackgroundInfo()); 255 ThemeBackgroundInfo());
223 ASSERT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxThemeChanged::ID)); 256 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxThemeChanged::ID));
224 } 257 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698