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/browser/web_contents_view.h"
21 #include "content/public/test/web_contents_tester.h"
23 using content::InterstitialPage
;
24 using content::NavigationEntry
;
25 using content::WebContents
;
26 using content::WebContentsTester
;
27 using content::WebContentsView
;
29 static const char* kGoogleURL
= "http://www.google.com/";
30 static const char* kGoodURL
= "http://www.goodguys.com/";
31 static const char* kBadURL
= "http://www.badguys.com/";
32 static const char* kBadURL2
= "http://www.badguys2.com/";
33 static const char* kBadURL3
= "http://www.badguys3.com/";
37 // A SafeBrowingBlockingPage class that does not create windows.
38 class TestSafeBrowsingBlockingPageV1
: public SafeBrowsingBlockingPageV1
{
40 TestSafeBrowsingBlockingPageV1(SafeBrowsingUIManager
* manager
,
41 WebContents
* web_contents
,
42 const UnsafeResourceList
& unsafe_resources
)
43 : SafeBrowsingBlockingPageV1(manager
, web_contents
, unsafe_resources
) {
44 // Don't delay details at all for the unittest.
45 malware_details_proceed_delay_ms_
= 0;
47 // Don't create a view.
48 interstitial_page()->DontCreateViewForTesting();
52 // A SafeBrowingBlockingPage class that does not create windows.
53 class TestSafeBrowsingBlockingPageV2
: public SafeBrowsingBlockingPageV2
{
55 TestSafeBrowsingBlockingPageV2(SafeBrowsingUIManager
* manager
,
56 WebContents
* web_contents
,
57 const UnsafeResourceList
& unsafe_resources
)
58 : SafeBrowsingBlockingPageV2(manager
, web_contents
, unsafe_resources
) {
59 // Don't delay details at all for the unittest.
60 malware_details_proceed_delay_ms_
= 0;
62 // Don't create a view.
63 interstitial_page()->DontCreateViewForTesting();
67 class TestSafeBrowsingUIManager
: public SafeBrowsingUIManager
{
69 explicit TestSafeBrowsingUIManager(SafeBrowsingService
* service
)
70 : SafeBrowsingUIManager(service
) {
73 virtual void SendSerializedMalwareDetails(
74 const std::string
& serialized
) OVERRIDE
{
75 details_
.push_back(serialized
);
78 std::list
<std::string
>* GetDetails() {
83 virtual ~TestSafeBrowsingUIManager() {}
85 std::list
<std::string
> details_
;
88 class TestSafeBrowsingBlockingPageFactory
89 : public SafeBrowsingBlockingPageFactory
{
91 TestSafeBrowsingBlockingPageFactory() { }
92 virtual ~TestSafeBrowsingBlockingPageFactory() { }
94 virtual SafeBrowsingBlockingPage
* CreateSafeBrowsingPage(
95 SafeBrowsingUIManager
* manager
,
96 WebContents
* web_contents
,
97 const SafeBrowsingBlockingPage::UnsafeResourceList
& unsafe_resources
)
99 // TODO(mattm): remove this when SafeBrowsingBlockingPageV2 supports
100 // multi-threat warnings.
101 if (unsafe_resources
.size() == 1 &&
102 (unsafe_resources
[0].threat_type
== SB_THREAT_TYPE_URL_MALWARE
||
103 unsafe_resources
[0].threat_type
== SB_THREAT_TYPE_URL_PHISHING
)) {
104 return new TestSafeBrowsingBlockingPageV2(manager
, web_contents
,
107 return new TestSafeBrowsingBlockingPageV1(manager
, web_contents
,
114 class SafeBrowsingBlockingPageTest
: public ChromeRenderViewHostTestHarness
{
116 // The decision the user made.
123 SafeBrowsingBlockingPageTest() {
125 // The safe browsing UI manager does not need a service for this test.
126 ui_manager_
= new TestSafeBrowsingUIManager(NULL
);
129 virtual void SetUp() OVERRIDE
{
130 ChromeRenderViewHostTestHarness::SetUp();
131 SafeBrowsingBlockingPage::RegisterFactory(&factory_
);
135 virtual void TearDown() OVERRIDE
{
136 // Release the UI manager before the BrowserThreads are destroyed.
138 SafeBrowsingBlockingPage::RegisterFactory(NULL
);
139 // Clean up singleton reference (crbug.com/110594).
140 MalwareDetails::RegisterFactory(NULL
);
141 ChromeRenderViewHostTestHarness::TearDown();
144 void OnBlockingPageComplete(bool proceed
) {
148 user_response_
= CANCEL
;
151 void Navigate(const char* url
, int page_id
) {
152 WebContentsTester::For(web_contents())->TestDidNavigate(
153 web_contents()->GetRenderViewHost(), page_id
, GURL(url
),
154 content::PAGE_TRANSITION_TYPED
);
157 void GoBack(bool is_cross_site
) {
158 NavigationEntry
* entry
=
159 web_contents()->GetController().GetEntryAtOffset(-1);
161 web_contents()->GetController().GoBack();
163 // The pending RVH should commit for cross-site navigations.
164 content::RenderViewHost
* rvh
= is_cross_site
?
165 WebContentsTester::For(web_contents())->GetPendingRenderViewHost() :
166 web_contents()->GetRenderViewHost();
167 WebContentsTester::For(web_contents())->TestDidNavigate(
170 GURL(entry
->GetURL()),
171 content::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_
;
239 // Tests showing a blocking page for a malware page and not proceeding.
240 TEST_F(SafeBrowsingBlockingPageTest
, MalwarePageDontProceed
) {
241 // Enable malware details.
242 Profile
* profile
= Profile::FromBrowserContext(
243 web_contents()->GetBrowserContext());
244 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
247 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
248 content::PAGE_TRANSITION_TYPED
, std::string());
251 // Simulate the load causing a safe browsing interstitial to be shown.
252 ShowInterstitial(false, kBadURL
);
253 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
254 ASSERT_TRUE(sb_interstitial
);
256 base::RunLoop().RunUntilIdle();
258 // Simulate the user clicking "don't proceed".
259 DontProceedThroughInterstitial(sb_interstitial
);
261 // The interstitial should be gone.
262 EXPECT_EQ(CANCEL
, user_response());
263 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
265 // We did not proceed, the pending entry should be gone.
266 EXPECT_FALSE(controller().GetPendingEntry());
268 // A report should have been sent.
269 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
270 ui_manager_
->GetDetails()->clear();
273 // Tests showing a blocking page for a malware page and then proceeding.
274 TEST_F(SafeBrowsingBlockingPageTest
, MalwarePageProceed
) {
275 // Enable malware reports.
276 Profile
* profile
= Profile::FromBrowserContext(
277 web_contents()->GetBrowserContext());
278 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
281 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
282 content::PAGE_TRANSITION_TYPED
, std::string());
284 // Simulate the load causing a safe browsing interstitial to be shown.
285 ShowInterstitial(false, kBadURL
);
286 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
287 ASSERT_TRUE(sb_interstitial
);
289 // Simulate the user clicking "proceed".
290 ProceedThroughInterstitial(sb_interstitial
);
292 // The interstitial is shown until the navigation commits.
293 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents()));
294 // Commit the navigation.
295 Navigate(kBadURL
, 1);
296 // The interstitial should be gone now.
297 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents()));
299 // A report should have been sent.
300 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
301 ui_manager_
->GetDetails()->clear();
304 // Tests showing a blocking page for a page that contains malware subresources
305 // and not proceeding.
306 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMalwareResourceDontProceed
) {
307 // Enable malware reports.
308 Profile
* profile
= Profile::FromBrowserContext(
309 web_contents()->GetBrowserContext());
310 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
312 // Navigate somewhere.
313 Navigate(kGoogleURL
, 1);
315 // Navigate somewhere else.
316 Navigate(kGoodURL
, 2);
318 // Simulate that page loading a bad-resource triggering an interstitial.
319 ShowInterstitial(true, kBadURL
);
321 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
322 ASSERT_TRUE(sb_interstitial
);
324 // Simulate the user clicking "don't proceed".
325 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
326 EXPECT_EQ(CANCEL
, user_response());
327 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
329 // We did not proceed, we should be back to the first page, the 2nd one should
330 // have been removed from the navigation controller.
331 ASSERT_EQ(1, controller().GetEntryCount());
332 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
334 // A report should have been sent.
335 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
336 ui_manager_
->GetDetails()->clear();
339 // Tests showing a blocking page for a page that contains malware subresources
341 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMalwareResourceProceed
) {
342 // Enable malware reports.
343 Profile
* profile
= Profile::FromBrowserContext(
344 web_contents()->GetBrowserContext());
345 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
347 // Navigate somewhere.
348 Navigate(kGoodURL
, 1);
350 // Simulate that page loading a bad-resource triggering an interstitial.
351 ShowInterstitial(true, kBadURL
);
353 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
354 ASSERT_TRUE(sb_interstitial
);
356 // Simulate the user clicking "proceed".
357 ProceedThroughInterstitial(sb_interstitial
);
358 EXPECT_EQ(OK
, user_response());
359 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
361 // We did proceed, we should be back to showing the page.
362 ASSERT_EQ(1, controller().GetEntryCount());
363 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
365 // A report should have been sent.
366 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
367 ui_manager_
->GetDetails()->clear();
370 // Tests showing a blocking page for a page that contains multiple malware
371 // subresources and not proceeding. This just tests that the extra malware
372 // subresources (which trigger queued interstitial pages) do not break anything.
373 TEST_F(SafeBrowsingBlockingPageTest
,
374 PageWithMultipleMalwareResourceDontProceed
) {
375 // Enable malware reports.
376 Profile
* profile
= Profile::FromBrowserContext(
377 web_contents()->GetBrowserContext());
378 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
380 // Navigate somewhere.
381 Navigate(kGoogleURL
, 1);
383 // Navigate somewhere else.
384 Navigate(kGoodURL
, 2);
386 // Simulate that page loading a bad-resource triggering an interstitial.
387 ShowInterstitial(true, kBadURL
);
389 // More bad resources loading causing more interstitials. The new
390 // interstitials should be queued.
391 ShowInterstitial(true, kBadURL2
);
392 ShowInterstitial(true, kBadURL3
);
394 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
395 ASSERT_TRUE(sb_interstitial
);
397 // Simulate the user clicking "don't proceed".
398 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
399 EXPECT_EQ(CANCEL
, user_response());
400 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
402 // We did not proceed, we should be back to the first page, the 2nd one should
403 // have been removed from the navigation controller.
404 ASSERT_EQ(1, controller().GetEntryCount());
405 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
407 // A report should have been sent.
408 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
409 ui_manager_
->GetDetails()->clear();
412 // Tests showing a blocking page for a page that contains multiple malware
413 // subresources and proceeding through the first interstitial, but not the next.
414 TEST_F(SafeBrowsingBlockingPageTest
,
415 PageWithMultipleMalwareResourceProceedThenDontProceed
) {
416 // Enable malware reports.
417 Profile
* profile
= Profile::FromBrowserContext(
418 web_contents()->GetBrowserContext());
419 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
421 // Navigate somewhere.
422 Navigate(kGoogleURL
, 1);
424 // Navigate somewhere else.
425 Navigate(kGoodURL
, 2);
427 // Simulate that page loading a bad-resource triggering an interstitial.
428 ShowInterstitial(true, kBadURL
);
430 // More bad resources loading causing more interstitials. The new
431 // interstitials should be queued.
432 ShowInterstitial(true, kBadURL2
);
433 ShowInterstitial(true, kBadURL3
);
435 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
436 ASSERT_TRUE(sb_interstitial
);
438 // Proceed through the 1st interstitial.
439 ProceedThroughInterstitial(sb_interstitial
);
440 EXPECT_EQ(OK
, user_response());
442 // A report should have been sent.
443 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
444 ui_manager_
->GetDetails()->clear();
448 // We should land to a 2nd interstitial (aggregating all the malware resources
449 // loaded while the 1st interstitial was showing).
450 sb_interstitial
= GetSafeBrowsingBlockingPage();
451 ASSERT_TRUE(sb_interstitial
);
453 // Don't proceed through the 2nd interstitial.
454 DontProceedThroughSubresourceInterstitial(sb_interstitial
);
455 EXPECT_EQ(CANCEL
, user_response());
456 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
458 // We did not proceed, we should be back to the first page, the 2nd one should
459 // have been removed from the navigation controller.
460 ASSERT_EQ(1, controller().GetEntryCount());
461 EXPECT_EQ(kGoogleURL
, controller().GetActiveEntry()->GetURL().spec());
463 // No report should have been sent -- we don't create a report the
465 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
466 ui_manager_
->GetDetails()->clear();
469 // Tests showing a blocking page for a page that contains multiple malware
470 // subresources and proceeding through the multiple interstitials.
471 TEST_F(SafeBrowsingBlockingPageTest
, PageWithMultipleMalwareResourceProceed
) {
472 // Enable malware reports.
473 Profile
* profile
= Profile::FromBrowserContext(
474 web_contents()->GetBrowserContext());
475 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
477 // Navigate somewhere else.
478 Navigate(kGoodURL
, 1);
480 // Simulate that page loading a bad-resource triggering an interstitial.
481 ShowInterstitial(true, kBadURL
);
483 // More bad resources loading causing more interstitials. The new
484 // interstitials should be queued.
485 ShowInterstitial(true, kBadURL2
);
486 ShowInterstitial(true, kBadURL3
);
488 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
489 ASSERT_TRUE(sb_interstitial
);
491 // Proceed through the 1st interstitial.
492 ProceedThroughInterstitial(sb_interstitial
);
493 EXPECT_EQ(OK
, user_response());
495 // A report should have been sent.
496 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
497 ui_manager_
->GetDetails()->clear();
501 // We should land to a 2nd interstitial (aggregating all the malware resources
502 // loaded while the 1st interstitial was showing).
503 sb_interstitial
= GetSafeBrowsingBlockingPage();
504 ASSERT_TRUE(sb_interstitial
);
506 // Proceed through the 2nd interstitial.
507 ProceedThroughInterstitial(sb_interstitial
);
508 EXPECT_EQ(OK
, user_response());
510 // We did proceed, we should be back to the initial page.
511 ASSERT_EQ(1, controller().GetEntryCount());
512 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
514 // No report should have been sent -- we don't create a report the
516 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
517 ui_manager_
->GetDetails()->clear();
520 // Tests showing a blocking page then navigating back and forth to make sure the
521 // controller entries are OK. http://crbug.com/17627
522 TEST_F(SafeBrowsingBlockingPageTest
, NavigatingBackAndForth
) {
523 // Enable malware reports.
524 Profile
* profile
= Profile::FromBrowserContext(
525 web_contents()->GetBrowserContext());
526 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
528 // Navigate somewhere.
529 Navigate(kGoodURL
, 1);
531 // Now navigate to a bad page triggerring an interstitial.
532 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
533 content::PAGE_TRANSITION_TYPED
, std::string());
534 ShowInterstitial(false, kBadURL
);
535 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
536 ASSERT_TRUE(sb_interstitial
);
538 // Proceed, then navigate back.
539 ProceedThroughInterstitial(sb_interstitial
);
540 Navigate(kBadURL
, 2); // Commit the navigation.
543 // We are back on the good page.
544 sb_interstitial
= GetSafeBrowsingBlockingPage();
545 ASSERT_FALSE(sb_interstitial
);
546 ASSERT_EQ(2, controller().GetEntryCount());
547 EXPECT_EQ(kGoodURL
, controller().GetActiveEntry()->GetURL().spec());
549 // Navigate forward to the malware URL.
550 web_contents()->GetController().GoForward();
551 ShowInterstitial(false, kBadURL
);
552 sb_interstitial
= GetSafeBrowsingBlockingPage();
553 ASSERT_TRUE(sb_interstitial
);
555 // Let's proceed and make sure everything is OK (bug 17627).
556 ProceedThroughInterstitial(sb_interstitial
);
557 Navigate(kBadURL
, 2); // Commit the navigation.
558 sb_interstitial
= GetSafeBrowsingBlockingPage();
559 ASSERT_FALSE(sb_interstitial
);
560 ASSERT_EQ(2, controller().GetEntryCount());
561 EXPECT_EQ(kBadURL
, controller().GetActiveEntry()->GetURL().spec());
563 // Two reports should have been sent.
564 EXPECT_EQ(2u, ui_manager_
->GetDetails()->size());
565 ui_manager_
->GetDetails()->clear();
568 // Tests that calling "don't proceed" after "proceed" has been called doesn't
569 // cause problems. http://crbug.com/30079
570 TEST_F(SafeBrowsingBlockingPageTest
, ProceedThenDontProceed
) {
571 // Enable malware reports.
572 Profile
* profile
= Profile::FromBrowserContext(
573 web_contents()->GetBrowserContext());
574 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, true);
577 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
578 content::PAGE_TRANSITION_TYPED
, std::string());
580 // Simulate the load causing a safe browsing interstitial to be shown.
581 ShowInterstitial(false, kBadURL
);
582 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
583 ASSERT_TRUE(sb_interstitial
);
585 base::RunLoop().RunUntilIdle();
587 // Simulate the user clicking "proceed" then "don't proceed" (before the
588 // interstitial is shown).
589 sb_interstitial
->interstitial_page_
->Proceed();
590 sb_interstitial
->interstitial_page_
->DontProceed();
591 // Proceed() and DontProceed() post a task to update the
592 // SafeBrowsingService::Client.
593 base::RunLoop().RunUntilIdle();
595 // The interstitial should be gone.
596 EXPECT_EQ(OK
, user_response());
597 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
599 // Only one report should have been sent.
600 EXPECT_EQ(1u, ui_manager_
->GetDetails()->size());
601 ui_manager_
->GetDetails()->clear();
604 // Tests showing a blocking page for a malware page with reports disabled.
605 TEST_F(SafeBrowsingBlockingPageTest
, MalwareReportsDisabled
) {
606 // Disable malware reports.
607 Profile
* profile
= Profile::FromBrowserContext(
608 web_contents()->GetBrowserContext());
609 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, false);
612 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
613 content::PAGE_TRANSITION_TYPED
, std::string());
615 // Simulate the load causing a safe browsing interstitial to be shown.
616 ShowInterstitial(false, kBadURL
);
617 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
618 ASSERT_TRUE(sb_interstitial
);
620 base::RunLoop().RunUntilIdle();
622 // Simulate the user clicking "don't proceed".
623 DontProceedThroughInterstitial(sb_interstitial
);
625 // The interstitial should be gone.
626 EXPECT_EQ(CANCEL
, user_response());
627 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
629 // We did not proceed, the pending entry should be gone.
630 EXPECT_FALSE(controller().GetPendingEntry());
632 // No report should have been sent.
633 EXPECT_EQ(0u, ui_manager_
->GetDetails()->size());
634 ui_manager_
->GetDetails()->clear();
637 // Test setting the malware report preferance
638 TEST_F(SafeBrowsingBlockingPageTest
, MalwareReports
) {
639 // Disable malware reports.
640 Profile
* profile
= Profile::FromBrowserContext(
641 web_contents()->GetBrowserContext());
642 profile
->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled
, false);
645 controller().LoadURL(GURL(kBadURL
), content::Referrer(),
646 content::PAGE_TRANSITION_TYPED
, std::string());
648 // Simulate the load causing a safe browsing interstitial to be shown.
649 ShowInterstitial(false, kBadURL
);
650 SafeBrowsingBlockingPage
* sb_interstitial
= GetSafeBrowsingBlockingPage();
651 ASSERT_TRUE(sb_interstitial
);
653 base::RunLoop().RunUntilIdle();
655 EXPECT_FALSE(profile
->GetPrefs()->GetBoolean(
656 prefs::kSafeBrowsingReportingEnabled
));
658 // Simulate the user check the report agreement checkbox.
659 sb_interstitial
->SetReportingPreference(true);
661 EXPECT_TRUE(profile
->GetPrefs()->GetBoolean(
662 prefs::kSafeBrowsingReportingEnabled
));
664 // Simulate the user uncheck the report agreement checkbox.
665 sb_interstitial
->SetReportingPreference(false);
667 EXPECT_FALSE(profile
->GetPrefs()->GetBoolean(
668 prefs::kSafeBrowsingReportingEnabled
));