| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 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 "chrome/browser/renderer_host/test/test_render_view_host.h" | 5 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profile.h" |
| 8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 9 #include "chrome/browser/tab_contents/navigation_entry.h" | 11 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 10 #include "chrome/browser/tab_contents/test_tab_contents.h" | 12 #include "chrome/browser/tab_contents/test_tab_contents.h" |
| 13 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/common/render_messages_params.h" | 15 #include "chrome/common/render_messages_params.h" |
| 13 | 16 |
| 14 static const char* kGoogleURL = "http://www.google.com/"; | 17 static const char* kGoogleURL = "http://www.google.com/"; |
| 15 static const char* kGoodURL = "http://www.goodguys.com/"; | 18 static const char* kGoodURL = "http://www.goodguys.com/"; |
| 16 static const char* kBadURL = "http://www.badguys.com/"; | 19 static const char* kBadURL = "http://www.badguys.com/"; |
| 17 static const char* kBadURL2 = "http://www.badguys2.com/"; | 20 static const char* kBadURL2 = "http://www.badguys2.com/"; |
| 18 static const char* kBadURL3 = "http://www.badguys3.com/"; | 21 static const char* kBadURL3 = "http://www.badguys3.com/"; |
| 19 | 22 |
| 20 // A SafeBrowingBlockingPage class that does not create windows. | 23 // A SafeBrowingBlockingPage class that does not create windows. |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 386 |
| 384 // Let's proceed and make sure everything is OK (bug 17627). | 387 // Let's proceed and make sure everything is OK (bug 17627). |
| 385 ProceedThroughInterstitial(sb_interstitial); | 388 ProceedThroughInterstitial(sb_interstitial); |
| 386 Navigate(kBadURL, 2); // Commit the navigation. | 389 Navigate(kBadURL, 2); // Commit the navigation. |
| 387 sb_interstitial = GetSafeBrowsingBlockingPage(); | 390 sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 388 ASSERT_FALSE(sb_interstitial); | 391 ASSERT_FALSE(sb_interstitial); |
| 389 ASSERT_EQ(2, controller().entry_count()); | 392 ASSERT_EQ(2, controller().entry_count()); |
| 390 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->url().spec()); | 393 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->url().spec()); |
| 391 } | 394 } |
| 392 | 395 |
| 393 // Tests that calling "don't proceed" after "proceed" has been called doesn't | 396 // |
| 394 // cause problems. http://crbug.com/30079 | |
| 395 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { | 397 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { |
| 396 // Start a load. | 398 // Start a load. |
| 397 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); | 399 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); |
| 398 | 400 |
| 399 // Simulate the load causing a safe browsing interstitial to be shown. | 401 // Simulate the load causing a safe browsing interstitial to be shown. |
| 400 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); | 402 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); |
| 401 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 403 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 402 ASSERT_TRUE(sb_interstitial); | 404 ASSERT_TRUE(sb_interstitial); |
| 403 | 405 |
| 404 MessageLoop::current()->RunAllPending(); | 406 MessageLoop::current()->RunAllPending(); |
| 405 | 407 |
| 406 // Simulate the user clicking "proceed" then "don't proceed" (before the | 408 // Simulate the user clicking "proceed" then "don't proceed" (before the |
| 407 // interstitial is shown). | 409 // interstitial is shown). |
| 408 sb_interstitial->Proceed(); | 410 sb_interstitial->Proceed(); |
| 409 sb_interstitial->DontProceed(); | 411 sb_interstitial->DontProceed(); |
| 410 // Proceed() and DontProceed() post a task to update the | 412 // Proceed() and DontProceed() post a task to update the |
| 411 // SafeBrowsingService::Client. | 413 // SafeBrowsingService::Client. |
| 412 MessageLoop::current()->RunAllPending(); | 414 MessageLoop::current()->RunAllPending(); |
| 413 | 415 |
| 414 // The interstitial should be gone. | 416 // The interstitial should be gone. |
| 415 EXPECT_EQ(OK, user_response()); | 417 EXPECT_EQ(OK, user_response()); |
| 416 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 418 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
| 417 } | 419 } |
| 420 |
| 421 // Test setting the malware report preferance |
| 422 TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { |
| 423 // Disable malware reports. |
| 424 contents()->profile()->GetPrefs()->SetBoolean( |
| 425 prefs::kSafeBrowsingReportingEnabled, false); |
| 426 |
| 427 // Start a load. |
| 428 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); |
| 429 |
| 430 // Simulate the load causing a safe browsing interstitial to be shown. |
| 431 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); |
| 432 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 433 ASSERT_TRUE(sb_interstitial); |
| 434 |
| 435 MessageLoop::current()->RunAllPending(); |
| 436 |
| 437 EXPECT_FALSE(contents()->profile()->GetPrefs()->GetBoolean( |
| 438 prefs::kSafeBrowsingReportingEnabled)); |
| 439 |
| 440 // Simulate the user check the report agreement checkbox. |
| 441 sb_interstitial->SetReportingPreference(true); |
| 442 |
| 443 EXPECT_TRUE(contents()->profile()->GetPrefs()->GetBoolean( |
| 444 prefs::kSafeBrowsingReportingEnabled)); |
| 445 |
| 446 // Simulate the user uncheck the report agreement checkbox. |
| 447 sb_interstitial->SetReportingPreference(false); |
| 448 |
| 449 EXPECT_FALSE(contents()->profile()->GetPrefs()->GetBoolean( |
| 450 prefs::kSafeBrowsingReportingEnabled)); |
| 451 } |
| OLD | NEW |