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

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_host_unittest.cc

Issue 6713084: Move the rest of the renderer->browser messages that belong in content. Also do a bunch of cleanup: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/task.h" 10 #include "base/task.h"
11 #include "chrome/browser/safe_browsing/client_side_detection_host.h" 11 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
12 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 12 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/render_messages.h" 15 #include "chrome/common/safebrowsing_messages.h"
16 #include "chrome/test/testing_profile.h" 16 #include "chrome/test/testing_profile.h"
17 #include "chrome/test/ui_test_utils.h" 17 #include "chrome/test/ui_test_utils.h"
18 #include "content/browser/browser_thread.h" 18 #include "content/browser/browser_thread.h"
19 #include "content/browser/renderer_host/test_render_view_host.h" 19 #include "content/browser/renderer_host/test_render_view_host.h"
20 #include "content/browser/tab_contents/test_tab_contents.h" 20 #include "content/browser/tab_contents/test_tab_contents.h"
21 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 #include "ipc/ipc_test_sink.h" 22 #include "ipc/ipc_test_sink.h"
23 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gmock/include/gmock/gmock-actions.h" 24 #include "testing/gmock/include/gmock/gmock-actions.h"
25 #include "testing/gmock/include/gmock/gmock-generated-nice-strict.h" 25 #include "testing/gmock/include/gmock/gmock-generated-nice-strict.h"
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 407
408 TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { 408 TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) {
409 // Navigate the tab to a page. We should see a StartPhishingDetection IPC. 409 // Navigate the tab to a page. We should see a StartPhishingDetection IPC.
410 GURL url("http://host.com/"); 410 GURL url("http://host.com/");
411 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, 411 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse,
412 &kFalse, &kFalse); 412 &kFalse, &kFalse);
413 NavigateAndCommit(url); 413 NavigateAndCommit(url);
414 WaitAndCheckPreClassificationChecks(); 414 WaitAndCheckPreClassificationChecks();
415 415
416 const IPC::Message* msg = process()->sink().GetFirstMessageMatching( 416 const IPC::Message* msg = process()->sink().GetFirstMessageMatching(
417 ViewMsg_StartPhishingDetection::ID); 417 SafeBrowsingMsg_StartPhishingDetection::ID);
418 ASSERT_TRUE(msg); 418 ASSERT_TRUE(msg);
419 Tuple1<GURL> actual_url; 419 Tuple1<GURL> actual_url;
420 ViewMsg_StartPhishingDetection::Read(msg, &actual_url); 420 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url);
421 EXPECT_EQ(url, actual_url.a); 421 EXPECT_EQ(url, actual_url.a);
422 EXPECT_EQ(rvh()->routing_id(), msg->routing_id()); 422 EXPECT_EQ(rvh()->routing_id(), msg->routing_id());
423 process()->sink().ClearMessages(); 423 process()->sink().ClearMessages();
424 424
425 // Now try an in-page navigation. This should not trigger an IPC. 425 // Now try an in-page navigation. This should not trigger an IPC.
426 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)).Times(0); 426 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)).Times(0);
427 url = GURL("http://host.com/#foo"); 427 url = GURL("http://host.com/#foo");
428 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); 428 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL);
429 NavigateAndCommit(url); 429 NavigateAndCommit(url);
430 WaitAndCheckPreClassificationChecks(); 430 WaitAndCheckPreClassificationChecks();
431 431
432 msg = process()->sink().GetFirstMessageMatching( 432 msg = process()->sink().GetFirstMessageMatching(
433 ViewMsg_StartPhishingDetection::ID); 433 SafeBrowsingMsg_StartPhishingDetection::ID);
434 ASSERT_FALSE(msg); 434 ASSERT_FALSE(msg);
435 435
436 // Navigate to a new host, which should cause another IPC. 436 // Navigate to a new host, which should cause another IPC.
437 url = GURL("http://host2.com/"); 437 url = GURL("http://host2.com/");
438 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, 438 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse,
439 &kFalse, &kFalse); 439 &kFalse, &kFalse);
440 NavigateAndCommit(url); 440 NavigateAndCommit(url);
441 WaitAndCheckPreClassificationChecks(); 441 WaitAndCheckPreClassificationChecks();
442 msg = process()->sink().GetFirstMessageMatching( 442 msg = process()->sink().GetFirstMessageMatching(
443 ViewMsg_StartPhishingDetection::ID); 443 SafeBrowsingMsg_StartPhishingDetection::ID);
444 ASSERT_TRUE(msg); 444 ASSERT_TRUE(msg);
445 ViewMsg_StartPhishingDetection::Read(msg, &actual_url); 445 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url);
446 EXPECT_EQ(url, actual_url.a); 446 EXPECT_EQ(url, actual_url.a);
447 EXPECT_EQ(rvh()->routing_id(), msg->routing_id()); 447 EXPECT_EQ(rvh()->routing_id(), msg->routing_id());
448 process()->sink().ClearMessages(); 448 process()->sink().ClearMessages();
449 449
450 // If IsPrivateIPAddress returns true, no IPC should be triggered. 450 // If IsPrivateIPAddress returns true, no IPC should be triggered.
451 url = GURL("http://host3.com/"); 451 url = GURL("http://host3.com/");
452 ExpectPreClassificationChecks(url, &kTrue, NULL, NULL, NULL, NULL, NULL); 452 ExpectPreClassificationChecks(url, &kTrue, NULL, NULL, NULL, NULL, NULL);
453 NavigateAndCommit(url); 453 NavigateAndCommit(url);
454 WaitAndCheckPreClassificationChecks(); 454 WaitAndCheckPreClassificationChecks();
455 msg = process()->sink().GetFirstMessageMatching( 455 msg = process()->sink().GetFirstMessageMatching(
456 ViewMsg_StartPhishingDetection::ID); 456 SafeBrowsingMsg_StartPhishingDetection::ID);
457 ASSERT_FALSE(msg); 457 ASSERT_FALSE(msg);
458 458
459 // If the connection is proxied, no IPC should be triggered. 459 // If the connection is proxied, no IPC should be triggered.
460 // Note: for this test to work correctly, the new URL must be on the 460 // Note: for this test to work correctly, the new URL must be on the
461 // same domain as the previous URL, otherwise it will create a new 461 // same domain as the previous URL, otherwise it will create a new
462 // RenderViewHost that won't have simulate_fetch_via_proxy set. 462 // RenderViewHost that won't have simulate_fetch_via_proxy set.
463 url = GURL("http://host3.com/abc"); 463 url = GURL("http://host3.com/abc");
464 rvh()->set_simulate_fetch_via_proxy(true); 464 rvh()->set_simulate_fetch_via_proxy(true);
465 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); 465 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL);
466 NavigateAndCommit(url); 466 NavigateAndCommit(url);
467 WaitAndCheckPreClassificationChecks(); 467 WaitAndCheckPreClassificationChecks();
468 msg = process()->sink().GetFirstMessageMatching( 468 msg = process()->sink().GetFirstMessageMatching(
469 ViewMsg_StartPhishingDetection::ID); 469 SafeBrowsingMsg_StartPhishingDetection::ID);
470 ASSERT_FALSE(msg); 470 ASSERT_FALSE(msg);
471 471
472 // If the tab is off-the-record there should be no IPC. Also, we shouldn't 472 // If the tab is off-the-record there should be no IPC. Also, we shouldn't
473 // even check the csd-whitelist. 473 // even check the csd-whitelist.
474 url = GURL("http://host4.com/"); 474 url = GURL("http://host4.com/");
475 ExpectPreClassificationChecks(url, &kFalse, &kTrue, NULL, NULL, NULL, NULL); 475 ExpectPreClassificationChecks(url, &kFalse, &kTrue, NULL, NULL, NULL, NULL);
476 NavigateAndCommit(url); 476 NavigateAndCommit(url);
477 WaitAndCheckPreClassificationChecks(); 477 WaitAndCheckPreClassificationChecks();
478 msg = process()->sink().GetFirstMessageMatching( 478 msg = process()->sink().GetFirstMessageMatching(
479 ViewMsg_StartPhishingDetection::ID); 479 SafeBrowsingMsg_StartPhishingDetection::ID);
480 ASSERT_FALSE(msg); 480 ASSERT_FALSE(msg);
481 481
482 // If the URL is on the csd whitelist, no IPC should be triggered. 482 // If the URL is on the csd whitelist, no IPC should be triggered.
483 url = GURL("http://host5.com/"); 483 url = GURL("http://host5.com/");
484 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kTrue, NULL, NULL, 484 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kTrue, NULL, NULL,
485 NULL); 485 NULL);
486 NavigateAndCommit(url); 486 NavigateAndCommit(url);
487 WaitAndCheckPreClassificationChecks(); 487 WaitAndCheckPreClassificationChecks();
488 msg = process()->sink().GetFirstMessageMatching( 488 msg = process()->sink().GetFirstMessageMatching(
489 ViewMsg_StartPhishingDetection::ID); 489 SafeBrowsingMsg_StartPhishingDetection::ID);
490 ASSERT_FALSE(msg); 490 ASSERT_FALSE(msg);
491 491
492 // If item is in the cache but it isn't valid, we will classify regardless 492 // If item is in the cache but it isn't valid, we will classify regardless
493 // of whether we are over the reporting limit. 493 // of whether we are over the reporting limit.
494 url = GURL("http://host6.com/"); 494 url = GURL("http://host6.com/");
495 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, &kTrue, 495 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, &kTrue,
496 NULL); 496 NULL);
497 NavigateAndCommit(url); 497 NavigateAndCommit(url);
498 WaitAndCheckPreClassificationChecks(); 498 WaitAndCheckPreClassificationChecks();
499 msg = process()->sink().GetFirstMessageMatching( 499 msg = process()->sink().GetFirstMessageMatching(
500 ViewMsg_StartPhishingDetection::ID); 500 SafeBrowsingMsg_StartPhishingDetection::ID);
501 ASSERT_TRUE(msg); 501 ASSERT_TRUE(msg);
502 ViewMsg_StartPhishingDetection::Read(msg, &actual_url); 502 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url);
503 EXPECT_EQ(url, actual_url.a); 503 EXPECT_EQ(url, actual_url.a);
504 EXPECT_EQ(rvh()->routing_id(), msg->routing_id()); 504 EXPECT_EQ(rvh()->routing_id(), msg->routing_id());
505 process()->sink().ClearMessages(); 505 process()->sink().ClearMessages();
506 506
507 // If the url isn't in the cache and we are over the reporting limit, we 507 // If the url isn't in the cache and we are over the reporting limit, we
508 // don't do classification. 508 // don't do classification.
509 url = GURL("http://host7.com/"); 509 url = GURL("http://host7.com/");
510 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, 510 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse,
511 &kFalse, &kTrue); 511 &kFalse, &kTrue);
512 NavigateAndCommit(url); 512 NavigateAndCommit(url);
513 WaitAndCheckPreClassificationChecks(); 513 WaitAndCheckPreClassificationChecks();
514 msg = process()->sink().GetFirstMessageMatching( 514 msg = process()->sink().GetFirstMessageMatching(
515 ViewMsg_StartPhishingDetection::ID); 515 SafeBrowsingMsg_StartPhishingDetection::ID);
516 ASSERT_FALSE(msg); 516 ASSERT_FALSE(msg);
517 517
518 // If result is cached, we will try and display the blocking page directly 518 // If result is cached, we will try and display the blocking page directly
519 // with no start classification message. 519 // with no start classification message.
520 CommandLine::ForCurrentProcess()->AppendSwitch( 520 CommandLine::ForCurrentProcess()->AppendSwitch(
521 switches::kEnableClientSidePhishingInterstitial); 521 switches::kEnableClientSidePhishingInterstitial);
522 url = GURL("http://host8.com/"); 522 url = GURL("http://host8.com/");
523 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, NULL, 523 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, NULL,
524 NULL); 524 NULL);
525 EXPECT_CALL(*sb_service_, 525 EXPECT_CALL(*sb_service_,
526 DisplayBlockingPage(Eq(url), Eq(url), _, _, _, _, _, _)) 526 DisplayBlockingPage(Eq(url), Eq(url), _, _, _, _, _, _))
527 .WillOnce(DeleteArg<5>()); 527 .WillOnce(DeleteArg<5>());
528 NavigateAndCommit(url); 528 NavigateAndCommit(url);
529 // Wait for CheckCsdWhitelist to be called on the IO thread. 529 // Wait for CheckCsdWhitelist to be called on the IO thread.
530 FlushIOMessageLoop(); 530 FlushIOMessageLoop();
531 // Wait for CheckCache() to be called on the UI thread. 531 // Wait for CheckCache() to be called on the UI thread.
532 MessageLoop::current()->RunAllPending(); 532 MessageLoop::current()->RunAllPending();
533 // Wait for DisplayBlockingPage to be called on the IO thread. 533 // Wait for DisplayBlockingPage to be called on the IO thread.
534 FlushIOMessageLoop(); 534 FlushIOMessageLoop();
535 // Now we check that all expected functions were indeed called on the two 535 // Now we check that all expected functions were indeed called on the two
536 // service objects. 536 // service objects.
537 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 537 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
538 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); 538 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get()));
539 msg = process()->sink().GetFirstMessageMatching( 539 msg = process()->sink().GetFirstMessageMatching(
540 ViewMsg_StartPhishingDetection::ID); 540 SafeBrowsingMsg_StartPhishingDetection::ID);
541 ASSERT_FALSE(msg); 541 ASSERT_FALSE(msg);
542 } 542 }
543 543
544 } // namespace safe_browsing 544 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698