OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; | 309 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; |
310 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; | 310 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; |
311 MockTestingProfile* mock_profile_; // We don't own this object | 311 MockTestingProfile* mock_profile_; // We don't own this object |
312 | 312 |
313 private: | 313 private: |
314 scoped_ptr<content::TestBrowserThread> ui_thread_; | 314 scoped_ptr<content::TestBrowserThread> ui_thread_; |
315 scoped_ptr<content::TestBrowserThread> file_user_blocking_thread_; | 315 scoped_ptr<content::TestBrowserThread> file_user_blocking_thread_; |
316 scoped_ptr<content::TestBrowserThread> io_thread_; | 316 scoped_ptr<content::TestBrowserThread> io_thread_; |
317 }; | 317 }; |
318 | 318 |
319 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 319 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { |
320 // Crashes on linux_chromeos and win_rel http://crbug.com/115979 | |
321 #define MAYBE_OnPhishingDetectionDoneInvalidVerdict \ | |
322 DISABLED_OnPhishingDetectionDoneInvalidVerdict | |
323 #define MAYBE_OnPhishingDetectionDoneVerdictNotPhishing \ | |
324 DISABLED_OnPhishingDetectionDoneVerdictNotPhishing | |
325 #else | |
326 #define MAYBE_OnPhishingDetectionDoneInvalidVerdict \ | |
327 OnPhishingDetectionDoneInvalidVerdict | |
328 #define MAYBE_OnPhishingDetectionDoneVerdictNotPhishing \ | |
329 OnPhishingDetectionDoneVerdictNotPhishing | |
330 #endif | |
331 | |
332 TEST_F(ClientSideDetectionHostTest, | |
333 MAYBE_OnPhishingDetectionDoneInvalidVerdict) { | |
334 // Case 0: renderer sends an invalid verdict string that we're unable to | 320 // Case 0: renderer sends an invalid verdict string that we're unable to |
335 // parse. | 321 // parse. |
336 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 322 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
337 contents(), | 323 contents(), |
338 csd_service_.get()); | 324 csd_service_.get()); |
339 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 325 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
340 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 326 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
341 OnPhishingDetectionDone("Invalid Protocol Buffer"); | 327 OnPhishingDetectionDone("Invalid Protocol Buffer"); |
342 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 328 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
343 } | 329 } |
344 | 330 |
345 #if defined(OS_LINUX) || defined(OS_WIN) | 331 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) { |
346 // Crashes on linux_chromeos and win_rel. http://crbug.com/115979 | |
347 #define MAYBE_OnPhishingDetectionDoneNotPhishing \ | |
348 DISABLED_OnPhishingDetectionDoneNotPhishing | |
349 #else | |
350 #define MAYBE_OnPhishingDetectionDoneNotPhishing \ | |
351 OnPhishingDetectionDoneNotPhishing | |
352 #endif | |
353 | |
354 TEST_F(ClientSideDetectionHostTest, | |
355 MAYBE_OnPhishingDetectionDoneNotPhishing) { | |
356 // Case 1: client thinks the page is phishing. The server does not agree. | 332 // Case 1: client thinks the page is phishing. The server does not agree. |
357 // No interstitial is shown. | 333 // No interstitial is shown. |
358 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 334 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
359 contents(), | 335 contents(), |
360 csd_service_.get()); | 336 csd_service_.get()); |
361 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 337 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
362 | 338 |
363 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 339 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
364 ClientPhishingRequest verdict; | 340 ClientPhishingRequest verdict; |
365 verdict.set_url("http://phishingurl.com/"); | 341 verdict.set_url("http://phishingurl.com/"); |
(...skipping 11 matching lines...) Expand all Loading... |
377 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 353 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
378 ASSERT_FALSE(cb.is_null()); | 354 ASSERT_FALSE(cb.is_null()); |
379 | 355 |
380 // Make sure DoDisplayBlockingPage is not going to be called. | 356 // Make sure DoDisplayBlockingPage is not going to be called. |
381 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)).Times(0); | 357 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)).Times(0); |
382 cb.Run(GURL(verdict.url()), false); | 358 cb.Run(GURL(verdict.url()), false); |
383 MessageLoop::current()->RunAllPending(); | 359 MessageLoop::current()->RunAllPending(); |
384 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 360 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
385 } | 361 } |
386 | 362 |
387 #if defined(OS_CHROMEOS) || defined(OS_WIN) | |
388 // Crashes on linux_chromeos and win_rel. http://crbug.com/115979 | |
389 TEST_F(ClientSideDetectionHostTest, FLAKY_OnPhishingDetectionDoneDisabled) { | |
390 #else | |
391 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { | 363 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { |
392 #endif | |
393 // Case 2: client thinks the page is phishing and so does the server but | 364 // Case 2: client thinks the page is phishing and so does the server but |
394 // showing the interstitial is disabled => no interstitial is shown. | 365 // showing the interstitial is disabled => no interstitial is shown. |
395 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 366 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
396 contents(), | 367 contents(), |
397 csd_service_.get()); | 368 csd_service_.get()); |
398 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 369 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
399 | 370 |
400 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 371 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
401 ClientPhishingRequest verdict; | 372 ClientPhishingRequest verdict; |
402 verdict.set_url("http://phishingurl.com/"); | 373 verdict.set_url("http://phishingurl.com/"); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 FROM_HERE, | 533 FROM_HERE, |
563 base::Bind(&MockSafeBrowsingService::InvokeOnBlockingPageComplete, | 534 base::Bind(&MockSafeBrowsingService::InvokeOnBlockingPageComplete, |
564 sb_service_.get(), resource.callback)); | 535 sb_service_.get(), resource.callback)); |
565 // Since the CsdClient object will be deleted on the UI thread I need | 536 // Since the CsdClient object will be deleted on the UI thread I need |
566 // to run the UI message loop. Post a task to stop the UI message loop | 537 // to run the UI message loop. Post a task to stop the UI message loop |
567 // after the client object destructor is called. | 538 // after the client object destructor is called. |
568 FlushIOMessageLoop(); | 539 FlushIOMessageLoop(); |
569 } | 540 } |
570 | 541 |
571 TEST_F(ClientSideDetectionHostTest, | 542 TEST_F(ClientSideDetectionHostTest, |
572 MAYBE_OnPhishingDetectionDoneVerdictNotPhishing) { | 543 OnPhishingDetectionDoneVerdictNotPhishing) { |
573 // Case 6: renderer sends a verdict string that isn't phishing. | 544 // Case 6: renderer sends a verdict string that isn't phishing. |
574 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 545 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
575 contents(), | 546 contents(), |
576 csd_service_.get()); | 547 csd_service_.get()); |
577 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 548 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
578 | 549 |
579 ClientPhishingRequest verdict; | 550 ClientPhishingRequest verdict; |
580 verdict.set_url("http://not-phishing.com/"); | 551 verdict.set_url("http://not-phishing.com/"); |
581 verdict.set_client_score(0.1f); | 552 verdict.set_client_score(0.1f); |
582 verdict.set_is_phishing(false); | 553 verdict.set_is_phishing(false); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 754 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
784 EXPECT_EQ(url, resource.url); | 755 EXPECT_EQ(url, resource.url); |
785 EXPECT_EQ(url, resource.original_url); | 756 EXPECT_EQ(url, resource.original_url); |
786 resource.callback.Reset(); | 757 resource.callback.Reset(); |
787 msg = process()->sink().GetFirstMessageMatching( | 758 msg = process()->sink().GetFirstMessageMatching( |
788 SafeBrowsingMsg_StartPhishingDetection::ID); | 759 SafeBrowsingMsg_StartPhishingDetection::ID); |
789 ASSERT_FALSE(msg); | 760 ASSERT_FALSE(msg); |
790 } | 761 } |
791 | 762 |
792 } // namespace safe_browsing | 763 } // namespace safe_browsing |
OLD | NEW |