OLD | NEW |
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 #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/task.h" | 8 #include "base/task.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" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 TabContentsWrapperTestHarness::SetUp(); | 142 TabContentsWrapperTestHarness::SetUp(); |
143 ui_thread_.reset(new BrowserThread(BrowserThread::UI, &message_loop_)); | 143 ui_thread_.reset(new BrowserThread(BrowserThread::UI, &message_loop_)); |
144 // Note: we're starting a real IO thread to make sure our DCHECKs that | 144 // Note: we're starting a real IO thread to make sure our DCHECKs that |
145 // verify which thread is running are actually tested. | 145 // verify which thread is running are actually tested. |
146 io_thread_.reset(new BrowserThread(BrowserThread::IO)); | 146 io_thread_.reset(new BrowserThread(BrowserThread::IO)); |
147 ASSERT_TRUE(io_thread_->Start()); | 147 ASSERT_TRUE(io_thread_->Start()); |
148 | 148 |
149 // Inject service classes. | 149 // Inject service classes. |
150 csd_service_.reset(new StrictMock<MockClientSideDetectionService>()); | 150 csd_service_.reset(new StrictMock<MockClientSideDetectionService>()); |
151 sb_service_ = new StrictMock<MockSafeBrowsingService>(); | 151 sb_service_ = new StrictMock<MockSafeBrowsingService>(); |
152 csd_host_ = contents_wrapper()->safebrowsing_detection_host(); | 152 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create( |
| 153 contents_wrapper()->tab_contents())); |
153 csd_host_->set_client_side_detection_service(csd_service_.get()); | 154 csd_host_->set_client_side_detection_service(csd_service_.get()); |
154 csd_host_->set_safe_browsing_service(sb_service_.get()); | 155 csd_host_->set_safe_browsing_service(sb_service_.get()); |
155 } | 156 } |
156 | 157 |
157 virtual void TearDown() { | 158 virtual void TearDown() { |
158 TabContentsWrapperTestHarness::TearDown(); | 159 TabContentsWrapperTestHarness::TearDown(); |
159 io_thread_.reset(); | 160 io_thread_.reset(); |
160 ui_thread_.reset(); | 161 ui_thread_.reset(); |
161 } | 162 } |
162 | 163 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 219 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
219 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 220 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
220 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); | 221 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); |
221 } | 222 } |
222 | 223 |
223 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { | 224 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { |
224 csd_host_->feature_extractor_.reset(extractor); | 225 csd_host_->feature_extractor_.reset(extractor); |
225 } | 226 } |
226 | 227 |
227 protected: | 228 protected: |
228 ClientSideDetectionHost* csd_host_; | 229 scoped_ptr<ClientSideDetectionHost> csd_host_; |
229 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; | 230 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; |
230 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; | 231 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; |
231 MockTestingProfile* mock_profile_; // We don't own this object | 232 MockTestingProfile* mock_profile_; // We don't own this object |
232 | 233 |
233 private: | 234 private: |
234 scoped_ptr<BrowserThread> ui_thread_; | 235 scoped_ptr<BrowserThread> ui_thread_; |
235 scoped_ptr<BrowserThread> io_thread_; | 236 scoped_ptr<BrowserThread> io_thread_; |
236 }; | 237 }; |
237 | 238 |
238 TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteInvalidVerdict) { | 239 TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteInvalidVerdict) { |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 612 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
612 EXPECT_EQ(url, resource.url); | 613 EXPECT_EQ(url, resource.url); |
613 EXPECT_EQ(url, resource.original_url); | 614 EXPECT_EQ(url, resource.original_url); |
614 delete resource.client; | 615 delete resource.client; |
615 msg = process()->sink().GetFirstMessageMatching( | 616 msg = process()->sink().GetFirstMessageMatching( |
616 SafeBrowsingMsg_StartPhishingDetection::ID); | 617 SafeBrowsingMsg_StartPhishingDetection::ID); |
617 ASSERT_FALSE(msg); | 618 ASSERT_FALSE(msg); |
618 } | 619 } |
619 | 620 |
620 } // namespace safe_browsing | 621 } // namespace safe_browsing |
OLD | NEW |