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

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

Issue 9323071: Use InterstitialPage through a delegate interface instead of deriving from it. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros Created 8 years, 10 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 "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"
11 #include "content/browser/tab_contents/interstitial_page.h"
11 #include "content/browser/tab_contents/test_tab_contents.h" 12 #include "content/browser/tab_contents/test_tab_contents.h"
12 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/navigation_entry.h"
13 #include "content/test/test_browser_thread.h" 14 #include "content/test/test_browser_thread.h"
14 15
15 using content::BrowserThread; 16 using content::BrowserThread;
16 using content::NavigationEntry; 17 using content::NavigationEntry;
17 using content::WebContents; 18 using content::WebContents;
18 using content::WebContentsView; 19 using content::WebContentsView;
19 20
20 static const char* kGoogleURL = "http://www.google.com/"; 21 static const char* kGoogleURL = "http://www.google.com/";
21 static const char* kGoodURL = "http://www.goodguys.com/"; 22 static const char* kGoodURL = "http://www.goodguys.com/";
22 static const char* kBadURL = "http://www.badguys.com/"; 23 static const char* kBadURL = "http://www.badguys.com/";
23 static const char* kBadURL2 = "http://www.badguys2.com/"; 24 static const char* kBadURL2 = "http://www.badguys2.com/";
24 static const char* kBadURL3 = "http://www.badguys3.com/"; 25 static const char* kBadURL3 = "http://www.badguys3.com/";
25 26
26 // A SafeBrowingBlockingPage class that does not create windows. 27 // A SafeBrowingBlockingPage class that does not create windows.
27 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { 28 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage {
28 public: 29 public:
29 TestSafeBrowsingBlockingPage(SafeBrowsingService* service, 30 TestSafeBrowsingBlockingPage(SafeBrowsingService* service,
30 WebContents* web_contents, 31 WebContents* web_contents,
31 const UnsafeResourceList& unsafe_resources) 32 const UnsafeResourceList& unsafe_resources)
32 : SafeBrowsingBlockingPage(service, web_contents, unsafe_resources) { 33 : SafeBrowsingBlockingPage(service, web_contents, unsafe_resources) {
33 // Don't delay details at all for the unittest. 34 // Don't delay details at all for the unittest.
34 malware_details_proceed_delay_ms_ = 0; 35 malware_details_proceed_delay_ms_ = 0;
36
37 // Don't create a view.
38 interstitial_page_->DontCreateViewForTesting();
35 } 39 }
36 40
37 // Overriden from InterstitialPage. Don't create a view.
38 virtual WebContentsView* CreateWebContentsView() {
39 return NULL;
40 }
41 }; 41 };
42 42
43 class TestSafeBrowsingService: public SafeBrowsingService { 43 class TestSafeBrowsingService: public SafeBrowsingService {
44 public: 44 public:
45 virtual ~TestSafeBrowsingService() {} 45 virtual ~TestSafeBrowsingService() {}
46 46
47 virtual void SendSerializedMalwareDetails(const std::string& serialized) { 47 virtual void SendSerializedMalwareDetails(const std::string& serialized) {
48 details_.push_back(serialized); 48 details_.push_back(serialized);
49 } 49 }
50 50
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource); 131 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource);
132 } 132 }
133 133
134 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is 134 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is
135 // showing. 135 // showing.
136 SafeBrowsingBlockingPage* GetSafeBrowsingBlockingPage() { 136 SafeBrowsingBlockingPage* GetSafeBrowsingBlockingPage() {
137 InterstitialPage* interstitial = 137 InterstitialPage* interstitial =
138 InterstitialPage::GetInterstitialPage(contents()); 138 InterstitialPage::GetInterstitialPage(contents());
139 if (!interstitial) 139 if (!interstitial)
140 return NULL; 140 return NULL;
141 return static_cast<SafeBrowsingBlockingPage*>(interstitial); 141 return static_cast<SafeBrowsingBlockingPage*>(
142 interstitial->GetDelegateForTesting());
142 } 143 }
143 144
144 UserResponse user_response() const { return user_response_; } 145 UserResponse user_response() const { return user_response_; }
145 void ResetUserResponse() { user_response_ = PENDING; } 146 void ResetUserResponse() { user_response_ = PENDING; }
146 147
147 static void ProceedThroughInterstitial( 148 static void ProceedThroughInterstitial(
148 SafeBrowsingBlockingPage* sb_interstitial) { 149 SafeBrowsingBlockingPage* sb_interstitial) {
149 sb_interstitial->Proceed(); 150 sb_interstitial->interstitial_page_->Proceed();
150 // Proceed() posts a task to update the SafeBrowsingService::Client. 151 // Proceed() posts a task to update the SafeBrowsingService::Client.
151 MessageLoop::current()->RunAllPending(); 152 MessageLoop::current()->RunAllPending();
152 } 153 }
153 154
154 static void DontProceedThroughInterstitial( 155 static void DontProceedThroughInterstitial(
155 SafeBrowsingBlockingPage* sb_interstitial) { 156 SafeBrowsingBlockingPage* sb_interstitial) {
156 sb_interstitial->DontProceed(); 157 sb_interstitial->interstitial_page_->DontProceed();
157 // DontProceed() posts a task to update the SafeBrowsingService::Client. 158 // DontProceed() posts a task to update the SafeBrowsingService::Client.
158 MessageLoop::current()->RunAllPending(); 159 MessageLoop::current()->RunAllPending();
159 } 160 }
160 161
161 void DontProceedThroughSubresourceInterstitial( 162 void DontProceedThroughSubresourceInterstitial(
162 SafeBrowsingBlockingPage* sb_interstitial) { 163 SafeBrowsingBlockingPage* sb_interstitial) {
163 // CommandReceived(kTakeMeBackCommand) does a back navigation for 164 // CommandReceived(kTakeMeBackCommand) does a back navigation for
164 // subresource interstitials. 165 // subresource interstitials.
165 GoBack(false); 166 GoBack(false);
166 // DontProceed() posts a task to update the SafeBrowsingService::Client. 167 // DontProceed() posts a task to update the SafeBrowsingService::Client.
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 534
534 // Simulate the load causing a safe browsing interstitial to be shown. 535 // Simulate the load causing a safe browsing interstitial to be shown.
535 ShowInterstitial(false, kBadURL); 536 ShowInterstitial(false, kBadURL);
536 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 537 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
537 ASSERT_TRUE(sb_interstitial); 538 ASSERT_TRUE(sb_interstitial);
538 539
539 MessageLoop::current()->RunAllPending(); 540 MessageLoop::current()->RunAllPending();
540 541
541 // Simulate the user clicking "proceed" then "don't proceed" (before the 542 // Simulate the user clicking "proceed" then "don't proceed" (before the
542 // interstitial is shown). 543 // interstitial is shown).
543 sb_interstitial->Proceed(); 544 sb_interstitial->interstitial_page_->Proceed();
544 sb_interstitial->DontProceed(); 545 sb_interstitial->interstitial_page_->DontProceed();
545 // Proceed() and DontProceed() post a task to update the 546 // Proceed() and DontProceed() post a task to update the
546 // SafeBrowsingService::Client. 547 // SafeBrowsingService::Client.
547 MessageLoop::current()->RunAllPending(); 548 MessageLoop::current()->RunAllPending();
548 549
549 // The interstitial should be gone. 550 // The interstitial should be gone.
550 EXPECT_EQ(OK, user_response()); 551 EXPECT_EQ(OK, user_response());
551 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 552 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
552 553
553 // Only one report should have been sent. 554 // Only one report should have been sent.
554 EXPECT_EQ(1u, service_->GetDetails()->size()); 555 EXPECT_EQ(1u, service_->GetDetails()->size());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 615
615 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( 616 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
616 prefs::kSafeBrowsingReportingEnabled)); 617 prefs::kSafeBrowsingReportingEnabled));
617 618
618 // Simulate the user uncheck the report agreement checkbox. 619 // Simulate the user uncheck the report agreement checkbox.
619 sb_interstitial->SetReportingPreference(false); 620 sb_interstitial->SetReportingPreference(false);
620 621
621 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 622 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
622 prefs::kSafeBrowsingReportingEnabled)); 623 prefs::kSafeBrowsingReportingEnabled));
623 } 624 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc ('k') | chrome/browser/ssl/ssl_blocking_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698