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
, int page_id
) {
124 WebContentsTester::For(web_contents())->TestDidNavigate(
125 web_contents()->GetMainFrame(), page_id
, GURL(url
),
126 ui::PAGE_TRANSITION_TYPED
);
129 void GoBack(bool is_cross_site
) {
130 NavigationEntry
* entry
=
131 web_contents()->GetController().GetEntryAtOffset(-1);
133 web_contents()->GetController().GoBack();
135 // The pending RVH should commit for cross-site navigations.
136 content::RenderFrameHost
* rfh
= is_cross_site
?
137 WebContentsTester::For(web_contents())->GetPendingMainFrame() :
138 web_contents()->GetMainFrame();
139 WebContentsTester::For(web_contents())->TestDidNavigate(
142 GURL(entry
->GetURL()),
143 ui::PAGE_TRANSITION_TYPED
);
146 void ShowInterstitial(bool is_subresource
, const char* url
) {
147 SafeBrowsingUIManager::UnsafeResource resource
;
148 InitResource(&resource
, is_subresource
, GURL(url
));
149 SafeBrowsingBlockingPage::ShowBlockingPage(ui_manager_
.get(), resource
);
152 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is
154 SafeBrowsingBlockingPage
* GetSafeBrowsingBlockingPage() {
155 InterstitialPage
* interstitial
=
156 InterstitialPage::GetInterstitialPage(web_contents());
159 return static_cast<SafeBrowsingBlockingPage
*>(
160 interstitial
->GetDelegateForTesting());
163 UserResponse
user_response() const { return user_response_
; }
164 void ResetUserResponse() { user_response_
= PENDING
; }
166 static void ProceedThroughInterstitial(
167 SafeBrowsingBlockingPage
* sb_interstitial
) {
168 sb_interstitial
->interstitial_page()->Proceed();
169 // Proceed() posts a task to update the SafeBrowsingService::Client.
170 base::RunLoop().RunUntilIdle();
173 static void DontProceedThroughInterstitial(
174 SafeBrowsingBlockingPage
* sb_interstitial
) {
175 sb_interstitial
->interstitial_page()->DontProceed();
176 // DontProceed() posts a task to update the SafeBrowsingService::Client.
177 base::RunLoop().RunUntilIdle();
180 void DontProceedThroughSubresourceInterstitial(
181 SafeBrowsingBlockingPage
* sb_interstitial
) {
182 // CommandReceived(kTakeMeBackCommand) does a back navigation for
183 // subresource interstitials.
185 // DontProceed() posts a task to update the SafeBrowsingService::Client.
186 base::RunLoop().RunUntilIdle();
189 scoped_refptr
<TestSafeBrowsingUIManager
> ui_manager_
;
192 void InitResource(SafeBrowsingUIManager::UnsafeResource
* resource
,
196 base::Bind(&SafeBrowsingBlockingPageTest::OnBlockingPageComplete
,
197 base::Unretained(this));
199 resource
->is_subresource
= is_subresource
;
200 resource
->threat_type
= SB_THREAT_TYPE_URL_MALWARE
;
201 resource
->render_process_host_id
=
202 web_contents()->GetRenderProcessHost()->GetID();
203 resource
->render_view_id
=
204 web_contents()->GetRenderViewHost()->GetRoutingID();
207 UserResponse user_response_
;
208 TestSafeBrowsingBlockingPageFactory factory_
;
212 // Tests showing a blocking page for a malware page and not proceeding.
213 TEST_F(SafeBrowsingBlockingPageTest
, MalwarePageDontProceed
) {
214 // Enable malware details.
215 Profile
* profile
= Profile::FromBrowserContext(
216 web_contents()->GetBrowserContext());
217 profile
->GetPrefs()->SetBoolean(
218 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
221 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
222 ui::PAGE_TRANSITION_TYPED
, std::string());
225 // Simulate the load causing a safe browsing interstitial to be shown.
226 ShowInterstitial(false, kBadURL
);
227 SafeBrowsingBlockingPage
* sb_interstitial
=
228 GetSafeBrowsingBlockingPage();
229 ASSERT_TRUE(sb_interstitial
);
231 base::RunLoop().RunUntilIdle();
233 // Simulate the user clicking "don't proceed".
234 DontProceedThroughInterstitial(sb_interstitial
);
236 // The interstitial should be gone.
237 EXPECT_EQ(CANCEL
, user_response());
238 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
240 // We did not proceed, the pending entry should be gone.
241 EXPECT_FALSE(controller().GetPendingEntry());
243 // A report should have been sent.
244 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
245 ui_manager_
->GetDetails()->clear();
248 // Tests showing a blocking page for a malware page and then proceeding.
249 TEST_F(SafeBrowsingBlockingPageTest
, MalwarePageProceed
) {
250 // Enable malware reports.
251 Profile
* profile
= Profile::FromBrowserContext(
252 web_contents()->GetBrowserContext());
253 profile
->GetPrefs()->SetBoolean(
254 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
257 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
258 ui::PAGE_TRANSITION_TYPED
, std::string());
260 // Simulate the load causing a safe browsing interstitial to be shown.
261 ShowInterstitial(false, kBadURL
);
262 SafeBrowsingBlockingPage
* sb_interstitial
=
263 GetSafeBrowsingBlockingPage();
264 ASSERT_TRUE(sb_interstitial
);
266 // Simulate the user clicking "proceed".
267 ProceedThroughInterstitial(sb_interstitial
);
269 // The interstitial is shown until the navigation commits.
270 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents()));
271 // Commit the navigation.
272 Navigate(kBadURL
, 1);
273 // The interstitial should be gone now.
274 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents()));
276 // A report should have been sent.
277 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
278 ui_manager_
->GetDetails()->clear();
281 // Tests showing a blocking page for a page that contains malware subresources
282 // and not proceeding.
283 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMalwareResourceDontProceed
) {
284 // Enable malware reports.
285 Profile
* profile
= Profile::FromBrowserContext(
286 web_contents()->GetBrowserContext());
287 profile
->GetPrefs()->SetBoolean(
288 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
290 // Navigate somewhere.
291 Navigate(kGoogleURL
, 1);
293 // Navigate somewhere else.
294 Navigate(kGoodURL
, 2);
296 // Simulate that page loading a bad-resource triggering an interstitial.
297 ShowInterstitial(true, kBadURL
);
299 SafeBrowsingBlockingPage
* sb_interstitial
=
300 GetSafeBrowsingBlockingPage();
301 ASSERT_TRUE(sb_interstitial
);
303 // Simulate the user clicking "don't proceed".
304 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
305 EXPECT_EQ(CANCEL
, user_response());
306 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
308 // We did not proceed, we should be back to the first page, the 2nd one should
309 // have been removed from the navigation controller.
310 ASSERT_EQ(1, controller().GetEntryCount());
311 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
313 // A report should have been sent.
314 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
315 ui_manager_
->GetDetails()->clear();
318 // Tests showing a blocking page for a page that contains malware subresources
320 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMalwareResourceProceed
) {
321 // Enable malware reports.
322 Profile
* profile
= Profile::FromBrowserContext(
323 web_contents()->GetBrowserContext());
324 profile
->GetPrefs()->SetBoolean(
325 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
327 // Navigate somewhere.
328 Navigate(kGoodURL
, 1);
330 // Simulate that page loading a bad-resource triggering an interstitial.
331 ShowInterstitial(true, kBadURL
);
333 SafeBrowsingBlockingPage
* sb_interstitial
=
334 GetSafeBrowsingBlockingPage();
335 ASSERT_TRUE(sb_interstitial
);
337 // Simulate the user clicking "proceed".
338 ProceedThroughInterstitial(sb_interstitial
);
339 EXPECT_EQ(OK
, user_response());
340 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
342 // We did proceed, we should be back to showing the page.
343 ASSERT_EQ(1, controller().GetEntryCount());
344 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
346 // A report should have been sent.
347 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
348 ui_manager_
->GetDetails()->clear();
351 // Tests showing a blocking page for a page that contains multiple malware
352 // subresources and not proceeding. This just tests that the extra malware
353 // subresources (which trigger queued interstitial pages) do not break anything.
354 TEST_F(SafeBrowsingBlockingPageTest
,
355 PageWithMultipleMalwareResourceDontProceed
) {
356 // Enable malware reports.
357 Profile
* profile
= Profile::FromBrowserContext(
358 web_contents()->GetBrowserContext());
359 profile
->GetPrefs()->SetBoolean(
360 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
362 // Navigate somewhere.
363 Navigate(kGoogleURL
, 1);
365 // Navigate somewhere else.
366 Navigate(kGoodURL
, 2);
368 // Simulate that page loading a bad-resource triggering an interstitial.
369 ShowInterstitial(true, kBadURL
);
371 // More bad resources loading causing more interstitials. The new
372 // interstitials should be queued.
373 ShowInterstitial(true, kBadURL2
);
374 ShowInterstitial(true, kBadURL3
);
376 SafeBrowsingBlockingPage
* sb_interstitial
=
377 GetSafeBrowsingBlockingPage();
378 ASSERT_TRUE(sb_interstitial
);
380 // Simulate the user clicking "don't proceed".
381 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
382 EXPECT_EQ(CANCEL
, user_response());
383 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
385 // We did not proceed, we should be back to the first page, the 2nd one should
386 // have been removed from the navigation controller.
387 ASSERT_EQ(1, controller().GetEntryCount());
388 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
390 // A report should have been sent.
391 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
392 ui_manager_
->GetDetails()->clear();
395 // Tests showing a blocking page for a page that contains multiple malware
396 // subresources and proceeding through the first interstitial, but not the next.
397 TEST_F(SafeBrowsingBlockingPageTest
,
398 PageWithMultipleMalwareResourceProceedThenDontProceed
) {
399 // Enable malware reports.
400 Profile
* profile
= Profile::FromBrowserContext(
401 web_contents()->GetBrowserContext());
402 profile
->GetPrefs()->SetBoolean(
403 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
405 // Navigate somewhere.
406 Navigate(kGoogleURL
, 1);
408 // Navigate somewhere else.
409 Navigate(kGoodURL
, 2);
411 // Simulate that page loading a bad-resource triggering an interstitial.
412 ShowInterstitial(true, kBadURL
);
414 // More bad resources loading causing more interstitials. The new
415 // interstitials should be queued.
416 ShowInterstitial(true, kBadURL2
);
417 ShowInterstitial(true, kBadURL3
);
419 SafeBrowsingBlockingPage
* sb_interstitial
=
420 GetSafeBrowsingBlockingPage();
421 ASSERT_TRUE(sb_interstitial
);
423 // Proceed through the 1st interstitial.
424 ProceedThroughInterstitial(sb_interstitial
);
425 EXPECT_EQ(OK
, user_response());
427 // A report should have been sent.
428 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
429 ui_manager_
->GetDetails()->clear();
433 // We should land to a 2nd interstitial (aggregating all the malware resources
434 // loaded while the 1st interstitial was showing).
435 sb_interstitial
= GetSafeBrowsingBlockingPage();
436 ASSERT_TRUE(sb_interstitial
);
438 // Don't proceed through the 2nd interstitial.
439 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
440 EXPECT_EQ(CANCEL
, user_response());
441 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
443 // We did not proceed, we should be back to the first page, the 2nd one should
444 // have been removed from the navigation controller.
445 ASSERT_EQ(1, controller().GetEntryCount());
446 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
448 // No report should have been sent -- we don't create a report the
450 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
451 ui_manager_
->GetDetails()->clear();
454 // Tests showing a blocking page for a page that contains multiple malware
455 // subresources and proceeding through the multiple interstitials.
456 TEST_F(SafeBrowsingBlockingPageTest
,
457 PageWithMultipleMalwareResourceProceed
) {
458 // Enable malware reports.
459 Profile
* profile
= Profile::FromBrowserContext(
460 web_contents()->GetBrowserContext());
461 profile
->GetPrefs()->SetBoolean(
462 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
464 // Navigate somewhere else.
465 Navigate(kGoodURL
, 1);
467 // Simulate that page loading a bad-resource triggering an interstitial.
468 ShowInterstitial(true, kBadURL
);
470 // More bad resources loading causing more interstitials. The new
471 // interstitials should be queued.
472 ShowInterstitial(true, kBadURL2
);
473 ShowInterstitial(true, kBadURL3
);
475 SafeBrowsingBlockingPage
* sb_interstitial
=
476 GetSafeBrowsingBlockingPage();
477 ASSERT_TRUE(sb_interstitial
);
479 // Proceed through the 1st interstitial.
480 ProceedThroughInterstitial(sb_interstitial
);
481 EXPECT_EQ(OK
, user_response());
483 // A report should have been sent.
484 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
485 ui_manager_
->GetDetails()->clear();
489 // We should land to a 2nd interstitial (aggregating all the malware resources
490 // loaded while the 1st interstitial was showing).
491 sb_interstitial
= GetSafeBrowsingBlockingPage();
492 ASSERT_TRUE(sb_interstitial
);
494 // Proceed through the 2nd interstitial.
495 ProceedThroughInterstitial(sb_interstitial
);
496 EXPECT_EQ(OK
, user_response());
498 // We did proceed, we should be back to the initial page.
499 ASSERT_EQ(1, controller().GetEntryCount());
500 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
502 // No report should have been sent -- we don't create a report the
504 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
505 ui_manager_
->GetDetails()->clear();
508 // Tests showing a blocking page then navigating back and forth to make sure the
509 // controller entries are OK. http://crbug.com/17627
510 TEST_F(SafeBrowsingBlockingPageTest
, NavigatingBackAndForth
) {
511 // Enable malware reports.
512 Profile
* profile
= Profile::FromBrowserContext(
513 web_contents()->GetBrowserContext());
514 profile
->GetPrefs()->SetBoolean(
515 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
517 // Navigate somewhere.
518 Navigate(kGoodURL
, 1);
520 // Now navigate to a bad page triggerring an interstitial.
521 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
522 ui::PAGE_TRANSITION_TYPED
, std::string());
523 ShowInterstitial(false, kBadURL
);
524 SafeBrowsingBlockingPage
* sb_interstitial
=
525 GetSafeBrowsingBlockingPage();
526 ASSERT_TRUE(sb_interstitial
);
528 // Proceed, then navigate back.
529 ProceedThroughInterstitial(sb_interstitial
);
530 Navigate(kBadURL
, 2); // Commit the navigation.
533 // We are back on the good page.
534 sb_interstitial
= GetSafeBrowsingBlockingPage();
535 ASSERT_FALSE(sb_interstitial
);
536 ASSERT_EQ(2, controller().GetEntryCount());
537 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
539 // Navigate forward to the malware URL.
540 web_contents()->GetController().GoForward();
541 ShowInterstitial(false, kBadURL
);
542 sb_interstitial
= GetSafeBrowsingBlockingPage();
543 ASSERT_TRUE(sb_interstitial
);
545 // Let's proceed and make sure everything is OK (bug 17627).
546 ProceedThroughInterstitial(sb_interstitial
);
547 Navigate(kBadURL
, 2); // Commit the navigation.
548 sb_interstitial
= GetSafeBrowsingBlockingPage();
549 ASSERT_FALSE(sb_interstitial
);
550 ASSERT_EQ(2, controller().GetEntryCount());
551 EXPECT_EQ(kBadURL
, controller().GetActiveEntry()->GetURL().spec());
553 // Two reports should have been sent.
554 EXPECT_EQ(2u, ui_manager_
->GetDetails()->size());
555 ui_manager_
->GetDetails()->clear();
558 // Tests that calling "don't proceed" after "proceed" has been called doesn't
559 // cause problems. http://crbug.com/30079
560 TEST_F(SafeBrowsingBlockingPageTest
, ProceedThenDontProceed
) {
561 // Enable malware reports.
562 Profile
* profile
= Profile::FromBrowserContext(
563 web_contents()->GetBrowserContext());
564 profile
->GetPrefs()->SetBoolean(
565 prefs::kSafeBrowsingExtendedReportingEnabled
, true);
568 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
569 ui::PAGE_TRANSITION_TYPED
, std::string());
571 // Simulate the load causing a safe browsing interstitial to be shown.
572 ShowInterstitial(false, kBadURL
);
573 SafeBrowsingBlockingPage
* sb_interstitial
=
574 GetSafeBrowsingBlockingPage();
575 ASSERT_TRUE(sb_interstitial
);
577 base::RunLoop().RunUntilIdle();
579 // Simulate the user clicking "proceed" then "don't proceed" (before the
580 // interstitial is shown).
581 sb_interstitial
->interstitial_page()->Proceed();
582 sb_interstitial
->interstitial_page()->DontProceed();
583 // Proceed() and DontProceed() post a task to update the
584 // SafeBrowsingService::Client.
585 base::RunLoop().RunUntilIdle();
587 // The interstitial should be gone.
588 EXPECT_EQ(OK
, user_response());
589 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
591 // Only one report should have been sent.
592 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
593 ui_manager_
->GetDetails()->clear();
596 // Tests showing a blocking page for a malware page with reports disabled.
597 TEST_F(SafeBrowsingBlockingPageTest
, MalwareReportsDisabled
) {
598 // Disable malware reports.
599 Profile
* profile
= Profile::FromBrowserContext(
600 web_contents()->GetBrowserContext());
601 profile
->GetPrefs()->SetBoolean(
602 prefs::kSafeBrowsingExtendedReportingEnabled
, false);
605 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
606 ui::PAGE_TRANSITION_TYPED
, std::string());
608 // Simulate the load causing a safe browsing interstitial to be shown.
609 ShowInterstitial(false, kBadURL
);
610 SafeBrowsingBlockingPage
* sb_interstitial
=
611 GetSafeBrowsingBlockingPage();
612 ASSERT_TRUE(sb_interstitial
);
614 base::RunLoop().RunUntilIdle();
616 // Simulate the user clicking "don't proceed".
617 DontProceedThroughInterstitial(sb_interstitial
);
619 // The interstitial should be gone.
620 EXPECT_EQ(CANCEL
, user_response());
621 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
623 // We did not proceed, the pending entry should be gone.
624 EXPECT_FALSE(controller().GetPendingEntry());
626 // No report should have been sent.
627 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
628 ui_manager_
->GetDetails()->clear();
631 // Test that toggling the checkbox has the anticipated effects.
632 TEST_F(SafeBrowsingBlockingPageTest
, MalwareReportsToggling
) {
633 // Disable malware reports.
634 Profile
* profile
= Profile::FromBrowserContext(
635 web_contents()->GetBrowserContext());
636 profile
->GetPrefs()->SetBoolean(
637 prefs::kSafeBrowsingExtendedReportingEnabled
, false);
640 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
641 ui::PAGE_TRANSITION_TYPED
, std::string());
643 // Simulate the load causing a safe browsing interstitial to be shown.
644 ShowInterstitial(false, kBadURL
);
645 SafeBrowsingBlockingPage
* sb_interstitial
=
646 GetSafeBrowsingBlockingPage();
647 ASSERT_TRUE(sb_interstitial
);
649 base::RunLoop().RunUntilIdle();
651 EXPECT_FALSE(profile
->GetPrefs()->GetBoolean(
652 prefs::kSafeBrowsingExtendedReportingEnabled
));
654 // Simulate the user check the report agreement checkbox.
655 sb_interstitial
->SetReportingPreference(true);
657 EXPECT_TRUE(profile
->GetPrefs()->GetBoolean(
658 prefs::kSafeBrowsingExtendedReportingEnabled
));
660 // Simulate the user uncheck the report agreement checkbox.
661 sb_interstitial
->SetReportingPreference(false);
663 EXPECT_FALSE(profile
->GetPrefs()->GetBoolean(
664 prefs::kSafeBrowsingExtendedReportingEnabled
));