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

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

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 "chrome/browser/prefs/pref_service.h" 5 #include "chrome/browser/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/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 interstitial->GetDelegateForTesting()); 180 interstitial->GetDelegateForTesting());
181 } 181 }
182 182
183 UserResponse user_response() const { return user_response_; } 183 UserResponse user_response() const { return user_response_; }
184 void ResetUserResponse() { user_response_ = PENDING; } 184 void ResetUserResponse() { user_response_ = PENDING; }
185 185
186 static void ProceedThroughInterstitial( 186 static void ProceedThroughInterstitial(
187 SafeBrowsingBlockingPage* sb_interstitial) { 187 SafeBrowsingBlockingPage* sb_interstitial) {
188 sb_interstitial->interstitial_page_->Proceed(); 188 sb_interstitial->interstitial_page_->Proceed();
189 // Proceed() posts a task to update the SafeBrowsingService::Client. 189 // Proceed() posts a task to update the SafeBrowsingService::Client.
190 MessageLoop::current()->RunAllPending(); 190 MessageLoop::current()->RunUntilIdle();
191 } 191 }
192 192
193 static void DontProceedThroughInterstitial( 193 static void DontProceedThroughInterstitial(
194 SafeBrowsingBlockingPage* sb_interstitial) { 194 SafeBrowsingBlockingPage* sb_interstitial) {
195 sb_interstitial->interstitial_page_->DontProceed(); 195 sb_interstitial->interstitial_page_->DontProceed();
196 // DontProceed() posts a task to update the SafeBrowsingService::Client. 196 // DontProceed() posts a task to update the SafeBrowsingService::Client.
197 MessageLoop::current()->RunAllPending(); 197 MessageLoop::current()->RunUntilIdle();
198 } 198 }
199 199
200 void DontProceedThroughSubresourceInterstitial( 200 void DontProceedThroughSubresourceInterstitial(
201 SafeBrowsingBlockingPage* sb_interstitial) { 201 SafeBrowsingBlockingPage* sb_interstitial) {
202 // CommandReceived(kTakeMeBackCommand) does a back navigation for 202 // CommandReceived(kTakeMeBackCommand) does a back navigation for
203 // subresource interstitials. 203 // subresource interstitials.
204 GoBack(false); 204 GoBack(false);
205 // DontProceed() posts a task to update the SafeBrowsingService::Client. 205 // DontProceed() posts a task to update the SafeBrowsingService::Client.
206 MessageLoop::current()->RunAllPending(); 206 MessageLoop::current()->RunUntilIdle();
207 } 207 }
208 208
209 scoped_refptr<TestSafeBrowsingService> service_; 209 scoped_refptr<TestSafeBrowsingService> service_;
210 210
211 private: 211 private:
212 void InitResource(SafeBrowsingService::UnsafeResource* resource, 212 void InitResource(SafeBrowsingService::UnsafeResource* resource,
213 bool is_subresource, 213 bool is_subresource,
214 const GURL& url) { 214 const GURL& url) {
215 resource->callback = 215 resource->callback =
216 base::Bind(&SafeBrowsingBlockingPageTest::OnBlockingPageComplete, 216 base::Bind(&SafeBrowsingBlockingPageTest::OnBlockingPageComplete,
(...skipping 24 matching lines...) Expand all
241 // Start a load. 241 // Start a load.
242 controller().LoadURL(GURL(kBadURL), content::Referrer(), 242 controller().LoadURL(GURL(kBadURL), content::Referrer(),
243 content::PAGE_TRANSITION_TYPED, std::string()); 243 content::PAGE_TRANSITION_TYPED, std::string());
244 244
245 245
246 // Simulate the load causing a safe browsing interstitial to be shown. 246 // Simulate the load causing a safe browsing interstitial to be shown.
247 ShowInterstitial(false, kBadURL); 247 ShowInterstitial(false, kBadURL);
248 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 248 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
249 ASSERT_TRUE(sb_interstitial); 249 ASSERT_TRUE(sb_interstitial);
250 250
251 MessageLoop::current()->RunAllPending(); 251 MessageLoop::current()->RunUntilIdle();
252 252
253 // Simulate the user clicking "don't proceed". 253 // Simulate the user clicking "don't proceed".
254 DontProceedThroughInterstitial(sb_interstitial); 254 DontProceedThroughInterstitial(sb_interstitial);
255 255
256 // The interstitial should be gone. 256 // The interstitial should be gone.
257 EXPECT_EQ(CANCEL, user_response()); 257 EXPECT_EQ(CANCEL, user_response());
258 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 258 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
259 259
260 // We did not proceed, the pending entry should be gone. 260 // We did not proceed, the pending entry should be gone.
261 EXPECT_FALSE(controller().GetPendingEntry()); 261 EXPECT_FALSE(controller().GetPendingEntry());
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 570
571 // Start a load. 571 // Start a load.
572 controller().LoadURL(GURL(kBadURL), content::Referrer(), 572 controller().LoadURL(GURL(kBadURL), content::Referrer(),
573 content::PAGE_TRANSITION_TYPED, std::string()); 573 content::PAGE_TRANSITION_TYPED, std::string());
574 574
575 // Simulate the load causing a safe browsing interstitial to be shown. 575 // Simulate the load causing a safe browsing interstitial to be shown.
576 ShowInterstitial(false, kBadURL); 576 ShowInterstitial(false, kBadURL);
577 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 577 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
578 ASSERT_TRUE(sb_interstitial); 578 ASSERT_TRUE(sb_interstitial);
579 579
580 MessageLoop::current()->RunAllPending(); 580 MessageLoop::current()->RunUntilIdle();
581 581
582 // Simulate the user clicking "proceed" then "don't proceed" (before the 582 // Simulate the user clicking "proceed" then "don't proceed" (before the
583 // interstitial is shown). 583 // interstitial is shown).
584 sb_interstitial->interstitial_page_->Proceed(); 584 sb_interstitial->interstitial_page_->Proceed();
585 sb_interstitial->interstitial_page_->DontProceed(); 585 sb_interstitial->interstitial_page_->DontProceed();
586 // Proceed() and DontProceed() post a task to update the 586 // Proceed() and DontProceed() post a task to update the
587 // SafeBrowsingService::Client. 587 // SafeBrowsingService::Client.
588 MessageLoop::current()->RunAllPending(); 588 MessageLoop::current()->RunUntilIdle();
589 589
590 // The interstitial should be gone. 590 // The interstitial should be gone.
591 EXPECT_EQ(OK, user_response()); 591 EXPECT_EQ(OK, user_response());
592 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 592 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
593 593
594 // Only one report should have been sent. 594 // Only one report should have been sent.
595 EXPECT_EQ(1u, service_->GetDetails()->size()); 595 EXPECT_EQ(1u, service_->GetDetails()->size());
596 service_->GetDetails()->clear(); 596 service_->GetDetails()->clear();
597 } 597 }
598 598
599 // Tests showing a blocking page for a malware page with reports disabled. 599 // Tests showing a blocking page for a malware page with reports disabled.
600 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { 600 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) {
601 // Disable malware reports. 601 // Disable malware reports.
602 Profile* profile = Profile::FromBrowserContext( 602 Profile* profile = Profile::FromBrowserContext(
603 web_contents()->GetBrowserContext()); 603 web_contents()->GetBrowserContext());
604 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); 604 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false);
605 605
606 // Start a load. 606 // Start a load.
607 controller().LoadURL(GURL(kBadURL), content::Referrer(), 607 controller().LoadURL(GURL(kBadURL), content::Referrer(),
608 content::PAGE_TRANSITION_TYPED, std::string()); 608 content::PAGE_TRANSITION_TYPED, std::string());
609 609
610 // Simulate the load causing a safe browsing interstitial to be shown. 610 // Simulate the load causing a safe browsing interstitial to be shown.
611 ShowInterstitial(false, kBadURL); 611 ShowInterstitial(false, kBadURL);
612 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 612 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
613 ASSERT_TRUE(sb_interstitial); 613 ASSERT_TRUE(sb_interstitial);
614 614
615 MessageLoop::current()->RunAllPending(); 615 MessageLoop::current()->RunUntilIdle();
616 616
617 // Simulate the user clicking "don't proceed". 617 // Simulate the user clicking "don't proceed".
618 DontProceedThroughInterstitial(sb_interstitial); 618 DontProceedThroughInterstitial(sb_interstitial);
619 619
620 // The interstitial should be gone. 620 // The interstitial should be gone.
621 EXPECT_EQ(CANCEL, user_response()); 621 EXPECT_EQ(CANCEL, user_response());
622 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 622 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
623 623
624 // We did not proceed, the pending entry should be gone. 624 // We did not proceed, the pending entry should be gone.
625 EXPECT_FALSE(controller().GetPendingEntry()); 625 EXPECT_FALSE(controller().GetPendingEntry());
(...skipping 12 matching lines...) Expand all
638 638
639 // Start a load. 639 // Start a load.
640 controller().LoadURL(GURL(kBadURL), content::Referrer(), 640 controller().LoadURL(GURL(kBadURL), content::Referrer(),
641 content::PAGE_TRANSITION_TYPED, std::string()); 641 content::PAGE_TRANSITION_TYPED, std::string());
642 642
643 // Simulate the load causing a safe browsing interstitial to be shown. 643 // Simulate the load causing a safe browsing interstitial to be shown.
644 ShowInterstitial(false, kBadURL); 644 ShowInterstitial(false, kBadURL);
645 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 645 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
646 ASSERT_TRUE(sb_interstitial); 646 ASSERT_TRUE(sb_interstitial);
647 647
648 MessageLoop::current()->RunAllPending(); 648 MessageLoop::current()->RunUntilIdle();
649 649
650 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 650 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
651 prefs::kSafeBrowsingReportingEnabled)); 651 prefs::kSafeBrowsingReportingEnabled));
652 652
653 // Simulate the user check the report agreement checkbox. 653 // Simulate the user check the report agreement checkbox.
654 sb_interstitial->SetReportingPreference(true); 654 sb_interstitial->SetReportingPreference(true);
655 655
656 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( 656 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
657 prefs::kSafeBrowsingReportingEnabled)); 657 prefs::kSafeBrowsingReportingEnabled));
658 658
659 // Simulate the user uncheck the report agreement checkbox. 659 // Simulate the user uncheck the report agreement checkbox.
660 sb_interstitial->SetReportingPreference(false); 660 sb_interstitial->SetReportingPreference(false);
661 661
662 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 662 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
663 prefs::kSafeBrowsingReportingEnabled)); 663 prefs::kSafeBrowsingReportingEnabled));
664 } 664 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698