| 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 | 4 |
| 5 #include <list> | 5 #include <list> |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/safe_browsing/malware_details.h" | 10 #include "chrome/browser/safe_browsing/malware_details.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 const UnsafeResourceList& unsafe_resources) | 55 const UnsafeResourceList& unsafe_resources) |
| 56 : SafeBrowsingBlockingPageV2(manager, web_contents, unsafe_resources) { | 56 : SafeBrowsingBlockingPageV2(manager, web_contents, unsafe_resources) { |
| 57 // Don't delay details at all for the unittest. | 57 // Don't delay details at all for the unittest. |
| 58 malware_details_proceed_delay_ms_ = 0; | 58 malware_details_proceed_delay_ms_ = 0; |
| 59 | 59 |
| 60 // Don't create a view. | 60 // Don't create a view. |
| 61 interstitial_page()->DontCreateViewForTesting(); | 61 interstitial_page()->DontCreateViewForTesting(); |
| 62 } | 62 } |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // A SafeBrowingBlockingPage class that does not create windows. |
| 66 class TestSafeBrowsingBlockingPageV3 : public SafeBrowsingBlockingPageV3 { |
| 67 public: |
| 68 TestSafeBrowsingBlockingPageV3(SafeBrowsingUIManager* manager, |
| 69 WebContents* web_contents, |
| 70 const UnsafeResourceList& unsafe_resources) |
| 71 : SafeBrowsingBlockingPageV3(manager, web_contents, unsafe_resources) { |
| 72 // Don't delay details at all for the unittest. |
| 73 malware_details_proceed_delay_ms_ = 0; |
| 74 |
| 75 // Don't create a view. |
| 76 interstitial_page()->DontCreateViewForTesting(); |
| 77 } |
| 78 }; |
| 79 |
| 65 class TestSafeBrowsingUIManager: public SafeBrowsingUIManager { | 80 class TestSafeBrowsingUIManager: public SafeBrowsingUIManager { |
| 66 public: | 81 public: |
| 67 explicit TestSafeBrowsingUIManager(SafeBrowsingService* service) | 82 explicit TestSafeBrowsingUIManager(SafeBrowsingService* service) |
| 68 : SafeBrowsingUIManager(service) { | 83 : SafeBrowsingUIManager(service) { |
| 69 } | 84 } |
| 70 | 85 |
| 71 virtual void SendSerializedMalwareDetails( | 86 virtual void SendSerializedMalwareDetails( |
| 72 const std::string& serialized) OVERRIDE { | 87 const std::string& serialized) OVERRIDE { |
| 73 details_.push_back(serialized); | 88 details_.push_back(serialized); |
| 74 } | 89 } |
| 75 | 90 |
| 76 std::list<std::string>* GetDetails() { | 91 std::list<std::string>* GetDetails() { |
| 77 return &details_; | 92 return &details_; |
| 78 } | 93 } |
| 79 | 94 |
| 80 private: | 95 private: |
| 81 virtual ~TestSafeBrowsingUIManager() {} | 96 virtual ~TestSafeBrowsingUIManager() {} |
| 82 | 97 |
| 83 std::list<std::string> details_; | 98 std::list<std::string> details_; |
| 84 }; | 99 }; |
| 85 | 100 |
| 101 template <class SBInterstitialPage> |
| 86 class TestSafeBrowsingBlockingPageFactory | 102 class TestSafeBrowsingBlockingPageFactory |
| 87 : public SafeBrowsingBlockingPageFactory { | 103 : public SafeBrowsingBlockingPageFactory { |
| 88 public: | 104 public: |
| 89 TestSafeBrowsingBlockingPageFactory() { } | 105 TestSafeBrowsingBlockingPageFactory() { } |
| 90 virtual ~TestSafeBrowsingBlockingPageFactory() { } | 106 virtual ~TestSafeBrowsingBlockingPageFactory() { } |
| 91 | 107 |
| 92 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 108 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 93 SafeBrowsingUIManager* manager, | 109 SafeBrowsingUIManager* manager, |
| 94 WebContents* web_contents, | 110 WebContents* web_contents, |
| 95 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) | 111 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) |
| 96 OVERRIDE { | 112 OVERRIDE { |
| 97 // TODO(mattm): remove this when SafeBrowsingBlockingPageV2 supports | 113 // TODO(mattm): remove this when SafeBrowsingBlockingPageV2 supports |
| 98 // multi-threat warnings. | 114 // multi-threat warnings. |
| 99 if (unsafe_resources.size() == 1 && | 115 if (unsafe_resources.size() == 1 && |
| 100 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || | 116 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 101 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING)) { | 117 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING)) { |
| 102 return new TestSafeBrowsingBlockingPageV2(manager, web_contents, | 118 return new SBInterstitialPage(manager, web_contents, unsafe_resources); |
| 103 unsafe_resources); | |
| 104 } | 119 } |
| 105 return new TestSafeBrowsingBlockingPageV1(manager, web_contents, | 120 return new TestSafeBrowsingBlockingPageV1(manager, web_contents, |
| 106 unsafe_resources); | 121 unsafe_resources); |
| 107 } | 122 } |
| 108 }; | 123 }; |
| 109 | 124 |
| 110 } // namespace | 125 } // namespace |
| 111 | 126 |
| 127 template <class SBInterstitialPage> |
| 112 class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { | 128 class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { |
| 113 public: | 129 public: |
| 114 // The decision the user made. | 130 // The decision the user made. |
| 115 enum UserResponse { | 131 enum UserResponse { |
| 116 PENDING, | 132 PENDING, |
| 117 OK, | 133 OK, |
| 118 CANCEL | 134 CANCEL |
| 119 }; | 135 }; |
| 120 | 136 |
| 121 SafeBrowsingBlockingPageTest() { | 137 SafeBrowsingBlockingPageTest() { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 resource->url = url; | 240 resource->url = url; |
| 225 resource->is_subresource = is_subresource; | 241 resource->is_subresource = is_subresource; |
| 226 resource->threat_type = SB_THREAT_TYPE_URL_MALWARE; | 242 resource->threat_type = SB_THREAT_TYPE_URL_MALWARE; |
| 227 resource->render_process_host_id = | 243 resource->render_process_host_id = |
| 228 web_contents()->GetRenderProcessHost()->GetID(); | 244 web_contents()->GetRenderProcessHost()->GetID(); |
| 229 resource->render_view_id = | 245 resource->render_view_id = |
| 230 web_contents()->GetRenderViewHost()->GetRoutingID(); | 246 web_contents()->GetRenderViewHost()->GetRoutingID(); |
| 231 } | 247 } |
| 232 | 248 |
| 233 UserResponse user_response_; | 249 UserResponse user_response_; |
| 234 TestSafeBrowsingBlockingPageFactory factory_; | 250 TestSafeBrowsingBlockingPageFactory<SBInterstitialPage> factory_; |
| 235 }; | 251 }; |
| 236 | 252 |
| 253 typedef ::testing::Types<TestSafeBrowsingBlockingPageV2, |
| 254 TestSafeBrowsingBlockingPageV3> InterstitialTestTypes; |
| 255 TYPED_TEST_CASE(SafeBrowsingBlockingPageTest, InterstitialTestTypes); |
| 256 |
| 237 // Tests showing a blocking page for a malware page and not proceeding. | 257 // Tests showing a blocking page for a malware page and not proceeding. |
| 238 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { | 258 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { |
| 239 // Enable malware details. | 259 // Enable malware details. |
| 240 Profile* profile = Profile::FromBrowserContext( | 260 Profile* profile = Profile::FromBrowserContext( |
| 241 web_contents()->GetBrowserContext()); | 261 this->web_contents()->GetBrowserContext()); |
| 242 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 262 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 243 | 263 |
| 244 // Start a load. | 264 // Start a load. |
| 245 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 265 this->controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 246 content::PAGE_TRANSITION_TYPED, std::string()); | 266 content::PAGE_TRANSITION_TYPED, std::string()); |
| 247 | 267 |
| 248 | 268 |
| 249 // Simulate the load causing a safe browsing interstitial to be shown. | 269 // Simulate the load causing a safe browsing interstitial to be shown. |
| 250 ShowInterstitial(false, kBadURL); | 270 this->ShowInterstitial(false, kBadURL); |
| 251 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 271 SafeBrowsingBlockingPage* sb_interstitial = |
| 272 this->GetSafeBrowsingBlockingPage(); |
| 252 ASSERT_TRUE(sb_interstitial); | 273 ASSERT_TRUE(sb_interstitial); |
| 253 | 274 |
| 254 base::RunLoop().RunUntilIdle(); | 275 base::RunLoop().RunUntilIdle(); |
| 255 | 276 |
| 256 // Simulate the user clicking "don't proceed". | 277 // Simulate the user clicking "don't proceed". |
| 257 DontProceedThroughInterstitial(sb_interstitial); | 278 this->DontProceedThroughInterstitial(sb_interstitial); |
| 258 | 279 |
| 259 // The interstitial should be gone. | 280 // The interstitial should be gone. |
| 260 EXPECT_EQ(CANCEL, user_response()); | 281 EXPECT_EQ(this->CANCEL, this->user_response()); |
| 261 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 282 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage()); |
| 262 | 283 |
| 263 // We did not proceed, the pending entry should be gone. | 284 // We did not proceed, the pending entry should be gone. |
| 264 EXPECT_FALSE(controller().GetPendingEntry()); | 285 EXPECT_FALSE(this->controller().GetPendingEntry()); |
| 265 | 286 |
| 266 // A report should have been sent. | 287 // A report should have been sent. |
| 267 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 288 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size()); |
| 268 ui_manager_->GetDetails()->clear(); | 289 this->ui_manager_->GetDetails()->clear(); |
| 269 } | 290 } |
| 270 | 291 |
| 271 // Tests showing a blocking page for a malware page and then proceeding. | 292 // Tests showing a blocking page for a malware page and then proceeding. |
| 272 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { | 293 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwarePageProceed) { |
| 273 // Enable malware reports. | 294 // Enable malware reports. |
| 274 Profile* profile = Profile::FromBrowserContext( | 295 Profile* profile = Profile::FromBrowserContext( |
| 275 web_contents()->GetBrowserContext()); | 296 this->web_contents()->GetBrowserContext()); |
| 276 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 297 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 277 | 298 |
| 278 // Start a load. | 299 // Start a load. |
| 279 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 300 this->controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 280 content::PAGE_TRANSITION_TYPED, std::string()); | 301 content::PAGE_TRANSITION_TYPED, std::string()); |
| 281 | 302 |
| 282 // Simulate the load causing a safe browsing interstitial to be shown. | 303 // Simulate the load causing a safe browsing interstitial to be shown. |
| 283 ShowInterstitial(false, kBadURL); | 304 this->ShowInterstitial(false, kBadURL); |
| 284 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 305 SafeBrowsingBlockingPage* sb_interstitial = |
| 306 this->GetSafeBrowsingBlockingPage(); |
| 285 ASSERT_TRUE(sb_interstitial); | 307 ASSERT_TRUE(sb_interstitial); |
| 286 | 308 |
| 287 // Simulate the user clicking "proceed". | 309 // Simulate the user clicking "proceed". |
| 288 ProceedThroughInterstitial(sb_interstitial); | 310 this->ProceedThroughInterstitial(sb_interstitial); |
| 289 | 311 |
| 290 // The interstitial is shown until the navigation commits. | 312 // The interstitial is shown until the navigation commits. |
| 291 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents())); | 313 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(this->web_contents())); |
| 292 // Commit the navigation. | 314 // Commit the navigation. |
| 293 Navigate(kBadURL, 1); | 315 this->Navigate(kBadURL, 1); |
| 294 // The interstitial should be gone now. | 316 // The interstitial should be gone now. |
| 295 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents())); | 317 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(this->web_contents())); |
| 296 | 318 |
| 297 // A report should have been sent. | 319 // A report should have been sent. |
| 298 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 320 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size()); |
| 299 ui_manager_->GetDetails()->clear(); | 321 this->ui_manager_->GetDetails()->clear(); |
| 300 } | 322 } |
| 301 | 323 |
| 302 // Tests showing a blocking page for a page that contains malware subresources | 324 // Tests showing a blocking page for a page that contains malware subresources |
| 303 // and not proceeding. | 325 // and not proceeding. |
| 304 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { | 326 TYPED_TEST(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { |
| 305 // Enable malware reports. | 327 // Enable malware reports. |
| 306 Profile* profile = Profile::FromBrowserContext( | 328 Profile* profile = Profile::FromBrowserContext( |
| 307 web_contents()->GetBrowserContext()); | 329 this->web_contents()->GetBrowserContext()); |
| 308 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 330 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 309 | 331 |
| 310 // Navigate somewhere. | 332 // Navigate somewhere. |
| 311 Navigate(kGoogleURL, 1); | 333 this->Navigate(kGoogleURL, 1); |
| 312 | 334 |
| 313 // Navigate somewhere else. | 335 // Navigate somewhere else. |
| 314 Navigate(kGoodURL, 2); | 336 this->Navigate(kGoodURL, 2); |
| 315 | 337 |
| 316 // Simulate that page loading a bad-resource triggering an interstitial. | 338 // Simulate that page loading a bad-resource triggering an interstitial. |
| 317 ShowInterstitial(true, kBadURL); | 339 this->ShowInterstitial(true, kBadURL); |
| 318 | 340 |
| 319 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 341 SafeBrowsingBlockingPage* sb_interstitial = |
| 342 this->GetSafeBrowsingBlockingPage(); |
| 320 ASSERT_TRUE(sb_interstitial); | 343 ASSERT_TRUE(sb_interstitial); |
| 321 | 344 |
| 322 // Simulate the user clicking "don't proceed". | 345 // Simulate the user clicking "don't proceed". |
| 323 DontProceedThroughSubresourceInterstitial(sb_interstitial); | 346 this->DontProceedThroughSubresourceInterstitial(sb_interstitial); |
| 324 EXPECT_EQ(CANCEL, user_response()); | 347 EXPECT_EQ(this->CANCEL, this->user_response()); |
| 325 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 348 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage()); |
| 326 | 349 |
| 327 // We did not proceed, we should be back to the first page, the 2nd one should | 350 // We did not proceed, we should be back to the first page, the 2nd one should |
| 328 // have been removed from the navigation controller. | 351 // have been removed from the navigation controller. |
| 329 ASSERT_EQ(1, controller().GetEntryCount()); | 352 ASSERT_EQ(1, this->controller().GetEntryCount()); |
| 330 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | 353 EXPECT_EQ(kGoogleURL, this->controller().GetActiveEntry()->GetURL().spec()); |
| 331 | 354 |
| 332 // A report should have been sent. | 355 // A report should have been sent. |
| 333 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 356 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size()); |
| 334 ui_manager_->GetDetails()->clear(); | 357 this->ui_manager_->GetDetails()->clear(); |
| 335 } | 358 } |
| 336 | 359 |
| 337 // Tests showing a blocking page for a page that contains malware subresources | 360 // Tests showing a blocking page for a page that contains malware subresources |
| 338 // and proceeding. | 361 // and proceeding. |
| 339 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { | 362 TYPED_TEST(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { |
| 340 // Enable malware reports. | 363 // Enable malware reports. |
| 341 Profile* profile = Profile::FromBrowserContext( | 364 Profile* profile = Profile::FromBrowserContext( |
| 342 web_contents()->GetBrowserContext()); | 365 this->web_contents()->GetBrowserContext()); |
| 343 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 366 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 344 | 367 |
| 345 // Navigate somewhere. | 368 // Navigate somewhere. |
| 346 Navigate(kGoodURL, 1); | 369 this->Navigate(kGoodURL, 1); |
| 347 | 370 |
| 348 // Simulate that page loading a bad-resource triggering an interstitial. | 371 // Simulate that page loading a bad-resource triggering an interstitial. |
| 349 ShowInterstitial(true, kBadURL); | 372 this->ShowInterstitial(true, kBadURL); |
| 350 | 373 |
| 351 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 374 SafeBrowsingBlockingPage* sb_interstitial = |
| 375 this->GetSafeBrowsingBlockingPage(); |
| 352 ASSERT_TRUE(sb_interstitial); | 376 ASSERT_TRUE(sb_interstitial); |
| 353 | 377 |
| 354 // Simulate the user clicking "proceed". | 378 // Simulate the user clicking "proceed". |
| 355 ProceedThroughInterstitial(sb_interstitial); | 379 this->ProceedThroughInterstitial(sb_interstitial); |
| 356 EXPECT_EQ(OK, user_response()); | 380 EXPECT_EQ(this->OK, this->user_response()); |
| 357 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 381 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage()); |
| 358 | 382 |
| 359 // We did proceed, we should be back to showing the page. | 383 // We did proceed, we should be back to showing the page. |
| 360 ASSERT_EQ(1, controller().GetEntryCount()); | 384 ASSERT_EQ(1, this->controller().GetEntryCount()); |
| 361 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); | 385 EXPECT_EQ(kGoodURL, this->controller().GetActiveEntry()->GetURL().spec()); |
| 362 | 386 |
| 363 // A report should have been sent. | 387 // A report should have been sent. |
| 364 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 388 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size()); |
| 365 ui_manager_->GetDetails()->clear(); | 389 this->ui_manager_->GetDetails()->clear(); |
| 366 } | 390 } |
| 367 | 391 |
| 368 // Tests showing a blocking page for a page that contains multiple malware | 392 // Tests showing a blocking page for a page that contains multiple malware |
| 369 // subresources and not proceeding. This just tests that the extra malware | 393 // subresources and not proceeding. This just tests that the extra malware |
| 370 // subresources (which trigger queued interstitial pages) do not break anything. | 394 // subresources (which trigger queued interstitial pages) do not break anything. |
| 371 TEST_F(SafeBrowsingBlockingPageTest, | 395 TYPED_TEST(SafeBrowsingBlockingPageTest, |
| 372 PageWithMultipleMalwareResourceDontProceed) { | 396 PageWithMultipleMalwareResourceDontProceed) { |
| 373 // Enable malware reports. | 397 // Enable malware reports. |
| 374 Profile* profile = Profile::FromBrowserContext( | 398 Profile* profile = Profile::FromBrowserContext( |
| 375 web_contents()->GetBrowserContext()); | 399 this->web_contents()->GetBrowserContext()); |
| 376 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 400 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 377 | 401 |
| 378 // Navigate somewhere. | 402 // Navigate somewhere. |
| 379 Navigate(kGoogleURL, 1); | 403 this->Navigate(kGoogleURL, 1); |
| 380 | 404 |
| 381 // Navigate somewhere else. | 405 // Navigate somewhere else. |
| 382 Navigate(kGoodURL, 2); | 406 this->Navigate(kGoodURL, 2); |
| 383 | 407 |
| 384 // Simulate that page loading a bad-resource triggering an interstitial. | 408 // Simulate that page loading a bad-resource triggering an interstitial. |
| 385 ShowInterstitial(true, kBadURL); | 409 this->ShowInterstitial(true, kBadURL); |
| 386 | 410 |
| 387 // More bad resources loading causing more interstitials. The new | 411 // More bad resources loading causing more interstitials. The new |
| 388 // interstitials should be queued. | 412 // interstitials should be queued. |
| 389 ShowInterstitial(true, kBadURL2); | 413 this->ShowInterstitial(true, kBadURL2); |
| 390 ShowInterstitial(true, kBadURL3); | 414 this->ShowInterstitial(true, kBadURL3); |
| 391 | 415 |
| 392 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 416 SafeBrowsingBlockingPage* sb_interstitial = |
| 417 this->GetSafeBrowsingBlockingPage(); |
| 393 ASSERT_TRUE(sb_interstitial); | 418 ASSERT_TRUE(sb_interstitial); |
| 394 | 419 |
| 395 // Simulate the user clicking "don't proceed". | 420 // Simulate the user clicking "don't proceed". |
| 396 DontProceedThroughSubresourceInterstitial(sb_interstitial); | 421 this->DontProceedThroughSubresourceInterstitial(sb_interstitial); |
| 397 EXPECT_EQ(CANCEL, user_response()); | 422 EXPECT_EQ(this->CANCEL, this->user_response()); |
| 398 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 423 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage()); |
| 399 | 424 |
| 400 // We did not proceed, we should be back to the first page, the 2nd one should | 425 // We did not proceed, we should be back to the first page, the 2nd one should |
| 401 // have been removed from the navigation controller. | 426 // have been removed from the navigation controller. |
| 402 ASSERT_EQ(1, controller().GetEntryCount()); | 427 ASSERT_EQ(1, this->controller().GetEntryCount()); |
| 403 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | 428 EXPECT_EQ(kGoogleURL, this->controller().GetActiveEntry()->GetURL().spec()); |
| 404 | 429 |
| 405 // A report should have been sent. | 430 // A report should have been sent. |
| 406 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 431 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size()); |
| 407 ui_manager_->GetDetails()->clear(); | 432 this->ui_manager_->GetDetails()->clear(); |
| 408 } | 433 } |
| 409 | 434 |
| 410 // Tests showing a blocking page for a page that contains multiple malware | 435 // Tests showing a blocking page for a page that contains multiple malware |
| 411 // subresources and proceeding through the first interstitial, but not the next. | 436 // subresources and proceeding through the first interstitial, but not the next. |
| 412 TEST_F(SafeBrowsingBlockingPageTest, | 437 TYPED_TEST(SafeBrowsingBlockingPageTest, |
| 413 PageWithMultipleMalwareResourceProceedThenDontProceed) { | 438 PageWithMultipleMalwareResourceProceedThenDontProceed) { |
| 414 // Enable malware reports. | 439 // Enable malware reports. |
| 415 Profile* profile = Profile::FromBrowserContext( | 440 Profile* profile = Profile::FromBrowserContext( |
| 416 web_contents()->GetBrowserContext()); | 441 this->web_contents()->GetBrowserContext()); |
| 417 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 442 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 418 | 443 |
| 419 // Navigate somewhere. | 444 // Navigate somewhere. |
| 420 Navigate(kGoogleURL, 1); | 445 this->Navigate(kGoogleURL, 1); |
| 421 | 446 |
| 422 // Navigate somewhere else. | 447 // Navigate somewhere else. |
| 423 Navigate(kGoodURL, 2); | 448 this->Navigate(kGoodURL, 2); |
| 424 | 449 |
| 425 // Simulate that page loading a bad-resource triggering an interstitial. | 450 // Simulate that page loading a bad-resource triggering an interstitial. |
| 426 ShowInterstitial(true, kBadURL); | 451 this->ShowInterstitial(true, kBadURL); |
| 427 | 452 |
| 428 // More bad resources loading causing more interstitials. The new | 453 // More bad resources loading causing more interstitials. The new |
| 429 // interstitials should be queued. | 454 // interstitials should be queued. |
| 430 ShowInterstitial(true, kBadURL2); | 455 this->ShowInterstitial(true, kBadURL2); |
| 431 ShowInterstitial(true, kBadURL3); | 456 this->ShowInterstitial(true, kBadURL3); |
| 432 | 457 |
| 433 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 458 SafeBrowsingBlockingPage* sb_interstitial = |
| 459 this->GetSafeBrowsingBlockingPage(); |
| 434 ASSERT_TRUE(sb_interstitial); | 460 ASSERT_TRUE(sb_interstitial); |
| 435 | 461 |
| 436 // Proceed through the 1st interstitial. | 462 // Proceed through the 1st interstitial. |
| 437 ProceedThroughInterstitial(sb_interstitial); | 463 this->ProceedThroughInterstitial(sb_interstitial); |
| 438 EXPECT_EQ(OK, user_response()); | 464 EXPECT_EQ(this->OK, this->user_response()); |
| 439 | 465 |
| 440 // A report should have been sent. | 466 // A report should have been sent. |
| 441 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 467 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size()); |
| 442 ui_manager_->GetDetails()->clear(); | 468 this->ui_manager_->GetDetails()->clear(); |
| 443 | 469 |
| 444 ResetUserResponse(); | 470 this->ResetUserResponse(); |
| 445 | 471 |
| 446 // We should land to a 2nd interstitial (aggregating all the malware resources | 472 // We should land to a 2nd interstitial (aggregating all the malware resources |
| 447 // loaded while the 1st interstitial was showing). | 473 // loaded while the 1st interstitial was showing). |
| 448 sb_interstitial = GetSafeBrowsingBlockingPage(); | 474 sb_interstitial = this->GetSafeBrowsingBlockingPage(); |
| 449 ASSERT_TRUE(sb_interstitial); | 475 ASSERT_TRUE(sb_interstitial); |
| 450 | 476 |
| 451 // Don't proceed through the 2nd interstitial. | 477 // Don't proceed through the 2nd interstitial. |
| 452 DontProceedThroughSubresourceInterstitial(sb_interstitial); | 478 this->DontProceedThroughSubresourceInterstitial(sb_interstitial); |
| 453 EXPECT_EQ(CANCEL, user_response()); | 479 EXPECT_EQ(this->CANCEL, this->user_response()); |
| 454 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 480 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage()); |
| 455 | 481 |
| 456 // We did not proceed, we should be back to the first page, the 2nd one should | 482 // We did not proceed, we should be back to the first page, the 2nd one should |
| 457 // have been removed from the navigation controller. | 483 // have been removed from the navigation controller. |
| 458 ASSERT_EQ(1, controller().GetEntryCount()); | 484 ASSERT_EQ(1, this->controller().GetEntryCount()); |
| 459 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); | 485 EXPECT_EQ(kGoogleURL, this->controller().GetActiveEntry()->GetURL().spec()); |
| 460 | 486 |
| 461 // No report should have been sent -- we don't create a report the | 487 // No report should have been sent -- we don't create a report the |
| 462 // second time. | 488 // second time. |
| 463 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 489 EXPECT_EQ(0u, this->ui_manager_->GetDetails()->size()); |
| 464 ui_manager_->GetDetails()->clear(); | 490 this->ui_manager_->GetDetails()->clear(); |
| 465 } | 491 } |
| 466 | 492 |
| 467 // Tests showing a blocking page for a page that contains multiple malware | 493 // Tests showing a blocking page for a page that contains multiple malware |
| 468 // subresources and proceeding through the multiple interstitials. | 494 // subresources and proceeding through the multiple interstitials. |
| 469 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { | 495 TYPED_TEST(SafeBrowsingBlockingPageTest, |
| 470 // Enable malware reports. | 496 PageWithMultipleMalwareResourceProceed) { |
| 471 Profile* profile = Profile::FromBrowserContext( | 497 // Enable malware reports. |
| 472 web_contents()->GetBrowserContext()); | 498 Profile* profile = Profile::FromBrowserContext( |
| 499 this->web_contents()->GetBrowserContext()); |
| 473 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 500 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 474 | 501 |
| 475 // Navigate somewhere else. | 502 // Navigate somewhere else. |
| 476 Navigate(kGoodURL, 1); | 503 this->Navigate(kGoodURL, 1); |
| 477 | 504 |
| 478 // Simulate that page loading a bad-resource triggering an interstitial. | 505 // Simulate that page loading a bad-resource triggering an interstitial. |
| 479 ShowInterstitial(true, kBadURL); | 506 this->ShowInterstitial(true, kBadURL); |
| 480 | 507 |
| 481 // More bad resources loading causing more interstitials. The new | 508 // More bad resources loading causing more interstitials. The new |
| 482 // interstitials should be queued. | 509 // interstitials should be queued. |
| 483 ShowInterstitial(true, kBadURL2); | 510 this->ShowInterstitial(true, kBadURL2); |
| 484 ShowInterstitial(true, kBadURL3); | 511 this->ShowInterstitial(true, kBadURL3); |
| 485 | 512 |
| 486 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 513 SafeBrowsingBlockingPage* sb_interstitial = |
| 514 this->GetSafeBrowsingBlockingPage(); |
| 487 ASSERT_TRUE(sb_interstitial); | 515 ASSERT_TRUE(sb_interstitial); |
| 488 | 516 |
| 489 // Proceed through the 1st interstitial. | 517 // Proceed through the 1st interstitial. |
| 490 ProceedThroughInterstitial(sb_interstitial); | 518 this->ProceedThroughInterstitial(sb_interstitial); |
| 491 EXPECT_EQ(OK, user_response()); | 519 EXPECT_EQ(this->OK, this->user_response()); |
| 492 | 520 |
| 493 // A report should have been sent. | 521 // A report should have been sent. |
| 494 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 522 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size()); |
| 495 ui_manager_->GetDetails()->clear(); | 523 this->ui_manager_->GetDetails()->clear(); |
| 496 | 524 |
| 497 ResetUserResponse(); | 525 this->ResetUserResponse(); |
| 498 | 526 |
| 499 // We should land to a 2nd interstitial (aggregating all the malware resources | 527 // We should land to a 2nd interstitial (aggregating all the malware resources |
| 500 // loaded while the 1st interstitial was showing). | 528 // loaded while the 1st interstitial was showing). |
| 501 sb_interstitial = GetSafeBrowsingBlockingPage(); | 529 sb_interstitial = this->GetSafeBrowsingBlockingPage(); |
| 502 ASSERT_TRUE(sb_interstitial); | 530 ASSERT_TRUE(sb_interstitial); |
| 503 | 531 |
| 504 // Proceed through the 2nd interstitial. | 532 // Proceed through the 2nd interstitial. |
| 505 ProceedThroughInterstitial(sb_interstitial); | 533 this->ProceedThroughInterstitial(sb_interstitial); |
| 506 EXPECT_EQ(OK, user_response()); | 534 EXPECT_EQ(this->OK, this->user_response()); |
| 507 | 535 |
| 508 // We did proceed, we should be back to the initial page. | 536 // We did proceed, we should be back to the initial page. |
| 509 ASSERT_EQ(1, controller().GetEntryCount()); | 537 ASSERT_EQ(1, this->controller().GetEntryCount()); |
| 510 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); | 538 EXPECT_EQ(kGoodURL, this->controller().GetActiveEntry()->GetURL().spec()); |
| 511 | 539 |
| 512 // No report should have been sent -- we don't create a report the | 540 // No report should have been sent -- we don't create a report the |
| 513 // second time. | 541 // second time. |
| 514 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 542 EXPECT_EQ(0u, this->ui_manager_->GetDetails()->size()); |
| 515 ui_manager_->GetDetails()->clear(); | 543 this->ui_manager_->GetDetails()->clear(); |
| 516 } | 544 } |
| 517 | 545 |
| 518 // Tests showing a blocking page then navigating back and forth to make sure the | 546 // Tests showing a blocking page then navigating back and forth to make sure the |
| 519 // controller entries are OK. http://crbug.com/17627 | 547 // controller entries are OK. http://crbug.com/17627 |
| 520 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { | 548 TYPED_TEST(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { |
| 521 // Enable malware reports. | 549 // Enable malware reports. |
| 522 Profile* profile = Profile::FromBrowserContext( | 550 Profile* profile = Profile::FromBrowserContext( |
| 523 web_contents()->GetBrowserContext()); | 551 this->web_contents()->GetBrowserContext()); |
| 524 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 552 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 525 | 553 |
| 526 // Navigate somewhere. | 554 // Navigate somewhere. |
| 527 Navigate(kGoodURL, 1); | 555 this->Navigate(kGoodURL, 1); |
| 528 | 556 |
| 529 // Now navigate to a bad page triggerring an interstitial. | 557 // Now navigate to a bad page triggerring an interstitial. |
| 530 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 558 this->controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 531 content::PAGE_TRANSITION_TYPED, std::string()); | 559 content::PAGE_TRANSITION_TYPED, std::string()); |
| 532 ShowInterstitial(false, kBadURL); | 560 this->ShowInterstitial(false, kBadURL); |
| 533 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 561 SafeBrowsingBlockingPage* sb_interstitial = |
| 562 this->GetSafeBrowsingBlockingPage(); |
| 534 ASSERT_TRUE(sb_interstitial); | 563 ASSERT_TRUE(sb_interstitial); |
| 535 | 564 |
| 536 // Proceed, then navigate back. | 565 // Proceed, then navigate back. |
| 537 ProceedThroughInterstitial(sb_interstitial); | 566 this->ProceedThroughInterstitial(sb_interstitial); |
| 538 Navigate(kBadURL, 2); // Commit the navigation. | 567 this->Navigate(kBadURL, 2); // Commit the navigation. |
| 539 GoBack(true); | 568 this->GoBack(true); |
| 540 | 569 |
| 541 // We are back on the good page. | 570 // We are back on the good page. |
| 542 sb_interstitial = GetSafeBrowsingBlockingPage(); | 571 sb_interstitial = this->GetSafeBrowsingBlockingPage(); |
| 543 ASSERT_FALSE(sb_interstitial); | 572 ASSERT_FALSE(sb_interstitial); |
| 544 ASSERT_EQ(2, controller().GetEntryCount()); | 573 ASSERT_EQ(2, this->controller().GetEntryCount()); |
| 545 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); | 574 EXPECT_EQ(kGoodURL, this->controller().GetActiveEntry()->GetURL().spec()); |
| 546 | 575 |
| 547 // Navigate forward to the malware URL. | 576 // Navigate forward to the malware URL. |
| 548 web_contents()->GetController().GoForward(); | 577 this->web_contents()->GetController().GoForward(); |
| 549 ShowInterstitial(false, kBadURL); | 578 this->ShowInterstitial(false, kBadURL); |
| 550 sb_interstitial = GetSafeBrowsingBlockingPage(); | 579 sb_interstitial = this->GetSafeBrowsingBlockingPage(); |
| 551 ASSERT_TRUE(sb_interstitial); | 580 ASSERT_TRUE(sb_interstitial); |
| 552 | 581 |
| 553 // Let's proceed and make sure everything is OK (bug 17627). | 582 // Let's proceed and make sure everything is OK (bug 17627). |
| 554 ProceedThroughInterstitial(sb_interstitial); | 583 this->ProceedThroughInterstitial(sb_interstitial); |
| 555 Navigate(kBadURL, 2); // Commit the navigation. | 584 this->Navigate(kBadURL, 2); // Commit the navigation. |
| 556 sb_interstitial = GetSafeBrowsingBlockingPage(); | 585 sb_interstitial = this->GetSafeBrowsingBlockingPage(); |
| 557 ASSERT_FALSE(sb_interstitial); | 586 ASSERT_FALSE(sb_interstitial); |
| 558 ASSERT_EQ(2, controller().GetEntryCount()); | 587 ASSERT_EQ(2, this->controller().GetEntryCount()); |
| 559 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec()); | 588 EXPECT_EQ(kBadURL, this->controller().GetActiveEntry()->GetURL().spec()); |
| 560 | 589 |
| 561 // Two reports should have been sent. | 590 // Two reports should have been sent. |
| 562 EXPECT_EQ(2u, ui_manager_->GetDetails()->size()); | 591 EXPECT_EQ(2u, this->ui_manager_->GetDetails()->size()); |
| 563 ui_manager_->GetDetails()->clear(); | 592 this->ui_manager_->GetDetails()->clear(); |
| 564 } | 593 } |
| 565 | 594 |
| 566 // Tests that calling "don't proceed" after "proceed" has been called doesn't | 595 // Tests that calling "don't proceed" after "proceed" has been called doesn't |
| 567 // cause problems. http://crbug.com/30079 | 596 // cause problems. http://crbug.com/30079 |
| 568 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { | 597 TYPED_TEST(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { |
| 569 // Enable malware reports. | 598 // Enable malware reports. |
| 570 Profile* profile = Profile::FromBrowserContext( | 599 Profile* profile = Profile::FromBrowserContext( |
| 571 web_contents()->GetBrowserContext()); | 600 this->web_contents()->GetBrowserContext()); |
| 572 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); | 601 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); |
| 573 | 602 |
| 574 // Start a load. | 603 // Start a load. |
| 575 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 604 this->controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 576 content::PAGE_TRANSITION_TYPED, std::string()); | 605 content::PAGE_TRANSITION_TYPED, std::string()); |
| 577 | 606 |
| 578 // Simulate the load causing a safe browsing interstitial to be shown. | 607 // Simulate the load causing a safe browsing interstitial to be shown. |
| 579 ShowInterstitial(false, kBadURL); | 608 this->ShowInterstitial(false, kBadURL); |
| 580 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 609 SafeBrowsingBlockingPage* sb_interstitial = |
| 610 this->GetSafeBrowsingBlockingPage(); |
| 581 ASSERT_TRUE(sb_interstitial); | 611 ASSERT_TRUE(sb_interstitial); |
| 582 | 612 |
| 583 base::RunLoop().RunUntilIdle(); | 613 base::RunLoop().RunUntilIdle(); |
| 584 | 614 |
| 585 // Simulate the user clicking "proceed" then "don't proceed" (before the | 615 // Simulate the user clicking "proceed" then "don't proceed" (before the |
| 586 // interstitial is shown). | 616 // interstitial is shown). |
| 587 sb_interstitial->interstitial_page_->Proceed(); | 617 sb_interstitial->interstitial_page_->Proceed(); |
| 588 sb_interstitial->interstitial_page_->DontProceed(); | 618 sb_interstitial->interstitial_page_->DontProceed(); |
| 589 // Proceed() and DontProceed() post a task to update the | 619 // Proceed() and DontProceed() post a task to update the |
| 590 // SafeBrowsingService::Client. | 620 // SafeBrowsingService::Client. |
| 591 base::RunLoop().RunUntilIdle(); | 621 base::RunLoop().RunUntilIdle(); |
| 592 | 622 |
| 593 // The interstitial should be gone. | 623 // The interstitial should be gone. |
| 594 EXPECT_EQ(OK, user_response()); | 624 EXPECT_EQ(this->OK, this->user_response()); |
| 595 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 625 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage()); |
| 596 | 626 |
| 597 // Only one report should have been sent. | 627 // Only one report should have been sent. |
| 598 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); | 628 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size()); |
| 599 ui_manager_->GetDetails()->clear(); | 629 this->ui_manager_->GetDetails()->clear(); |
| 600 } | 630 } |
| 601 | 631 |
| 602 // Tests showing a blocking page for a malware page with reports disabled. | 632 // Tests showing a blocking page for a malware page with reports disabled. |
| 603 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { | 633 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { |
| 604 // Disable malware reports. | 634 // Disable malware reports. |
| 605 Profile* profile = Profile::FromBrowserContext( | 635 Profile* profile = Profile::FromBrowserContext( |
| 606 web_contents()->GetBrowserContext()); | 636 this->web_contents()->GetBrowserContext()); |
| 607 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); | 637 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); |
| 608 | 638 |
| 609 // Start a load. | 639 // Start a load. |
| 610 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 640 this->controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 611 content::PAGE_TRANSITION_TYPED, std::string()); | 641 content::PAGE_TRANSITION_TYPED, std::string()); |
| 612 | 642 |
| 613 // Simulate the load causing a safe browsing interstitial to be shown. | 643 // Simulate the load causing a safe browsing interstitial to be shown. |
| 614 ShowInterstitial(false, kBadURL); | 644 this->ShowInterstitial(false, kBadURL); |
| 615 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 645 SafeBrowsingBlockingPage* sb_interstitial = |
| 646 this->GetSafeBrowsingBlockingPage(); |
| 616 ASSERT_TRUE(sb_interstitial); | 647 ASSERT_TRUE(sb_interstitial); |
| 617 | 648 |
| 618 base::RunLoop().RunUntilIdle(); | 649 base::RunLoop().RunUntilIdle(); |
| 619 | 650 |
| 620 // Simulate the user clicking "don't proceed". | 651 // Simulate the user clicking "don't proceed". |
| 621 DontProceedThroughInterstitial(sb_interstitial); | 652 this->DontProceedThroughInterstitial(sb_interstitial); |
| 622 | 653 |
| 623 // The interstitial should be gone. | 654 // The interstitial should be gone. |
| 624 EXPECT_EQ(CANCEL, user_response()); | 655 EXPECT_EQ(this->CANCEL, this->user_response()); |
| 625 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 656 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage()); |
| 626 | 657 |
| 627 // We did not proceed, the pending entry should be gone. | 658 // We did not proceed, the pending entry should be gone. |
| 628 EXPECT_FALSE(controller().GetPendingEntry()); | 659 EXPECT_FALSE(this->controller().GetPendingEntry()); |
| 629 | 660 |
| 630 // No report should have been sent. | 661 // No report should have been sent. |
| 631 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); | 662 EXPECT_EQ(0u, this->ui_manager_->GetDetails()->size()); |
| 632 ui_manager_->GetDetails()->clear(); | 663 this->ui_manager_->GetDetails()->clear(); |
| 633 } | 664 } |
| 634 | 665 |
| 635 // Test setting the malware report preferance | 666 // Test setting the malware report preferance |
| 636 TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { | 667 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwareReports) { |
| 637 // Disable malware reports. | 668 // Disable malware reports. |
| 638 Profile* profile = Profile::FromBrowserContext( | 669 Profile* profile = Profile::FromBrowserContext( |
| 639 web_contents()->GetBrowserContext()); | 670 this->web_contents()->GetBrowserContext()); |
| 640 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); | 671 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); |
| 641 | 672 |
| 642 // Start a load. | 673 // Start a load. |
| 643 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 674 this->controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 644 content::PAGE_TRANSITION_TYPED, std::string()); | 675 content::PAGE_TRANSITION_TYPED, std::string()); |
| 645 | 676 |
| 646 // Simulate the load causing a safe browsing interstitial to be shown. | 677 // Simulate the load causing a safe browsing interstitial to be shown. |
| 647 ShowInterstitial(false, kBadURL); | 678 this->ShowInterstitial(false, kBadURL); |
| 648 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 679 SafeBrowsingBlockingPage* sb_interstitial = |
| 680 this->GetSafeBrowsingBlockingPage(); |
| 649 ASSERT_TRUE(sb_interstitial); | 681 ASSERT_TRUE(sb_interstitial); |
| 650 | 682 |
| 651 base::RunLoop().RunUntilIdle(); | 683 base::RunLoop().RunUntilIdle(); |
| 652 | 684 |
| 653 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 685 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( |
| 654 prefs::kSafeBrowsingReportingEnabled)); | 686 prefs::kSafeBrowsingReportingEnabled)); |
| 655 | 687 |
| 656 // Simulate the user check the report agreement checkbox. | 688 // Simulate the user check the report agreement checkbox. |
| 657 sb_interstitial->SetReportingPreference(true); | 689 sb_interstitial->SetReportingPreference(true); |
| 658 | 690 |
| 659 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( | 691 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( |
| 660 prefs::kSafeBrowsingReportingEnabled)); | 692 prefs::kSafeBrowsingReportingEnabled)); |
| 661 | 693 |
| 662 // Simulate the user uncheck the report agreement checkbox. | 694 // Simulate the user uncheck the report agreement checkbox. |
| 663 sb_interstitial->SetReportingPreference(false); | 695 sb_interstitial->SetReportingPreference(false); |
| 664 | 696 |
| 665 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( | 697 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( |
| 666 prefs::kSafeBrowsingReportingEnabled)); | 698 prefs::kSafeBrowsingReportingEnabled)); |
| 667 } | 699 } |
| OLD | NEW |