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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.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 tests 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 // This test creates a fake safebrowsing service, where we can inject 5 // This test creates a fake safebrowsing service, where we can inject
6 // malware and phishing urls. It then uses a real browser to go to 6 // malware and phishing urls. It then uses a real browser to go to
7 // these urls, and sends "goback" or "proceed" commands and verifies 7 // these urls, and sends "goback" or "proceed" commands and verifies
8 // they work. 8 // they work.
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/safe_browsing/malware_details.h" 14 #include "chrome/browser/safe_browsing/malware_details.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/browser/renderer_host/resource_dispatcher_host.h" 23 #include "content/browser/renderer_host/resource_dispatcher_host.h"
24 #include "content/browser/tab_contents/interstitial_page.h"
24 #include "content/public/browser/navigation_controller.h" 25 #include "content/public/browser/navigation_controller.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_view.h" 27 #include "content/public/browser/web_contents_view.h"
27 #include "content/test/test_browser_thread.h" 28 #include "content/test/test_browser_thread.h"
28 29
29 using content::BrowserThread; 30 using content::BrowserThread;
30 using content::NavigationController; 31 using content::NavigationController;
31 using content::WebContents; 32 using content::WebContents;
32 33
33 // A SafeBrowingService class that allows us to inject the malicious URLs. 34 // A SafeBrowingService class that allows us to inject the malicious URLs.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void AddURLResult(const GURL& url, 258 void AddURLResult(const GURL& url,
258 SafeBrowsingService::UrlCheckResult checkresult) { 259 SafeBrowsingService::UrlCheckResult checkresult) {
259 FakeSafeBrowsingService* service = 260 FakeSafeBrowsingService* service =
260 static_cast<FakeSafeBrowsingService*>( 261 static_cast<FakeSafeBrowsingService*>(
261 g_browser_process->safe_browsing_service()); 262 g_browser_process->safe_browsing_service());
262 263
263 ASSERT_TRUE(service); 264 ASSERT_TRUE(service);
264 service->AddURLResult(url, checkresult); 265 service->AddURLResult(url, checkresult);
265 } 266 }
266 267
267 void SendCommand(const std::string& command) { 268 TestSafeBrowsingBlockingPage* GetSafeBrowsingBlockingPage() {
268 WebContents* contents =
269 browser()->GetSelectedTabContentsWrapper()->web_contents();
270 // We use InterstitialPage::GetInterstitialPage(tab) instead of 269 // We use InterstitialPage::GetInterstitialPage(tab) instead of
271 // tab->GetInterstitialPage() because the tab doesn't have a pointer 270 // tab->GetInterstitialPage() because the tab doesn't have a pointer
272 // to its interstital page until it gets a command from the renderer 271 // to its interstital page until it gets a command from the renderer
273 // that it has indeed displayed it -- and this sometimes happens after 272 // that it has indeed displayed it -- and this sometimes happens after
274 // NavigateToURL returns. 273 // NavigateToURL returns.
275 SafeBrowsingBlockingPage* interstitial_page = 274 WebContents* contents =
276 static_cast<SafeBrowsingBlockingPage*>( 275 browser()->GetSelectedTabContentsWrapper()->web_contents();
277 InterstitialPage::GetInterstitialPage(contents)); 276 return static_cast<TestSafeBrowsingBlockingPage*>(
278 ASSERT_TRUE(interstitial_page); 277 contents->GetInterstitialPage()->GetDelegateForTesting());
279 interstitial_page->CommandReceived(command); 278 }
279
280 void SendCommand(const std::string& command) {
281 GetSafeBrowsingBlockingPage()->CommandReceived(command);
280 } 282 }
281 283
282 void DontProceedThroughInterstitial() { 284 void DontProceedThroughInterstitial() {
283 WebContents* contents = 285 WebContents* contents =
284 browser()->GetSelectedTabContentsWrapper()->web_contents(); 286 browser()->GetSelectedTabContentsWrapper()->web_contents();
285 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( 287 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage(
286 contents); 288 contents);
287 ASSERT_TRUE(interstitial_page); 289 ASSERT_TRUE(interstitial_page);
288 interstitial_page->DontProceed(); 290 interstitial_page->DontProceed();
289 } 291 }
290 292
291 void ProceedThroughInterstitial() { 293 void ProceedThroughInterstitial() {
292 WebContents* contents = 294 WebContents* contents =
293 browser()->GetSelectedTabContentsWrapper()->web_contents(); 295 browser()->GetSelectedTabContentsWrapper()->web_contents();
294 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( 296 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage(
295 contents); 297 contents);
296 ASSERT_TRUE(interstitial_page); 298 ASSERT_TRUE(interstitial_page);
297 interstitial_page->Proceed(); 299 interstitial_page->Proceed();
298 } 300 }
299 301
300 void AssertNoInterstitial(bool wait_for_delete) { 302 void AssertNoInterstitial(bool wait_for_delete) {
301 WebContents* contents = 303 WebContents* contents =
302 browser()->GetSelectedTabContentsWrapper()->web_contents(); 304 browser()->GetSelectedTabContentsWrapper()->web_contents();
303 305
304 if (contents->ShowingInterstitialPage() && wait_for_delete) { 306 if (contents->ShowingInterstitialPage() && wait_for_delete) {
305 // We'll get notified when the interstitial is deleted. 307 // We'll get notified when the interstitial is deleted.
306 static_cast<TestSafeBrowsingBlockingPage*>( 308 GetSafeBrowsingBlockingPage()->set_wait_for_delete();
307 contents->GetInterstitialPage())->set_wait_for_delete();
308 ui_test_utils::RunMessageLoop(); 309 ui_test_utils::RunMessageLoop();
309 } 310 }
310 311
311 // Can't use InterstitialPage::GetInterstitialPage() because that 312 // Can't use InterstitialPage::GetInterstitialPage() because that
312 // gets updated after the TestSafeBrowsingBlockingPage destructor 313 // gets updated after the TestSafeBrowsingBlockingPage destructor
313 ASSERT_FALSE(contents->ShowingInterstitialPage()); 314 ASSERT_FALSE(contents->ShowingInterstitialPage());
314 } 315 }
315 316
316 bool YesInterstitial() { 317 bool YesInterstitial() {
317 WebContents* contents = 318 WebContents* contents =
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 SendCommand("\"proceed\""); // Simulate the user clicking "back" 584 SendCommand("\"proceed\""); // Simulate the user clicking "back"
584 AssertNoInterstitial(true); // Assert the interstitial is gone 585 AssertNoInterstitial(true); // Assert the interstitial is gone
585 586
586 EXPECT_EQ( 587 EXPECT_EQ(
587 url, 588 url,
588 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); 589 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL());
589 AssertReportSent(); 590 AssertReportSent();
590 } 591 }
591 592
592 } // namespace 593 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698