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

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

Issue 292123015: Remove WebContents::IsActiveEntry from Instant Extended and from WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: done? Created 6 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
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 content::WebContents* web_contents) { 131 content::WebContents* web_contents) {
132 EXPECT_NE(static_cast<content::WebContents*>(NULL), web_contents); 132 EXPECT_NE(static_cast<content::WebContents*>(NULL), web_contents);
133 return SearchTabHelper::FromWebContents(web_contents); 133 return SearchTabHelper::FromWebContents(web_contents);
134 } 134 }
135 135
136 void SetupMockDelegateAndPolicy() { 136 void SetupMockDelegateAndPolicy() {
137 content::WebContents* contents = web_contents(); 137 content::WebContents* contents = web_contents();
138 ASSERT_NE(static_cast<content::WebContents*>(NULL), contents); 138 ASSERT_NE(static_cast<content::WebContents*>(NULL), contents);
139 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); 139 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents);
140 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); 140 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
141 search_tab_helper->ipc_router().set_delegate(mock_delegate()); 141 search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate());
142 search_tab_helper->ipc_router().set_policy( 142 search_tab_helper->ipc_router().set_policy_for_testing(
143 make_scoped_ptr(new MockSearchIPCRouterPolicy) 143 make_scoped_ptr(new MockSearchIPCRouterPolicy)
144 .PassAs<SearchIPCRouter::Policy>()); 144 .PassAs<SearchIPCRouter::Policy>());
145 } 145 }
146 146
147 bool MessageWasSent(uint32 id) { 147 bool MessageWasSent(uint32 id) {
148 return process()->sink().GetFirstMessageMatching(id) != NULL; 148 return process()->sink().GetFirstMessageMatching(id) != NULL;
149 } 149 }
150 150
151 void VerifyDisplayInstantResultsMsg(bool expected_param_value) { 151 void VerifyDisplayInstantResultsMsg(bool expected_param_value) {
152 SetupMockDelegateAndPolicy(); 152 SetupMockDelegateAndPolicy();
(...skipping 12 matching lines...) Expand all
165 } 165 }
166 166
167 MockSearchIPCRouterDelegate* mock_delegate() { return &delegate_; } 167 MockSearchIPCRouterDelegate* mock_delegate() { return &delegate_; }
168 168
169 MockSearchIPCRouterPolicy* GetSearchIPCRouterPolicy() { 169 MockSearchIPCRouterPolicy* GetSearchIPCRouterPolicy() {
170 content::WebContents* contents = web_contents(); 170 content::WebContents* contents = web_contents();
171 EXPECT_NE(static_cast<content::WebContents*>(NULL), contents); 171 EXPECT_NE(static_cast<content::WebContents*>(NULL), contents);
172 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); 172 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents);
173 EXPECT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); 173 EXPECT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
174 return static_cast<MockSearchIPCRouterPolicy*>( 174 return static_cast<MockSearchIPCRouterPolicy*>(
175 search_tab_helper->ipc_router().policy()); 175 search_tab_helper->ipc_router().policy_for_testing());
176 } 176 }
177 177
178 SearchIPCRouter& GetSearchIPCRouter() { 178 SearchIPCRouter& GetSearchIPCRouter() {
179 return GetSearchTabHelper(web_contents())->ipc_router(); 179 return GetSearchTabHelper(web_contents())->ipc_router();
180 } 180 }
181 181
182 int GetSearchIPCRouterSeqNo() {
183 return GetSearchIPCRouter().page_seq_no_for_testing();
184 }
185
182 void OnMessageReceived(const IPC::Message& message) { 186 void OnMessageReceived(const IPC::Message& message) {
183 GetSearchIPCRouter().OnMessageReceived(message); 187 GetSearchIPCRouter().OnMessageReceived(message);
184 } 188 }
185 189
186 bool IsActiveTab(content::WebContents* contents) { 190 bool IsActiveTab(content::WebContents* contents) {
187 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_; 191 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_;
188 } 192 }
189 193
190 private: 194 private:
191 MockSearchIPCRouterDelegate delegate_; 195 MockSearchIPCRouterDelegate delegate_;
192 base::FieldTrialList field_trial_list_; 196 base::FieldTrialList field_trial_list_;
193 }; 197 };
194 198
195 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) { 199 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) {
196 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 200 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
197 SetupMockDelegateAndPolicy(); 201 SetupMockDelegateAndPolicy();
198 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 202 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
199 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1); 203 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1);
200 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1) 204 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1)
201 .WillOnce(testing::Return(true)); 205 .WillOnce(testing::Return(true));
202 206
203 content::WebContents* contents = web_contents(); 207 content::WebContents* contents = web_contents();
204 scoped_ptr<IPC::Message> message( 208 scoped_ptr<IPC::Message> message(
205 new ChromeViewHostMsg_SetVoiceSearchSupported( 209 new ChromeViewHostMsg_SetVoiceSearchSupported(
206 contents->GetRoutingID(), 210 contents->GetRoutingID(),
207 contents->GetController().GetVisibleEntry()->GetPageID(), 211 GetSearchIPCRouterSeqNo(),
kmadhusu 2014/05/30 18:05:39 style nit: Please move this argument to the previo
Avi (use Gerrit) 2014/05/30 18:10:23 Done.
208 true)); 212 true));
209 OnMessageReceived(*message); 213 OnMessageReceived(*message);
210 } 214 }
211 215
212 TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) { 216 TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) {
213 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 217 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
214 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(0); 218 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(0);
215 SetupMockDelegateAndPolicy(); 219 SetupMockDelegateAndPolicy();
216 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 220 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
217 EXPECT_CALL(*policy, ShouldProcessSetVoiceSearchSupport()).Times(1) 221 EXPECT_CALL(*policy, ShouldProcessSetVoiceSearchSupport()).Times(1)
218 .WillOnce(testing::Return(false)); 222 .WillOnce(testing::Return(false));
219 223
220 content::WebContents* contents = web_contents(); 224 content::WebContents* contents = web_contents();
221 scoped_ptr<IPC::Message> message( 225 scoped_ptr<IPC::Message> message(
222 new ChromeViewHostMsg_SetVoiceSearchSupported( 226 new ChromeViewHostMsg_SetVoiceSearchSupported(
223 contents->GetRoutingID(), 227 contents->GetRoutingID(),
224 contents->GetController().GetVisibleEntry()->GetPageID(), 228 GetSearchIPCRouterSeqNo(),
225 true)); 229 true));
226 OnMessageReceived(*message); 230 OnMessageReceived(*message);
227 } 231 }
228 232
229 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { 233 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) {
230 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 234 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
231 SetupMockDelegateAndPolicy(); 235 SetupMockDelegateAndPolicy();
232 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 236 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
233 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); 237 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1);
234 238
235 content::WebContents* contents = web_contents(); 239 content::WebContents* contents = web_contents();
236 bool is_active_tab = IsActiveTab(contents); 240 bool is_active_tab = IsActiveTab(contents);
237 EXPECT_TRUE(is_active_tab); 241 EXPECT_TRUE(is_active_tab);
238 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 242 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
239 .WillOnce(testing::Return(true)); 243 .WillOnce(testing::Return(true));
240 244
241 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox( 245 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox(
242 contents->GetRoutingID(), 246 contents->GetRoutingID(),
243 contents->GetController().GetVisibleEntry()->GetPageID(), 247 GetSearchIPCRouterSeqNo(),
244 OMNIBOX_FOCUS_VISIBLE)); 248 OMNIBOX_FOCUS_VISIBLE));
245 OnMessageReceived(*message); 249 OnMessageReceived(*message);
246 } 250 }
247 251
248 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) { 252 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) {
249 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 253 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
250 SetupMockDelegateAndPolicy(); 254 SetupMockDelegateAndPolicy();
251 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 255 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
252 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 256 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
253 257
254 content::WebContents* contents = web_contents(); 258 content::WebContents* contents = web_contents();
255 bool is_active_tab = IsActiveTab(contents); 259 bool is_active_tab = IsActiveTab(contents);
256 EXPECT_TRUE(is_active_tab); 260 EXPECT_TRUE(is_active_tab);
257 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 261 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
258 .WillOnce(testing::Return(false)); 262 .WillOnce(testing::Return(false));
259 263
260 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox( 264 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox(
261 contents->GetRoutingID(), 265 contents->GetRoutingID(),
262 contents->GetController().GetVisibleEntry()->GetPageID(), 266 GetSearchIPCRouterSeqNo(),
263 OMNIBOX_FOCUS_VISIBLE)); 267 OMNIBOX_FOCUS_VISIBLE));
264 OnMessageReceived(*message); 268 OnMessageReceived(*message);
265 } 269 }
266 270
267 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) { 271 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) {
268 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 272 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
269 content::WebContents* contents = web_contents(); 273 content::WebContents* contents = web_contents();
270 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents)); 274 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents));
271 EXPECT_TRUE(IsActiveTab(contents)); 275 EXPECT_TRUE(IsActiveTab(contents));
272 276
(...skipping 20 matching lines...) Expand all
293 content::WebContents* contents = web_contents(); 297 content::WebContents* contents = web_contents();
294 bool is_active_tab = IsActiveTab(contents); 298 bool is_active_tab = IsActiveTab(contents);
295 EXPECT_TRUE(is_active_tab); 299 EXPECT_TRUE(is_active_tab);
296 300
297 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 301 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
298 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) 302 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
299 .WillOnce(testing::Return(true)); 303 .WillOnce(testing::Return(true));
300 304
301 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 305 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate(
302 contents->GetRoutingID(), 306 contents->GetRoutingID(),
303 contents->GetController().GetVisibleEntry()->GetPageID(), 307 GetSearchIPCRouterSeqNo(),
304 destination_url, CURRENT_TAB, true)); 308 destination_url, CURRENT_TAB, true));
305 OnMessageReceived(*message); 309 OnMessageReceived(*message);
306 } 310 }
307 311
308 TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) { 312 TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) {
309 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 313 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
310 SetupMockDelegateAndPolicy(); 314 SetupMockDelegateAndPolicy();
311 GURL destination_url("www.foo.com"); 315 GURL destination_url("www.foo.com");
312 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, 316 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
313 true)).Times(0); 317 true)).Times(0);
314 content::WebContents* contents = web_contents(); 318 content::WebContents* contents = web_contents();
315 bool is_active_tab = IsActiveTab(contents); 319 bool is_active_tab = IsActiveTab(contents);
316 EXPECT_TRUE(is_active_tab); 320 EXPECT_TRUE(is_active_tab);
317 321
318 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 322 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
319 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) 323 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
320 .WillOnce(testing::Return(false)); 324 .WillOnce(testing::Return(false));
321 325
322 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 326 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate(
323 contents->GetRoutingID(), 327 contents->GetRoutingID(),
324 contents->GetController().GetVisibleEntry()->GetPageID(), 328 GetSearchIPCRouterSeqNo(),
325 destination_url, CURRENT_TAB, true)); 329 destination_url, CURRENT_TAB, true));
326 OnMessageReceived(*message); 330 OnMessageReceived(*message);
327 } 331 }
328 332
329 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) { 333 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) {
330 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 334 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
331 SetupMockDelegateAndPolicy(); 335 SetupMockDelegateAndPolicy();
332 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 336 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
333 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(1); 337 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(1);
334 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 338 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
335 .WillOnce(testing::Return(true)); 339 .WillOnce(testing::Return(true));
336 340
337 content::WebContents* contents = web_contents(); 341 content::WebContents* contents = web_contents();
338 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent( 342 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent(
339 contents->GetRoutingID(), 343 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
340 contents->GetController().GetVisibleEntry()->GetPageID(),
341 NTP_MOUSEOVER)); 344 NTP_MOUSEOVER));
342 OnMessageReceived(*message); 345 OnMessageReceived(*message);
343 } 346 }
344 347
345 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) { 348 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) {
346 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 349 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
347 SetupMockDelegateAndPolicy(); 350 SetupMockDelegateAndPolicy();
348 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 351 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
349 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); 352 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0);
350 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 353 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
351 .WillOnce(testing::Return(false)); 354 .WillOnce(testing::Return(false));
352 355
353 content::WebContents* contents = web_contents(); 356 content::WebContents* contents = web_contents();
354 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent( 357 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent(
355 contents->GetRoutingID(), 358 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
356 contents->GetController().GetVisibleEntry()->GetPageID(),
357 NTP_MOUSEOVER)); 359 NTP_MOUSEOVER));
358 OnMessageReceived(*message); 360 OnMessageReceived(*message);
359 } 361 }
360 362
361 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) { 363 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) {
362 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 364 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
363 SetupMockDelegateAndPolicy(); 365 SetupMockDelegateAndPolicy();
364 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 366 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
365 EXPECT_CALL(*mock_delegate(), 367 EXPECT_CALL(*mock_delegate(),
366 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1); 368 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1);
367 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 369 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
368 .WillOnce(testing::Return(true)); 370 .WillOnce(testing::Return(true));
369 371
370 content::WebContents* contents = web_contents(); 372 content::WebContents* contents = web_contents();
371 scoped_ptr<IPC::Message> message( 373 scoped_ptr<IPC::Message> message(
372 new ChromeViewHostMsg_LogMostVisitedImpression( 374 new ChromeViewHostMsg_LogMostVisitedImpression(
373 contents->GetRoutingID(), 375 contents->GetRoutingID(),
374 contents->GetController().GetVisibleEntry()->GetPageID(), 376 GetSearchIPCRouterSeqNo(),
375 3, 377 3,
376 base::ASCIIToUTF16("Server"))); 378 base::ASCIIToUTF16("Server")));
377 OnMessageReceived(*message); 379 OnMessageReceived(*message);
378 } 380 }
379 381
380 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) { 382 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) {
381 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 383 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
382 SetupMockDelegateAndPolicy(); 384 SetupMockDelegateAndPolicy();
383 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 385 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
384 EXPECT_CALL(*mock_delegate(), 386 EXPECT_CALL(*mock_delegate(),
385 OnLogMostVisitedNavigation(3, base::ASCIIToUTF16("Server"))).Times(1); 387 OnLogMostVisitedNavigation(3, base::ASCIIToUTF16("Server"))).Times(1);
386 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 388 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
387 .WillOnce(testing::Return(true)); 389 .WillOnce(testing::Return(true));
388 390
389 content::WebContents* contents = web_contents(); 391 content::WebContents* contents = web_contents();
390 scoped_ptr<IPC::Message> message( 392 scoped_ptr<IPC::Message> message(
391 new ChromeViewHostMsg_LogMostVisitedNavigation( 393 new ChromeViewHostMsg_LogMostVisitedNavigation(
392 contents->GetRoutingID(), 394 contents->GetRoutingID(),
393 contents->GetController().GetVisibleEntry()->GetPageID(), 395 GetSearchIPCRouterSeqNo(),
394 3, 396 3,
395 base::ASCIIToUTF16("Server"))); 397 base::ASCIIToUTF16("Server")));
396 OnMessageReceived(*message); 398 OnMessageReceived(*message);
397 } 399 }
398 400
399 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) { 401 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) {
400 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 402 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
401 SetupMockDelegateAndPolicy(); 403 SetupMockDelegateAndPolicy();
402 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 404 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
403 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); 405 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
404 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1); 406 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1);
405 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) 407 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
406 .WillOnce(testing::Return(true)); 408 .WillOnce(testing::Return(true));
407 409
408 content::WebContents* contents = web_contents(); 410 content::WebContents* contents = web_contents();
409 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( 411 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck(
410 contents->GetRoutingID(), 412 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity));
411 contents->GetController().GetVisibleEntry()->GetPageID(),
412 test_identity));
413 OnMessageReceived(*message); 413 OnMessageReceived(*message);
414 } 414 }
415 415
416 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) { 416 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) {
417 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 417 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
418 SetupMockDelegateAndPolicy(); 418 SetupMockDelegateAndPolicy();
419 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 419 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
420 420
421 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); 421 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
422 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0); 422 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0);
423 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) 423 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
424 .WillOnce(testing::Return(false)); 424 .WillOnce(testing::Return(false));
425 425
426 content::WebContents* contents = web_contents(); 426 content::WebContents* contents = web_contents();
427 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( 427 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck(
428 contents->GetRoutingID(), 428 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity));
429 contents->GetController().GetVisibleEntry()->GetPageID(),
430 test_identity));
431 OnMessageReceived(*message); 429 OnMessageReceived(*message);
432 } 430 }
433 431
434 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) { 432 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) {
435 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 433 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
436 SetupMockDelegateAndPolicy(); 434 SetupMockDelegateAndPolicy();
437 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 435 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
438 GURL item_url("www.foo.com"); 436 GURL item_url("www.foo.com");
439 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1); 437 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1);
440 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) 438 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
441 .WillOnce(testing::Return(true)); 439 .WillOnce(testing::Return(true));
442 440
443 content::WebContents* contents = web_contents(); 441 content::WebContents* contents = web_contents();
444 scoped_ptr<IPC::Message> message( 442 scoped_ptr<IPC::Message> message(
445 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 443 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
446 contents->GetRoutingID(), 444 contents->GetRoutingID(),
447 contents->GetController().GetVisibleEntry()->GetPageID(), 445 GetSearchIPCRouterSeqNo(),
448 item_url)); 446 item_url));
449 OnMessageReceived(*message); 447 OnMessageReceived(*message);
450 } 448 }
451 449
452 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) { 450 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) {
453 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 451 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
454 SetupMockDelegateAndPolicy(); 452 SetupMockDelegateAndPolicy();
455 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 453 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
456 GURL item_url("www.foo.com"); 454 GURL item_url("www.foo.com");
457 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); 455 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
458 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) 456 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
459 .WillOnce(testing::Return(false)); 457 .WillOnce(testing::Return(false));
460 458
461 content::WebContents* contents = web_contents(); 459 content::WebContents* contents = web_contents();
462 scoped_ptr<IPC::Message> message( 460 scoped_ptr<IPC::Message> message(
463 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 461 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
464 contents->GetRoutingID(), 462 contents->GetRoutingID(),
465 contents->GetController().GetVisibleEntry()->GetPageID(), 463 GetSearchIPCRouterSeqNo(),
466 item_url)); 464 item_url));
467 OnMessageReceived(*message); 465 OnMessageReceived(*message);
468 } 466 }
469 467
470 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) { 468 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) {
471 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 469 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
472 SetupMockDelegateAndPolicy(); 470 SetupMockDelegateAndPolicy();
473 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 471 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
474 GURL item_url("www.foo.com"); 472 GURL item_url("www.foo.com");
475 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1); 473 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1);
476 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1) 474 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
477 .WillOnce(testing::Return(true)); 475 .WillOnce(testing::Return(true));
478 476
479 content::WebContents* contents = web_contents(); 477 content::WebContents* contents = web_contents();
480 scoped_ptr<IPC::Message> message( 478 scoped_ptr<IPC::Message> message(
481 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 479 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
482 contents->GetRoutingID(), 480 contents->GetRoutingID(),
483 contents->GetController().GetVisibleEntry()->GetPageID(), 481 GetSearchIPCRouterSeqNo(),
484 item_url)); 482 item_url));
485 OnMessageReceived(*message); 483 OnMessageReceived(*message);
486 } 484 }
487 485
488 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) { 486 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) {
489 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 487 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
490 SetupMockDelegateAndPolicy(); 488 SetupMockDelegateAndPolicy();
491 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 489 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
492 GURL item_url("www.foo.com"); 490 GURL item_url("www.foo.com");
493 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); 491 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
494 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1) 492 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
495 .WillOnce(testing::Return(false)); 493 .WillOnce(testing::Return(false));
496 494
497 content::WebContents* contents = web_contents(); 495 content::WebContents* contents = web_contents();
498 scoped_ptr<IPC::Message> message( 496 scoped_ptr<IPC::Message> message(
499 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 497 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
500 contents->GetRoutingID(), 498 contents->GetRoutingID(),
501 contents->GetController().GetVisibleEntry()->GetPageID(), 499 GetSearchIPCRouterSeqNo(),
502 item_url)); 500 item_url));
503 OnMessageReceived(*message); 501 OnMessageReceived(*message);
504 } 502 }
505 503
506 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) { 504 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) {
507 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 505 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
508 SetupMockDelegateAndPolicy(); 506 SetupMockDelegateAndPolicy();
509 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 507 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
510 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1); 508 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1);
511 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) 509 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
512 .WillOnce(testing::Return(true)); 510 .WillOnce(testing::Return(true));
513 511
514 content::WebContents* contents = web_contents(); 512 content::WebContents* contents = web_contents();
515 scoped_ptr<IPC::Message> message( 513 scoped_ptr<IPC::Message> message(
516 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 514 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
517 contents->GetRoutingID(), 515 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
518 contents->GetController().GetVisibleEntry()->GetPageID()));
519 OnMessageReceived(*message); 516 OnMessageReceived(*message);
520 } 517 }
521 518
522 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) { 519 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) {
523 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 520 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
524 SetupMockDelegateAndPolicy(); 521 SetupMockDelegateAndPolicy();
525 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 522 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
526 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); 523 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
527 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) 524 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
528 .WillOnce(testing::Return(false)); 525 .WillOnce(testing::Return(false));
529 526
530 content::WebContents* contents = web_contents(); 527 content::WebContents* contents = web_contents();
531 scoped_ptr<IPC::Message> message( 528 scoped_ptr<IPC::Message> message(
532 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 529 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
533 contents->GetRoutingID(), 530 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
534 contents->GetController().GetVisibleEntry()->GetPageID()));
535 OnMessageReceived(*message); 531 OnMessageReceived(*message);
536 } 532 }
537 533
538 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) { 534 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) {
539 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 535 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
540 SetupMockDelegateAndPolicy(); 536 SetupMockDelegateAndPolicy();
541 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 537 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
538 int page_seq_no = GetSearchIPCRouterSeqNo();
542 539
543 content::WebContents* contents = web_contents(); 540 content::WebContents* contents = web_contents();
544 bool is_active_tab = IsActiveTab(contents); 541 bool is_active_tab = IsActiveTab(contents);
545 int invalid_page_id = 1000;
546 GURL item_url("www.foo.com"); 542 GURL item_url("www.foo.com");
547 EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB, 543 EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB,
548 true)).Times(0); 544 true)).Times(0);
545 // At this point, in a real test, the navigation would cause the
546 // SearchIPCRouter's page sequence to advance. In this test it doesn't, so
547 // we'll decrement the sequence number on this side to simulate it.
548 --page_seq_no;
549 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); 549 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
550 550
551 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 551 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate(
552 contents->GetRoutingID(), invalid_page_id, item_url, CURRENT_TAB, 552 contents->GetRoutingID(), page_seq_no, item_url,
553 true)); 553 CURRENT_TAB, true));
554 OnMessageReceived(*message); 554 OnMessageReceived(*message);
555 555
556 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); 556 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
557 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0); 557 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0);
558 message.reset(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 558 message.reset(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
559 contents->GetRoutingID(), invalid_page_id, item_url)); 559 contents->GetRoutingID(), page_seq_no, item_url));
560 OnMessageReceived(*message); 560 OnMessageReceived(*message);
561 561
562 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); 562 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
563 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0); 563 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0);
564 message.reset(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 564 message.reset(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
565 contents->GetRoutingID(), invalid_page_id, item_url)); 565 contents->GetRoutingID(), page_seq_no, item_url));
566 OnMessageReceived(*message); 566 OnMessageReceived(*message);
567 567
568 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); 568 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
569 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0); 569 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0);
570 message.reset(new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 570 message.reset(new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
571 contents->GetRoutingID(), invalid_page_id)); 571 contents->GetRoutingID(), page_seq_no));
572 OnMessageReceived(*message); 572 OnMessageReceived(*message);
573 573
574 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 574 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
575 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); 575 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0);
576 message.reset(new ChromeViewHostMsg_FocusOmnibox( 576 message.reset(new ChromeViewHostMsg_FocusOmnibox(
577 contents->GetRoutingID(), invalid_page_id, OMNIBOX_FOCUS_VISIBLE)); 577 contents->GetRoutingID(), page_seq_no,
578 OMNIBOX_FOCUS_VISIBLE));
578 OnMessageReceived(*message); 579 OnMessageReceived(*message);
579 580
580 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); 581 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0);
581 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0); 582 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0);
582 message.reset(new ChromeViewHostMsg_LogEvent(contents->GetRoutingID(), 583 message.reset(new ChromeViewHostMsg_LogEvent(contents->GetRoutingID(),
583 invalid_page_id, NTP_MOUSEOVER)); 584 page_seq_no,
585 NTP_MOUSEOVER));
584 OnMessageReceived(*message); 586 OnMessageReceived(*message);
585 587
586 base::string16 text; 588 base::string16 text;
587 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); 589 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
588 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0); 590 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0);
589 message.reset(new ChromeViewHostMsg_PasteAndOpenDropdown( 591 message.reset(new ChromeViewHostMsg_PasteAndOpenDropdown(
590 contents->GetRoutingID(), invalid_page_id, text)); 592 contents->GetRoutingID(), page_seq_no, text));
591 OnMessageReceived(*message); 593 OnMessageReceived(*message);
592 } 594 }
593 595
594 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { 596 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) {
595 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 597 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
596 SetupMockDelegateAndPolicy(); 598 SetupMockDelegateAndPolicy();
597 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 599 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
598 600
599 content::WebContents* contents = web_contents(); 601 content::WebContents* contents = web_contents();
600 bool is_active_tab = IsActiveTab(contents); 602 bool is_active_tab = IsActiveTab(contents);
601 EXPECT_TRUE(is_active_tab); 603 EXPECT_TRUE(is_active_tab);
602 604
603 base::string16 text; 605 base::string16 text;
604 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1); 606 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1);
605 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 607 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
606 .WillOnce(testing::Return(true)); 608 .WillOnce(testing::Return(true));
607 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown( 609 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown(
608 contents->GetRoutingID(), 610 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
609 contents->GetController().GetVisibleEntry()->GetPageID(), text));
610 OnMessageReceived(*message); 611 OnMessageReceived(*message);
611 } 612 }
612 613
613 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) { 614 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) {
614 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 615 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
615 SetupMockDelegateAndPolicy(); 616 SetupMockDelegateAndPolicy();
616 base::string16 text; 617 base::string16 text;
617 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); 618 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
618 619
619 content::WebContents* contents = web_contents(); 620 content::WebContents* contents = web_contents();
620 bool is_active_tab = IsActiveTab(contents); 621 bool is_active_tab = IsActiveTab(contents);
621 EXPECT_TRUE(is_active_tab); 622 EXPECT_TRUE(is_active_tab);
622 623
623 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 624 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
624 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 625 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
625 .WillOnce(testing::Return(false)); 626 .WillOnce(testing::Return(false));
626 627
627 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown( 628 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown(
628 contents->GetRoutingID(), 629 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
629 contents->GetController().GetVisibleEntry()->GetPageID(), text));
630 OnMessageReceived(*message); 630 OnMessageReceived(*message);
631 } 631 }
632 632
633 TEST_F(SearchIPCRouterTest, SendSetPromoInformationMsg) { 633 TEST_F(SearchIPCRouterTest, SendSetPromoInformationMsg) {
634 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 634 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
635 SetupMockDelegateAndPolicy(); 635 SetupMockDelegateAndPolicy();
636 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 636 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
637 EXPECT_CALL(*policy, ShouldSendSetPromoInformation()).Times(1) 637 EXPECT_CALL(*policy, ShouldSendSetPromoInformation()).Times(1)
638 .WillOnce(testing::Return(true)); 638 .WillOnce(testing::Return(true));
639 639
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 920 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
921 SetupMockDelegateAndPolicy(); 921 SetupMockDelegateAndPolicy();
922 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 922 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
923 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1) 923 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
924 .WillOnce(testing::Return(false)); 924 .WillOnce(testing::Return(false));
925 925
926 process()->sink().ClearMessages(); 926 process()->sink().ClearMessages();
927 GetSearchIPCRouter().ToggleVoiceSearch(); 927 GetSearchIPCRouter().ToggleVoiceSearch();
928 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID)); 928 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
929 } 929 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | chrome/browser/ui/search/search_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698