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

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

Issue 10542010: TabContentsWrapper -> TabContents, part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, rename Created 8 years, 6 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" 9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h"
10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" 10 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
11 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 11 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
14 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/safe_browsing/csd.pb.h" 16 #include "chrome/common/safe_browsing/csd.pb.h"
17 #include "chrome/common/safe_browsing/safebrowsing_messages.h" 17 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
18 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/mock_render_process_host.h" 20 #include "content/public/test/mock_render_process_host.h"
21 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread.h"
22 #include "content/public/test/test_renderer_host.h" 22 #include "content/public/test/test_renderer_host.h"
23 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
24 #include "ipc/ipc_test_sink.h" 24 #include "ipc/ipc_test_sink.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 // Helper function which quits the UI message loop from the IO message loop. 148 // Helper function which quits the UI message loop from the IO message loop.
149 void QuitUIMessageLoopFromIO() { 149 void QuitUIMessageLoopFromIO() {
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
151 BrowserThread::PostTask(BrowserThread::UI, 151 BrowserThread::PostTask(BrowserThread::UI,
152 FROM_HERE, 152 FROM_HERE,
153 MessageLoop::QuitClosure()); 153 MessageLoop::QuitClosure());
154 } 154 }
155 } // namespace 155 } // namespace
156 156
157 class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness { 157 class ClientSideDetectionHostTest : public TabContentsTestHarness {
158 public: 158 public:
159 virtual void SetUp() { 159 virtual void SetUp() {
160 // Set custom profile object so that we can mock calls to IsOffTheRecord. 160 // Set custom profile object so that we can mock calls to IsOffTheRecord.
161 // This needs to happen before we call the parent SetUp() function. We use 161 // This needs to happen before we call the parent SetUp() function. We use
162 // a nice mock because other parts of the code are calling IsOffTheRecord. 162 // a nice mock because other parts of the code are calling IsOffTheRecord.
163 mock_profile_ = new NiceMock<MockTestingProfile>(); 163 mock_profile_ = new NiceMock<MockTestingProfile>();
164 browser_context_.reset(mock_profile_); 164 browser_context_.reset(mock_profile_);
165 165
166 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, 166 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI,
167 &message_loop_)); 167 &message_loop_));
168 file_user_blocking_thread_.reset( 168 file_user_blocking_thread_.reset(
169 new content::TestBrowserThread(BrowserThread::FILE_USER_BLOCKING, 169 new content::TestBrowserThread(BrowserThread::FILE_USER_BLOCKING,
170 &message_loop_)); 170 &message_loop_));
171 // Note: we're starting a real IO thread to make sure our DCHECKs that 171 // Note: we're starting a real IO thread to make sure our DCHECKs that
172 // verify which thread is running are actually tested. 172 // verify which thread is running are actually tested.
173 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); 173 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO));
174 ASSERT_TRUE(io_thread_->Start()); 174 ASSERT_TRUE(io_thread_->Start());
175 175
176 TabContentsWrapperTestHarness::SetUp(); 176 TabContentsTestHarness::SetUp();
177 177
178 // Inject service classes. 178 // Inject service classes.
179 csd_service_.reset(new StrictMock<MockClientSideDetectionService>()); 179 csd_service_.reset(new StrictMock<MockClientSideDetectionService>());
180 sb_service_ = new StrictMock<MockSafeBrowsingService>(); 180 sb_service_ = new StrictMock<MockSafeBrowsingService>();
181 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create( 181 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create(
182 contents_wrapper()->web_contents())); 182 tab_contents()->web_contents()));
183 csd_host_->set_client_side_detection_service(csd_service_.get()); 183 csd_host_->set_client_side_detection_service(csd_service_.get());
184 csd_host_->set_safe_browsing_service(sb_service_.get()); 184 csd_host_->set_safe_browsing_service(sb_service_.get());
185 // We need to create this here since we don't call 185 // We need to create this here since we don't call
186 // DidNavigateMainFramePostCommit in this test. 186 // DidNavigateMainFramePostCommit in this test.
187 csd_host_->browse_info_.reset(new BrowseInfo); 187 csd_host_->browse_info_.reset(new BrowseInfo);
188 } 188 }
189 189
190 static void RunAllPendingOnIO(base::WaitableEvent* event) { 190 static void RunAllPendingOnIO(base::WaitableEvent* event) {
191 MessageLoop::current()->RunAllPending(); 191 MessageLoop::current()->RunAllPending();
192 event->Signal(); 192 event->Signal();
193 } 193 }
194 194
195 virtual void TearDown() { 195 virtual void TearDown() {
196 // Delete the host object on the UI thread and release the 196 // Delete the host object on the UI thread and release the
197 // SafeBrowsingService. 197 // SafeBrowsingService.
198 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, 198 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE,
199 csd_host_.release()); 199 csd_host_.release());
200 sb_service_ = NULL; 200 sb_service_ = NULL;
201 message_loop_.RunAllPending(); 201 message_loop_.RunAllPending();
202 TabContentsWrapperTestHarness::TearDown(); 202 TabContentsTestHarness::TearDown();
203 203
204 // Let the tasks on the IO thread run to avoid memory leaks. 204 // Let the tasks on the IO thread run to avoid memory leaks.
205 base::WaitableEvent done(false, false); 205 base::WaitableEvent done(false, false);
206 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 206 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
207 base::Bind(RunAllPendingOnIO, &done)); 207 base::Bind(RunAllPendingOnIO, &done));
208 done.Wait(); 208 done.Wait();
209 io_thread_.reset(); 209 io_thread_.reset();
210 message_loop_.RunAllPending(); 210 message_loop_.RunAllPending();
211 file_user_blocking_thread_.reset(); 211 file_user_blocking_thread_.reset();
212 ui_thread_.reset(); 212 ui_thread_.reset();
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); 783 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get()));
784 EXPECT_EQ(url, resource.url); 784 EXPECT_EQ(url, resource.url);
785 EXPECT_EQ(url, resource.original_url); 785 EXPECT_EQ(url, resource.original_url);
786 resource.callback.Reset(); 786 resource.callback.Reset();
787 msg = process()->sink().GetFirstMessageMatching( 787 msg = process()->sink().GetFirstMessageMatching(
788 SafeBrowsingMsg_StartPhishingDetection::ID); 788 SafeBrowsingMsg_StartPhishingDetection::ID);
789 ASSERT_FALSE(msg); 789 ASSERT_FALSE(msg);
790 } 790 }
791 791
792 } // namespace safe_browsing 792 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698