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