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
3 // found in the LICENSE file.
7 #include "base/prefs/pref_service.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/safe_browsing/malware_details.h"
11 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 #include "chrome/browser/safe_browsing/ui_manager.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "content/public/browser/interstitial_page.h"
17 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/web_contents_tester.h"
22 using content::InterstitialPage
;
23 using content::NavigationEntry
;
24 using content::WebContents
;
25 using content::WebContentsTester
;
27 static const char* kGoogleURL
= "http://www.google.com/";
28 static const char* kGoodURL
= "http://www.goodguys.com/";
29 static const char* kBadURL
= "http://www.badguys.com/";
30 static const char* kBadURL2
= "http://www.badguys2.com/";
31 static const char* kBadURL3
= "http://www.badguys3.com/";
35 // A SafeBrowingBlockingPage class that does not create windows.
36 class TestSafeBrowsingBlockingPage
: public SafeBrowsingBlockingPage
{
38 TestSafeBrowsingBlockingPage(SafeBrowsingUIManager
* manager
,
39 WebContents
* web_contents
,
40 const UnsafeResourceList
& unsafe_resources
)
41 : SafeBrowsingBlockingPage(manager
, web_contents
, unsafe_resources
) {
42 // Don't delay details at all for the unittest.
43 malware_details_proceed_delay_ms_
= 0;
44 DontCreateViewForTesting();
48 class TestSafeBrowsingUIManager
: public SafeBrowsingUIManager
{
50 explicit TestSafeBrowsingUIManager(SafeBrowsingService
* service
)
51 : SafeBrowsingUIManager(service
) {
54 void SendSerializedMalwareDetails(const std::string
& serialized
) override
{
55 details_
.push_back(serialized
);
58 std::list
<std::string
>* GetDetails() {
63 ~TestSafeBrowsingUIManager() override
{}
65 std::list
<std::string
> details_
;
68 class TestSafeBrowsingBlockingPageFactory
69 : public SafeBrowsingBlockingPageFactory
{
71 TestSafeBrowsingBlockingPageFactory() { }
72 ~TestSafeBrowsingBlockingPageFactory() override
{}
74 SafeBrowsingBlockingPage
* CreateSafeBrowsingPage(
75 SafeBrowsingUIManager
* manager
,
76 WebContents
* web_contents
,
77 const SafeBrowsingBlockingPage::UnsafeResourceList
& unsafe_resources
)
79 return new TestSafeBrowsingBlockingPage(manager
, web_contents
,
86 class SafeBrowsingBlockingPageTest
: public ChromeRenderViewHostTestHarness
{
88 // The decision the user made.
95 SafeBrowsingBlockingPageTest() {
97 // The safe browsing UI manager does not need a service for this test.
98 ui_manager_
= new TestSafeBrowsingUIManager(NULL
);
101 void SetUp() override
{
102 ChromeRenderViewHostTestHarness::SetUp();
103 SafeBrowsingBlockingPage::RegisterFactory(&factory_
);
107 void TearDown() override
{
108 // Release the UI manager before the BrowserThreads are destroyed.
110 SafeBrowsingBlockingPage::RegisterFactory(NULL
);
111 // Clean up singleton reference (crbug.com/110594).
112 MalwareDetails::RegisterFactory(NULL
);
113 ChromeRenderViewHostTestHarness::TearDown();
116 void OnBlockingPageComplete(bool proceed
) {
120 user_response_
= CANCEL
;
123 void Navigate(const char* url
,
126 bool did_create_new_entry
) {
127 NavigateInternal(url
, page_id
, nav_entry_id
, did_create_new_entry
, false);
130 void NavigateCrossSite(const char* url
,
133 bool did_create_new_entry
) {
134 NavigateInternal(url
, page_id
, nav_entry_id
, did_create_new_entry
, true);
137 void NavigateInternal(const char* url
,
140 bool did_create_new_entry
,
141 bool is_cross_site
) {
142 // The pending RVH should commit for cross-site navigations.
143 content::RenderFrameHost
* render_frame_host
=
145 ? content::WebContentsTester::For(web_contents())
146 ->GetPendingMainFrame()
147 : web_contents()->GetMainFrame();
149 content::WebContentsTester::For(web_contents())
150 ->TestDidNavigate(render_frame_host
, page_id
, nav_entry_id
,
151 did_create_new_entry
, GURL(url
),
152 ui::PAGE_TRANSITION_TYPED
);
155 void GoBack(bool is_cross_site
) {
156 NavigationEntry
* entry
=
157 web_contents()->GetController().GetEntryAtOffset(-1);
159 web_contents()->GetController().GoBack();
161 // The pending RVH should commit for cross-site navigations.
162 content::RenderFrameHost
* rfh
= is_cross_site
?
163 WebContentsTester::For(web_contents())->GetPendingMainFrame() :
164 web_contents()->GetMainFrame();
165 WebContentsTester::For(web_contents())->TestDidNavigate(
168 entry
->GetUniqueID(),
171 ui::PAGE_TRANSITION_TYPED
);
174 void ShowInterstitial(bool is_subresource
, const char* url
) {
175 SafeBrowsingUIManager::UnsafeResource resource
;
176 InitResource(&resource
, is_subresource
, GURL(url
));
177 SafeBrowsingBlockingPage::ShowBlockingPage(ui_manager_
.get(), resource
);
180 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is
182 SafeBrowsingBlockingPage
* GetSafeBrowsingBlockingPage() {
183 InterstitialPage
* interstitial
=
184 InterstitialPage::GetInterstitialPage(web_contents());
187 return static_cast<SafeBrowsingBlockingPage
*>(
188 interstitial
->GetDelegateForTesting());
191 UserResponse
user_response() const { return user_response_
; }
192 void ResetUserResponse() { user_response_
= PENDING
; }
194 static void ProceedThroughInterstitial(
195 SafeBrowsingBlockingPage
* sb_interstitial
) {
196 sb_interstitial
->interstitial_page()->Proceed();
197 // Proceed() posts a task to update the SafeBrowsingService::Client.
198 base::RunLoop().RunUntilIdle();
201 static void DontProceedThroughInterstitial(
202 SafeBrowsingBlockingPage
* sb_interstitial
) {
203 sb_interstitial
->interstitial_page()->DontProceed();
204 // DontProceed() posts a task to update the SafeBrowsingService::Client.
205 base::RunLoop().RunUntilIdle();
208 void DontProceedThroughSubresourceInterstitial(
209 SafeBrowsingBlockingPage
* sb_interstitial
) {
210 // CommandReceived(kTakeMeBackCommand) does a back navigation for
211 // subresource interstitials.
213 // DontProceed() posts a task to update the SafeBrowsingService::Client.
214 base::RunLoop().RunUntilIdle();
217 scoped_refptr
<TestSafeBrowsingUIManager
> ui_manager_
;
220 void InitResource(SafeBrowsingUIManager::UnsafeResource
* resource
,
224 base::Bind(&SafeBrowsingBlockingPageTest::OnBlockingPageComplete
,
225 base::Unretained(this));
227 resource
->is_subresource
= is_subresource
;
228 resource
->threat_type
= SB_THREAT_TYPE_URL_MALWARE
;
229 resource
->render_process_host_id
=
230 web_contents()->GetRenderProcessHost()->GetID();
231 resource
->render_view_id
=
232 web_contents()->GetRenderViewHost()->GetRoutingID();
233 resource
->threat_source
= SafeBrowsingUIManager::FROM_DEVICE
;
236 UserResponse user_response_
;
237 TestSafeBrowsingBlockingPageFactory factory_
;
241 // Tests showing a blocking page for a malware page and not proceeding.
242 TEST_F(SafeBrowsingBlockingPageTest
, MalwarePageDontProceed
) {
243 // Enable malware details.
244 Profile
* profile
= Profile::FromBrowserContext(
245 web_contents()->GetBrowserContext());
246 profile
->GetPrefs()->SetBoolean(
247 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
250 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
251 ui::PAGE_TRANSITION_TYPED
, std::string());
254 // Simulate the load causing a safe browsing interstitial to be shown.
255 ShowInterstitial(false, kBadURL
);
256 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
257 ASSERT_TRUE(sb_interstitial
);
259 base::RunLoop().RunUntilIdle();
261 // Simulate the user clicking "don't proceed".
262 DontProceedThroughInterstitial(sb_interstitial
);
264 // The interstitial should be gone.
265 EXPECT_EQ(CANCEL
, user_response());
266 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
268 // We did not proceed, the pending entry should be gone.
269 EXPECT_FALSE(controller().GetPendingEntry());
271 // A report should have been sent.
272 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
273 ui_manager_
->GetDetails()->clear();
276 // Tests showing a blocking page for a malware page and then proceeding.
277 TEST_F(SafeBrowsingBlockingPageTest
, MalwarePageProceed
) {
278 // Enable malware reports.
279 Profile
* profile
= Profile::FromBrowserContext(
280 web_contents()->GetBrowserContext());
281 profile
->GetPrefs()->SetBoolean(
282 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
285 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
286 ui::PAGE_TRANSITION_TYPED
, std::string());
287 int pending_id
= controller().GetPendingEntry()->GetUniqueID();
289 // Simulate the load causing a safe browsing interstitial to be shown.
290 ShowInterstitial(false, kBadURL
);
291 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
292 ASSERT_TRUE(sb_interstitial
);
294 // Simulate the user clicking "proceed".
295 ProceedThroughInterstitial(sb_interstitial
);
297 // The interstitial is shown until the navigation commits.
298 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents()));
299 // Commit the navigation.
300 Navigate(kBadURL
, 1, pending_id
, true);
301 // The interstitial should be gone now.
302 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents()));
304 // A report should have been sent.
305 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
306 ui_manager_
->GetDetails()->clear();
309 // Tests showing a blocking page for a page that contains malware subresources
310 // and not proceeding.
311 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMalwareResourceDontProceed
) {
312 // Enable malware reports.
313 Profile
* profile
= Profile::FromBrowserContext(
314 web_contents()->GetBrowserContext());
315 profile
->GetPrefs()->SetBoolean(
316 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
318 // Navigate somewhere.
319 Navigate(kGoogleURL
, 1, 0, true);
321 // Navigate somewhere else.
322 Navigate(kGoodURL
, 2, 0, true);
324 // Simulate that page loading a bad-resource triggering an interstitial.
325 ShowInterstitial(true, kBadURL
);
327 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
328 ASSERT_TRUE(sb_interstitial
);
330 // Simulate the user clicking "don't proceed".
331 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
332 EXPECT_EQ(CANCEL
, user_response());
333 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
335 // We did not proceed, we should be back to the first page, the 2nd one should
336 // have been removed from the navigation controller.
337 ASSERT_EQ(1, controller().GetEntryCount());
338 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
340 // A report should have been sent.
341 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
342 ui_manager_
->GetDetails()->clear();
345 // Tests showing a blocking page for a page that contains malware subresources
347 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMalwareResourceProceed
) {
348 // Enable malware reports.
349 Profile
* profile
= Profile::FromBrowserContext(
350 web_contents()->GetBrowserContext());
351 profile
->GetPrefs()->SetBoolean(
352 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
354 // Navigate somewhere.
355 Navigate(kGoodURL
, 1, 0, true);
357 // Simulate that page loading a bad-resource triggering an interstitial.
358 ShowInterstitial(true, kBadURL
);
360 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
361 ASSERT_TRUE(sb_interstitial
);
363 // Simulate the user clicking "proceed".
364 ProceedThroughInterstitial(sb_interstitial
);
365 EXPECT_EQ(OK
, user_response());
366 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
368 // We did proceed, we should be back to showing the page.
369 ASSERT_EQ(1, controller().GetEntryCount());
370 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
372 // A report should have been sent.
373 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
374 ui_manager_
->GetDetails()->clear();
377 // Tests showing a blocking page for a page that contains multiple malware
378 // subresources and not proceeding. This just tests that the extra malware
379 // subresources (which trigger queued interstitial pages) do not break anything.
380 TEST_F(SafeBrowsingBlockingPageTest
,
381 PageWithMultipleMalwareResourceDontProceed
) {
382 // Enable malware reports.
383 Profile
* profile
= Profile::FromBrowserContext(
384 web_contents()->GetBrowserContext());
385 profile
->GetPrefs()->SetBoolean(
386 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
388 // Navigate somewhere.
389 Navigate(kGoogleURL
, 1, 0, true);
391 // Navigate somewhere else.
392 Navigate(kGoodURL
, 2, 0, true);
394 // Simulate that page loading a bad-resource triggering an interstitial.
395 ShowInterstitial(true, kBadURL
);
397 // More bad resources loading causing more interstitials. The new
398 // interstitials should be queued.
399 ShowInterstitial(true, kBadURL2
);
400 ShowInterstitial(true, kBadURL3
);
402 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
403 ASSERT_TRUE(sb_interstitial
);
405 // Simulate the user clicking "don't proceed".
406 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
407 EXPECT_EQ(CANCEL
, user_response());
408 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
410 // We did not proceed, we should be back to the first page, the 2nd one should
411 // have been removed from the navigation controller.
412 ASSERT_EQ(1, controller().GetEntryCount());
413 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
415 // A report should have been sent.
416 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
417 ui_manager_
->GetDetails()->clear();
420 // Tests showing a blocking page for a page that contains multiple malware
421 // subresources and proceeding through the first interstitial, but not the next.
422 TEST_F(SafeBrowsingBlockingPageTest
,
423 PageWithMultipleMalwareResourceProceedThenDontProceed
) {
424 // Enable malware reports.
425 Profile
* profile
= Profile::FromBrowserContext(
426 web_contents()->GetBrowserContext());
427 profile
->GetPrefs()->SetBoolean(
428 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
430 // Navigate somewhere.
431 Navigate(kGoogleURL
, 1, 0, true);
433 // Navigate somewhere else.
434 Navigate(kGoodURL
, 2, 0, true);
436 // Simulate that page loading a bad-resource triggering an interstitial.
437 ShowInterstitial(true, kBadURL
);
439 // More bad resources loading causing more interstitials. The new
440 // interstitials should be queued.
441 ShowInterstitial(true, kBadURL2
);
442 ShowInterstitial(true, kBadURL3
);
444 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
445 ASSERT_TRUE(sb_interstitial
);
447 // Proceed through the 1st interstitial.
448 ProceedThroughInterstitial(sb_interstitial
);
449 EXPECT_EQ(OK
, user_response());
451 // A report should have been sent.
452 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
453 ui_manager_
->GetDetails()->clear();
457 // We should land to a 2nd interstitial (aggregating all the malware resources
458 // loaded while the 1st interstitial was showing).
459 sb_interstitial
= GetSafeBrowsingBlockingPage();
460 ASSERT_TRUE(sb_interstitial
);
462 // Don't proceed through the 2nd interstitial.
463 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
464 EXPECT_EQ(CANCEL
, user_response());
465 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
467 // We did not proceed, we should be back to the first page, the 2nd one should
468 // have been removed from the navigation controller.
469 ASSERT_EQ(1, controller().GetEntryCount());
470 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
472 // No report should have been sent -- we don't create a report the
474 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
475 ui_manager_
->GetDetails()->clear();
478 // Tests showing a blocking page for a page that contains multiple malware
479 // subresources and proceeding through the multiple interstitials.
480 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMultipleMalwareResourceProceed
) {
481 // Enable malware reports.
482 Profile
* profile
= Profile::FromBrowserContext(
483 web_contents()->GetBrowserContext());
484 profile
->GetPrefs()->SetBoolean(
485 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
487 // Navigate somewhere else.
488 Navigate(kGoodURL
, 1, 0, true);
490 // Simulate that page loading a bad-resource triggering an interstitial.
491 ShowInterstitial(true, kBadURL
);
493 // More bad resources loading causing more interstitials. The new
494 // interstitials should be queued.
495 ShowInterstitial(true, kBadURL2
);
496 ShowInterstitial(true, kBadURL3
);
498 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
499 ASSERT_TRUE(sb_interstitial
);
501 // Proceed through the 1st interstitial.
502 ProceedThroughInterstitial(sb_interstitial
);
503 EXPECT_EQ(OK
, user_response());
505 // A report should have been sent.
506 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
507 ui_manager_
->GetDetails()->clear();
511 // We should land to a 2nd interstitial (aggregating all the malware resources
512 // loaded while the 1st interstitial was showing).
513 sb_interstitial
= GetSafeBrowsingBlockingPage();
514 ASSERT_TRUE(sb_interstitial
);
516 // Proceed through the 2nd interstitial.
517 ProceedThroughInterstitial(sb_interstitial
);
518 EXPECT_EQ(OK
, user_response());
520 // We did proceed, we should be back to the initial page.
521 ASSERT_EQ(1, controller().GetEntryCount());
522 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
524 // No report should have been sent -- we don't create a report the
526 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
527 ui_manager_
->GetDetails()->clear();
530 // Tests showing a blocking page then navigating back and forth to make sure the
531 // controller entries are OK. http://crbug.com/17627
532 TEST_F(SafeBrowsingBlockingPageTest
, NavigatingBackAndForth
) {
533 // Enable malware reports.
534 Profile
* profile
= Profile::FromBrowserContext(
535 web_contents()->GetBrowserContext());
536 profile
->GetPrefs()->SetBoolean(
537 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
539 // Navigate somewhere.
540 Navigate(kGoodURL
, 1, 0, true);
542 // Now navigate to a bad page triggerring an interstitial.
543 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
544 ui::PAGE_TRANSITION_TYPED
, std::string());
545 int pending_id
= controller().GetPendingEntry()->GetUniqueID();
546 ShowInterstitial(false, kBadURL
);
547 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
548 ASSERT_TRUE(sb_interstitial
);
550 // Proceed, then navigate back.
551 ProceedThroughInterstitial(sb_interstitial
);
552 NavigateCrossSite(kBadURL
, 2, pending_id
, true); // Commit the navigation.
555 // We are back on the good page.
556 sb_interstitial
= GetSafeBrowsingBlockingPage();
557 ASSERT_FALSE(sb_interstitial
);
558 ASSERT_EQ(2, controller().GetEntryCount());
559 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
561 // Navigate forward to the malware URL.
562 web_contents()->GetController().GoForward();
563 pending_id
= controller().GetPendingEntry()->GetUniqueID();
564 ShowInterstitial(false, kBadURL
);
565 sb_interstitial
= GetSafeBrowsingBlockingPage();
566 ASSERT_TRUE(sb_interstitial
);
568 // Let's proceed and make sure everything is OK (bug 17627).
569 ProceedThroughInterstitial(sb_interstitial
);
570 // Commit the navigation.
571 NavigateCrossSite(kBadURL
, 2, pending_id
, false);
572 sb_interstitial
= GetSafeBrowsingBlockingPage();
573 ASSERT_FALSE(sb_interstitial
);
574 ASSERT_EQ(2, controller().GetEntryCount());
575 EXPECT_EQ(kBadURL
, controller().GetActiveEntry()->GetURL().spec());
577 // Two reports should have been sent.
578 EXPECT_EQ(2u, ui_manager_
->GetDetails()->size());
579 ui_manager_
->GetDetails()->clear();
582 // Tests that calling "don't proceed" after "proceed" has been called doesn't
583 // cause problems. http://crbug.com/30079
584 TEST_F(SafeBrowsingBlockingPageTest
, ProceedThenDontProceed
) {
585 // Enable malware reports.
586 Profile
* profile
= Profile::FromBrowserContext(
587 web_contents()->GetBrowserContext());
588 profile
->GetPrefs()->SetBoolean(
589 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
592 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
593 ui::PAGE_TRANSITION_TYPED
, std::string());
595 // Simulate the load causing a safe browsing interstitial to be shown.
596 ShowInterstitial(false, kBadURL
);
597 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
598 ASSERT_TRUE(sb_interstitial
);
600 base::RunLoop().RunUntilIdle();
602 // Simulate the user clicking "proceed" then "don't proceed" (before the
603 // interstitial is shown).
604 sb_interstitial
->interstitial_page()->Proceed();
605 sb_interstitial
->interstitial_page()->DontProceed();
606 // Proceed() and DontProceed() post a task to update the
607 // SafeBrowsingService::Client.
608 base::RunLoop().RunUntilIdle();
610 // The interstitial should be gone.
611 EXPECT_EQ(OK
, user_response());
612 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
614 // Only one report should have been sent.
615 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
616 ui_manager_
->GetDetails()->clear();
619 // Tests showing a blocking page for a malware page with reports disabled.
620 TEST_F(SafeBrowsingBlockingPageTest
, MalwareReportsDisabled
) {
621 // Disable malware reports.
622 Profile
* profile
= Profile::FromBrowserContext(
623 web_contents()->GetBrowserContext());
624 profile
->GetPrefs()->SetBoolean(
625 prefs::kSafeBrowsingExtendedReportingEnabled
, false);
628 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
629 ui::PAGE_TRANSITION_TYPED
, std::string());
631 // Simulate the load causing a safe browsing interstitial to be shown.
632 ShowInterstitial(false, kBadURL
);
633 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
634 ASSERT_TRUE(sb_interstitial
);
636 base::RunLoop().RunUntilIdle();
638 // Simulate the user clicking "don't proceed".
639 DontProceedThroughInterstitial(sb_interstitial
);
641 // The interstitial should be gone.
642 EXPECT_EQ(CANCEL
, user_response());
643 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
645 // We did not proceed, the pending entry should be gone.
646 EXPECT_FALSE(controller().GetPendingEntry());
648 // No report should have been sent.
649 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
650 ui_manager_
->GetDetails()->clear();
653 // Test that toggling the checkbox has the anticipated effects.
654 TEST_F(SafeBrowsingBlockingPageTest
, MalwareReportsToggling
) {
655 // Disable malware reports.
656 Profile
* profile
= Profile::FromBrowserContext(
657 web_contents()->GetBrowserContext());
658 profile
->GetPrefs()->SetBoolean(
659 prefs::kSafeBrowsingExtendedReportingEnabled
, false);
662 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
663 ui::PAGE_TRANSITION_TYPED
, std::string());
665 // Simulate the load causing a safe browsing interstitial to be shown.
666 ShowInterstitial(false, kBadURL
);
667 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
668 ASSERT_TRUE(sb_interstitial
);
670 base::RunLoop().RunUntilIdle();
672 EXPECT_FALSE(profile
->GetPrefs()->GetBoolean(
673 prefs::kSafeBrowsingExtendedReportingEnabled
));
675 // Simulate the user check the report agreement checkbox.
676 sb_interstitial
->SetReportingPreference(true);
678 EXPECT_TRUE(profile
->GetPrefs()->GetBoolean(
679 prefs::kSafeBrowsingExtendedReportingEnabled
));
681 // Simulate the user uncheck the report agreement checkbox.
682 sb_interstitial
->SetReportingPreference(false);
684 EXPECT_FALSE(profile
->GetPrefs()->GetBoolean(
685 prefs::kSafeBrowsingExtendedReportingEnabled
));