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

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

Issue 342068: Third patch in getting rid of caching MessageLoop pointers and always using C... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/chrome_thread.h"
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
8 #include "chrome/browser/tab_contents/navigation_entry.h" 9 #include "chrome/browser/tab_contents/navigation_entry.h"
9 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
10 11
11 using webkit_glue::PasswordForm; 12 using webkit_glue::PasswordForm;
12 13
13 static const char* kGoogleURL = "http://www.google.com/"; 14 static const char* kGoogleURL = "http://www.google.com/";
14 static const char* kGoodURL = "http://www.goodguys.com/"; 15 static const char* kGoodURL = "http://www.goodguys.com/";
15 static const char* kBadURL = "http://www.badguys.com/"; 16 static const char* kBadURL = "http://www.badguys.com/";
16 static const char* kBadURL2 = "http://www.badguys2.com/"; 17 static const char* kBadURL2 = "http://www.badguys2.com/";
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 class SafeBrowsingBlockingPageTest : public RenderViewHostTestHarness, 67 class SafeBrowsingBlockingPageTest : public RenderViewHostTestHarness,
67 public SafeBrowsingService::Client { 68 public SafeBrowsingService::Client {
68 public: 69 public:
69 // The decision the user made. 70 // The decision the user made.
70 enum UserResponse { 71 enum UserResponse {
71 PENDING, 72 PENDING,
72 OK, 73 OK,
73 CANCEL 74 CANCEL
74 }; 75 };
75 76
76 SafeBrowsingBlockingPageTest() { 77 SafeBrowsingBlockingPageTest()
78 : io_thread_(ChromeThread::IO, MessageLoop::current()) {
77 ResetUserResponse(); 79 ResetUserResponse();
78 service_ = new SafeBrowsingService(); 80 service_ = new SafeBrowsingService();
79 } 81 }
80 82
81 virtual void SetUp() { 83 virtual void SetUp() {
82 RenderViewHostTestHarness::SetUp(); 84 RenderViewHostTestHarness::SetUp();
83 SafeBrowsingBlockingPage::RegisterFactory(&factory_); 85 SafeBrowsingBlockingPage::RegisterFactory(&factory_);
84 ResetUserResponse(); 86 ResetUserResponse();
85 } 87 }
86 88
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 resource->url = url; 152 resource->url = url;
151 resource->resource_type = resource_type; 153 resource->resource_type = resource_type;
152 resource->threat_type = SafeBrowsingService::URL_MALWARE; 154 resource->threat_type = SafeBrowsingService::URL_MALWARE;
153 resource->render_process_host_id = contents_->process()->id(); 155 resource->render_process_host_id = contents_->process()->id();
154 resource->render_view_id = contents_->render_view_host()->routing_id(); 156 resource->render_view_id = contents_->render_view_host()->routing_id();
155 } 157 }
156 158
157 UserResponse user_response_; 159 UserResponse user_response_;
158 scoped_refptr<SafeBrowsingService> service_; 160 scoped_refptr<SafeBrowsingService> service_;
159 TestSafeBrowsingBlockingPageFactory factory_; 161 TestSafeBrowsingBlockingPageFactory factory_;
162 ChromeThread io_thread_;
160 }; 163 };
161 164
162 // Tests showing a blocking page for a malware page and not proceeding. 165 // Tests showing a blocking page for a malware page and not proceeding.
163 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { 166 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) {
164 // Start a load. 167 // Start a load.
165 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); 168 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED);
166 169
167 // Simulate the load causing a safe browsing interstitial to be shown. 170 // Simulate the load causing a safe browsing interstitial to be shown.
168 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); 171 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL);
169 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 172 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
170 ASSERT_TRUE(sb_interstitial); 173 ASSERT_TRUE(sb_interstitial);
171 174
175 MessageLoop::current()->RunAllPending();
176
172 // Simulate the user clicking "don't proceed". 177 // Simulate the user clicking "don't proceed".
173 DontProceedThroughInterstitial(sb_interstitial); 178 DontProceedThroughInterstitial(sb_interstitial);
174 179
175 // The interstitial should be gone. 180 // The interstitial should be gone.
176 EXPECT_EQ(CANCEL, user_response()); 181 EXPECT_EQ(CANCEL, user_response());
177 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 182 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
178 183
179 // We did not proceed, the pending entry should be gone. 184 // We did not proceed, the pending entry should be gone.
180 EXPECT_FALSE(controller().pending_entry()); 185 EXPECT_FALSE(controller().pending_entry());
181 } 186 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 ASSERT_TRUE(sb_interstitial); 397 ASSERT_TRUE(sb_interstitial);
393 398
394 // Let's proceed and make sure everything is OK (bug 17627). 399 // Let's proceed and make sure everything is OK (bug 17627).
395 ProceedThroughInterstitial(sb_interstitial); 400 ProceedThroughInterstitial(sb_interstitial);
396 Navigate(kBadURL, 2); // Commit the navigation. 401 Navigate(kBadURL, 2); // Commit the navigation.
397 sb_interstitial = GetSafeBrowsingBlockingPage(); 402 sb_interstitial = GetSafeBrowsingBlockingPage();
398 ASSERT_FALSE(sb_interstitial); 403 ASSERT_FALSE(sb_interstitial);
399 ASSERT_EQ(2, controller().entry_count()); 404 ASSERT_EQ(2, controller().entry_count());
400 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->url().spec()); 405 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->url().spec());
401 } 406 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/browser/safe_browsing/safe_browsing_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698