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

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 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 // 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 void SendCommand(const std::string& command) { 268 void SendCommand(const std::string& command) {
268 WebContents* contents = 269 WebContents* contents =
269 browser()->GetSelectedTabContentsWrapper()->web_contents(); 270 browser()->GetSelectedTabContentsWrapper()->web_contents();
270 // We use InterstitialPage::GetInterstitialPage(tab) instead of 271 // We use InterstitialPage::GetInterstitialPage(tab) instead of
271 // tab->GetInterstitialPage() because the tab doesn't have a pointer 272 // tab->GetInterstitialPage() because the tab doesn't have a pointer
272 // to its interstital page until it gets a command from the renderer 273 // to its interstital page until it gets a command from the renderer
273 // that it has indeed displayed it -- and this sometimes happens after 274 // that it has indeed displayed it -- and this sometimes happens after
274 // NavigateToURL returns. 275 // NavigateToURL returns.
275 SafeBrowsingBlockingPage* interstitial_page = 276 SafeBrowsingBlockingPage* interstitial_page =
276 static_cast<SafeBrowsingBlockingPage*>( 277 static_cast<SafeBrowsingBlockingPage*>(
277 InterstitialPage::GetInterstitialPage(contents)); 278 InterstitialPage::GetInterstitialPage(contents)->
279 GetDelegateForTesting());
278 ASSERT_TRUE(interstitial_page); 280 ASSERT_TRUE(interstitial_page);
279 interstitial_page->CommandReceived(command); 281 interstitial_page->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 static_cast<TestSafeBrowsingBlockingPage*>(
307 contents->GetInterstitialPage())->set_wait_for_delete(); 309 contents->GetInterstitialPage()->GetDelegateForTesting())->
310 set_wait_for_delete();
308 ui_test_utils::RunMessageLoop(); 311 ui_test_utils::RunMessageLoop();
309 } 312 }
310 313
311 // Can't use InterstitialPage::GetInterstitialPage() because that 314 // Can't use InterstitialPage::GetInterstitialPage() because that
312 // gets updated after the TestSafeBrowsingBlockingPage destructor 315 // gets updated after the TestSafeBrowsingBlockingPage destructor
313 ASSERT_FALSE(contents->ShowingInterstitialPage()); 316 ASSERT_FALSE(contents->ShowingInterstitialPage());
314 } 317 }
315 318
316 bool YesInterstitial() { 319 bool YesInterstitial() {
317 WebContents* contents = 320 WebContents* contents =
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 SendCommand("\"proceed\""); // Simulate the user clicking "back" 594 SendCommand("\"proceed\""); // Simulate the user clicking "back"
592 AssertNoInterstitial(true); // Assert the interstitial is gone 595 AssertNoInterstitial(true); // Assert the interstitial is gone
593 596
594 EXPECT_EQ( 597 EXPECT_EQ(
595 url, 598 url,
596 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); 599 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL());
597 AssertReportSent(); 600 AssertReportSent();
598 } 601 }
599 602
600 } // namespace 603 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698