Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/prefs/pref_service.h" 5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/profiles/profile.h" 6 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/safe_browsing/malware_details.h" 7 #include "chrome/browser/safe_browsing/malware_details.h"
8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
10 #include "chrome/browser/safe_browsing/ui_manager.h" 10 #include "chrome/browser/safe_browsing/ui_manager.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { 113 class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness {
114 public: 114 public:
115 // The decision the user made. 115 // The decision the user made.
116 enum UserResponse { 116 enum UserResponse {
117 PENDING, 117 PENDING,
118 OK, 118 OK,
119 CANCEL 119 CANCEL
120 }; 120 };
121 121
122 SafeBrowsingBlockingPageTest() 122 SafeBrowsingBlockingPageTest()
123 : ui_thread_(BrowserThread::UI, MessageLoop::current()), 123 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
124 file_user_blocking_thread_( 124 file_user_blocking_thread_(
125 BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), 125 BrowserThread::FILE_USER_BLOCKING, base::MessageLoop::current()),
126 io_thread_(BrowserThread::IO, MessageLoop::current()) { 126 io_thread_(BrowserThread::IO, base::MessageLoop::current()) {
127 ResetUserResponse(); 127 ResetUserResponse();
128 // The safe browsing UI manager does not need a service for this test. 128 // The safe browsing UI manager does not need a service for this test.
129 ui_manager_ = new TestSafeBrowsingUIManager(NULL); 129 ui_manager_ = new TestSafeBrowsingUIManager(NULL);
130 } 130 }
131 131
132 virtual void SetUp() { 132 virtual void SetUp() {
133 ChromeRenderViewHostTestHarness::SetUp(); 133 ChromeRenderViewHostTestHarness::SetUp();
134 SafeBrowsingBlockingPage::RegisterFactory(&factory_); 134 SafeBrowsingBlockingPage::RegisterFactory(&factory_);
135 MalwareDetails::RegisterFactory(NULL); // Create it fresh each time. 135 MalwareDetails::RegisterFactory(NULL); // Create it fresh each time.
136 ResetUserResponse(); 136 ResetUserResponse();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 interstitial->GetDelegateForTesting()); 189 interstitial->GetDelegateForTesting());
190 } 190 }
191 191
192 UserResponse user_response() const { return user_response_; } 192 UserResponse user_response() const { return user_response_; }
193 void ResetUserResponse() { user_response_ = PENDING; } 193 void ResetUserResponse() { user_response_ = PENDING; }
194 194
195 static void ProceedThroughInterstitial( 195 static void ProceedThroughInterstitial(
196 SafeBrowsingBlockingPage* sb_interstitial) { 196 SafeBrowsingBlockingPage* sb_interstitial) {
197 sb_interstitial->interstitial_page_->Proceed(); 197 sb_interstitial->interstitial_page_->Proceed();
198 // Proceed() posts a task to update the SafeBrowsingService::Client. 198 // Proceed() posts a task to update the SafeBrowsingService::Client.
199 MessageLoop::current()->RunUntilIdle(); 199 base::MessageLoop::current()->RunUntilIdle();
200 } 200 }
201 201
202 static void DontProceedThroughInterstitial( 202 static void DontProceedThroughInterstitial(
203 SafeBrowsingBlockingPage* sb_interstitial) { 203 SafeBrowsingBlockingPage* sb_interstitial) {
204 sb_interstitial->interstitial_page_->DontProceed(); 204 sb_interstitial->interstitial_page_->DontProceed();
205 // DontProceed() posts a task to update the SafeBrowsingService::Client. 205 // DontProceed() posts a task to update the SafeBrowsingService::Client.
206 MessageLoop::current()->RunUntilIdle(); 206 base::MessageLoop::current()->RunUntilIdle();
207 } 207 }
208 208
209 void DontProceedThroughSubresourceInterstitial( 209 void DontProceedThroughSubresourceInterstitial(
210 SafeBrowsingBlockingPage* sb_interstitial) { 210 SafeBrowsingBlockingPage* sb_interstitial) {
211 // CommandReceived(kTakeMeBackCommand) does a back navigation for 211 // CommandReceived(kTakeMeBackCommand) does a back navigation for
212 // subresource interstitials. 212 // subresource interstitials.
213 GoBack(false); 213 GoBack(false);
214 // DontProceed() posts a task to update the SafeBrowsingService::Client. 214 // DontProceed() posts a task to update the SafeBrowsingService::Client.
215 MessageLoop::current()->RunUntilIdle(); 215 base::MessageLoop::current()->RunUntilIdle();
216 } 216 }
217 217
218 scoped_refptr<TestSafeBrowsingUIManager> ui_manager_; 218 scoped_refptr<TestSafeBrowsingUIManager> ui_manager_;
219 219
220 private: 220 private:
221 void InitResource(SafeBrowsingUIManager::UnsafeResource* resource, 221 void InitResource(SafeBrowsingUIManager::UnsafeResource* resource,
222 bool is_subresource, 222 bool is_subresource,
223 const GURL& url) { 223 const GURL& url) {
224 resource->callback = 224 resource->callback =
225 base::Bind(&SafeBrowsingBlockingPageTest::OnBlockingPageComplete, 225 base::Bind(&SafeBrowsingBlockingPageTest::OnBlockingPageComplete,
(...skipping 24 matching lines...) Expand all
250 // Start a load. 250 // Start a load.
251 controller().LoadURL(GURL(kBadURL), content::Referrer(), 251 controller().LoadURL(GURL(kBadURL), content::Referrer(),
252 content::PAGE_TRANSITION_TYPED, std::string()); 252 content::PAGE_TRANSITION_TYPED, std::string());
253 253
254 254
255 // Simulate the load causing a safe browsing interstitial to be shown. 255 // Simulate the load causing a safe browsing interstitial to be shown.
256 ShowInterstitial(false, kBadURL); 256 ShowInterstitial(false, kBadURL);
257 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 257 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
258 ASSERT_TRUE(sb_interstitial); 258 ASSERT_TRUE(sb_interstitial);
259 259
260 MessageLoop::current()->RunUntilIdle(); 260 base::MessageLoop::current()->RunUntilIdle();
261 261
262 // Simulate the user clicking "don't proceed". 262 // Simulate the user clicking "don't proceed".
263 DontProceedThroughInterstitial(sb_interstitial); 263 DontProceedThroughInterstitial(sb_interstitial);
264 264
265 // The interstitial should be gone. 265 // The interstitial should be gone.
266 EXPECT_EQ(CANCEL, user_response()); 266 EXPECT_EQ(CANCEL, user_response());
267 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 267 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
268 268
269 // We did not proceed, the pending entry should be gone. 269 // We did not proceed, the pending entry should be gone.
270 EXPECT_FALSE(controller().GetPendingEntry()); 270 EXPECT_FALSE(controller().GetPendingEntry());
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 579
580 // Start a load. 580 // Start a load.
581 controller().LoadURL(GURL(kBadURL), content::Referrer(), 581 controller().LoadURL(GURL(kBadURL), content::Referrer(),
582 content::PAGE_TRANSITION_TYPED, std::string()); 582 content::PAGE_TRANSITION_TYPED, std::string());
583 583
584 // Simulate the load causing a safe browsing interstitial to be shown. 584 // Simulate the load causing a safe browsing interstitial to be shown.
585 ShowInterstitial(false, kBadURL); 585 ShowInterstitial(false, kBadURL);
586 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 586 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
587 ASSERT_TRUE(sb_interstitial); 587 ASSERT_TRUE(sb_interstitial);
588 588
589 MessageLoop::current()->RunUntilIdle(); 589 base::MessageLoop::current()->RunUntilIdle();
590 590
591 // Simulate the user clicking "proceed" then "don't proceed" (before the 591 // Simulate the user clicking "proceed" then "don't proceed" (before the
592 // interstitial is shown). 592 // interstitial is shown).
593 sb_interstitial->interstitial_page_->Proceed(); 593 sb_interstitial->interstitial_page_->Proceed();
594 sb_interstitial->interstitial_page_->DontProceed(); 594 sb_interstitial->interstitial_page_->DontProceed();
595 // Proceed() and DontProceed() post a task to update the 595 // Proceed() and DontProceed() post a task to update the
596 // SafeBrowsingService::Client. 596 // SafeBrowsingService::Client.
597 MessageLoop::current()->RunUntilIdle(); 597 base::MessageLoop::current()->RunUntilIdle();
598 598
599 // The interstitial should be gone. 599 // The interstitial should be gone.
600 EXPECT_EQ(OK, user_response()); 600 EXPECT_EQ(OK, user_response());
601 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 601 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
602 602
603 // Only one report should have been sent. 603 // Only one report should have been sent.
604 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 604 EXPECT_EQ(1u, ui_manager_->GetDetails()->size());
605 ui_manager_->GetDetails()->clear(); 605 ui_manager_->GetDetails()->clear();
606 } 606 }
607 607
608 // Tests showing a blocking page for a malware page with reports disabled. 608 // Tests showing a blocking page for a malware page with reports disabled.
609 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { 609 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) {
610 // Disable malware reports. 610 // Disable malware reports.
611 Profile* profile = Profile::FromBrowserContext( 611 Profile* profile = Profile::FromBrowserContext(
612 web_contents()->GetBrowserContext()); 612 web_contents()->GetBrowserContext());
613 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); 613 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false);
614 614
615 // Start a load. 615 // Start a load.
616 controller().LoadURL(GURL(kBadURL), content::Referrer(), 616 controller().LoadURL(GURL(kBadURL), content::Referrer(),
617 content::PAGE_TRANSITION_TYPED, std::string()); 617 content::PAGE_TRANSITION_TYPED, std::string());
618 618
619 // Simulate the load causing a safe browsing interstitial to be shown. 619 // Simulate the load causing a safe browsing interstitial to be shown.
620 ShowInterstitial(false, kBadURL); 620 ShowInterstitial(false, kBadURL);
621 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 621 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
622 ASSERT_TRUE(sb_interstitial); 622 ASSERT_TRUE(sb_interstitial);
623 623
624 MessageLoop::current()->RunUntilIdle(); 624 base::MessageLoop::current()->RunUntilIdle();
625 625
626 // Simulate the user clicking "don't proceed". 626 // Simulate the user clicking "don't proceed".
627 DontProceedThroughInterstitial(sb_interstitial); 627 DontProceedThroughInterstitial(sb_interstitial);
628 628
629 // The interstitial should be gone. 629 // The interstitial should be gone.
630 EXPECT_EQ(CANCEL, user_response()); 630 EXPECT_EQ(CANCEL, user_response());
631 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 631 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
632 632
633 // We did not proceed, the pending entry should be gone. 633 // We did not proceed, the pending entry should be gone.
634 EXPECT_FALSE(controller().GetPendingEntry()); 634 EXPECT_FALSE(controller().GetPendingEntry());
(...skipping 12 matching lines...) Expand all
647 647
648 // Start a load. 648 // Start a load.
649 controller().LoadURL(GURL(kBadURL), content::Referrer(), 649 controller().LoadURL(GURL(kBadURL), content::Referrer(),
650 content::PAGE_TRANSITION_TYPED, std::string()); 650 content::PAGE_TRANSITION_TYPED, std::string());
651 651
652 // Simulate the load causing a safe browsing interstitial to be shown. 652 // Simulate the load causing a safe browsing interstitial to be shown.
653 ShowInterstitial(false, kBadURL); 653 ShowInterstitial(false, kBadURL);
654 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 654 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
655 ASSERT_TRUE(sb_interstitial); 655 ASSERT_TRUE(sb_interstitial);
656 656
657 MessageLoop::current()->RunUntilIdle(); 657 base::MessageLoop::current()->RunUntilIdle();
658 658
659 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 659 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
660 prefs::kSafeBrowsingReportingEnabled)); 660 prefs::kSafeBrowsingReportingEnabled));
661 661
662 // Simulate the user check the report agreement checkbox. 662 // Simulate the user check the report agreement checkbox.
663 sb_interstitial->SetReportingPreference(true); 663 sb_interstitial->SetReportingPreference(true);
664 664
665 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( 665 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
666 prefs::kSafeBrowsingReportingEnabled)); 666 prefs::kSafeBrowsingReportingEnabled));
667 667
668 // Simulate the user uncheck the report agreement checkbox. 668 // Simulate the user uncheck the report agreement checkbox.
669 sb_interstitial->SetReportingPreference(false); 669 sb_interstitial->SetReportingPreference(false);
670 670
671 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 671 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
672 prefs::kSafeBrowsingReportingEnabled)); 672 prefs::kSafeBrowsingReportingEnabled));
673 } 673 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698