| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // |
| 5 // TODO(mattm): remove / merge this file with |
| 6 // safe_browsing_blocking_page_unittest.cc once the SBInterstitial field trial |
| 7 // finishes. |
| 4 | 8 |
| 5 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 6 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 7 #include "chrome/browser/safe_browsing/malware_details.h" | 11 #include "chrome/browser/safe_browsing/malware_details.h" |
| 8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 9 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 11 #include "content/public/browser/interstitial_page.h" | 15 #include "content/public/browser/interstitial_page.h" |
| 12 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 25 | 29 |
| 26 static const char* kGoogleURL = "http://www.google.com/"; | 30 static const char* kGoogleURL = "http://www.google.com/"; |
| 27 static const char* kGoodURL = "http://www.goodguys.com/"; | 31 static const char* kGoodURL = "http://www.goodguys.com/"; |
| 28 static const char* kBadURL = "http://www.badguys.com/"; | 32 static const char* kBadURL = "http://www.badguys.com/"; |
| 29 static const char* kBadURL2 = "http://www.badguys2.com/"; | 33 static const char* kBadURL2 = "http://www.badguys2.com/"; |
| 30 static const char* kBadURL3 = "http://www.badguys3.com/"; | 34 static const char* kBadURL3 = "http://www.badguys3.com/"; |
| 31 | 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 // A SafeBrowingBlockingPage class that does not create windows. | 38 // A SafeBrowingBlockingPage class that does not create windows. |
| 35 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { | 39 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPageV2 { |
| 36 public: | 40 public: |
| 37 TestSafeBrowsingBlockingPage(SafeBrowsingService* service, | 41 TestSafeBrowsingBlockingPage(SafeBrowsingService* service, |
| 38 WebContents* web_contents, | 42 WebContents* web_contents, |
| 39 const UnsafeResourceList& unsafe_resources) | 43 const UnsafeResourceList& unsafe_resources) |
| 40 : SafeBrowsingBlockingPage(service, web_contents, unsafe_resources) { | 44 : SafeBrowsingBlockingPageV2(service, web_contents, unsafe_resources) { |
| 41 // Don't delay details at all for the unittest. | 45 // Don't delay details at all for the unittest. |
| 42 malware_details_proceed_delay_ms_ = 0; | 46 malware_details_proceed_delay_ms_ = 0; |
| 43 | 47 |
| 44 // Don't create a view. | 48 // Don't create a view. |
| 45 interstitial_page()->DontCreateViewForTesting(); | 49 interstitial_page()->DontCreateViewForTesting(); |
| 46 } | 50 } |
| 47 }; | 51 }; |
| 48 | 52 |
| 49 class TestSafeBrowsingService: public SafeBrowsingService { | 53 class TestSafeBrowsingService: public SafeBrowsingService { |
| 50 public: | 54 public: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 72 SafeBrowsingService* service, | 76 SafeBrowsingService* service, |
| 73 WebContents* web_contents, | 77 WebContents* web_contents, |
| 74 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) { | 78 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) { |
| 75 return new TestSafeBrowsingBlockingPage(service, web_contents, | 79 return new TestSafeBrowsingBlockingPage(service, web_contents, |
| 76 unsafe_resources); | 80 unsafe_resources); |
| 77 } | 81 } |
| 78 }; | 82 }; |
| 79 | 83 |
| 80 } // namespace | 84 } // namespace |
| 81 | 85 |
| 82 class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { | 86 class SafeBrowsingBlockingPageV2Test : public ChromeRenderViewHostTestHarness { |
| 83 public: | 87 public: |
| 84 // The decision the user made. | 88 // The decision the user made. |
| 85 enum UserResponse { | 89 enum UserResponse { |
| 86 PENDING, | 90 PENDING, |
| 87 OK, | 91 OK, |
| 88 CANCEL | 92 CANCEL |
| 89 }; | 93 }; |
| 90 | 94 |
| 91 SafeBrowsingBlockingPageTest() | 95 SafeBrowsingBlockingPageV2Test() |
| 92 : ui_thread_(BrowserThread::UI, MessageLoop::current()), | 96 : ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| 93 file_user_blocking_thread_( | 97 file_user_blocking_thread_( |
| 94 BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), | 98 BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), |
| 95 io_thread_(BrowserThread::IO, MessageLoop::current()) { | 99 io_thread_(BrowserThread::IO, MessageLoop::current()) { |
| 96 ResetUserResponse(); | 100 ResetUserResponse(); |
| 97 service_ = new TestSafeBrowsingService(); | 101 service_ = new TestSafeBrowsingService(); |
| 98 } | 102 } |
| 99 | 103 |
| 100 virtual void SetUp() { | 104 virtual void SetUp() { |
| 101 ChromeRenderViewHostTestHarness::SetUp(); | 105 ChromeRenderViewHostTestHarness::SetUp(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 MessageLoop::current()->RunAllPending(); | 186 MessageLoop::current()->RunAllPending(); |
| 183 } | 187 } |
| 184 | 188 |
| 185 scoped_refptr<TestSafeBrowsingService> service_; | 189 scoped_refptr<TestSafeBrowsingService> service_; |
| 186 | 190 |
| 187 private: | 191 private: |
| 188 void InitResource(SafeBrowsingService::UnsafeResource* resource, | 192 void InitResource(SafeBrowsingService::UnsafeResource* resource, |
| 189 bool is_subresource, | 193 bool is_subresource, |
| 190 const GURL& url) { | 194 const GURL& url) { |
| 191 resource->callback = | 195 resource->callback = |
| 192 base::Bind(&SafeBrowsingBlockingPageTest::OnBlockingPageComplete, | 196 base::Bind(&SafeBrowsingBlockingPageV2Test::OnBlockingPageComplete, |
| 193 base::Unretained(this)); | 197 base::Unretained(this)); |
| 194 resource->url = url; | 198 resource->url = url; |
| 195 resource->is_subresource = is_subresource; | 199 resource->is_subresource = is_subresource; |
| 196 resource->threat_type = SafeBrowsingService::URL_MALWARE; | 200 resource->threat_type = SafeBrowsingService::URL_MALWARE; |
| 197 resource->render_process_host_id = contents()->GetRenderProcessHost()-> | 201 resource->render_process_host_id = contents()->GetRenderProcessHost()-> |
| 198 GetID(); | 202 GetID(); |
| 199 resource->render_view_id = contents()->GetRenderViewHost()->GetRoutingID(); | 203 resource->render_view_id = contents()->GetRenderViewHost()->GetRoutingID(); |
| 200 } | 204 } |
| 201 | 205 |
| 202 UserResponse user_response_; | 206 UserResponse user_response_; |
| 203 TestSafeBrowsingBlockingPageFactory factory_; | 207 TestSafeBrowsingBlockingPageFactory factory_; |
| 204 content::TestBrowserThread ui_thread_; | 208 content::TestBrowserThread ui_thread_; |
| 205 content::TestBrowserThread file_user_blocking_thread_; | 209 content::TestBrowserThread file_user_blocking_thread_; |
| 206 content::TestBrowserThread io_thread_; | 210 content::TestBrowserThread io_thread_; |
| 207 }; | 211 }; |
| 208 | 212 |
| 209 // Tests showing a blocking page for a malware page and not proceeding. | 213 // Tests showing a blocking page for a malware page and not proceeding. |
| 210 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { | 214 TEST_F(SafeBrowsingBlockingPageV2Test, MalwarePageDontProceed) { |
| 211 // Enable malware details. | 215 // Enable malware details. |
| 212 Profile* profile = Profile::FromBrowserContext( | 216 Profile* profile = Profile::FromBrowserContext( |
| 213 contents()->GetBrowserContext()); | 217 contents()->GetBrowserContext()); |
| 214 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 218 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 215 | 219 |
| 216 // Start a load. | 220 // Start a load. |
| 217 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 221 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 218 content::PAGE_TRANSITION_TYPED, std::string()); | 222 content::PAGE_TRANSITION_TYPED, std::string()); |
| 219 | 223 |
| 220 | 224 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 234 | 238 |
| 235 // We did not proceed, the pending entry should be gone. | 239 // We did not proceed, the pending entry should be gone. |
| 236 EXPECT_FALSE(controller().GetPendingEntry()); | 240 EXPECT_FALSE(controller().GetPendingEntry()); |
| 237 | 241 |
| 238 // A report should have been sent. | 242 // A report should have been sent. |
| 239 EXPECT_EQ(1u, service_->GetDetails()->size()); | 243 EXPECT_EQ(1u, service_->GetDetails()->size()); |
| 240 service_->GetDetails()->clear(); | 244 service_->GetDetails()->clear(); |
| 241 } | 245 } |
| 242 | 246 |
| 243 // Tests showing a blocking page for a malware page and then proceeding. | 247 // Tests showing a blocking page for a malware page and then proceeding. |
| 244 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { | 248 TEST_F(SafeBrowsingBlockingPageV2Test, MalwarePageProceed) { |
| 245 // Enable malware reports. | 249 // Enable malware reports. |
| 246 Profile* profile = Profile::FromBrowserContext( | 250 Profile* profile = Profile::FromBrowserContext( |
| 247 contents()->GetBrowserContext()); | 251 contents()->GetBrowserContext()); |
| 248 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 252 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 249 | 253 |
| 250 // Start a load. | 254 // Start a load. |
| 251 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 255 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 252 content::PAGE_TRANSITION_TYPED, std::string()); | 256 content::PAGE_TRANSITION_TYPED, std::string()); |
| 253 | 257 |
| 254 // Simulate the load causing a safe browsing interstitial to be shown. | 258 // Simulate the load causing a safe browsing interstitial to be shown. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 266 // The interstitial should be gone now. | 270 // The interstitial should be gone now. |
| 267 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(contents())); | 271 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(contents())); |
| 268 | 272 |
| 269 // A report should have been sent. | 273 // A report should have been sent. |
| 270 EXPECT_EQ(1u, service_->GetDetails()->size()); | 274 EXPECT_EQ(1u, service_->GetDetails()->size()); |
| 271 service_->GetDetails()->clear(); | 275 service_->GetDetails()->clear(); |
| 272 } | 276 } |
| 273 | 277 |
| 274 // Tests showing a blocking page for a page that contains malware subresources | 278 // Tests showing a blocking page for a page that contains malware subresources |
| 275 // and not proceeding. | 279 // and not proceeding. |
| 276 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { | 280 TEST_F(SafeBrowsingBlockingPageV2Test, PageWithMalwareResourceDontProceed) { |
| 277 // Enable malware reports. | 281 // Enable malware reports. |
| 278 Profile* profile = Profile::FromBrowserContext( | 282 Profile* profile = Profile::FromBrowserContext( |
| 279 contents()->GetBrowserContext()); | 283 contents()->GetBrowserContext()); |
| 280 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 284 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 281 | 285 |
| 282 // Navigate somewhere. | 286 // Navigate somewhere. |
| 283 Navigate(kGoogleURL, 1); | 287 Navigate(kGoogleURL, 1); |
| 284 | 288 |
| 285 // Navigate somewhere else. | 289 // Navigate somewhere else. |
| 286 Navigate(kGoodURL, 2); | 290 Navigate(kGoodURL, 2); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 301 ASSERT_EQ(1, controller().GetEntryCount()); | 305 ASSERT_EQ(1, controller().GetEntryCount()); |
| 302 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | 306 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); |
| 303 | 307 |
| 304 // A report should have been sent. | 308 // A report should have been sent. |
| 305 EXPECT_EQ(1u, service_->GetDetails()->size()); | 309 EXPECT_EQ(1u, service_->GetDetails()->size()); |
| 306 service_->GetDetails()->clear(); | 310 service_->GetDetails()->clear(); |
| 307 } | 311 } |
| 308 | 312 |
| 309 // Tests showing a blocking page for a page that contains malware subresources | 313 // Tests showing a blocking page for a page that contains malware subresources |
| 310 // and proceeding. | 314 // and proceeding. |
| 311 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { | 315 TEST_F(SafeBrowsingBlockingPageV2Test, PageWithMalwareResourceProceed) { |
| 312 // Enable malware reports. | 316 // Enable malware reports. |
| 313 Profile* profile = Profile::FromBrowserContext( | 317 Profile* profile = Profile::FromBrowserContext( |
| 314 contents()->GetBrowserContext()); | 318 contents()->GetBrowserContext()); |
| 315 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 319 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 316 | 320 |
| 317 // Navigate somewhere. | 321 // Navigate somewhere. |
| 318 Navigate(kGoodURL, 1); | 322 Navigate(kGoodURL, 1); |
| 319 | 323 |
| 320 // Simulate that page loading a bad-resource triggering an interstitial. | 324 // Simulate that page loading a bad-resource triggering an interstitial. |
| 321 ShowInterstitial(true, kBadURL); | 325 ShowInterstitial(true, kBadURL); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 333 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); | 337 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); |
| 334 | 338 |
| 335 // A report should have been sent. | 339 // A report should have been sent. |
| 336 EXPECT_EQ(1u, service_->GetDetails()->size()); | 340 EXPECT_EQ(1u, service_->GetDetails()->size()); |
| 337 service_->GetDetails()->clear(); | 341 service_->GetDetails()->clear(); |
| 338 } | 342 } |
| 339 | 343 |
| 340 // Tests showing a blocking page for a page that contains multiple malware | 344 // Tests showing a blocking page for a page that contains multiple malware |
| 341 // subresources and not proceeding. This just tests that the extra malware | 345 // subresources and not proceeding. This just tests that the extra malware |
| 342 // subresources (which trigger queued interstitial pages) do not break anything. | 346 // subresources (which trigger queued interstitial pages) do not break anything. |
| 343 TEST_F(SafeBrowsingBlockingPageTest, | 347 TEST_F(SafeBrowsingBlockingPageV2Test, |
| 344 PageWithMultipleMalwareResourceDontProceed) { | 348 PageWithMultipleMalwareResourceDontProceed) { |
| 345 // Enable malware reports. | 349 // Enable malware reports. |
| 346 Profile* profile = Profile::FromBrowserContext( | 350 Profile* profile = Profile::FromBrowserContext( |
| 347 contents()->GetBrowserContext()); | 351 contents()->GetBrowserContext()); |
| 348 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 352 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 349 | 353 |
| 350 // Navigate somewhere. | 354 // Navigate somewhere. |
| 351 Navigate(kGoogleURL, 1); | 355 Navigate(kGoogleURL, 1); |
| 352 | 356 |
| 353 // Navigate somewhere else. | 357 // Navigate somewhere else. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 372 // We did not proceed, we should be back to the first page, the 2nd one should | 376 // We did not proceed, we should be back to the first page, the 2nd one should |
| 373 // have been removed from the navigation controller. | 377 // have been removed from the navigation controller. |
| 374 ASSERT_EQ(1, controller().GetEntryCount()); | 378 ASSERT_EQ(1, controller().GetEntryCount()); |
| 375 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | 379 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); |
| 376 | 380 |
| 377 // A report should have been sent. | 381 // A report should have been sent. |
| 378 EXPECT_EQ(1u, service_->GetDetails()->size()); | 382 EXPECT_EQ(1u, service_->GetDetails()->size()); |
| 379 service_->GetDetails()->clear(); | 383 service_->GetDetails()->clear(); |
| 380 } | 384 } |
| 381 | 385 |
| 382 // Tests showing a blocking page for a page that contains multiple malware | |
| 383 // subresources and proceeding through the first interstitial, but not the next. | |
| 384 TEST_F(SafeBrowsingBlockingPageTest, | |
| 385 PageWithMultipleMalwareResourceProceedThenDontProceed) { | |
| 386 // Enable malware reports. | |
| 387 Profile* profile = Profile::FromBrowserContext( | |
| 388 contents()->GetBrowserContext()); | |
| 389 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | |
| 390 | |
| 391 // Navigate somewhere. | |
| 392 Navigate(kGoogleURL, 1); | |
| 393 | |
| 394 // Navigate somewhere else. | |
| 395 Navigate(kGoodURL, 2); | |
| 396 | |
| 397 // Simulate that page loading a bad-resource triggering an interstitial. | |
| 398 ShowInterstitial(true, kBadURL); | |
| 399 | |
| 400 // More bad resources loading causing more interstitials. The new | |
| 401 // interstitials should be queued. | |
| 402 ShowInterstitial(true, kBadURL2); | |
| 403 ShowInterstitial(true, kBadURL3); | |
| 404 | |
| 405 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | |
| 406 ASSERT_TRUE(sb_interstitial); | |
| 407 | |
| 408 // Proceed through the 1st interstitial. | |
| 409 ProceedThroughInterstitial(sb_interstitial); | |
| 410 EXPECT_EQ(OK, user_response()); | |
| 411 | |
| 412 // A report should have been sent. | |
| 413 EXPECT_EQ(1u, service_->GetDetails()->size()); | |
| 414 service_->GetDetails()->clear(); | |
| 415 | |
| 416 ResetUserResponse(); | |
| 417 | |
| 418 // We should land to a 2nd interstitial (aggregating all the malware resources | |
| 419 // loaded while the 1st interstitial was showing). | |
| 420 sb_interstitial = GetSafeBrowsingBlockingPage(); | |
| 421 ASSERT_TRUE(sb_interstitial); | |
| 422 | |
| 423 // Don't proceed through the 2nd interstitial. | |
| 424 DontProceedThroughSubresourceInterstitial(sb_interstitial); | |
| 425 EXPECT_EQ(CANCEL, user_response()); | |
| 426 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | |
| 427 | |
| 428 // We did not proceed, we should be back to the first page, the 2nd one should | |
| 429 // have been removed from the navigation controller. | |
| 430 ASSERT_EQ(1, controller().GetEntryCount()); | |
| 431 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | |
| 432 | |
| 433 // No report should have been sent -- we don't create a report the | |
| 434 // second time. | |
| 435 EXPECT_EQ(0u, service_->GetDetails()->size()); | |
| 436 service_->GetDetails()->clear(); | |
| 437 } | |
| 438 | |
| 439 // Tests showing a blocking page for a page that contains multiple malware | |
| 440 // subresources and proceeding through the multiple interstitials. | |
| 441 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { | |
| 442 // Enable malware reports. | |
| 443 Profile* profile = Profile::FromBrowserContext( | |
| 444 contents()->GetBrowserContext()); | |
| 445 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | |
| 446 | |
| 447 // Navigate somewhere else. | |
| 448 Navigate(kGoodURL, 1); | |
| 449 | |
| 450 // Simulate that page loading a bad-resource triggering an interstitial. | |
| 451 ShowInterstitial(true, kBadURL); | |
| 452 | |
| 453 // More bad resources loading causing more interstitials. The new | |
| 454 // interstitials should be queued. | |
| 455 ShowInterstitial(true, kBadURL2); | |
| 456 ShowInterstitial(true, kBadURL3); | |
| 457 | |
| 458 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | |
| 459 ASSERT_TRUE(sb_interstitial); | |
| 460 | |
| 461 // Proceed through the 1st interstitial. | |
| 462 ProceedThroughInterstitial(sb_interstitial); | |
| 463 EXPECT_EQ(OK, user_response()); | |
| 464 | |
| 465 // A report should have been sent. | |
| 466 EXPECT_EQ(1u, service_->GetDetails()->size()); | |
| 467 service_->GetDetails()->clear(); | |
| 468 | |
| 469 ResetUserResponse(); | |
| 470 | |
| 471 // We should land to a 2nd interstitial (aggregating all the malware resources | |
| 472 // loaded while the 1st interstitial was showing). | |
| 473 sb_interstitial = GetSafeBrowsingBlockingPage(); | |
| 474 ASSERT_TRUE(sb_interstitial); | |
| 475 | |
| 476 // Proceed through the 2nd interstitial. | |
| 477 ProceedThroughInterstitial(sb_interstitial); | |
| 478 EXPECT_EQ(OK, user_response()); | |
| 479 | |
| 480 // We did proceed, we should be back to the initial page. | |
| 481 ASSERT_EQ(1, controller().GetEntryCount()); | |
| 482 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); | |
| 483 | |
| 484 // No report should have been sent -- we don't create a report the | |
| 485 // second time. | |
| 486 EXPECT_EQ(0u, service_->GetDetails()->size()); | |
| 487 service_->GetDetails()->clear(); | |
| 488 } | |
| 489 | |
| 490 // Tests showing a blocking page then navigating back and forth to make sure the | 386 // Tests showing a blocking page then navigating back and forth to make sure the |
| 491 // controller entries are OK. http://crbug.com/17627 | 387 // controller entries are OK. http://crbug.com/17627 |
| 492 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { | 388 TEST_F(SafeBrowsingBlockingPageV2Test, NavigatingBackAndForth) { |
| 493 // Enable malware reports. | 389 // Enable malware reports. |
| 494 Profile* profile = Profile::FromBrowserContext( | 390 Profile* profile = Profile::FromBrowserContext( |
| 495 contents()->GetBrowserContext()); | 391 contents()->GetBrowserContext()); |
| 496 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 392 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 497 | 393 |
| 498 // Navigate somewhere. | 394 // Navigate somewhere. |
| 499 Navigate(kGoodURL, 1); | 395 Navigate(kGoodURL, 1); |
| 500 | 396 |
| 501 // Now navigate to a bad page triggerring an interstitial. | 397 // Now navigate to a bad page triggerring an interstitial. |
| 502 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 398 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 530 ASSERT_EQ(2, controller().GetEntryCount()); | 426 ASSERT_EQ(2, controller().GetEntryCount()); |
| 531 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec()); | 427 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec()); |
| 532 | 428 |
| 533 // Two reports should have been sent. | 429 // Two reports should have been sent. |
| 534 EXPECT_EQ(2u, service_->GetDetails()->size()); | 430 EXPECT_EQ(2u, service_->GetDetails()->size()); |
| 535 service_->GetDetails()->clear(); | 431 service_->GetDetails()->clear(); |
| 536 } | 432 } |
| 537 | 433 |
| 538 // Tests that calling "don't proceed" after "proceed" has been called doesn't | 434 // Tests that calling "don't proceed" after "proceed" has been called doesn't |
| 539 // cause problems. http://crbug.com/30079 | 435 // cause problems. http://crbug.com/30079 |
| 540 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { | 436 TEST_F(SafeBrowsingBlockingPageV2Test, ProceedThenDontProceed) { |
| 541 // Enable malware reports. | 437 // Enable malware reports. |
| 542 Profile* profile = Profile::FromBrowserContext( | 438 Profile* profile = Profile::FromBrowserContext( |
| 543 contents()->GetBrowserContext()); | 439 contents()->GetBrowserContext()); |
| 544 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 440 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 545 | 441 |
| 546 // Start a load. | 442 // Start a load. |
| 547 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 443 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 548 content::PAGE_TRANSITION_TYPED, std::string()); | 444 content::PAGE_TRANSITION_TYPED, std::string()); |
| 549 | 445 |
| 550 // Simulate the load causing a safe browsing interstitial to be shown. | 446 // Simulate the load causing a safe browsing interstitial to be shown. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 565 // The interstitial should be gone. | 461 // The interstitial should be gone. |
| 566 EXPECT_EQ(OK, user_response()); | 462 EXPECT_EQ(OK, user_response()); |
| 567 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 463 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
| 568 | 464 |
| 569 // Only one report should have been sent. | 465 // Only one report should have been sent. |
| 570 EXPECT_EQ(1u, service_->GetDetails()->size()); | 466 EXPECT_EQ(1u, service_->GetDetails()->size()); |
| 571 service_->GetDetails()->clear(); | 467 service_->GetDetails()->clear(); |
| 572 } | 468 } |
| 573 | 469 |
| 574 // Tests showing a blocking page for a malware page with reports disabled. | 470 // Tests showing a blocking page for a malware page with reports disabled. |
| 575 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { | 471 TEST_F(SafeBrowsingBlockingPageV2Test, MalwareReportsDisabled) { |
| 576 // Disable malware reports. | 472 // Disable malware reports. |
| 577 Profile* profile = Profile::FromBrowserContext( | 473 Profile* profile = Profile::FromBrowserContext( |
| 578 contents()->GetBrowserContext()); | 474 contents()->GetBrowserContext()); |
| 579 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); | 475 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); |
| 580 | 476 |
| 581 // Start a load. | 477 // Start a load. |
| 582 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 478 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 583 content::PAGE_TRANSITION_TYPED, std::string()); | 479 content::PAGE_TRANSITION_TYPED, std::string()); |
| 584 | 480 |
| 585 // Simulate the load causing a safe browsing interstitial to be shown. | 481 // Simulate the load causing a safe browsing interstitial to be shown. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 598 | 494 |
| 599 // We did not proceed, the pending entry should be gone. | 495 // We did not proceed, the pending entry should be gone. |
| 600 EXPECT_FALSE(controller().GetPendingEntry()); | 496 EXPECT_FALSE(controller().GetPendingEntry()); |
| 601 | 497 |
| 602 // No report should have been sent. | 498 // No report should have been sent. |
| 603 EXPECT_EQ(0u, service_->GetDetails()->size()); | 499 EXPECT_EQ(0u, service_->GetDetails()->size()); |
| 604 service_->GetDetails()->clear(); | 500 service_->GetDetails()->clear(); |
| 605 } | 501 } |
| 606 | 502 |
| 607 // Test setting the malware report preferance | 503 // Test setting the malware report preferance |
| 608 TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { | 504 TEST_F(SafeBrowsingBlockingPageV2Test, MalwareReports) { |
| 609 // Disable malware reports. | 505 // Disable malware reports. |
| 610 Profile* profile = Profile::FromBrowserContext( | 506 Profile* profile = Profile::FromBrowserContext( |
| 611 contents()->GetBrowserContext()); | 507 contents()->GetBrowserContext()); |
| 612 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); | 508 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); |
| 613 | 509 |
| 614 // Start a load. | 510 // Start a load. |
| 615 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 511 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 616 content::PAGE_TRANSITION_TYPED, std::string()); | 512 content::PAGE_TRANSITION_TYPED, std::string()); |
| 617 | 513 |
| 618 // Simulate the load causing a safe browsing interstitial to be shown. | 514 // Simulate the load causing a safe browsing interstitial to be shown. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 630 | 526 |
| 631 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( | 527 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( |
| 632 prefs::kSafeBrowsingReportingEnabled)); | 528 prefs::kSafeBrowsingReportingEnabled)); |
| 633 | 529 |
| 634 // Simulate the user uncheck the report agreement checkbox. | 530 // Simulate the user uncheck the report agreement checkbox. |
| 635 sb_interstitial->SetReportingPreference(false); | 531 sb_interstitial->SetReportingPreference(false); |
| 636 | 532 |
| 637 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 533 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( |
| 638 prefs::kSafeBrowsingReportingEnabled)); | 534 prefs::kSafeBrowsingReportingEnabled)); |
| 639 } | 535 } |
| OLD | NEW |