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();
235 UserResponse user_response_
;
236 TestSafeBrowsingBlockingPageFactory factory_
;
240 // Tests showing a blocking page for a malware page and not proceeding.
241 TEST_F(SafeBrowsingBlockingPageTest
, MalwarePageDontProceed
) {
242 // Enable malware details.
243 Profile
* profile
= Profile::FromBrowserContext(
244 web_contents()->GetBrowserContext());
245 profile
->GetPrefs()->SetBoolean(
246 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
249 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
250 ui::PAGE_TRANSITION_TYPED
, std::string());
253 // Simulate the load causing a safe browsing interstitial to be shown.
254 ShowInterstitial(false, kBadURL
);
255 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
256 ASSERT_TRUE(sb_interstitial
);
258 base::RunLoop().RunUntilIdle();
260 // Simulate the user clicking "don't proceed".
261 DontProceedThroughInterstitial(sb_interstitial
);
263 // The interstitial should be gone.
264 EXPECT_EQ(CANCEL
, user_response());
265 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
267 // We did not proceed, the pending entry should be gone.
268 EXPECT_FALSE(controller().GetPendingEntry());
270 // A report should have been sent.
271 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
272 ui_manager_
->GetDetails()->clear();
275 // Tests showing a blocking page for a malware page and then proceeding.
276 TEST_F(SafeBrowsingBlockingPageTest
, MalwarePageProceed
) {
277 // Enable malware reports.
278 Profile
* profile
= Profile::FromBrowserContext(
279 web_contents()->GetBrowserContext());
280 profile
->GetPrefs()->SetBoolean(
281 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
284 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
285 ui::PAGE_TRANSITION_TYPED
, std::string());
286 int pending_id
= controller().GetPendingEntry()->GetUniqueID();
288 // Simulate the load causing a safe browsing interstitial to be shown.
289 ShowInterstitial(false, kBadURL
);
290 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
291 ASSERT_TRUE(sb_interstitial
);
293 // Simulate the user clicking "proceed".
294 ProceedThroughInterstitial(sb_interstitial
);
296 // The interstitial is shown until the navigation commits.
297 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents()));
298 // Commit the navigation.
299 Navigate(kBadURL
, 1, pending_id
, true);
300 // The interstitial should be gone now.
301 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents()));
303 // A report should have been sent.
304 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
305 ui_manager_
->GetDetails()->clear();
308 // Tests showing a blocking page for a page that contains malware subresources
309 // and not proceeding.
310 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMalwareResourceDontProceed
) {
311 // Enable malware reports.
312 Profile
* profile
= Profile::FromBrowserContext(
313 web_contents()->GetBrowserContext());
314 profile
->GetPrefs()->SetBoolean(
315 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
317 // Navigate somewhere.
318 Navigate(kGoogleURL
, 1, 0, true);
320 // Navigate somewhere else.
321 Navigate(kGoodURL
, 2, 0, true);
323 // Simulate that page loading a bad-resource triggering an interstitial.
324 ShowInterstitial(true, kBadURL
);
326 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
327 ASSERT_TRUE(sb_interstitial
);
329 // Simulate the user clicking "don't proceed".
330 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
331 EXPECT_EQ(CANCEL
, user_response());
332 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
334 // We did not proceed, we should be back to the first page, the 2nd one should
335 // have been removed from the navigation controller.
336 ASSERT_EQ(1, controller().GetEntryCount());
337 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
339 // A report should have been sent.
340 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
341 ui_manager_
->GetDetails()->clear();
344 // Tests showing a blocking page for a page that contains malware subresources
346 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMalwareResourceProceed
) {
347 // Enable malware reports.
348 Profile
* profile
= Profile::FromBrowserContext(
349 web_contents()->GetBrowserContext());
350 profile
->GetPrefs()->SetBoolean(
351 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
353 // Navigate somewhere.
354 Navigate(kGoodURL
, 1, 0, true);
356 // Simulate that page loading a bad-resource triggering an interstitial.
357 ShowInterstitial(true, kBadURL
);
359 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
360 ASSERT_TRUE(sb_interstitial
);
362 // Simulate the user clicking "proceed".
363 ProceedThroughInterstitial(sb_interstitial
);
364 EXPECT_EQ(OK
, user_response());
365 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
367 // We did proceed, we should be back to showing the page.
368 ASSERT_EQ(1, controller().GetEntryCount());
369 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
371 // A report should have been sent.
372 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
373 ui_manager_
->GetDetails()->clear();
376 // Tests showing a blocking page for a page that contains multiple malware
377 // subresources and not proceeding. This just tests that the extra malware
378 // subresources (which trigger queued interstitial pages) do not break anything.
379 TEST_F(SafeBrowsingBlockingPageTest
,
380 PageWithMultipleMalwareResourceDontProceed
) {
381 // Enable malware reports.
382 Profile
* profile
= Profile::FromBrowserContext(
383 web_contents()->GetBrowserContext());
384 profile
->GetPrefs()->SetBoolean(
385 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
387 // Navigate somewhere.
388 Navigate(kGoogleURL
, 1, 0, true);
390 // Navigate somewhere else.
391 Navigate(kGoodURL
, 2, 0, true);
393 // Simulate that page loading a bad-resource triggering an interstitial.
394 ShowInterstitial(true, kBadURL
);
396 // More bad resources loading causing more interstitials. The new
397 // interstitials should be queued.
398 ShowInterstitial(true, kBadURL2
);
399 ShowInterstitial(true, kBadURL3
);
401 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
402 ASSERT_TRUE(sb_interstitial
);
404 // Simulate the user clicking "don't proceed".
405 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
406 EXPECT_EQ(CANCEL
, user_response());
407 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
409 // We did not proceed, we should be back to the first page, the 2nd one should
410 // have been removed from the navigation controller.
411 ASSERT_EQ(1, controller().GetEntryCount());
412 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
414 // A report should have been sent.
415 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
416 ui_manager_
->GetDetails()->clear();
419 // Tests showing a blocking page for a page that contains multiple malware
420 // subresources and proceeding through the first interstitial, but not the next.
421 TEST_F(SafeBrowsingBlockingPageTest
,
422 PageWithMultipleMalwareResourceProceedThenDontProceed
) {
423 // Enable malware reports.
424 Profile
* profile
= Profile::FromBrowserContext(
425 web_contents()->GetBrowserContext());
426 profile
->GetPrefs()->SetBoolean(
427 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
429 // Navigate somewhere.
430 Navigate(kGoogleURL
, 1, 0, true);
432 // Navigate somewhere else.
433 Navigate(kGoodURL
, 2, 0, true);
435 // Simulate that page loading a bad-resource triggering an interstitial.
436 ShowInterstitial(true, kBadURL
);
438 // More bad resources loading causing more interstitials. The new
439 // interstitials should be queued.
440 ShowInterstitial(true, kBadURL2
);
441 ShowInterstitial(true, kBadURL3
);
443 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
444 ASSERT_TRUE(sb_interstitial
);
446 // Proceed through the 1st interstitial.
447 ProceedThroughInterstitial(sb_interstitial
);
448 EXPECT_EQ(OK
, user_response());
450 // A report should have been sent.
451 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
452 ui_manager_
->GetDetails()->clear();
456 // We should land to a 2nd interstitial (aggregating all the malware resources
457 // loaded while the 1st interstitial was showing).
458 sb_interstitial
= GetSafeBrowsingBlockingPage();
459 ASSERT_TRUE(sb_interstitial
);
461 // Don't proceed through the 2nd interstitial.
462 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
463 EXPECT_EQ(CANCEL
, user_response());
464 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
466 // We did not proceed, we should be back to the first page, the 2nd one should
467 // have been removed from the navigation controller.
468 ASSERT_EQ(1, controller().GetEntryCount());
469 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
471 // No report should have been sent -- we don't create a report the
473 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
474 ui_manager_
->GetDetails()->clear();
477 // Tests showing a blocking page for a page that contains multiple malware
478 // subresources and proceeding through the multiple interstitials.
479 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMultipleMalwareResourceProceed
) {
480 // Enable malware reports.
481 Profile
* profile
= Profile::FromBrowserContext(
482 web_contents()->GetBrowserContext());
483 profile
->GetPrefs()->SetBoolean(
484 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
486 // Navigate somewhere else.
487 Navigate(kGoodURL
, 1, 0, true);
489 // Simulate that page loading a bad-resource triggering an interstitial.
490 ShowInterstitial(true, kBadURL
);
492 // More bad resources loading causing more interstitials. The new
493 // interstitials should be queued.
494 ShowInterstitial(true, kBadURL2
);
495 ShowInterstitial(true, kBadURL3
);
497 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
498 ASSERT_TRUE(sb_interstitial
);
500 // Proceed through the 1st interstitial.
501 ProceedThroughInterstitial(sb_interstitial
);
502 EXPECT_EQ(OK
, user_response());
504 // A report should have been sent.
505 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
506 ui_manager_
->GetDetails()->clear();
510 // We should land to a 2nd interstitial (aggregating all the malware resources
511 // loaded while the 1st interstitial was showing).
512 sb_interstitial
= GetSafeBrowsingBlockingPage();
513 ASSERT_TRUE(sb_interstitial
);
515 // Proceed through the 2nd interstitial.
516 ProceedThroughInterstitial(sb_interstitial
);
517 EXPECT_EQ(OK
, user_response());
519 // We did proceed, we should be back to the initial page.
520 ASSERT_EQ(1, controller().GetEntryCount());
521 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
523 // No report should have been sent -- we don't create a report the
525 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
526 ui_manager_
->GetDetails()->clear();
529 // Tests showing a blocking page then navigating back and forth to make sure the
530 // controller entries are OK. http://crbug.com/17627
531 TEST_F(SafeBrowsingBlockingPageTest
, NavigatingBackAndForth
) {
532 // Enable malware reports.
533 Profile
* profile
= Profile::FromBrowserContext(
534 web_contents()->GetBrowserContext());
535 profile
->GetPrefs()->SetBoolean(
536 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
538 // Navigate somewhere.
539 Navigate(kGoodURL
, 1, 0, true);
541 // Now navigate to a bad page triggerring an interstitial.
542 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
543 ui::PAGE_TRANSITION_TYPED
, std::string());
544 int pending_id
= controller().GetPendingEntry()->GetUniqueID();
545 ShowInterstitial(false, kBadURL
);
546 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
547 ASSERT_TRUE(sb_interstitial
);
549 // Proceed, then navigate back.
550 ProceedThroughInterstitial(sb_interstitial
);
551 NavigateCrossSite(kBadURL
, 2, pending_id
, true); // Commit the navigation.
554 // We are back on the good page.
555 sb_interstitial
= GetSafeBrowsingBlockingPage();
556 ASSERT_FALSE(sb_interstitial
);
557 ASSERT_EQ(2, controller().GetEntryCount());
558 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
560 // Navigate forward to the malware URL.
561 web_contents()->GetController().GoForward();
562 pending_id
= controller().GetPendingEntry()->GetUniqueID();
563 ShowInterstitial(false, kBadURL
);
564 sb_interstitial
= GetSafeBrowsingBlockingPage();
565 ASSERT_TRUE(sb_interstitial
);
567 // Let's proceed and make sure everything is OK (bug 17627).
568 ProceedThroughInterstitial(sb_interstitial
);
569 // Commit the navigation.
570 NavigateCrossSite(kBadURL
, 2, pending_id
, false);
571 sb_interstitial
= GetSafeBrowsingBlockingPage();
572 ASSERT_FALSE(sb_interstitial
);
573 ASSERT_EQ(2, controller().GetEntryCount());
574 EXPECT_EQ(kBadURL
, controller().GetActiveEntry()->GetURL().spec());
576 // Two reports should have been sent.
577 EXPECT_EQ(2u, ui_manager_
->GetDetails()->size());
578 ui_manager_
->GetDetails()->clear();
581 // Tests that calling "don't proceed" after "proceed" has been called doesn't
582 // cause problems. http://crbug.com/30079
583 TEST_F(SafeBrowsingBlockingPageTest
, ProceedThenDontProceed
) {
584 // Enable malware reports.
585 Profile
* profile
= Profile::FromBrowserContext(
586 web_contents()->GetBrowserContext());
587 profile
->GetPrefs()->SetBoolean(
588 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
591 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
592 ui::PAGE_TRANSITION_TYPED
, std::string());
594 // Simulate the load causing a safe browsing interstitial to be shown.
595 ShowInterstitial(false, kBadURL
);
596 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
597 ASSERT_TRUE(sb_interstitial
);
599 base::RunLoop().RunUntilIdle();
601 // Simulate the user clicking "proceed" then "don't proceed" (before the
602 // interstitial is shown).
603 sb_interstitial
->interstitial_page()->Proceed();
604 sb_interstitial
->interstitial_page()->DontProceed();
605 // Proceed() and DontProceed() post a task to update the
606 // SafeBrowsingService::Client.
607 base::RunLoop().RunUntilIdle();
609 // The interstitial should be gone.
610 EXPECT_EQ(OK
, user_response());
611 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
613 // Only one report should have been sent.
614 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
615 ui_manager_
->GetDetails()->clear();
618 // Tests showing a blocking page for a malware page with reports disabled.
619 TEST_F(SafeBrowsingBlockingPageTest
, MalwareReportsDisabled
) {
620 // Disable malware reports.
621 Profile
* profile
= Profile::FromBrowserContext(
622 web_contents()->GetBrowserContext());
623 profile
->GetPrefs()->SetBoolean(
624 prefs::kSafeBrowsingExtendedReportingEnabled
, false);
627 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
628 ui::PAGE_TRANSITION_TYPED
, std::string());
630 // Simulate the load causing a safe browsing interstitial to be shown.
631 ShowInterstitial(false, kBadURL
);
632 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
633 ASSERT_TRUE(sb_interstitial
);
635 base::RunLoop().RunUntilIdle();
637 // Simulate the user clicking "don't proceed".
638 DontProceedThroughInterstitial(sb_interstitial
);
640 // The interstitial should be gone.
641 EXPECT_EQ(CANCEL
, user_response());
642 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
644 // We did not proceed, the pending entry should be gone.
645 EXPECT_FALSE(controller().GetPendingEntry());
647 // No report should have been sent.
648 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
649 ui_manager_
->GetDetails()->clear();
652 // Test that toggling the checkbox has the anticipated effects.
653 TEST_F(SafeBrowsingBlockingPageTest
, MalwareReportsToggling
) {
654 // Disable malware reports.
655 Profile
* profile
= Profile::FromBrowserContext(
656 web_contents()->GetBrowserContext());
657 profile
->GetPrefs()->SetBoolean(
658 prefs::kSafeBrowsingExtendedReportingEnabled
, false);
661 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
662 ui::PAGE_TRANSITION_TYPED
, std::string());
664 // Simulate the load causing a safe browsing interstitial to be shown.
665 ShowInterstitial(false, kBadURL
);
666 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
667 ASSERT_TRUE(sb_interstitial
);
669 base::RunLoop().RunUntilIdle();
671 EXPECT_FALSE(profile
->GetPrefs()->GetBoolean(
672 prefs::kSafeBrowsingExtendedReportingEnabled
));
674 // Simulate the user check the report agreement checkbox.
675 sb_interstitial
->SetReportingPreference(true);
677 EXPECT_TRUE(profile
->GetPrefs()->GetBoolean(
678 prefs::kSafeBrowsingExtendedReportingEnabled
));
680 // Simulate the user uncheck the report agreement checkbox.
681 sb_interstitial
->SetReportingPreference(false);
683 EXPECT_FALSE(profile
->GetPrefs()->GetBoolean(
684 prefs::kSafeBrowsingExtendedReportingEnabled
));