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