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

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

Issue 2515823002: Remove WebContents::GetRoutingID(). (Closed)
Patch Set: add render_view_host.h include in resource_dispatcher_host_unittest.cc Created 4 years 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_ipc_router.h" 5 #include "chrome/browser/ui/search/search_ipc_router.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <tuple> 10 #include <tuple>
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 SetupMockDelegateAndPolicy(); 189 SetupMockDelegateAndPolicy();
190 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 190 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
191 content::WebContents* contents = web_contents(); 191 content::WebContents* contents = web_contents();
192 bool is_active_tab = IsActiveTab(contents); 192 bool is_active_tab = IsActiveTab(contents);
193 EXPECT_TRUE(is_active_tab); 193 EXPECT_TRUE(is_active_tab);
194 194
195 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 195 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
196 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); 196 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0);
197 197
198 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox( 198 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
199 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 199 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
200 OMNIBOX_FOCUS_VISIBLE)); 200 OMNIBOX_FOCUS_VISIBLE));
201 } 201 }
202 202
203 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { 203 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) {
204 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 204 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
205 SetupMockDelegateAndPolicy(); 205 SetupMockDelegateAndPolicy();
206 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 206 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
207 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); 207 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1);
208 208
209 content::WebContents* contents = web_contents(); 209 content::WebContents* contents = web_contents();
210 bool is_active_tab = IsActiveTab(contents); 210 bool is_active_tab = IsActiveTab(contents);
211 EXPECT_TRUE(is_active_tab); 211 EXPECT_TRUE(is_active_tab);
212 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 212 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
213 .WillOnce(testing::Return(true)); 213 .WillOnce(testing::Return(true));
214 214
215 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox( 215 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
216 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 216 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
217 OMNIBOX_FOCUS_VISIBLE)); 217 OMNIBOX_FOCUS_VISIBLE));
218 } 218 }
219 219
220 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) { 220 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) {
221 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 221 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
222 SetupMockDelegateAndPolicy(); 222 SetupMockDelegateAndPolicy();
223 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 223 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
224 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 224 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
225 225
226 content::WebContents* contents = web_contents(); 226 content::WebContents* contents = web_contents();
227 bool is_active_tab = IsActiveTab(contents); 227 bool is_active_tab = IsActiveTab(contents);
228 EXPECT_TRUE(is_active_tab); 228 EXPECT_TRUE(is_active_tab);
229 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 229 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
230 .WillOnce(testing::Return(false)); 230 .WillOnce(testing::Return(false));
231 231
232 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox( 232 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
233 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 233 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
234 OMNIBOX_FOCUS_VISIBLE)); 234 OMNIBOX_FOCUS_VISIBLE));
235 } 235 }
236 236
237 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) { 237 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) {
238 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 238 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
239 content::WebContents* contents = web_contents(); 239 content::WebContents* contents = web_contents();
240 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents)); 240 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents));
241 EXPECT_TRUE(IsActiveTab(contents)); 241 EXPECT_TRUE(IsActiveTab(contents));
242 242
243 // Add a new tab to deactivate the current tab. 243 // Add a new tab to deactivate the current tab.
(...skipping 15 matching lines...) Expand all
259 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 259 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
260 SetupMockDelegateAndPolicy(); 260 SetupMockDelegateAndPolicy();
261 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 261 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
262 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta)) 262 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta))
263 .Times(1); 263 .Times(1);
264 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 264 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
265 .WillOnce(testing::Return(true)); 265 .WillOnce(testing::Return(true));
266 266
267 content::WebContents* contents = web_contents(); 267 content::WebContents* contents = web_contents();
268 OnMessageReceived(ChromeViewHostMsg_LogEvent( 268 OnMessageReceived(ChromeViewHostMsg_LogEvent(
269 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 269 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
270 NTP_ALL_TILES_LOADED, delta)); 270 NTP_ALL_TILES_LOADED, delta));
271 } 271 }
272 272
273 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) { 273 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) {
274 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123); 274 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123);
275 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 275 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
276 SetupMockDelegateAndPolicy(); 276 SetupMockDelegateAndPolicy();
277 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 277 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
278 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta)) 278 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta))
279 .Times(0); 279 .Times(0);
280 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 280 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
281 .WillOnce(testing::Return(false)); 281 .WillOnce(testing::Return(false));
282 282
283 content::WebContents* contents = web_contents(); 283 content::WebContents* contents = web_contents();
284 OnMessageReceived(ChromeViewHostMsg_LogEvent( 284 OnMessageReceived(ChromeViewHostMsg_LogEvent(
285 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 285 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
286 NTP_ALL_TILES_LOADED, delta)); 286 NTP_ALL_TILES_LOADED, delta));
287 } 287 }
288 288
289 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) { 289 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) {
290 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 290 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
291 SetupMockDelegateAndPolicy(); 291 SetupMockDelegateAndPolicy();
292 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 292 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
293 EXPECT_CALL(*mock_delegate(), 293 EXPECT_CALL(*mock_delegate(),
294 OnLogMostVisitedImpression(3, NTPLoggingTileSource::SERVER)).Times(1); 294 OnLogMostVisitedImpression(3, NTPLoggingTileSource::SERVER)).Times(1);
295 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 295 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
296 .WillOnce(testing::Return(true)); 296 .WillOnce(testing::Return(true));
297 297
298 content::WebContents* contents = web_contents(); 298 content::WebContents* contents = web_contents();
299 OnMessageReceived(ChromeViewHostMsg_LogMostVisitedImpression( 299 OnMessageReceived(ChromeViewHostMsg_LogMostVisitedImpression(
300 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 3, 300 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
301 NTPLoggingTileSource::SERVER)); 301 3, NTPLoggingTileSource::SERVER));
302 } 302 }
303 303
304 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) { 304 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) {
305 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 305 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
306 SetupMockDelegateAndPolicy(); 306 SetupMockDelegateAndPolicy();
307 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 307 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
308 EXPECT_CALL(*mock_delegate(), 308 EXPECT_CALL(*mock_delegate(),
309 OnLogMostVisitedNavigation(3, NTPLoggingTileSource::SERVER)).Times(1); 309 OnLogMostVisitedNavigation(3, NTPLoggingTileSource::SERVER)).Times(1);
310 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 310 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
311 .WillOnce(testing::Return(true)); 311 .WillOnce(testing::Return(true));
312 312
313 content::WebContents* contents = web_contents(); 313 content::WebContents* contents = web_contents();
314 OnMessageReceived(ChromeViewHostMsg_LogMostVisitedNavigation( 314 OnMessageReceived(ChromeViewHostMsg_LogMostVisitedNavigation(
315 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 3, 315 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
316 NTPLoggingTileSource::SERVER)); 316 3, NTPLoggingTileSource::SERVER));
317 } 317 }
318 318
319 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) { 319 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) {
320 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 320 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
321 SetupMockDelegateAndPolicy(); 321 SetupMockDelegateAndPolicy();
322 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 322 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
323 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); 323 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
324 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1); 324 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1);
325 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) 325 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
326 .WillOnce(testing::Return(true)); 326 .WillOnce(testing::Return(true));
327 327
328 content::WebContents* contents = web_contents(); 328 content::WebContents* contents = web_contents();
329 OnMessageReceived(ChromeViewHostMsg_ChromeIdentityCheck( 329 OnMessageReceived(ChromeViewHostMsg_ChromeIdentityCheck(
330 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity)); 330 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
331 test_identity));
331 } 332 }
332 333
333 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) { 334 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) {
334 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 335 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
335 SetupMockDelegateAndPolicy(); 336 SetupMockDelegateAndPolicy();
336 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 337 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
337 338
338 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); 339 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
339 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0); 340 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0);
340 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) 341 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
341 .WillOnce(testing::Return(false)); 342 .WillOnce(testing::Return(false));
342 343
343 content::WebContents* contents = web_contents(); 344 content::WebContents* contents = web_contents();
344 OnMessageReceived(ChromeViewHostMsg_ChromeIdentityCheck( 345 OnMessageReceived(ChromeViewHostMsg_ChromeIdentityCheck(
345 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity)); 346 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
347 test_identity));
346 } 348 }
347 349
348 TEST_F(SearchIPCRouterTest, ProcessHistorySyncCheckMsg) { 350 TEST_F(SearchIPCRouterTest, ProcessHistorySyncCheckMsg) {
349 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 351 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
350 SetupMockDelegateAndPolicy(); 352 SetupMockDelegateAndPolicy();
351 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 353 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
352 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(1); 354 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(1);
353 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1) 355 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1)
354 .WillOnce(testing::Return(true)); 356 .WillOnce(testing::Return(true));
355 357
356 content::WebContents* contents = web_contents(); 358 content::WebContents* contents = web_contents();
357 OnMessageReceived(ChromeViewHostMsg_HistorySyncCheck( 359 OnMessageReceived(ChromeViewHostMsg_HistorySyncCheck(
358 contents->GetRoutingID(), GetSearchIPCRouterSeqNo())); 360 contents->GetRenderViewHost()->GetRoutingID(),
361 GetSearchIPCRouterSeqNo()));
359 } 362 }
360 363
361 TEST_F(SearchIPCRouterTest, IgnoreHistorySyncCheckMsg) { 364 TEST_F(SearchIPCRouterTest, IgnoreHistorySyncCheckMsg) {
362 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 365 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
363 SetupMockDelegateAndPolicy(); 366 SetupMockDelegateAndPolicy();
364 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 367 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
365 368
366 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(0); 369 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(0);
367 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1) 370 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1)
368 .WillOnce(testing::Return(false)); 371 .WillOnce(testing::Return(false));
369 372
370 content::WebContents* contents = web_contents(); 373 content::WebContents* contents = web_contents();
371 OnMessageReceived(ChromeViewHostMsg_HistorySyncCheck( 374 OnMessageReceived(ChromeViewHostMsg_HistorySyncCheck(
372 contents->GetRoutingID(), GetSearchIPCRouterSeqNo())); 375 contents->GetRenderViewHost()->GetRoutingID(),
376 GetSearchIPCRouterSeqNo()));
373 } 377 }
374 378
375 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) { 379 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) {
376 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 380 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
377 SetupMockDelegateAndPolicy(); 381 SetupMockDelegateAndPolicy();
378 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 382 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
379 GURL item_url("www.foo.com"); 383 GURL item_url("www.foo.com");
380 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1); 384 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1);
381 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) 385 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
382 .WillOnce(testing::Return(true)); 386 .WillOnce(testing::Return(true));
383 387
384 content::WebContents* contents = web_contents(); 388 content::WebContents* contents = web_contents();
385 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 389 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
386 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url)); 390 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
391 item_url));
387 } 392 }
388 393
389 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) { 394 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) {
390 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 395 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
391 SetupMockDelegateAndPolicy(); 396 SetupMockDelegateAndPolicy();
392 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 397 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
393 GURL item_url("www.foo.com"); 398 GURL item_url("www.foo.com");
394 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); 399 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
395 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) 400 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
396 .WillOnce(testing::Return(false)); 401 .WillOnce(testing::Return(false));
397 402
398 content::WebContents* contents = web_contents(); 403 content::WebContents* contents = web_contents();
399 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 404 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
400 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url)); 405 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
406 item_url));
401 } 407 }
402 408
403 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) { 409 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) {
404 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 410 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
405 SetupMockDelegateAndPolicy(); 411 SetupMockDelegateAndPolicy();
406 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 412 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
407 GURL item_url("www.foo.com"); 413 GURL item_url("www.foo.com");
408 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1); 414 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1);
409 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1) 415 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
410 .WillOnce(testing::Return(true)); 416 .WillOnce(testing::Return(true));
411 417
412 content::WebContents* contents = web_contents(); 418 content::WebContents* contents = web_contents();
413 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 419 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
414 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url)); 420 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
421 item_url));
415 } 422 }
416 423
417 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) { 424 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) {
418 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 425 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
419 SetupMockDelegateAndPolicy(); 426 SetupMockDelegateAndPolicy();
420 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 427 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
421 GURL item_url("www.foo.com"); 428 GURL item_url("www.foo.com");
422 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); 429 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
423 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1) 430 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
424 .WillOnce(testing::Return(false)); 431 .WillOnce(testing::Return(false));
425 432
426 content::WebContents* contents = web_contents(); 433 content::WebContents* contents = web_contents();
427 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 434 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
428 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url)); 435 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
436 item_url));
429 } 437 }
430 438
431 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) { 439 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) {
432 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 440 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
433 SetupMockDelegateAndPolicy(); 441 SetupMockDelegateAndPolicy();
434 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 442 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
435 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1); 443 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1);
436 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) 444 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
437 .WillOnce(testing::Return(true)); 445 .WillOnce(testing::Return(true));
438 446
439 content::WebContents* contents = web_contents(); 447 content::WebContents* contents = web_contents();
440 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 448 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
441 contents->GetRoutingID(), GetSearchIPCRouterSeqNo())); 449 contents->GetRenderViewHost()->GetRoutingID(),
450 GetSearchIPCRouterSeqNo()));
442 } 451 }
443 452
444 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) { 453 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) {
445 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 454 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
446 SetupMockDelegateAndPolicy(); 455 SetupMockDelegateAndPolicy();
447 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 456 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
448 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); 457 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
449 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) 458 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
450 .WillOnce(testing::Return(false)); 459 .WillOnce(testing::Return(false));
451 460
452 content::WebContents* contents = web_contents(); 461 content::WebContents* contents = web_contents();
453 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 462 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
454 contents->GetRoutingID(), GetSearchIPCRouterSeqNo())); 463 contents->GetRenderViewHost()->GetRoutingID(),
464 GetSearchIPCRouterSeqNo()));
455 } 465 }
456 466
457 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) { 467 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) {
458 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 468 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
459 SetupMockDelegateAndPolicy(); 469 SetupMockDelegateAndPolicy();
460 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 470 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
461 int page_seq_no = GetSearchIPCRouterSeqNo(); 471 int page_seq_no = GetSearchIPCRouterSeqNo();
462 472
463 content::WebContents* contents = web_contents(); 473 content::WebContents* contents = web_contents();
464 bool is_active_tab = IsActiveTab(contents); 474 bool is_active_tab = IsActiveTab(contents);
465 GURL item_url("www.foo.com"); 475 GURL item_url("www.foo.com");
466 476
467 // Navigate away from the NTP. Afterwards, all messages should be ignored. 477 // Navigate away from the NTP. Afterwards, all messages should be ignored.
468 NavigateAndCommitActiveTab(item_url); 478 NavigateAndCommitActiveTab(item_url);
469 479
470 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); 480 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
471 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0); 481 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0);
472 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 482 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
473 contents->GetRoutingID(), page_seq_no, item_url)); 483 contents->GetRenderViewHost()->GetRoutingID(), page_seq_no, item_url));
474 484
475 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); 485 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
476 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0); 486 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0);
477 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 487 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
478 contents->GetRoutingID(), page_seq_no, item_url)); 488 contents->GetRenderViewHost()->GetRoutingID(), page_seq_no, item_url));
479 489
480 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); 490 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
481 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0); 491 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0);
482 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 492 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
483 contents->GetRoutingID(), page_seq_no)); 493 contents->GetRenderViewHost()->GetRoutingID(), page_seq_no));
484 494
485 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 495 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
486 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); 496 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0);
487 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox( 497 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
488 contents->GetRoutingID(), page_seq_no, OMNIBOX_FOCUS_VISIBLE)); 498 contents->GetRenderViewHost()->GetRoutingID(), page_seq_no,
499 OMNIBOX_FOCUS_VISIBLE));
489 500
490 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123); 501 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123);
491 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta)) 502 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta))
492 .Times(0); 503 .Times(0);
493 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0); 504 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0);
494 OnMessageReceived( 505 OnMessageReceived(
495 ChromeViewHostMsg_LogEvent(contents->GetRoutingID(), page_seq_no, 506 ChromeViewHostMsg_LogEvent(contents->GetRenderViewHost()->GetRoutingID(),
496 NTP_ALL_TILES_LOADED, delta)); 507 page_seq_no, NTP_ALL_TILES_LOADED, delta));
497 508
498 base::string16 text; 509 base::string16 text;
499 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); 510 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
500 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0); 511 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0);
501 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown( 512 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
502 contents->GetRoutingID(), page_seq_no, text)); 513 contents->GetRenderViewHost()->GetRoutingID(), page_seq_no, text));
503 } 514 }
504 515
505 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { 516 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) {
506 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 517 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
507 SetupMockDelegateAndPolicy(); 518 SetupMockDelegateAndPolicy();
508 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 519 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
509 520
510 content::WebContents* contents = web_contents(); 521 content::WebContents* contents = web_contents();
511 bool is_active_tab = IsActiveTab(contents); 522 bool is_active_tab = IsActiveTab(contents);
512 EXPECT_TRUE(is_active_tab); 523 EXPECT_TRUE(is_active_tab);
513 524
514 base::string16 text; 525 base::string16 text;
515 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1); 526 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1);
516 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 527 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
517 .WillOnce(testing::Return(true)); 528 .WillOnce(testing::Return(true));
518 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown( 529 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
519 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text)); 530 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
531 text));
520 } 532 }
521 533
522 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) { 534 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) {
523 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 535 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
524 SetupMockDelegateAndPolicy(); 536 SetupMockDelegateAndPolicy();
525 base::string16 text; 537 base::string16 text;
526 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); 538 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
527 539
528 content::WebContents* contents = web_contents(); 540 content::WebContents* contents = web_contents();
529 bool is_active_tab = IsActiveTab(contents); 541 bool is_active_tab = IsActiveTab(contents);
530 EXPECT_TRUE(is_active_tab); 542 EXPECT_TRUE(is_active_tab);
531 543
532 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 544 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
533 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 545 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
534 .WillOnce(testing::Return(false)); 546 .WillOnce(testing::Return(false));
535 547
536 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown( 548 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
537 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text)); 549 contents->GetRenderViewHost()->GetRoutingID(), GetSearchIPCRouterSeqNo(),
550 text));
538 } 551 }
539 552
540 TEST_F(SearchIPCRouterTest, SendSetSuggestionToPrefetch) { 553 TEST_F(SearchIPCRouterTest, SendSetSuggestionToPrefetch) {
541 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 554 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
542 SetupMockDelegateAndPolicy(); 555 SetupMockDelegateAndPolicy();
543 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 556 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
544 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1) 557 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1)
545 .WillOnce(testing::Return(true)); 558 .WillOnce(testing::Return(true));
546 559
547 process()->sink().ClearMessages(); 560 process()->sink().ClearMessages();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 .WillOnce(testing::Return(false)); 700 .WillOnce(testing::Return(false));
688 701
689 process()->sink().ClearMessages(); 702 process()->sink().ClearMessages();
690 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams()); 703 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams());
691 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID)); 704 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID));
692 } 705 }
693 706
694 TEST_F(SearchIPCRouterTest, SpuriousMessageTypesIgnored) { 707 TEST_F(SearchIPCRouterTest, SpuriousMessageTypesIgnored) {
695 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 708 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
696 SetupMockDelegateAndPolicy(); 709 SetupMockDelegateAndPolicy();
697 const int routing_id = web_contents()->GetRoutingID(); 710 const int routing_id = web_contents()->GetRenderViewHost()->GetRoutingID();
698 711
699 // Construct a series of synthetic messages for each valid IPC message type, 712 // Construct a series of synthetic messages for each valid IPC message type,
700 // ensuring the router ignores them all. 713 // ensuring the router ignores them all.
701 for (int i = 0; i < LastIPCMsgStart; ++i) { 714 for (int i = 0; i < LastIPCMsgStart; ++i) {
702 const int message_id = i << 16; 715 const int message_id = i << 16;
703 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); 716 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i);
704 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); 717 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW);
705 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; 718 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i;
706 } 719 }
707 } 720 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_tab_unittest.cc ('k') | chrome/browser/ui/search/search_tab_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698