safe_browsing_blocking_page_unittest.cc revision 3f50c38dc070f4bb515c1b64450dae14f316474e
1// Copyright (c) 2010 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. 4 5#include "chrome/browser/renderer_host/test/test_render_view_host.h" 6 7#include "chrome/browser/browser_thread.h" 8#include "chrome/browser/prefs/pref_service.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/tab_contents/navigation_entry.h" 13#include "chrome/browser/tab_contents/test_tab_contents.h" 14#include "chrome/common/pref_names.h" 15#include "chrome/common/render_messages.h" 16#include "chrome/common/render_messages_params.h" 17 18static const char* kGoogleURL = "http://www.google.com/"; 19static const char* kGoodURL = "http://www.goodguys.com/"; 20static const char* kBadURL = "http://www.badguys.com/"; 21static const char* kBadURL2 = "http://www.badguys2.com/"; 22static const char* kBadURL3 = "http://www.badguys3.com/"; 23 24// A SafeBrowingBlockingPage class that does not create windows. 25class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { 26 public: 27 TestSafeBrowsingBlockingPage(SafeBrowsingService* service, 28 TabContents* tab_contents, 29 const UnsafeResourceList& unsafe_resources) 30 : SafeBrowsingBlockingPage(service, tab_contents, unsafe_resources) { 31 } 32 33 // Overriden from InterstitialPage. Don't create a view. 34 virtual TabContentsView* CreateTabContentsView() { 35 return NULL; 36 } 37}; 38 39class TestSafeBrowsingService: public SafeBrowsingService { 40 public: 41 virtual ~TestSafeBrowsingService() {} 42 virtual void ReportMalwareDetails(scoped_refptr<MalwareDetails> details) { 43 details_.push_back(details); 44 } 45 46 std::list<scoped_refptr<MalwareDetails> >* GetDetails() { 47 return &details_; 48 } 49 50 std::list<scoped_refptr<MalwareDetails> > details_; 51}; 52 53class TestSafeBrowsingBlockingPageFactory 54 : public SafeBrowsingBlockingPageFactory { 55 public: 56 TestSafeBrowsingBlockingPageFactory() { } 57 ~TestSafeBrowsingBlockingPageFactory() { } 58 59 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( 60 SafeBrowsingService* service, 61 TabContents* tab_contents, 62 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) { 63 return new TestSafeBrowsingBlockingPage(service, tab_contents, 64 unsafe_resources); 65 } 66}; 67 68class SafeBrowsingBlockingPageTest : public RenderViewHostTestHarness, 69 public SafeBrowsingService::Client { 70 public: 71 // The decision the user made. 72 enum UserResponse { 73 PENDING, 74 OK, 75 CANCEL 76 }; 77 78 SafeBrowsingBlockingPageTest() 79 : ui_thread_(BrowserThread::UI, MessageLoop::current()), 80 io_thread_(BrowserThread::IO, MessageLoop::current()) { 81 ResetUserResponse(); 82 service_ = new TestSafeBrowsingService(); 83 } 84 85 virtual void SetUp() { 86 RenderViewHostTestHarness::SetUp(); 87 SafeBrowsingBlockingPage::RegisterFactory(&factory_); 88 ResetUserResponse(); 89 } 90 91 // SafeBrowsingService::Client implementation. 92 virtual void OnUrlCheckResult(const GURL& url, 93 SafeBrowsingService::UrlCheckResult result) { 94 } 95 virtual void OnBlockingPageComplete(bool proceed) { 96 if (proceed) 97 user_response_ = OK; 98 else 99 user_response_ = CANCEL; 100 } 101 102 void Navigate(const char* url, int page_id) { 103 ViewHostMsg_FrameNavigate_Params params; 104 InitNavigateParams(¶ms, page_id, GURL(url), PageTransition::TYPED); 105 contents()->TestDidNavigate(contents_->render_view_host(), params); 106 } 107 108 void GoBack() { 109 NavigationEntry* entry = contents()->controller().GetEntryAtOffset(-1); 110 ASSERT_TRUE(entry); 111 contents()->controller().GoBack(); 112 Navigate(entry->url().spec().c_str(), entry->page_id()); 113 } 114 115 void ShowInterstitial(ResourceType::Type resource_type, 116 const char* url) { 117 SafeBrowsingService::UnsafeResource resource; 118 InitResource(&resource, resource_type, GURL(url)); 119 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource); 120 } 121 122 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is 123 // showing. 124 SafeBrowsingBlockingPage* GetSafeBrowsingBlockingPage() { 125 InterstitialPage* interstitial = 126 InterstitialPage::GetInterstitialPage(contents()); 127 if (!interstitial) 128 return NULL; 129 return static_cast<SafeBrowsingBlockingPage*>(interstitial); 130 } 131 132 UserResponse user_response() const { return user_response_; } 133 void ResetUserResponse() { user_response_ = PENDING; } 134 135 static void ProceedThroughInterstitial( 136 SafeBrowsingBlockingPage* sb_interstitial) { 137 sb_interstitial->Proceed(); 138 // Proceed() posts a task to update the SafeBrowsingService::Client. 139 MessageLoop::current()->RunAllPending(); 140 } 141 142 static void DontProceedThroughInterstitial( 143 SafeBrowsingBlockingPage* sb_interstitial) { 144 sb_interstitial->DontProceed(); 145 // DontProceed() posts a task to update the SafeBrowsingService::Client. 146 MessageLoop::current()->RunAllPending(); 147 } 148 149 scoped_refptr<TestSafeBrowsingService> service_; 150 151 private: 152 void InitResource(SafeBrowsingService::UnsafeResource* resource, 153 ResourceType::Type resource_type, 154 const GURL& url) { 155 resource->client = this; 156 resource->url = url; 157 resource->resource_type = resource_type; 158 resource->threat_type = SafeBrowsingService::URL_MALWARE; 159 resource->render_process_host_id = contents_->GetRenderProcessHost()->id(); 160 resource->render_view_id = contents_->render_view_host()->routing_id(); 161 } 162 163 UserResponse user_response_; 164 TestSafeBrowsingBlockingPageFactory factory_; 165 BrowserThread ui_thread_; 166 BrowserThread io_thread_; 167}; 168 169// Tests showing a blocking page for a malware page and not proceeding. 170TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { 171 // Enable malware details. 172 contents()->profile()->GetPrefs()->SetBoolean( 173 prefs::kSafeBrowsingReportingEnabled, true); 174 175 // Start a load. 176 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); 177 178 179 // Simulate the load causing a safe browsing interstitial to be shown. 180 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); 181 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 182 ASSERT_TRUE(sb_interstitial); 183 184 MessageLoop::current()->RunAllPending(); 185 186 // Simulate the user clicking "don't proceed". 187 DontProceedThroughInterstitial(sb_interstitial); 188 189 // The interstitial should be gone. 190 EXPECT_EQ(CANCEL, user_response()); 191 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 192 193 // We did not proceed, the pending entry should be gone. 194 EXPECT_FALSE(controller().pending_entry()); 195 196 // A report should have been sent. 197 EXPECT_EQ(1u, service_->GetDetails()->size()); 198 service_->GetDetails()->clear(); 199} 200 201// Tests showing a blocking page for a malware page and then proceeding. 202TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { 203 // Enable malware reports. 204 contents()->profile()->GetPrefs()->SetBoolean( 205 prefs::kSafeBrowsingReportingEnabled, true); 206 207 // Start a load. 208 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); 209 210 // Simulate the load causing a safe browsing interstitial to be shown. 211 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); 212 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 213 ASSERT_TRUE(sb_interstitial); 214 215 // Simulate the user clicking "proceed". 216 ProceedThroughInterstitial(sb_interstitial); 217 218 // The interstitial is shown until the navigation commits. 219 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(contents())); 220 // Commit the navigation. 221 Navigate(kBadURL, 1); 222 // The interstitial should be gone now. 223 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(contents())); 224 225 // A report should have been sent. 226 EXPECT_EQ(1u, service_->GetDetails()->size()); 227 service_->GetDetails()->clear(); 228} 229 230// Tests showing a blocking page for a page that contains malware subresources 231// and not proceeding. 232TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { 233 // Enable malware reports. 234 contents()->profile()->GetPrefs()->SetBoolean( 235 prefs::kSafeBrowsingReportingEnabled, true); 236 237 // Navigate somewhere. 238 Navigate(kGoogleURL, 1); 239 240 // Navigate somewhere else. 241 Navigate(kGoodURL, 2); 242 243 // Simulate that page loading a bad-resource triggering an interstitial. 244 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL); 245 246 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 247 ASSERT_TRUE(sb_interstitial); 248 249 // Simulate the user clicking "don't proceed". 250 DontProceedThroughInterstitial(sb_interstitial); 251 EXPECT_EQ(CANCEL, user_response()); 252 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 253 254 // We did not proceed, we should be back to the first page, the 2nd one should 255 // have been removed from the navigation controller. 256 ASSERT_EQ(1, controller().entry_count()); 257 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->url().spec()); 258 259 // A report should have been sent. 260 EXPECT_EQ(1u, service_->GetDetails()->size()); 261 service_->GetDetails()->clear(); 262} 263 264// Tests showing a blocking page for a page that contains malware subresources 265// and proceeding. 266TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { 267 // Enable malware reports. 268 contents()->profile()->GetPrefs()->SetBoolean( 269 prefs::kSafeBrowsingReportingEnabled, true); 270 271 // Navigate somewhere. 272 Navigate(kGoodURL, 1); 273 274 // Simulate that page loading a bad-resource triggering an interstitial. 275 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL); 276 277 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 278 ASSERT_TRUE(sb_interstitial); 279 280 // Simulate the user clicking "proceed". 281 ProceedThroughInterstitial(sb_interstitial); 282 EXPECT_EQ(OK, user_response()); 283 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 284 285 // We did proceed, we should be back to showing the page. 286 ASSERT_EQ(1, controller().entry_count()); 287 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->url().spec()); 288 289 // A report should have been sent. 290 EXPECT_EQ(1u, service_->GetDetails()->size()); 291 service_->GetDetails()->clear(); 292} 293 294// Tests showing a blocking page for a page that contains multiple malware 295// subresources and not proceeding. This just tests that the extra malware 296// subresources (which trigger queued interstitial pages) do not break anything. 297TEST_F(SafeBrowsingBlockingPageTest, 298 PageWithMultipleMalwareResourceDontProceed) { 299 // Enable malware reports. 300 contents()->profile()->GetPrefs()->SetBoolean( 301 prefs::kSafeBrowsingReportingEnabled, true); 302 303 // Navigate somewhere. 304 Navigate(kGoogleURL, 1); 305 306 // Navigate somewhere else. 307 Navigate(kGoodURL, 2); 308 309 // Simulate that page loading a bad-resource triggering an interstitial. 310 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL); 311 312 // More bad resources loading causing more interstitials. The new 313 // interstitials should be queued. 314 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL2); 315 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL3); 316 317 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 318 ASSERT_TRUE(sb_interstitial); 319 320 // Simulate the user clicking "don't proceed". 321 DontProceedThroughInterstitial(sb_interstitial); 322 EXPECT_EQ(CANCEL, user_response()); 323 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 324 325 // We did not proceed, we should be back to the first page, the 2nd one should 326 // have been removed from the navigation controller. 327 ASSERT_EQ(1, controller().entry_count()); 328 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->url().spec()); 329 330 // A report should have been sent. 331 EXPECT_EQ(1u, service_->GetDetails()->size()); 332 service_->GetDetails()->clear(); 333} 334 335// Tests showing a blocking page for a page that contains multiple malware 336// subresources and proceeding through the first interstitial, but not the next. 337TEST_F(SafeBrowsingBlockingPageTest, 338 PageWithMultipleMalwareResourceProceedThenDontProceed) { 339 // Enable malware reports. 340 contents()->profile()->GetPrefs()->SetBoolean( 341 prefs::kSafeBrowsingReportingEnabled, true); 342 343 // Navigate somewhere. 344 Navigate(kGoogleURL, 1); 345 346 // Navigate somewhere else. 347 Navigate(kGoodURL, 2); 348 349 // Simulate that page loading a bad-resource triggering an interstitial. 350 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL); 351 352 // More bad resources loading causing more interstitials. The new 353 // interstitials should be queued. 354 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL2); 355 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL3); 356 357 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 358 ASSERT_TRUE(sb_interstitial); 359 360 // Proceed through the 1st interstitial. 361 ProceedThroughInterstitial(sb_interstitial); 362 EXPECT_EQ(OK, user_response()); 363 364 // A report should have been sent. 365 EXPECT_EQ(1u, service_->GetDetails()->size()); 366 service_->GetDetails()->clear(); 367 368 ResetUserResponse(); 369 370 // We should land to a 2nd interstitial (aggregating all the malware resources 371 // loaded while the 1st interstitial was showing). 372 sb_interstitial = GetSafeBrowsingBlockingPage(); 373 ASSERT_TRUE(sb_interstitial); 374 375 // Don't proceed through the 2nd interstitial. 376 DontProceedThroughInterstitial(sb_interstitial); 377 EXPECT_EQ(CANCEL, user_response()); 378 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 379 380 // We did not proceed, we should be back to the first page, the 2nd one should 381 // have been removed from the navigation controller. 382 ASSERT_EQ(1, controller().entry_count()); 383 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->url().spec()); 384 385 // No report should have been sent -- we don't create a report the 386 // second time. 387 EXPECT_EQ(0u, service_->GetDetails()->size()); 388 service_->GetDetails()->clear(); 389} 390 391// Tests showing a blocking page for a page that contains multiple malware 392// subresources and proceeding through the multiple interstitials. 393TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { 394 // Enable malware reports. 395 contents()->profile()->GetPrefs()->SetBoolean( 396 prefs::kSafeBrowsingReportingEnabled, true); 397 398 // Navigate somewhere else. 399 Navigate(kGoodURL, 1); 400 401 // Simulate that page loading a bad-resource triggering an interstitial. 402 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL); 403 404 // More bad resources loading causing more interstitials. The new 405 // interstitials should be queued. 406 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL2); 407 ShowInterstitial(ResourceType::SUB_RESOURCE, kBadURL3); 408 409 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 410 ASSERT_TRUE(sb_interstitial); 411 412 // Proceed through the 1st interstitial. 413 ProceedThroughInterstitial(sb_interstitial); 414 EXPECT_EQ(OK, user_response()); 415 416 // A report should have been sent. 417 EXPECT_EQ(1u, service_->GetDetails()->size()); 418 service_->GetDetails()->clear(); 419 420 ResetUserResponse(); 421 422 // We should land to a 2nd interstitial (aggregating all the malware resources 423 // loaded while the 1st interstitial was showing). 424 sb_interstitial = GetSafeBrowsingBlockingPage(); 425 ASSERT_TRUE(sb_interstitial); 426 427 // Proceed through the 2nd interstitial. 428 ProceedThroughInterstitial(sb_interstitial); 429 EXPECT_EQ(OK, user_response()); 430 431 // We did proceed, we should be back to the initial page. 432 ASSERT_EQ(1, controller().entry_count()); 433 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->url().spec()); 434 435 // No report should have been sent -- we don't create a report the 436 // second time. 437 EXPECT_EQ(0u, service_->GetDetails()->size()); 438 service_->GetDetails()->clear(); 439} 440 441// Tests showing a blocking page then navigating back and forth to make sure the 442// controller entries are OK. http://crbug.com/17627 443TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { 444 // Enable malware reports. 445 contents()->profile()->GetPrefs()->SetBoolean( 446 prefs::kSafeBrowsingReportingEnabled, true); 447 448 // Navigate somewhere. 449 Navigate(kGoodURL, 1); 450 451 // Now navigate to a bad page triggerring an interstitial. 452 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); 453 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); 454 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 455 ASSERT_TRUE(sb_interstitial); 456 457 // Proceed, then navigate back. 458 ProceedThroughInterstitial(sb_interstitial); 459 Navigate(kBadURL, 2); // Commit the navigation. 460 GoBack(); 461 462 // We are back on the good page. 463 sb_interstitial = GetSafeBrowsingBlockingPage(); 464 ASSERT_FALSE(sb_interstitial); 465 ASSERT_EQ(2, controller().entry_count()); 466 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->url().spec()); 467 468 // Navigate forward to the malware URL. 469 contents()->controller().GoForward(); 470 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); 471 sb_interstitial = GetSafeBrowsingBlockingPage(); 472 ASSERT_TRUE(sb_interstitial); 473 474 // Let's proceed and make sure everything is OK (bug 17627). 475 ProceedThroughInterstitial(sb_interstitial); 476 Navigate(kBadURL, 2); // Commit the navigation. 477 sb_interstitial = GetSafeBrowsingBlockingPage(); 478 ASSERT_FALSE(sb_interstitial); 479 ASSERT_EQ(2, controller().entry_count()); 480 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->url().spec()); 481 482 // Two reports should have been sent. 483 EXPECT_EQ(2u, service_->GetDetails()->size()); 484 service_->GetDetails()->clear(); 485} 486 487// Tests that calling "don't proceed" after "proceed" has been called doesn't 488// cause problems. http://crbug.com/30079 489TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { 490 // Enable malware reports. 491 contents()->profile()->GetPrefs()->SetBoolean( 492 prefs::kSafeBrowsingReportingEnabled, true); 493 494 // Start a load. 495 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); 496 497 // Simulate the load causing a safe browsing interstitial to be shown. 498 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); 499 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 500 ASSERT_TRUE(sb_interstitial); 501 502 MessageLoop::current()->RunAllPending(); 503 504 // Simulate the user clicking "proceed" then "don't proceed" (before the 505 // interstitial is shown). 506 sb_interstitial->Proceed(); 507 sb_interstitial->DontProceed(); 508 // Proceed() and DontProceed() post a task to update the 509 // SafeBrowsingService::Client. 510 MessageLoop::current()->RunAllPending(); 511 512 // The interstitial should be gone. 513 EXPECT_EQ(OK, user_response()); 514 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 515 516 // Only one report should have been sent. 517 EXPECT_EQ(1u, service_->GetDetails()->size()); 518 service_->GetDetails()->clear(); 519} 520 521// Tests showing a blocking page for a malware page with reports disabled. 522TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { 523 // Disable malware reports. 524 contents()->profile()->GetPrefs()->SetBoolean( 525 prefs::kSafeBrowsingReportingEnabled, false); 526 527 // Start a load. 528 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); 529 530 // Simulate the load causing a safe browsing interstitial to be shown. 531 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); 532 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 533 ASSERT_TRUE(sb_interstitial); 534 535 MessageLoop::current()->RunAllPending(); 536 537 // Simulate the user clicking "don't proceed". 538 DontProceedThroughInterstitial(sb_interstitial); 539 540 // The interstitial should be gone. 541 EXPECT_EQ(CANCEL, user_response()); 542 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 543 544 // We did not proceed, the pending entry should be gone. 545 EXPECT_FALSE(controller().pending_entry()); 546 547 // No report should have been sent. 548 EXPECT_EQ(0u, service_->GetDetails()->size()); 549 service_->GetDetails()->clear(); 550} 551 552// Test setting the malware report preferance 553TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { 554 // Disable malware reports. 555 contents()->profile()->GetPrefs()->SetBoolean( 556 prefs::kSafeBrowsingReportingEnabled, false); 557 558 // Start a load. 559 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); 560 561 // Simulate the load causing a safe browsing interstitial to be shown. 562 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); 563 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 564 ASSERT_TRUE(sb_interstitial); 565 566 MessageLoop::current()->RunAllPending(); 567 568 EXPECT_FALSE(contents()->profile()->GetPrefs()->GetBoolean( 569 prefs::kSafeBrowsingReportingEnabled)); 570 571 // Simulate the user check the report agreement checkbox. 572 sb_interstitial->SetReportingPreference(true); 573 574 EXPECT_TRUE(contents()->profile()->GetPrefs()->GetBoolean( 575 prefs::kSafeBrowsingReportingEnabled)); 576 577 // Simulate the user uncheck the report agreement checkbox. 578 sb_interstitial->SetReportingPreference(false); 579 580 EXPECT_FALSE(contents()->profile()->GetPrefs()->GetBoolean( 581 prefs::kSafeBrowsingReportingEnabled)); 582} 583