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 <list> | 5 #include <list> |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
10 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 10 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
11 #include "chrome/browser/safe_browsing/threat_details.h" | 11 #include "chrome/browser/safe_browsing/threat_details.h" |
12 #include "chrome/browser/safe_browsing/ui_manager.h" | 12 #include "chrome/browser/safe_browsing/ui_manager.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
15 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
16 #include "content/public/browser/interstitial_page.h" | 16 #include "content/public/browser/interstitial_page.h" |
17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "content/public/test/web_contents_tester.h" | 20 #include "content/public/test/web_contents_tester.h" |
(...skipping 25 matching lines...) Expand all Loading... |
46 : SafeBrowsingBlockingPage(manager, | 46 : SafeBrowsingBlockingPage(manager, |
47 web_contents, | 47 web_contents, |
48 main_frame_url, | 48 main_frame_url, |
49 unsafe_resources) { | 49 unsafe_resources) { |
50 // Don't delay details at all for the unittest. | 50 // Don't delay details at all for the unittest. |
51 threat_details_proceed_delay_ms_ = 0; | 51 threat_details_proceed_delay_ms_ = 0; |
52 DontCreateViewForTesting(); | 52 DontCreateViewForTesting(); |
53 } | 53 } |
54 }; | 54 }; |
55 | 55 |
56 class TestSafeBrowsingUIManager: public SafeBrowsingUIManager { | |
57 public: | |
58 explicit TestSafeBrowsingUIManager(SafeBrowsingService* service) | |
59 : SafeBrowsingUIManager(service) { | |
60 } | |
61 | |
62 void SendSerializedThreatDetails(const std::string& serialized) override { | |
63 details_.push_back(serialized); | |
64 } | |
65 | |
66 std::list<std::string>* GetDetails() { | |
67 return &details_; | |
68 } | |
69 | |
70 private: | |
71 ~TestSafeBrowsingUIManager() override {} | |
72 | |
73 std::list<std::string> details_; | |
74 }; | |
75 | |
76 class TestSafeBrowsingBlockingPageFactory | 56 class TestSafeBrowsingBlockingPageFactory |
77 : public SafeBrowsingBlockingPageFactory { | 57 : public SafeBrowsingBlockingPageFactory { |
78 public: | 58 public: |
79 TestSafeBrowsingBlockingPageFactory() { } | 59 TestSafeBrowsingBlockingPageFactory() { } |
80 ~TestSafeBrowsingBlockingPageFactory() override {} | 60 ~TestSafeBrowsingBlockingPageFactory() override {} |
81 | 61 |
82 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 62 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
83 SafeBrowsingUIManager* manager, | 63 SafeBrowsingUIManager* manager, |
84 WebContents* web_contents, | 64 WebContents* web_contents, |
85 const GURL& main_frame_url, | 65 const GURL& main_frame_url, |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 DontProceedThroughInterstitial(sb_interstitial); | 253 DontProceedThroughInterstitial(sb_interstitial); |
274 | 254 |
275 // The interstitial should be gone. | 255 // The interstitial should be gone. |
276 EXPECT_EQ(CANCEL, user_response()); | 256 EXPECT_EQ(CANCEL, user_response()); |
277 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 257 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
278 | 258 |
279 // We did not proceed, the pending entry should be gone. | 259 // We did not proceed, the pending entry should be gone. |
280 EXPECT_FALSE(controller().GetPendingEntry()); | 260 EXPECT_FALSE(controller().GetPendingEntry()); |
281 | 261 |
282 // A report should have been sent. | 262 // A report should have been sent. |
283 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 263 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
284 ui_manager_->GetDetails()->clear(); | 264 ui_manager_->GetThreatDetails()->clear(); |
285 } | 265 } |
286 | 266 |
287 // Tests showing a blocking page for a malware page and then proceeding. | 267 // Tests showing a blocking page for a malware page and then proceeding. |
288 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { | 268 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { |
289 // Enable malware reports. | 269 // Enable malware reports. |
290 Profile* profile = Profile::FromBrowserContext( | 270 Profile* profile = Profile::FromBrowserContext( |
291 web_contents()->GetBrowserContext()); | 271 web_contents()->GetBrowserContext()); |
292 profile->GetPrefs()->SetBoolean( | 272 profile->GetPrefs()->SetBoolean( |
293 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 273 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
294 | 274 |
(...skipping 11 matching lines...) Expand all Loading... |
306 ProceedThroughInterstitial(sb_interstitial); | 286 ProceedThroughInterstitial(sb_interstitial); |
307 | 287 |
308 // The interstitial is shown until the navigation commits. | 288 // The interstitial is shown until the navigation commits. |
309 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents())); | 289 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents())); |
310 // Commit the navigation. | 290 // Commit the navigation. |
311 Navigate(kBadURL, 1, pending_id, true); | 291 Navigate(kBadURL, 1, pending_id, true); |
312 // The interstitial should be gone now. | 292 // The interstitial should be gone now. |
313 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents())); | 293 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents())); |
314 | 294 |
315 // A report should have been sent. | 295 // A report should have been sent. |
316 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 296 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
317 ui_manager_->GetDetails()->clear(); | 297 ui_manager_->GetThreatDetails()->clear(); |
318 } | 298 } |
319 | 299 |
320 // Tests showing a blocking page for a page that contains malware subresources | 300 // Tests showing a blocking page for a page that contains malware subresources |
321 // and not proceeding. | 301 // and not proceeding. |
322 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { | 302 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { |
323 // Enable malware reports. | 303 // Enable malware reports. |
324 Profile* profile = Profile::FromBrowserContext( | 304 Profile* profile = Profile::FromBrowserContext( |
325 web_contents()->GetBrowserContext()); | 305 web_contents()->GetBrowserContext()); |
326 profile->GetPrefs()->SetBoolean( | 306 profile->GetPrefs()->SetBoolean( |
327 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 307 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
(...skipping 14 matching lines...) Expand all Loading... |
342 DontProceedThroughSubresourceInterstitial(sb_interstitial); | 322 DontProceedThroughSubresourceInterstitial(sb_interstitial); |
343 EXPECT_EQ(CANCEL, user_response()); | 323 EXPECT_EQ(CANCEL, user_response()); |
344 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 324 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
345 | 325 |
346 // We did not proceed, we should be back to the first page, the 2nd one should | 326 // We did not proceed, we should be back to the first page, the 2nd one should |
347 // have been removed from the navigation controller. | 327 // have been removed from the navigation controller. |
348 ASSERT_EQ(1, controller().GetEntryCount()); | 328 ASSERT_EQ(1, controller().GetEntryCount()); |
349 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | 329 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); |
350 | 330 |
351 // A report should have been sent. | 331 // A report should have been sent. |
352 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 332 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
353 ui_manager_->GetDetails()->clear(); | 333 ui_manager_->GetThreatDetails()->clear(); |
354 } | 334 } |
355 | 335 |
356 // Tests showing a blocking page for a page that contains malware subresources | 336 // Tests showing a blocking page for a page that contains malware subresources |
357 // and proceeding. | 337 // and proceeding. |
358 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { | 338 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { |
359 // Enable malware reports. | 339 // Enable malware reports. |
360 Profile* profile = Profile::FromBrowserContext( | 340 Profile* profile = Profile::FromBrowserContext( |
361 web_contents()->GetBrowserContext()); | 341 web_contents()->GetBrowserContext()); |
362 profile->GetPrefs()->SetBoolean( | 342 profile->GetPrefs()->SetBoolean( |
363 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 343 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
(...skipping 10 matching lines...) Expand all Loading... |
374 // Simulate the user clicking "proceed". | 354 // Simulate the user clicking "proceed". |
375 ProceedThroughInterstitial(sb_interstitial); | 355 ProceedThroughInterstitial(sb_interstitial); |
376 EXPECT_EQ(OK, user_response()); | 356 EXPECT_EQ(OK, user_response()); |
377 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 357 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
378 | 358 |
379 // We did proceed, we should be back to showing the page. | 359 // We did proceed, we should be back to showing the page. |
380 ASSERT_EQ(1, controller().GetEntryCount()); | 360 ASSERT_EQ(1, controller().GetEntryCount()); |
381 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); | 361 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); |
382 | 362 |
383 // A report should have been sent. | 363 // A report should have been sent. |
384 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 364 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
385 ui_manager_->GetDetails()->clear(); | 365 ui_manager_->GetThreatDetails()->clear(); |
386 } | 366 } |
387 | 367 |
388 // Tests showing a blocking page for a page that contains multiple malware | 368 // Tests showing a blocking page for a page that contains multiple malware |
389 // subresources and not proceeding. This just tests that the extra malware | 369 // subresources and not proceeding. This just tests that the extra malware |
390 // subresources (which trigger queued interstitial pages) do not break anything. | 370 // subresources (which trigger queued interstitial pages) do not break anything. |
391 TEST_F(SafeBrowsingBlockingPageTest, | 371 TEST_F(SafeBrowsingBlockingPageTest, |
392 PageWithMultipleMalwareResourceDontProceed) { | 372 PageWithMultipleMalwareResourceDontProceed) { |
393 // Enable malware reports. | 373 // Enable malware reports. |
394 Profile* profile = Profile::FromBrowserContext( | 374 Profile* profile = Profile::FromBrowserContext( |
395 web_contents()->GetBrowserContext()); | 375 web_contents()->GetBrowserContext()); |
(...skipping 21 matching lines...) Expand all Loading... |
417 DontProceedThroughSubresourceInterstitial(sb_interstitial); | 397 DontProceedThroughSubresourceInterstitial(sb_interstitial); |
418 EXPECT_EQ(CANCEL, user_response()); | 398 EXPECT_EQ(CANCEL, user_response()); |
419 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 399 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
420 | 400 |
421 // We did not proceed, we should be back to the first page, the 2nd one should | 401 // We did not proceed, we should be back to the first page, the 2nd one should |
422 // have been removed from the navigation controller. | 402 // have been removed from the navigation controller. |
423 ASSERT_EQ(1, controller().GetEntryCount()); | 403 ASSERT_EQ(1, controller().GetEntryCount()); |
424 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | 404 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); |
425 | 405 |
426 // A report should have been sent. | 406 // A report should have been sent. |
427 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 407 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
428 ui_manager_->GetDetails()->clear(); | 408 ui_manager_->GetThreatDetails()->clear(); |
429 } | 409 } |
430 | 410 |
431 // Tests showing a blocking page for a page that contains multiple malware | 411 // Tests showing a blocking page for a page that contains multiple malware |
432 // subresources and proceeding through the first interstitial, but not the next. | 412 // subresources and proceeding through the first interstitial, but not the next. |
433 TEST_F(SafeBrowsingBlockingPageTest, | 413 TEST_F(SafeBrowsingBlockingPageTest, |
434 PageWithMultipleMalwareResourceProceedThenDontProceed) { | 414 PageWithMultipleMalwareResourceProceedThenDontProceed) { |
435 // Enable malware reports. | 415 // Enable malware reports. |
436 Profile* profile = Profile::FromBrowserContext( | 416 Profile* profile = Profile::FromBrowserContext( |
437 web_contents()->GetBrowserContext()); | 417 web_contents()->GetBrowserContext()); |
438 profile->GetPrefs()->SetBoolean( | 418 profile->GetPrefs()->SetBoolean( |
(...skipping 14 matching lines...) Expand all Loading... |
453 ShowInterstitial(true, kBadURL3); | 433 ShowInterstitial(true, kBadURL3); |
454 | 434 |
455 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 435 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
456 ASSERT_TRUE(sb_interstitial); | 436 ASSERT_TRUE(sb_interstitial); |
457 | 437 |
458 // Proceed through the 1st interstitial. | 438 // Proceed through the 1st interstitial. |
459 ProceedThroughInterstitial(sb_interstitial); | 439 ProceedThroughInterstitial(sb_interstitial); |
460 EXPECT_EQ(OK, user_response()); | 440 EXPECT_EQ(OK, user_response()); |
461 | 441 |
462 // A report should have been sent. | 442 // A report should have been sent. |
463 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 443 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
464 ui_manager_->GetDetails()->clear(); | 444 ui_manager_->GetThreatDetails()->clear(); |
465 | 445 |
466 ResetUserResponse(); | 446 ResetUserResponse(); |
467 | 447 |
468 // We should land to a 2nd interstitial (aggregating all the malware resources | 448 // We should land to a 2nd interstitial (aggregating all the malware resources |
469 // loaded while the 1st interstitial was showing). | 449 // loaded while the 1st interstitial was showing). |
470 sb_interstitial = GetSafeBrowsingBlockingPage(); | 450 sb_interstitial = GetSafeBrowsingBlockingPage(); |
471 ASSERT_TRUE(sb_interstitial); | 451 ASSERT_TRUE(sb_interstitial); |
472 | 452 |
473 // Don't proceed through the 2nd interstitial. | 453 // Don't proceed through the 2nd interstitial. |
474 DontProceedThroughSubresourceInterstitial(sb_interstitial); | 454 DontProceedThroughSubresourceInterstitial(sb_interstitial); |
475 EXPECT_EQ(CANCEL, user_response()); | 455 EXPECT_EQ(CANCEL, user_response()); |
476 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 456 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
477 | 457 |
478 // We did not proceed, we should be back to the first page, the 2nd one should | 458 // We did not proceed, we should be back to the first page, the 2nd one should |
479 // have been removed from the navigation controller. | 459 // have been removed from the navigation controller. |
480 ASSERT_EQ(1, controller().GetEntryCount()); | 460 ASSERT_EQ(1, controller().GetEntryCount()); |
481 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | 461 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); |
482 | 462 |
483 // No report should have been sent -- we don't create a report the | 463 // No report should have been sent -- we don't create a report the |
484 // second time. | 464 // second time. |
485 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 465 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
486 ui_manager_->GetDetails()->clear(); | 466 ui_manager_->GetThreatDetails()->clear(); |
487 } | 467 } |
488 | 468 |
489 // Tests showing a blocking page for a page that contains multiple malware | 469 // Tests showing a blocking page for a page that contains multiple malware |
490 // subresources and proceeding through the multiple interstitials. | 470 // subresources and proceeding through the multiple interstitials. |
491 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { | 471 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { |
492 // Enable malware reports. | 472 // Enable malware reports. |
493 Profile* profile = Profile::FromBrowserContext( | 473 Profile* profile = Profile::FromBrowserContext( |
494 web_contents()->GetBrowserContext()); | 474 web_contents()->GetBrowserContext()); |
495 profile->GetPrefs()->SetBoolean( | 475 profile->GetPrefs()->SetBoolean( |
496 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 476 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
(...skipping 10 matching lines...) Expand all Loading... |
507 ShowInterstitial(true, kBadURL3); | 487 ShowInterstitial(true, kBadURL3); |
508 | 488 |
509 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 489 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
510 ASSERT_TRUE(sb_interstitial); | 490 ASSERT_TRUE(sb_interstitial); |
511 | 491 |
512 // Proceed through the 1st interstitial. | 492 // Proceed through the 1st interstitial. |
513 ProceedThroughInterstitial(sb_interstitial); | 493 ProceedThroughInterstitial(sb_interstitial); |
514 EXPECT_EQ(OK, user_response()); | 494 EXPECT_EQ(OK, user_response()); |
515 | 495 |
516 // A report should have been sent. | 496 // A report should have been sent. |
517 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 497 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
518 ui_manager_->GetDetails()->clear(); | 498 ui_manager_->GetThreatDetails()->clear(); |
519 | 499 |
520 ResetUserResponse(); | 500 ResetUserResponse(); |
521 | 501 |
522 // We should land to a 2nd interstitial (aggregating all the malware resources | 502 // We should land to a 2nd interstitial (aggregating all the malware resources |
523 // loaded while the 1st interstitial was showing). | 503 // loaded while the 1st interstitial was showing). |
524 sb_interstitial = GetSafeBrowsingBlockingPage(); | 504 sb_interstitial = GetSafeBrowsingBlockingPage(); |
525 ASSERT_TRUE(sb_interstitial); | 505 ASSERT_TRUE(sb_interstitial); |
526 | 506 |
527 // Proceed through the 2nd interstitial. | 507 // Proceed through the 2nd interstitial. |
528 ProceedThroughInterstitial(sb_interstitial); | 508 ProceedThroughInterstitial(sb_interstitial); |
529 EXPECT_EQ(OK, user_response()); | 509 EXPECT_EQ(OK, user_response()); |
530 | 510 |
531 // We did proceed, we should be back to the initial page. | 511 // We did proceed, we should be back to the initial page. |
532 ASSERT_EQ(1, controller().GetEntryCount()); | 512 ASSERT_EQ(1, controller().GetEntryCount()); |
533 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); | 513 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); |
534 | 514 |
535 // No report should have been sent -- we don't create a report the | 515 // No report should have been sent -- we don't create a report the |
536 // second time. | 516 // second time. |
537 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 517 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
538 ui_manager_->GetDetails()->clear(); | 518 ui_manager_->GetThreatDetails()->clear(); |
539 } | 519 } |
540 | 520 |
541 // Tests showing a blocking page then navigating back and forth to make sure the | 521 // Tests showing a blocking page then navigating back and forth to make sure the |
542 // controller entries are OK. http://crbug.com/17627 | 522 // controller entries are OK. http://crbug.com/17627 |
543 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { | 523 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { |
544 // Enable malware reports. | 524 // Enable malware reports. |
545 Profile* profile = Profile::FromBrowserContext( | 525 Profile* profile = Profile::FromBrowserContext( |
546 web_contents()->GetBrowserContext()); | 526 web_contents()->GetBrowserContext()); |
547 profile->GetPrefs()->SetBoolean( | 527 profile->GetPrefs()->SetBoolean( |
548 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 528 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
(...skipping 30 matching lines...) Expand all Loading... |
579 // Let's proceed and make sure everything is OK (bug 17627). | 559 // Let's proceed and make sure everything is OK (bug 17627). |
580 ProceedThroughInterstitial(sb_interstitial); | 560 ProceedThroughInterstitial(sb_interstitial); |
581 // Commit the navigation. | 561 // Commit the navigation. |
582 NavigateCrossSite(kBadURL, 2, pending_id, false); | 562 NavigateCrossSite(kBadURL, 2, pending_id, false); |
583 sb_interstitial = GetSafeBrowsingBlockingPage(); | 563 sb_interstitial = GetSafeBrowsingBlockingPage(); |
584 ASSERT_FALSE(sb_interstitial); | 564 ASSERT_FALSE(sb_interstitial); |
585 ASSERT_EQ(2, controller().GetEntryCount()); | 565 ASSERT_EQ(2, controller().GetEntryCount()); |
586 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec()); | 566 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec()); |
587 | 567 |
588 // Two reports should have been sent. | 568 // Two reports should have been sent. |
589 EXPECT_EQ(2u, ui_manager_->GetDetails()->size()); | 569 EXPECT_EQ(2u, ui_manager_->GetThreatDetails()->size()); |
590 ui_manager_->GetDetails()->clear(); | 570 ui_manager_->GetThreatDetails()->clear(); |
591 } | 571 } |
592 | 572 |
593 // Tests that calling "don't proceed" after "proceed" has been called doesn't | 573 // Tests that calling "don't proceed" after "proceed" has been called doesn't |
594 // cause problems. http://crbug.com/30079 | 574 // cause problems. http://crbug.com/30079 |
595 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { | 575 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { |
596 // Enable malware reports. | 576 // Enable malware reports. |
597 Profile* profile = Profile::FromBrowserContext( | 577 Profile* profile = Profile::FromBrowserContext( |
598 web_contents()->GetBrowserContext()); | 578 web_contents()->GetBrowserContext()); |
599 profile->GetPrefs()->SetBoolean( | 579 profile->GetPrefs()->SetBoolean( |
600 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 580 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
(...skipping 15 matching lines...) Expand all Loading... |
616 sb_interstitial->interstitial_page()->DontProceed(); | 596 sb_interstitial->interstitial_page()->DontProceed(); |
617 // Proceed() and DontProceed() post a task to update the | 597 // Proceed() and DontProceed() post a task to update the |
618 // SafeBrowsingService::Client. | 598 // SafeBrowsingService::Client. |
619 base::RunLoop().RunUntilIdle(); | 599 base::RunLoop().RunUntilIdle(); |
620 | 600 |
621 // The interstitial should be gone. | 601 // The interstitial should be gone. |
622 EXPECT_EQ(OK, user_response()); | 602 EXPECT_EQ(OK, user_response()); |
623 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 603 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
624 | 604 |
625 // Only one report should have been sent. | 605 // Only one report should have been sent. |
626 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 606 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
627 ui_manager_->GetDetails()->clear(); | 607 ui_manager_->GetThreatDetails()->clear(); |
628 } | 608 } |
629 | 609 |
630 // Tests showing a blocking page for a malware page with reports disabled. | 610 // Tests showing a blocking page for a malware page with reports disabled. |
631 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { | 611 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { |
632 // Disable malware reports. | 612 // Disable malware reports. |
633 Profile* profile = Profile::FromBrowserContext( | 613 Profile* profile = Profile::FromBrowserContext( |
634 web_contents()->GetBrowserContext()); | 614 web_contents()->GetBrowserContext()); |
635 profile->GetPrefs()->SetBoolean( | 615 profile->GetPrefs()->SetBoolean( |
636 prefs::kSafeBrowsingExtendedReportingEnabled, false); | 616 prefs::kSafeBrowsingExtendedReportingEnabled, false); |
637 | 617 |
(...skipping 13 matching lines...) Expand all Loading... |
651 DontProceedThroughInterstitial(sb_interstitial); | 631 DontProceedThroughInterstitial(sb_interstitial); |
652 | 632 |
653 // The interstitial should be gone. | 633 // The interstitial should be gone. |
654 EXPECT_EQ(CANCEL, user_response()); | 634 EXPECT_EQ(CANCEL, user_response()); |
655 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 635 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
656 | 636 |
657 // We did not proceed, the pending entry should be gone. | 637 // We did not proceed, the pending entry should be gone. |
658 EXPECT_FALSE(controller().GetPendingEntry()); | 638 EXPECT_FALSE(controller().GetPendingEntry()); |
659 | 639 |
660 // No report should have been sent. | 640 // No report should have been sent. |
661 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 641 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
662 ui_manager_->GetDetails()->clear(); | 642 ui_manager_->GetThreatDetails()->clear(); |
663 } | 643 } |
664 | 644 |
665 // Test that toggling the checkbox has the anticipated effects. | 645 // Test that toggling the checkbox has the anticipated effects. |
666 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) { | 646 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) { |
667 // Disable malware reports. | 647 // Disable malware reports. |
668 Profile* profile = Profile::FromBrowserContext( | 648 Profile* profile = Profile::FromBrowserContext( |
669 web_contents()->GetBrowserContext()); | 649 web_contents()->GetBrowserContext()); |
670 profile->GetPrefs()->SetBoolean( | 650 profile->GetPrefs()->SetBoolean( |
671 prefs::kSafeBrowsingExtendedReportingEnabled, false); | 651 prefs::kSafeBrowsingExtendedReportingEnabled, false); |
672 | 652 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 base::RunLoop().RunUntilIdle(); | 700 base::RunLoop().RunUntilIdle(); |
721 | 701 |
722 // Simulate the user clicking "don't proceed". | 702 // Simulate the user clicking "don't proceed". |
723 DontProceedThroughInterstitial(sb_interstitial); | 703 DontProceedThroughInterstitial(sb_interstitial); |
724 | 704 |
725 // The interstitial should be gone. | 705 // The interstitial should be gone. |
726 EXPECT_EQ(CANCEL, user_response()); | 706 EXPECT_EQ(CANCEL, user_response()); |
727 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 707 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
728 | 708 |
729 // No report should have been sent. | 709 // No report should have been sent. |
730 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 710 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
731 ui_manager_->GetDetails()->clear(); | 711 ui_manager_->GetThreatDetails()->clear(); |
732 } | 712 } |
733 | 713 |
734 // Test that extended reporting option is not shown on blocking an HTTPS | 714 // Test that extended reporting option is not shown on blocking an HTTPS |
735 // subresource on an HTTPS page, and no report is sent. | 715 // subresource on an HTTPS page, and no report is sent. |
736 TEST_F(SafeBrowsingBlockingPageTest, | 716 TEST_F(SafeBrowsingBlockingPageTest, |
737 ExtendedReportingNotShownOnSecurePageWithSecureSubresource) { | 717 ExtendedReportingNotShownOnSecurePageWithSecureSubresource) { |
738 // Enable malware details. | 718 // Enable malware details. |
739 Profile* profile = Profile::FromBrowserContext( | 719 Profile* profile = Profile::FromBrowserContext( |
740 web_contents()->GetBrowserContext()); | 720 web_contents()->GetBrowserContext()); |
741 profile->GetPrefs()->SetBoolean( | 721 profile->GetPrefs()->SetBoolean( |
(...skipping 13 matching lines...) Expand all Loading... |
755 base::RunLoop().RunUntilIdle(); | 735 base::RunLoop().RunUntilIdle(); |
756 | 736 |
757 // Simulate the user clicking "don't proceed". | 737 // Simulate the user clicking "don't proceed". |
758 DontProceedThroughInterstitial(sb_interstitial); | 738 DontProceedThroughInterstitial(sb_interstitial); |
759 | 739 |
760 // The interstitial should be gone. | 740 // The interstitial should be gone. |
761 EXPECT_EQ(CANCEL, user_response()); | 741 EXPECT_EQ(CANCEL, user_response()); |
762 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 742 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
763 | 743 |
764 // No report should have been sent. | 744 // No report should have been sent. |
765 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 745 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
766 ui_manager_->GetDetails()->clear(); | 746 ui_manager_->GetThreatDetails()->clear(); |
767 } | 747 } |
768 | 748 |
769 // Test that extended reporting option is not shown on blocking an HTTP | 749 // Test that extended reporting option is not shown on blocking an HTTP |
770 // subresource on an HTTPS page, and no report is sent. | 750 // subresource on an HTTPS page, and no report is sent. |
771 TEST_F(SafeBrowsingBlockingPageTest, | 751 TEST_F(SafeBrowsingBlockingPageTest, |
772 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource) { | 752 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource) { |
773 // Enable malware details. | 753 // Enable malware details. |
774 Profile* profile = Profile::FromBrowserContext( | 754 Profile* profile = Profile::FromBrowserContext( |
775 web_contents()->GetBrowserContext()); | 755 web_contents()->GetBrowserContext()); |
776 profile->GetPrefs()->SetBoolean( | 756 profile->GetPrefs()->SetBoolean( |
(...skipping 13 matching lines...) Expand all Loading... |
790 base::RunLoop().RunUntilIdle(); | 770 base::RunLoop().RunUntilIdle(); |
791 | 771 |
792 // Simulate the user clicking "don't proceed". | 772 // Simulate the user clicking "don't proceed". |
793 DontProceedThroughInterstitial(sb_interstitial); | 773 DontProceedThroughInterstitial(sb_interstitial); |
794 | 774 |
795 // The interstitial should be gone. | 775 // The interstitial should be gone. |
796 EXPECT_EQ(CANCEL, user_response()); | 776 EXPECT_EQ(CANCEL, user_response()); |
797 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 777 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
798 | 778 |
799 // No report should have been sent. | 779 // No report should have been sent. |
800 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 780 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
801 ui_manager_->GetDetails()->clear(); | 781 ui_manager_->GetThreatDetails()->clear(); |
802 } | 782 } |
803 | 783 |
804 // Test that extended reporting option is shown on blocking an HTTPS | 784 // Test that extended reporting option is shown on blocking an HTTPS |
805 // subresource on an HTTP page. | 785 // subresource on an HTTP page. |
806 TEST_F(SafeBrowsingBlockingPageTest, | 786 TEST_F(SafeBrowsingBlockingPageTest, |
807 ExtendedReportingOnInsecurePageWithSecureSubresource) { | 787 ExtendedReportingOnInsecurePageWithSecureSubresource) { |
808 // Enable malware details. | 788 // Enable malware details. |
809 Profile* profile = Profile::FromBrowserContext( | 789 Profile* profile = Profile::FromBrowserContext( |
810 web_contents()->GetBrowserContext()); | 790 web_contents()->GetBrowserContext()); |
811 profile->GetPrefs()->SetBoolean( | 791 profile->GetPrefs()->SetBoolean( |
(...skipping 13 matching lines...) Expand all Loading... |
825 base::RunLoop().RunUntilIdle(); | 805 base::RunLoop().RunUntilIdle(); |
826 | 806 |
827 // Simulate the user clicking "don't proceed". | 807 // Simulate the user clicking "don't proceed". |
828 DontProceedThroughInterstitial(sb_interstitial); | 808 DontProceedThroughInterstitial(sb_interstitial); |
829 | 809 |
830 // The interstitial should be gone. | 810 // The interstitial should be gone. |
831 EXPECT_EQ(CANCEL, user_response()); | 811 EXPECT_EQ(CANCEL, user_response()); |
832 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 812 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
833 | 813 |
834 // A report should have been sent. | 814 // A report should have been sent. |
835 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 815 EXPECT_EQ(1u, ui_manager_->GetThreatDetails()->size()); |
836 ui_manager_->GetDetails()->clear(); | 816 ui_manager_->GetThreatDetails()->clear(); |
837 } | 817 } |
838 | 818 |
839 // Test that extended reporting option is not shown on blocking an HTTPS | 819 // Test that extended reporting option is not shown on blocking an HTTPS |
840 // subresource on an HTTPS page while there is a pending load for an HTTP page, | 820 // subresource on an HTTPS page while there is a pending load for an HTTP page, |
841 // and no report is sent. | 821 // and no report is sent. |
842 TEST_F(SafeBrowsingBlockingPageTest, | 822 TEST_F(SafeBrowsingBlockingPageTest, |
843 ExtendedReportingNotShownOnSecurePageWithPendingInsecureLoad) { | 823 ExtendedReportingNotShownOnSecurePageWithPendingInsecureLoad) { |
844 // Enable malware details. | 824 // Enable malware details. |
845 Profile* profile = Profile::FromBrowserContext( | 825 Profile* profile = Profile::FromBrowserContext( |
846 web_contents()->GetBrowserContext()); | 826 web_contents()->GetBrowserContext()); |
(...skipping 21 matching lines...) Expand all Loading... |
868 base::RunLoop().RunUntilIdle(); | 848 base::RunLoop().RunUntilIdle(); |
869 | 849 |
870 // Simulate the user clicking "don't proceed". | 850 // Simulate the user clicking "don't proceed". |
871 DontProceedThroughInterstitial(sb_interstitial); | 851 DontProceedThroughInterstitial(sb_interstitial); |
872 | 852 |
873 // The interstitial should be gone. | 853 // The interstitial should be gone. |
874 EXPECT_EQ(CANCEL, user_response()); | 854 EXPECT_EQ(CANCEL, user_response()); |
875 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 855 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
876 | 856 |
877 // No report should have been sent. | 857 // No report should have been sent. |
878 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 858 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
879 ui_manager_->GetDetails()->clear(); | 859 ui_manager_->GetThreatDetails()->clear(); |
880 } | 860 } |
881 | 861 |
882 // TODO(mattm): Add test for extended reporting not shown or sent in incognito | 862 // TODO(mattm): Add test for extended reporting not shown or sent in incognito |
883 // window. | 863 // window. |
884 | 864 |
885 } // namespace safe_browsing | 865 } // namespace safe_browsing |
OLD | NEW |