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

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

Issue 9030010: Move most of the remaining users of WebContentsObserver::tab_contents() to use web_contents(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 12 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/tab_contents.h" 24 #include "content/browser/tab_contents/tab_contents.h"
25 #include "content/browser/tab_contents/tab_contents_view.h" 25 #include "content/browser/tab_contents/tab_contents_view.h"
26 #include "content/test/test_browser_thread.h" 26 #include "content/test/test_browser_thread.h"
27 27
28 using content::BrowserThread; 28 using content::BrowserThread;
29 using content::WebContents;
29 30
30 // A SafeBrowingService class that allows us to inject the malicious URLs. 31 // A SafeBrowingService class that allows us to inject the malicious URLs.
31 class FakeSafeBrowsingService : public SafeBrowsingService { 32 class FakeSafeBrowsingService : public SafeBrowsingService {
32 public: 33 public:
33 FakeSafeBrowsingService() {} 34 FakeSafeBrowsingService() {}
34 35
35 virtual ~FakeSafeBrowsingService() {} 36 virtual ~FakeSafeBrowsingService() {}
36 37
37 // Called on the IO thread to check if the given url is safe or not. If we 38 // Called on the IO thread to check if the given url is safe or not. If we
38 // can synchronously determine that the url is safe, CheckUrl returns true. 39 // can synchronously determine that the url is safe, CheckUrl returns true.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 virtual SafeBrowsingService* CreateSafeBrowsingService() { 97 virtual SafeBrowsingService* CreateSafeBrowsingService() {
97 return new FakeSafeBrowsingService(); 98 return new FakeSafeBrowsingService();
98 } 99 }
99 }; 100 };
100 101
101 // A MalwareDetails class lets us intercept calls from the renderer. 102 // A MalwareDetails class lets us intercept calls from the renderer.
102 class FakeMalwareDetails : public MalwareDetails { 103 class FakeMalwareDetails : public MalwareDetails {
103 public: 104 public:
104 FakeMalwareDetails(SafeBrowsingService* sb_service, 105 FakeMalwareDetails(SafeBrowsingService* sb_service,
105 TabContents* tab_contents, 106 WebContents* web_contents,
106 const SafeBrowsingService::UnsafeResource& unsafe_resource) 107 const SafeBrowsingService::UnsafeResource& unsafe_resource)
107 : MalwareDetails(sb_service, tab_contents, unsafe_resource) { } 108 : MalwareDetails(sb_service, web_contents, unsafe_resource) { }
108 109
109 virtual ~FakeMalwareDetails() {} 110 virtual ~FakeMalwareDetails() {}
110 111
111 virtual void AddDOMDetails( 112 virtual void AddDOMDetails(
112 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params) { 113 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params) {
113 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 114 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
114 MalwareDetails::AddDOMDetails(params); 115 MalwareDetails::AddDOMDetails(params);
115 116
116 // Notify the UI thread that we got the dom details. 117 // Notify the UI thread that we got the dom details.
117 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 118 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 155
155 }; 156 };
156 157
157 class TestMalwareDetailsFactory : public MalwareDetailsFactory { 158 class TestMalwareDetailsFactory : public MalwareDetailsFactory {
158 public: 159 public:
159 TestMalwareDetailsFactory() { } 160 TestMalwareDetailsFactory() { }
160 virtual ~TestMalwareDetailsFactory() { } 161 virtual ~TestMalwareDetailsFactory() { }
161 162
162 virtual MalwareDetails* CreateMalwareDetails( 163 virtual MalwareDetails* CreateMalwareDetails(
163 SafeBrowsingService* sb_service, 164 SafeBrowsingService* sb_service,
164 TabContents* tab_contents, 165 WebContents* web_contents,
165 const SafeBrowsingService::UnsafeResource& unsafe_resource) { 166 const SafeBrowsingService::UnsafeResource& unsafe_resource) {
166 details_ = new FakeMalwareDetails(sb_service, tab_contents, 167 details_ = new FakeMalwareDetails(sb_service, web_contents,
167 unsafe_resource); 168 unsafe_resource);
168 return details_; 169 return details_;
169 } 170 }
170 171
171 FakeMalwareDetails* get_details() { 172 FakeMalwareDetails* get_details() {
172 return details_; 173 return details_;
173 } 174 }
174 175
175 private: 176 private:
176 FakeMalwareDetails* details_; 177 FakeMalwareDetails* details_;
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 prefs::kSafeBrowsingReportingEnabled)); 560 prefs::kSafeBrowsingReportingEnabled));
560 561
561 SendCommand("\"proceed\""); // Simulate the user clicking "back" 562 SendCommand("\"proceed\""); // Simulate the user clicking "back"
562 AssertNoInterstitial(true); // Assert the interstitial is gone 563 AssertNoInterstitial(true); // Assert the interstitial is gone
563 564
564 EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL()); 565 EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL());
565 AssertReportSent(); 566 AssertReportSent();
566 } 567 }
567 568
568 } // namespace 569 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/malware_details.cc ('k') | chrome/browser/tab_contents/thumbnail_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698