| 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 // Note: this test uses RenderViewFakeResourcesTest in order to set up a | 5 // Note: this test uses RenderViewFakeResourcesTest in order to set up a |
| 6 // real RenderThread to hold the phishing Scorer object. | 6 // real RenderThread to hold the phishing Scorer object. |
| 7 | 7 |
| 8 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 8 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 void OnStartPhishingDetection(PhishingClassifierDelegate* delegate, | 94 void OnStartPhishingDetection(PhishingClassifierDelegate* delegate, |
| 95 const GURL& url) { | 95 const GURL& url) { |
| 96 delegate->OnStartPhishingDetection(url); | 96 delegate->OnStartPhishingDetection(url); |
| 97 } | 97 } |
| 98 | 98 |
| 99 scoped_ptr<ClientPhishingRequest> verdict_; | 99 scoped_ptr<ClientPhishingRequest> verdict_; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 TEST_F(PhishingClassifierDelegateTest, Navigation) { | 102 TEST_F(PhishingClassifierDelegateTest, DISABLED_Navigation) { |
| 103 MockPhishingClassifier* classifier = | 103 MockPhishingClassifier* classifier = |
| 104 new StrictMock<MockPhishingClassifier>(view()); | 104 new StrictMock<MockPhishingClassifier>(view()); |
| 105 PhishingClassifierDelegate* delegate = | 105 PhishingClassifierDelegate* delegate = |
| 106 PhishingClassifierDelegate::Create(view(), classifier); | 106 PhishingClassifierDelegate::Create(view(), classifier); |
| 107 MockScorer scorer; | 107 MockScorer scorer; |
| 108 delegate->SetPhishingScorer(&scorer); | 108 delegate->SetPhishingScorer(&scorer); |
| 109 ASSERT_TRUE(classifier->is_ready()); | 109 ASSERT_TRUE(classifier->is_ready()); |
| 110 | 110 |
| 111 // Test an initial load. We expect classification to happen normally. | 111 // Test an initial load. We expect classification to happen normally. |
| 112 EXPECT_CALL(*classifier, CancelPendingClassification()).Times(2); | 112 EXPECT_CALL(*classifier, CancelPendingClassification()).Times(2); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 OnStartPhishingDetection(delegate, GURL("http://host.com/#foo2")); | 216 OnStartPhishingDetection(delegate, GURL("http://host.com/#foo2")); |
| 217 page_text = ASCIIToUTF16("dummy"); | 217 page_text = ASCIIToUTF16("dummy"); |
| 218 EXPECT_CALL(*classifier, CancelPendingClassification()); | 218 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 219 delegate->PageCaptured(&page_text, false); | 219 delegate->PageCaptured(&page_text, false); |
| 220 Mock::VerifyAndClearExpectations(classifier); | 220 Mock::VerifyAndClearExpectations(classifier); |
| 221 | 221 |
| 222 // The delegate will cancel pending classification on destruction. | 222 // The delegate will cancel pending classification on destruction. |
| 223 EXPECT_CALL(*classifier, CancelPendingClassification()); | 223 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 TEST_F(PhishingClassifierDelegateTest, NoScorer) { | 226 TEST_F(PhishingClassifierDelegateTest, DISABLED_NoScorer) { |
| 227 // For this test, we'll create the delegate with no scorer available yet. | 227 // For this test, we'll create the delegate with no scorer available yet. |
| 228 MockPhishingClassifier* classifier = | 228 MockPhishingClassifier* classifier = |
| 229 new StrictMock<MockPhishingClassifier>(view()); | 229 new StrictMock<MockPhishingClassifier>(view()); |
| 230 PhishingClassifierDelegate* delegate = | 230 PhishingClassifierDelegate* delegate = |
| 231 PhishingClassifierDelegate::Create(view(), classifier); | 231 PhishingClassifierDelegate::Create(view(), classifier); |
| 232 ASSERT_FALSE(classifier->is_ready()); | 232 ASSERT_FALSE(classifier->is_ready()); |
| 233 | 233 |
| 234 // Queue up a pending classification, cancel it, then queue up another one. | 234 // Queue up a pending classification, cancel it, then queue up another one. |
| 235 LoadURL("http://host.com/"); | 235 LoadURL("http://host.com/"); |
| 236 string16 page_text = ASCIIToUTF16("dummy"); | 236 string16 page_text = ASCIIToUTF16("dummy"); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 253 // If we set a new scorer while a classification is going on the | 253 // If we set a new scorer while a classification is going on the |
| 254 // classification should be cancelled. | 254 // classification should be cancelled. |
| 255 EXPECT_CALL(*classifier, CancelPendingClassification()); | 255 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 256 delegate->SetPhishingScorer(&scorer); | 256 delegate->SetPhishingScorer(&scorer); |
| 257 Mock::VerifyAndClearExpectations(classifier); | 257 Mock::VerifyAndClearExpectations(classifier); |
| 258 | 258 |
| 259 // The delegate will cancel pending classification on destruction. | 259 // The delegate will cancel pending classification on destruction. |
| 260 EXPECT_CALL(*classifier, CancelPendingClassification()); | 260 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 TEST_F(PhishingClassifierDelegateTest, NoScorer_Ref) { | 263 TEST_F(PhishingClassifierDelegateTest, DISABLED_NoScorer_Ref) { |
| 264 // Similar to the last test, but navigates within the page before | 264 // Similar to the last test, but navigates within the page before |
| 265 // setting the scorer. | 265 // setting the scorer. |
| 266 MockPhishingClassifier* classifier = | 266 MockPhishingClassifier* classifier = |
| 267 new StrictMock<MockPhishingClassifier>(view()); | 267 new StrictMock<MockPhishingClassifier>(view()); |
| 268 PhishingClassifierDelegate* delegate = | 268 PhishingClassifierDelegate* delegate = |
| 269 PhishingClassifierDelegate::Create(view(), classifier); | 269 PhishingClassifierDelegate::Create(view(), classifier); |
| 270 ASSERT_FALSE(classifier->is_ready()); | 270 ASSERT_FALSE(classifier->is_ready()); |
| 271 | 271 |
| 272 // Queue up a pending classification, cancel it, then queue up another one. | 272 // Queue up a pending classification, cancel it, then queue up another one. |
| 273 LoadURL("http://host.com/"); | 273 LoadURL("http://host.com/"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 285 page_text = ASCIIToUTF16("dummy"); | 285 page_text = ASCIIToUTF16("dummy"); |
| 286 EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)); | 286 EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)); |
| 287 MockScorer scorer; | 287 MockScorer scorer; |
| 288 delegate->SetPhishingScorer(&scorer); | 288 delegate->SetPhishingScorer(&scorer); |
| 289 Mock::VerifyAndClearExpectations(classifier); | 289 Mock::VerifyAndClearExpectations(classifier); |
| 290 | 290 |
| 291 // The delegate will cancel pending classification on destruction. | 291 // The delegate will cancel pending classification on destruction. |
| 292 EXPECT_CALL(*classifier, CancelPendingClassification()); | 292 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 293 } | 293 } |
| 294 | 294 |
| 295 TEST_F(PhishingClassifierDelegateTest, NoStartPhishingDetection) { | 295 TEST_F(PhishingClassifierDelegateTest, DISABLED_NoStartPhishingDetection) { |
| 296 // Tests the behavior when OnStartPhishingDetection has not yet been called | 296 // Tests the behavior when OnStartPhishingDetection has not yet been called |
| 297 // when the page load finishes. | 297 // when the page load finishes. |
| 298 MockPhishingClassifier* classifier = | 298 MockPhishingClassifier* classifier = |
| 299 new StrictMock<MockPhishingClassifier>(view()); | 299 new StrictMock<MockPhishingClassifier>(view()); |
| 300 PhishingClassifierDelegate* delegate = | 300 PhishingClassifierDelegate* delegate = |
| 301 PhishingClassifierDelegate::Create(view(), classifier); | 301 PhishingClassifierDelegate::Create(view(), classifier); |
| 302 MockScorer scorer; | 302 MockScorer scorer; |
| 303 delegate->SetPhishingScorer(&scorer); | 303 delegate->SetPhishingScorer(&scorer); |
| 304 ASSERT_TRUE(classifier->is_ready()); | 304 ASSERT_TRUE(classifier->is_ready()); |
| 305 | 305 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 EXPECT_CALL(*classifier, CancelPendingClassification()); | 358 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 359 EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)); | 359 EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)); |
| 360 delegate->PageCaptured(&page_text, false); | 360 delegate->PageCaptured(&page_text, false); |
| 361 Mock::VerifyAndClearExpectations(classifier); | 361 Mock::VerifyAndClearExpectations(classifier); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // The delegate will cancel pending classification on destruction. | 364 // The delegate will cancel pending classification on destruction. |
| 365 EXPECT_CALL(*classifier, CancelPendingClassification()); | 365 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 366 } | 366 } |
| 367 | 367 |
| 368 TEST_F(PhishingClassifierDelegateTest, IgnorePreliminaryCapture) { | 368 TEST_F(PhishingClassifierDelegateTest, DISABLED_IgnorePreliminaryCapture) { |
| 369 // Tests that preliminary PageCaptured notifications are ignored. | 369 // Tests that preliminary PageCaptured notifications are ignored. |
| 370 MockPhishingClassifier* classifier = | 370 MockPhishingClassifier* classifier = |
| 371 new StrictMock<MockPhishingClassifier>(view()); | 371 new StrictMock<MockPhishingClassifier>(view()); |
| 372 PhishingClassifierDelegate* delegate = | 372 PhishingClassifierDelegate* delegate = |
| 373 PhishingClassifierDelegate::Create(view(), classifier); | 373 PhishingClassifierDelegate::Create(view(), classifier); |
| 374 MockScorer scorer; | 374 MockScorer scorer; |
| 375 delegate->SetPhishingScorer(&scorer); | 375 delegate->SetPhishingScorer(&scorer); |
| 376 ASSERT_TRUE(classifier->is_ready()); | 376 ASSERT_TRUE(classifier->is_ready()); |
| 377 | 377 |
| 378 EXPECT_CALL(*classifier, CancelPendingClassification()); | 378 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 390 EXPECT_CALL(*classifier, CancelPendingClassification()); | 390 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 391 EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)); | 391 EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)); |
| 392 delegate->PageCaptured(&page_text, false); | 392 delegate->PageCaptured(&page_text, false); |
| 393 Mock::VerifyAndClearExpectations(classifier); | 393 Mock::VerifyAndClearExpectations(classifier); |
| 394 } | 394 } |
| 395 | 395 |
| 396 // The delegate will cancel pending classification on destruction. | 396 // The delegate will cancel pending classification on destruction. |
| 397 EXPECT_CALL(*classifier, CancelPendingClassification()); | 397 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 398 } | 398 } |
| 399 | 399 |
| 400 TEST_F(PhishingClassifierDelegateTest, DuplicatePageCapture) { | 400 TEST_F(PhishingClassifierDelegateTest, DISABLED_DuplicatePageCapture) { |
| 401 // Tests that a second PageCaptured notification causes classification to | 401 // Tests that a second PageCaptured notification causes classification to |
| 402 // be cancelled. | 402 // be cancelled. |
| 403 MockPhishingClassifier* classifier = | 403 MockPhishingClassifier* classifier = |
| 404 new StrictMock<MockPhishingClassifier>(view()); | 404 new StrictMock<MockPhishingClassifier>(view()); |
| 405 PhishingClassifierDelegate* delegate = | 405 PhishingClassifierDelegate* delegate = |
| 406 PhishingClassifierDelegate::Create(view(), classifier); | 406 PhishingClassifierDelegate::Create(view(), classifier); |
| 407 MockScorer scorer; | 407 MockScorer scorer; |
| 408 delegate->SetPhishingScorer(&scorer); | 408 delegate->SetPhishingScorer(&scorer); |
| 409 ASSERT_TRUE(classifier->is_ready()); | 409 ASSERT_TRUE(classifier->is_ready()); |
| 410 | 410 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 424 | 424 |
| 425 page_text = ASCIIToUTF16("phish"); | 425 page_text = ASCIIToUTF16("phish"); |
| 426 EXPECT_CALL(*classifier, CancelPendingClassification()); | 426 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 427 delegate->PageCaptured(&page_text, false); | 427 delegate->PageCaptured(&page_text, false); |
| 428 Mock::VerifyAndClearExpectations(classifier); | 428 Mock::VerifyAndClearExpectations(classifier); |
| 429 | 429 |
| 430 // The delegate will cancel pending classification on destruction. | 430 // The delegate will cancel pending classification on destruction. |
| 431 EXPECT_CALL(*classifier, CancelPendingClassification()); | 431 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 432 } | 432 } |
| 433 | 433 |
| 434 TEST_F(PhishingClassifierDelegateTest, PhishingDetectionDone) { | 434 TEST_F(PhishingClassifierDelegateTest, DISABLED_PhishingDetectionDone) { |
| 435 // Tests that a PhishingDetectionDone IPC is sent to the browser | 435 // Tests that a PhishingDetectionDone IPC is sent to the browser |
| 436 // whenever we finish classification. | 436 // whenever we finish classification. |
| 437 MockPhishingClassifier* classifier = | 437 MockPhishingClassifier* classifier = |
| 438 new StrictMock<MockPhishingClassifier>(view()); | 438 new StrictMock<MockPhishingClassifier>(view()); |
| 439 PhishingClassifierDelegate* delegate = | 439 PhishingClassifierDelegate* delegate = |
| 440 PhishingClassifierDelegate::Create(view(), classifier); | 440 PhishingClassifierDelegate::Create(view(), classifier); |
| 441 MockScorer scorer; | 441 MockScorer scorer; |
| 442 delegate->SetPhishingScorer(&scorer); | 442 delegate->SetPhishingScorer(&scorer); |
| 443 ASSERT_TRUE(classifier->is_ready()); | 443 ASSERT_TRUE(classifier->is_ready()); |
| 444 | 444 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 464 verdict.set_is_phishing(false); // Send IPC even if site is not phishing. | 464 verdict.set_is_phishing(false); // Send IPC even if site is not phishing. |
| 465 RunClassificationDone(delegate, verdict); | 465 RunClassificationDone(delegate, verdict); |
| 466 ASSERT_TRUE(verdict_.get()); | 466 ASSERT_TRUE(verdict_.get()); |
| 467 EXPECT_EQ(verdict.SerializeAsString(), verdict_->SerializeAsString()); | 467 EXPECT_EQ(verdict.SerializeAsString(), verdict_->SerializeAsString()); |
| 468 | 468 |
| 469 // The delegate will cancel pending classification on destruction. | 469 // The delegate will cancel pending classification on destruction. |
| 470 EXPECT_CALL(*classifier, CancelPendingClassification()); | 470 EXPECT_CALL(*classifier, CancelPendingClassification()); |
| 471 } | 471 } |
| 472 | 472 |
| 473 } // namespace safe_browsing | 473 } // namespace safe_browsing |
| OLD | NEW |