Chromium Code Reviews| 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 "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 5 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 virtual ~InterceptingMessageFilter() {} | 125 virtual ~InterceptingMessageFilter() {} |
| 126 | 126 |
| 127 scoped_ptr<ClientPhishingRequest> verdict_; | 127 scoped_ptr<ClientPhishingRequest> verdict_; |
| 128 base::MessageLoop* waiting_message_loop_; | 128 base::MessageLoop* waiting_message_loop_; |
| 129 base::Closure quit_closure_; | 129 base::Closure quit_closure_; |
| 130 scoped_ptr<base::RunLoop> run_loop_; | 130 scoped_ptr<base::RunLoop> run_loop_; |
| 131 }; | 131 }; |
| 132 } // namespace | 132 } // namespace |
| 133 | 133 |
| 134 class PhishingClassifierDelegateTest : public InProcessBrowserTest { | 134 class PhishingClassifierDelegateTest : public InProcessBrowserTest { |
| 135 public: | |
| 136 void CancelCalled() { | |
| 137 if (runner_.get()) { | |
| 138 content::BrowserThread::PostTask( | |
| 139 content::BrowserThread::UI, FROM_HERE, runner_->QuitClosure()); | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 protected: | 135 protected: |
| 144 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 136 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 145 command_line->AppendSwitch(switches::kSingleProcess); | 137 command_line->AppendSwitch(switches::kSingleProcess); |
| 146 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
| 147 // Don't want to try to create a GPU process. | 139 // Don't want to try to create a GPU process. |
| 148 command_line->AppendSwitch(switches::kDisableGpu); | 140 command_line->AppendSwitch(switches::kDisableGpu); |
| 149 #endif | 141 #endif |
| 150 } | 142 } |
| 151 | 143 |
| 152 virtual void SetUpOnMainThread() OVERRIDE { | 144 virtual void SetUpOnMainThread() OVERRIDE { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 content::WaitForLoadStop(GetWebContents()); | 247 content::WaitForLoadStop(GetWebContents()); |
| 256 } | 248 } |
| 257 | 249 |
| 258 scoped_refptr<InterceptingMessageFilter> intercepting_filter_; | 250 scoped_refptr<InterceptingMessageFilter> intercepting_filter_; |
| 259 GURL response_url_; | 251 GURL response_url_; |
| 260 std::string response_content_; | 252 std::string response_content_; |
| 261 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; | 253 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; |
| 262 scoped_ptr<ClientPhishingRequest> verdict_; | 254 scoped_ptr<ClientPhishingRequest> verdict_; |
| 263 StrictMock<MockPhishingClassifier>* classifier_; // Owned by |delegate_|. | 255 StrictMock<MockPhishingClassifier>* classifier_; // Owned by |delegate_|. |
| 264 PhishingClassifierDelegate* delegate_; // Owned by the RenderView. | 256 PhishingClassifierDelegate* delegate_; // Owned by the RenderView. |
| 265 scoped_refptr<content::MessageLoopRunner> runner_; | |
| 266 }; | 257 }; |
| 267 | 258 |
| 268 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, Navigation) { | 259 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, Navigation) { |
| 269 MockScorer scorer; | 260 MockScorer scorer; |
| 270 delegate_->SetPhishingScorer(&scorer); | 261 delegate_->SetPhishingScorer(&scorer); |
| 271 ASSERT_TRUE(classifier_->is_ready()); | 262 ASSERT_TRUE(classifier_->is_ready()); |
| 272 | 263 |
| 273 // Test an initial load. We expect classification to happen normally. | 264 // Test an initial load. We expect classification to happen normally. |
| 274 EXPECT_CALL(*classifier_, CancelPendingClassification()).Times(2); | |
| 275 std::string port = base::IntToString(embedded_test_server_->port()); | 265 std::string port = base::IntToString(embedded_test_server_->port()); |
| 276 std::string html = "<html><body><iframe src=\"http://sub1.com:"; | 266 std::string html = "<html><body><iframe src=\"http://sub1.com:"; |
| 277 html += port; | 267 html += port; |
| 278 html += "/\"></iframe></body></html>"; | 268 html += "/\"></iframe></body></html>"; |
| 279 GURL url = LoadHtml("host.com", html); | 269 GURL url = LoadHtml("host.com", html); |
| 280 Mock::VerifyAndClearExpectations(classifier_); | 270 Mock::VerifyAndClearExpectations(classifier_); |
| 281 OnStartPhishingDetection(url); | 271 OnStartPhishingDetection(url); |
| 282 base::string16 page_text = ASCIIToUTF16("dummy"); | 272 base::string16 page_text = ASCIIToUTF16("dummy"); |
| 283 { | 273 { |
| 284 InSequence s; | 274 InSequence s; |
| 285 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 275 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 286 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); | 276 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); |
| 287 PageCaptured(&page_text, false); | 277 PageCaptured(&page_text, false); |
| 288 Mock::VerifyAndClearExpectations(classifier_); | 278 Mock::VerifyAndClearExpectations(classifier_); |
| 289 } | 279 } |
| 290 | 280 |
| 291 // Reloading the same page should not trigger a reclassification. | |
| 292 // However, it will cancel any pending classification since the | |
| 293 // content is being replaced. | |
|
mattm
2014/07/10 03:21:01
It would be good to update and keep more of these
Avi (use Gerrit)
2014/07/10 15:14:07
Done.
| |
| 294 EXPECT_CALL(*classifier_, CancelPendingClassification()).Times(2); | |
| 295 | |
| 296 content::TestNavigationObserver observer(GetWebContents()); | 281 content::TestNavigationObserver observer(GetWebContents()); |
| 297 chrome::Reload(browser(), CURRENT_TAB); | 282 chrome::Reload(browser(), CURRENT_TAB); |
| 298 observer.Wait(); | 283 observer.Wait(); |
| 299 | 284 |
| 300 Mock::VerifyAndClearExpectations(classifier_); | 285 Mock::VerifyAndClearExpectations(classifier_); |
| 301 OnStartPhishingDetection(url); | 286 OnStartPhishingDetection(url); |
| 302 page_text = ASCIIToUTF16("dummy"); | 287 page_text = ASCIIToUTF16("dummy"); |
| 303 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 288 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 304 PageCaptured(&page_text, false); | 289 PageCaptured(&page_text, false); |
| 305 Mock::VerifyAndClearExpectations(classifier_); | 290 Mock::VerifyAndClearExpectations(classifier_); |
| 306 | 291 |
| 307 // Navigating in a subframe will not change the toplevel URL. However, this | |
| 308 // should cancel pending classification since the page content is changing. | |
| 309 // Currently, we do not start a new classification after subframe loads. | |
| 310 EXPECT_CALL(*classifier_, CancelPendingClassification()) | |
| 311 .WillOnce(Invoke(this, &PhishingClassifierDelegateTest::CancelCalled)); | |
| 312 | |
| 313 runner_ = new content::MessageLoopRunner; | |
| 314 NavigateMainFrame(GURL(std::string("http://sub2.com:") + port + "/")); | |
| 315 | |
| 316 runner_->Run(); | |
| 317 runner_ = NULL; | |
| 318 | |
| 319 Mock::VerifyAndClearExpectations(classifier_); | |
| 320 | |
| 321 OnStartPhishingDetection(url); | 292 OnStartPhishingDetection(url); |
| 322 page_text = ASCIIToUTF16("dummy"); | 293 page_text = ASCIIToUTF16("dummy"); |
| 323 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 294 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 324 PageCaptured(&page_text, false); | 295 PageCaptured(&page_text, false); |
| 325 Mock::VerifyAndClearExpectations(classifier_); | 296 Mock::VerifyAndClearExpectations(classifier_); |
| 326 | 297 |
| 327 // Scrolling to an anchor works similarly to a subframe navigation, but | 298 // Scrolling to an anchor works similarly to a subframe navigation, but |
| 328 // see the TODO in PhishingClassifierDelegate::DidCommitProvisionalLoad. | 299 // see the TODO in PhishingClassifierDelegate::DidCommitProvisionalLoad. |
|
mattm
2014/07/10 03:21:01
that TODO no longer exists
Avi (use Gerrit)
2014/07/10 15:14:07
Done.
Avi (use Gerrit)
2014/07/10 15:14:08
Done.
| |
| 329 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 330 GURL foo_url = GURL(url.spec() + "#foo"); | 300 GURL foo_url = GURL(url.spec() + "#foo"); |
| 331 ui_test_utils::NavigateToURL(browser(), foo_url); | 301 ui_test_utils::NavigateToURL(browser(), foo_url); |
| 332 Mock::VerifyAndClearExpectations(classifier_); | 302 Mock::VerifyAndClearExpectations(classifier_); |
| 333 OnStartPhishingDetection(url); | 303 OnStartPhishingDetection(url); |
| 334 page_text = ASCIIToUTF16("dummy"); | 304 page_text = ASCIIToUTF16("dummy"); |
| 335 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 305 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 336 PageCaptured(&page_text, false); | 306 PageCaptured(&page_text, false); |
| 337 Mock::VerifyAndClearExpectations(classifier_); | 307 Mock::VerifyAndClearExpectations(classifier_); |
| 338 | 308 |
| 339 // Now load a new toplevel page, which should trigger another classification. | |
| 340 EXPECT_CALL(*classifier_, CancelPendingClassification()) | |
| 341 .WillOnce(Invoke(this, &PhishingClassifierDelegateTest::CancelCalled)); | |
| 342 | |
| 343 runner_ = new content::MessageLoopRunner; | |
| 344 url = LoadHtml("host2.com", "dummy2"); | |
| 345 runner_->Run(); | |
| 346 runner_ = NULL; | |
| 347 | |
| 348 Mock::VerifyAndClearExpectations(classifier_); | 309 Mock::VerifyAndClearExpectations(classifier_); |
| 349 page_text = ASCIIToUTF16("dummy2"); | 310 page_text = ASCIIToUTF16("dummy2"); |
| 350 OnStartPhishingDetection(url); | 311 OnStartPhishingDetection(url); |
| 351 { | 312 { |
| 352 InSequence s; | 313 InSequence s; |
| 353 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 314 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 354 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); | |
| 355 PageCaptured(&page_text, false); | 315 PageCaptured(&page_text, false); |
| 356 Mock::VerifyAndClearExpectations(classifier_); | 316 Mock::VerifyAndClearExpectations(classifier_); |
| 357 } | 317 } |
| 358 | 318 |
| 359 // No classification should happen on back/forward navigation. | |
| 360 // Note: in practice, the browser will not send a StartPhishingDetection IPC | |
| 361 // in this case. However, we want to make sure that the delegate behaves | |
| 362 // correctly regardless. | |
| 363 EXPECT_CALL(*classifier_, CancelPendingClassification()).Times(2); | |
| 364 GoBack(); | 319 GoBack(); |
| 365 Mock::VerifyAndClearExpectations(classifier_); | 320 Mock::VerifyAndClearExpectations(classifier_); |
| 366 | 321 |
| 367 page_text = ASCIIToUTF16("dummy"); | 322 page_text = ASCIIToUTF16("dummy"); |
| 368 OnStartPhishingDetection(url); | 323 OnStartPhishingDetection(url); |
| 369 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 324 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 370 PageCaptured(&page_text, false); | 325 PageCaptured(&page_text, false); |
| 371 Mock::VerifyAndClearExpectations(classifier_); | 326 Mock::VerifyAndClearExpectations(classifier_); |
| 372 | 327 |
| 373 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 374 GoForward(); | 328 GoForward(); |
| 375 Mock::VerifyAndClearExpectations(classifier_); | 329 Mock::VerifyAndClearExpectations(classifier_); |
| 376 | 330 |
| 377 page_text = ASCIIToUTF16("dummy2"); | 331 page_text = ASCIIToUTF16("dummy2"); |
| 378 OnStartPhishingDetection(url); | 332 OnStartPhishingDetection(url); |
| 379 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 333 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 380 PageCaptured(&page_text, false); | 334 PageCaptured(&page_text, false); |
| 381 Mock::VerifyAndClearExpectations(classifier_); | 335 Mock::VerifyAndClearExpectations(classifier_); |
| 382 | 336 |
| 383 // Now go back again and scroll to a different anchor. | 337 // Now go back again and scroll to a different anchor. |
| 384 // No classification should happen. | 338 // No classification should happen. |
| 385 EXPECT_CALL(*classifier_, CancelPendingClassification()).Times(2); | |
| 386 GoBack(); | 339 GoBack(); |
| 387 Mock::VerifyAndClearExpectations(classifier_); | 340 Mock::VerifyAndClearExpectations(classifier_); |
| 388 page_text = ASCIIToUTF16("dummy"); | 341 page_text = ASCIIToUTF16("dummy"); |
| 389 | 342 |
| 390 OnStartPhishingDetection(url); | 343 OnStartPhishingDetection(url); |
| 391 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 344 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 392 PageCaptured(&page_text, false); | 345 PageCaptured(&page_text, false); |
| 393 Mock::VerifyAndClearExpectations(classifier_); | 346 Mock::VerifyAndClearExpectations(classifier_); |
| 394 | 347 |
| 395 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 396 GURL foo2_url = GURL(foo_url.spec() + "2"); | 348 GURL foo2_url = GURL(foo_url.spec() + "2"); |
| 397 ui_test_utils::NavigateToURL(browser(), foo2_url); | 349 ui_test_utils::NavigateToURL(browser(), foo2_url); |
| 398 Mock::VerifyAndClearExpectations(classifier_); | 350 Mock::VerifyAndClearExpectations(classifier_); |
| 399 | 351 |
| 400 OnStartPhishingDetection(url); | 352 OnStartPhishingDetection(url); |
| 401 page_text = ASCIIToUTF16("dummy"); | 353 page_text = ASCIIToUTF16("dummy"); |
| 402 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 354 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 403 PageCaptured(&page_text, false); | 355 PageCaptured(&page_text, false); |
| 404 Mock::VerifyAndClearExpectations(classifier_); | 356 Mock::VerifyAndClearExpectations(classifier_); |
| 405 | 357 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 } | 420 } |
| 469 | 421 |
| 470 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, | 422 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, |
| 471 NoStartPhishingDetection) { | 423 NoStartPhishingDetection) { |
| 472 // Tests the behavior when OnStartPhishingDetection has not yet been called | 424 // Tests the behavior when OnStartPhishingDetection has not yet been called |
| 473 // when the page load finishes. | 425 // when the page load finishes. |
| 474 MockScorer scorer; | 426 MockScorer scorer; |
| 475 delegate_->SetPhishingScorer(&scorer); | 427 delegate_->SetPhishingScorer(&scorer); |
| 476 ASSERT_TRUE(classifier_->is_ready()); | 428 ASSERT_TRUE(classifier_->is_ready()); |
| 477 | 429 |
| 478 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 479 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); | 430 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); |
| 480 Mock::VerifyAndClearExpectations(classifier_); | 431 Mock::VerifyAndClearExpectations(classifier_); |
| 481 base::string16 page_text = ASCIIToUTF16("phish"); | 432 base::string16 page_text = ASCIIToUTF16("phish"); |
| 482 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 433 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 483 PageCaptured(&page_text, false); | 434 PageCaptured(&page_text, false); |
| 484 Mock::VerifyAndClearExpectations(classifier_); | 435 Mock::VerifyAndClearExpectations(classifier_); |
| 485 // Now simulate the StartPhishingDetection IPC. We expect classification | 436 // Now simulate the StartPhishingDetection IPC. We expect classification |
| 486 // to begin. | 437 // to begin. |
| 487 page_text = ASCIIToUTF16("phish"); | 438 page_text = ASCIIToUTF16("phish"); |
| 488 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); | 439 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); |
| 489 OnStartPhishingDetection(url); | 440 OnStartPhishingDetection(url); |
| 490 Mock::VerifyAndClearExpectations(classifier_); | 441 Mock::VerifyAndClearExpectations(classifier_); |
| 491 | 442 |
| 492 // Now try again, but this time we will navigate the page away before | 443 // Now try again, but this time we will navigate the page away before |
| 493 // the IPC is sent. | 444 // the IPC is sent. |
| 494 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 495 LoadHtml("host2.com", "<html><body>phish</body></html>"); | 445 LoadHtml("host2.com", "<html><body>phish</body></html>"); |
| 496 Mock::VerifyAndClearExpectations(classifier_); | 446 Mock::VerifyAndClearExpectations(classifier_); |
| 497 page_text = ASCIIToUTF16("phish"); | 447 page_text = ASCIIToUTF16("phish"); |
| 498 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 499 PageCaptured(&page_text, false); | 448 PageCaptured(&page_text, false); |
| 500 Mock::VerifyAndClearExpectations(classifier_); | 449 Mock::VerifyAndClearExpectations(classifier_); |
| 501 | 450 |
| 502 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 503 LoadHtml("host3.com", "<html><body>phish</body></html>"); | 451 LoadHtml("host3.com", "<html><body>phish</body></html>"); |
| 504 Mock::VerifyAndClearExpectations(classifier_); | 452 Mock::VerifyAndClearExpectations(classifier_); |
| 505 OnStartPhishingDetection(url); | 453 OnStartPhishingDetection(url); |
| 506 | 454 |
| 507 // In this test, the original page is a redirect, which we do not get a | 455 // In this test, the original page is a redirect, which we do not get a |
| 508 // StartPhishingDetection IPC for. We use location.replace() to load a | 456 // StartPhishingDetection IPC for. We use location.replace() to load a |
| 509 // new page while reusing the original session history entry, and check that | 457 // new page while reusing the original session history entry, and check that |
| 510 // classification begins correctly for the landing page. | 458 // classification begins correctly for the landing page. |
| 511 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 512 LoadHtml("host4.com", "<html><body>abc</body></html>"); | 459 LoadHtml("host4.com", "<html><body>abc</body></html>"); |
| 513 Mock::VerifyAndClearExpectations(classifier_); | 460 Mock::VerifyAndClearExpectations(classifier_); |
| 514 page_text = ASCIIToUTF16("abc"); | 461 page_text = ASCIIToUTF16("abc"); |
| 515 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 462 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 516 PageCaptured(&page_text, false); | 463 PageCaptured(&page_text, false); |
| 517 Mock::VerifyAndClearExpectations(classifier_); | 464 Mock::VerifyAndClearExpectations(classifier_); |
| 518 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 519 | 465 |
| 520 ui_test_utils::NavigateToURL( | 466 ui_test_utils::NavigateToURL( |
| 521 browser(), GURL("javascript:location.replace(\'redir\');")); | 467 browser(), GURL("javascript:location.replace(\'redir\');")); |
| 522 | 468 |
| 523 Mock::VerifyAndClearExpectations(classifier_); | 469 Mock::VerifyAndClearExpectations(classifier_); |
| 524 | 470 |
| 525 std::string url_str = "http://host4.com:"; | 471 std::string url_str = "http://host4.com:"; |
| 526 url_str += base::IntToString(embedded_test_server_->port()); | 472 url_str += base::IntToString(embedded_test_server_->port()); |
| 527 url_str += "/redir"; | 473 url_str += "/redir"; |
| 528 OnStartPhishingDetection(GURL(url_str)); | 474 OnStartPhishingDetection(GURL(url_str)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 539 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 485 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 540 } | 486 } |
| 541 | 487 |
| 542 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, | 488 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, |
| 543 IgnorePreliminaryCapture) { | 489 IgnorePreliminaryCapture) { |
| 544 // Tests that preliminary PageCaptured notifications are ignored. | 490 // Tests that preliminary PageCaptured notifications are ignored. |
| 545 MockScorer scorer; | 491 MockScorer scorer; |
| 546 delegate_->SetPhishingScorer(&scorer); | 492 delegate_->SetPhishingScorer(&scorer); |
| 547 ASSERT_TRUE(classifier_->is_ready()); | 493 ASSERT_TRUE(classifier_->is_ready()); |
| 548 | 494 |
| 549 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 550 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); | 495 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); |
| 551 Mock::VerifyAndClearExpectations(classifier_); | 496 Mock::VerifyAndClearExpectations(classifier_); |
| 552 OnStartPhishingDetection(url); | 497 OnStartPhishingDetection(url); |
| 553 base::string16 page_text = ASCIIToUTF16("phish"); | 498 base::string16 page_text = ASCIIToUTF16("phish"); |
| 554 PageCaptured(&page_text, true); | 499 PageCaptured(&page_text, true); |
| 555 | 500 |
| 556 // Once the non-preliminary capture happens, classification should begin. | 501 // Once the non-preliminary capture happens, classification should begin. |
| 557 page_text = ASCIIToUTF16("phish"); | 502 page_text = ASCIIToUTF16("phish"); |
| 558 { | 503 { |
| 559 InSequence s; | 504 InSequence s; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 573 #define Maybe_DuplicatePageCapture DuplicatePageCapture | 518 #define Maybe_DuplicatePageCapture DuplicatePageCapture |
| 574 #endif | 519 #endif |
| 575 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, | 520 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, |
| 576 Maybe_DuplicatePageCapture) { | 521 Maybe_DuplicatePageCapture) { |
| 577 // Tests that a second PageCaptured notification causes classification to | 522 // Tests that a second PageCaptured notification causes classification to |
| 578 // be cancelled. | 523 // be cancelled. |
| 579 MockScorer scorer; | 524 MockScorer scorer; |
| 580 delegate_->SetPhishingScorer(&scorer); | 525 delegate_->SetPhishingScorer(&scorer); |
| 581 ASSERT_TRUE(classifier_->is_ready()); | 526 ASSERT_TRUE(classifier_->is_ready()); |
| 582 | 527 |
| 583 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 584 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); | 528 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); |
| 585 Mock::VerifyAndClearExpectations(classifier_); | 529 Mock::VerifyAndClearExpectations(classifier_); |
| 586 OnStartPhishingDetection(url); | 530 OnStartPhishingDetection(url); |
| 587 base::string16 page_text = ASCIIToUTF16("phish"); | 531 base::string16 page_text = ASCIIToUTF16("phish"); |
| 588 { | 532 { |
| 589 InSequence s; | 533 InSequence s; |
| 590 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 534 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 591 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); | 535 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); |
| 592 PageCaptured(&page_text, false); | 536 PageCaptured(&page_text, false); |
| 593 Mock::VerifyAndClearExpectations(classifier_); | 537 Mock::VerifyAndClearExpectations(classifier_); |
| 594 } | 538 } |
| 595 | 539 |
| 596 page_text = ASCIIToUTF16("phish"); | 540 page_text = ASCIIToUTF16("phish"); |
| 597 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 598 PageCaptured(&page_text, false); | 541 PageCaptured(&page_text, false); |
| 599 Mock::VerifyAndClearExpectations(classifier_); | 542 Mock::VerifyAndClearExpectations(classifier_); |
| 600 | 543 |
| 601 // The delegate will cancel pending classification on destruction. | 544 // The delegate will cancel pending classification on destruction. |
| 602 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 545 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 603 } | 546 } |
| 604 | 547 |
| 605 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, PhishingDetectionDone) { | 548 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, PhishingDetectionDone) { |
| 606 // Tests that a PhishingDetectionDone IPC is sent to the browser | 549 // Tests that a PhishingDetectionDone IPC is sent to the browser |
| 607 // whenever we finish classification. | 550 // whenever we finish classification. |
| 608 MockScorer scorer; | 551 MockScorer scorer; |
| 609 delegate_->SetPhishingScorer(&scorer); | 552 delegate_->SetPhishingScorer(&scorer); |
| 610 ASSERT_TRUE(classifier_->is_ready()); | 553 ASSERT_TRUE(classifier_->is_ready()); |
| 611 | 554 |
| 612 // Start by loading a page to populate the delegate's state. | 555 // Start by loading a page to populate the delegate's state. |
| 613 EXPECT_CALL(*classifier_, CancelPendingClassification()); | |
| 614 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); | 556 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); |
| 615 Mock::VerifyAndClearExpectations(classifier_); | 557 Mock::VerifyAndClearExpectations(classifier_); |
| 616 base::string16 page_text = ASCIIToUTF16("phish"); | 558 base::string16 page_text = ASCIIToUTF16("phish"); |
| 617 OnStartPhishingDetection(url); | 559 OnStartPhishingDetection(url); |
| 618 { | 560 { |
| 619 InSequence s; | 561 InSequence s; |
| 620 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 562 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 621 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); | 563 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); |
| 622 PageCaptured(&page_text, false); | 564 PageCaptured(&page_text, false); |
| 623 Mock::VerifyAndClearExpectations(classifier_); | 565 Mock::VerifyAndClearExpectations(classifier_); |
| 624 } | 566 } |
| 625 | 567 |
| 626 // Now run the callback to simulate the classifier finishing. | 568 // Now run the callback to simulate the classifier finishing. |
| 627 ClientPhishingRequest verdict; | 569 ClientPhishingRequest verdict; |
| 628 verdict.set_url(url.spec()); | 570 verdict.set_url(url.spec()); |
| 629 verdict.set_client_score(0.8f); | 571 verdict.set_client_score(0.8f); |
| 630 verdict.set_is_phishing(false); // Send IPC even if site is not phishing. | 572 verdict.set_is_phishing(false); // Send IPC even if site is not phishing. |
| 631 RunClassificationDone(verdict); | 573 RunClassificationDone(verdict); |
| 632 ASSERT_TRUE(intercepting_filter_->verdict()); | 574 ASSERT_TRUE(intercepting_filter_->verdict()); |
| 633 EXPECT_EQ(verdict.SerializeAsString(), | 575 EXPECT_EQ(verdict.SerializeAsString(), |
| 634 intercepting_filter_->verdict()->SerializeAsString()); | 576 intercepting_filter_->verdict()->SerializeAsString()); |
| 635 | 577 |
| 636 // The delegate will cancel pending classification on destruction. | 578 // The delegate will cancel pending classification on destruction. |
| 637 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 579 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 638 } | 580 } |
| 639 | 581 |
| 640 } // namespace safe_browsing | 582 } // namespace safe_browsing |
| OLD | NEW |