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

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

Issue 128993004: Fix subtle bug with the in-process utility thread usage in unit tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 6 years, 11 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 "chrome/browser/safe_browsing/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
23 #include "chrome/browser/safe_browsing/database_manager.h" 23 #include "chrome/browser/safe_browsing/database_manager.h"
24 #include "chrome/browser/safe_browsing/download_feedback_service.h" 24 #include "chrome/browser/safe_browsing/download_feedback_service.h"
25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
26 #include "chrome/browser/safe_browsing/signature_util.h" 26 #include "chrome/browser/safe_browsing/signature_util.h"
27 #include "chrome/common/safe_browsing/csd.pb.h" 27 #include "chrome/common/safe_browsing/csd.pb.h"
28 #include "content/public/browser/render_process_host.h"
29 #include "content/public/test/mock_download_item.h" 28 #include "content/public/test/mock_download_item.h"
30 #include "content/public/test/test_browser_thread_bundle.h" 29 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "content/public/test/test_utils.h"
31 #include "net/cert/x509_certificate.h" 31 #include "net/cert/x509_certificate.h"
32 #include "net/http/http_status_code.h" 32 #include "net/http/http_status_code.h"
33 #include "net/url_request/test_url_fetcher_factory.h" 33 #include "net/url_request/test_url_fetcher_factory.h"
34 #include "net/url_request/url_fetcher_delegate.h" 34 #include "net/url_request/url_fetcher_delegate.h"
35 #include "net/url_request/url_request_status.h" 35 #include "net/url_request/url_request_status.h"
36 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
37 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
38 #include "third_party/zlib/google/zip.h" 38 #include "third_party/zlib/google/zip.h"
39 #include "url/gurl.h" 39 #include "url/gurl.h"
40 40
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 base::Owned(check))); 150 base::Owned(check)));
151 } 151 }
152 152
153 class DownloadProtectionServiceTest : public testing::Test { 153 class DownloadProtectionServiceTest : public testing::Test {
154 protected: 154 protected:
155 DownloadProtectionServiceTest() 155 DownloadProtectionServiceTest()
156 : test_browser_thread_bundle_( 156 : test_browser_thread_bundle_(
157 content::TestBrowserThreadBundle::IO_MAINLOOP) { 157 content::TestBrowserThreadBundle::IO_MAINLOOP) {
158 } 158 }
159 virtual void SetUp() { 159 virtual void SetUp() {
160 content::RenderProcessHost::SetRunRendererInProcess(true);
161 // Start real threads for the IO and File threads so that the DCHECKs 160 // Start real threads for the IO and File threads so that the DCHECKs
162 // to test that we're on the correct thread work. 161 // to test that we're on the correct thread work.
163 sb_service_ = new StrictMock<FakeSafeBrowsingService>(); 162 sb_service_ = new StrictMock<FakeSafeBrowsingService>();
164 sb_service_->Initialize(); 163 sb_service_->Initialize();
165 signature_util_ = new StrictMock<MockSignatureUtil>(); 164 signature_util_ = new StrictMock<MockSignatureUtil>();
166 download_service_ = sb_service_->download_protection_service(); 165 download_service_ = sb_service_->download_protection_service();
167 download_service_->signature_util_ = signature_util_; 166 download_service_->signature_util_ = signature_util_;
168 download_service_->SetEnabled(true); 167 download_service_->SetEnabled(true);
169 base::RunLoop().RunUntilIdle(); 168 base::RunLoop().RunUntilIdle();
170 has_result_ = false; 169 has_result_ = false;
171 170
172 base::FilePath source_path; 171 base::FilePath source_path;
173 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); 172 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path));
174 testdata_path_ = source_path 173 testdata_path_ = source_path
175 .AppendASCII("chrome") 174 .AppendASCII("chrome")
176 .AppendASCII("test") 175 .AppendASCII("test")
177 .AppendASCII("data") 176 .AppendASCII("data")
178 .AppendASCII("safe_browsing") 177 .AppendASCII("safe_browsing")
179 .AppendASCII("download_protection"); 178 .AppendASCII("download_protection");
180 } 179 }
181 180
182 virtual void TearDown() { 181 virtual void TearDown() {
183 sb_service_->ShutDown(); 182 sb_service_->ShutDown();
184 // Flush all of the thread message loops to ensure that there are no 183 // Flush all of the thread message loops to ensure that there are no
185 // tasks currently running. 184 // tasks currently running.
186 FlushThreadMessageLoops(); 185 FlushThreadMessageLoops();
187 sb_service_ = NULL; 186 sb_service_ = NULL;
188 content::RenderProcessHost::SetRunRendererInProcess(false);
189 } 187 }
190 188
191 bool RequestContainsResource(const ClientDownloadRequest& request, 189 bool RequestContainsResource(const ClientDownloadRequest& request,
192 ClientDownloadRequest::ResourceType type, 190 ClientDownloadRequest::ResourceType type,
193 const std::string& url, 191 const std::string& url,
194 const std::string& referrer) { 192 const std::string& referrer) {
195 for (int i = 0; i < request.resources_size(); ++i) { 193 for (int i = 0; i < request.resources_size(); ++i) {
196 if (request.resources(i).url() == url && 194 if (request.resources(i).url() == url &&
197 request.resources(i).type() == type && 195 request.resources(i).type() == type &&
198 (referrer.empty() || request.resources(i).referrer() == referrer)) { 196 (referrer.empty() || request.resources(i).referrer() == referrer)) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 ", got " << result_; 309 ", got " << result_;
312 } 310 }
313 311
314 protected: 312 protected:
315 scoped_refptr<FakeSafeBrowsingService> sb_service_; 313 scoped_refptr<FakeSafeBrowsingService> sb_service_;
316 scoped_refptr<MockSignatureUtil> signature_util_; 314 scoped_refptr<MockSignatureUtil> signature_util_;
317 DownloadProtectionService* download_service_; 315 DownloadProtectionService* download_service_;
318 DownloadProtectionService::DownloadCheckResult result_; 316 DownloadProtectionService::DownloadCheckResult result_;
319 bool has_result_; 317 bool has_result_;
320 content::TestBrowserThreadBundle test_browser_thread_bundle_; 318 content::TestBrowserThreadBundle test_browser_thread_bundle_;
319 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_;
321 base::FilePath testdata_path_; 320 base::FilePath testdata_path_;
322 }; 321 };
323 322
324 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { 323 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) {
325 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); 324 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
326 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); 325 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
327 std::vector<GURL> url_chain; 326 std::vector<GURL> url_chain;
328 GURL referrer("http://www.google.com/"); 327 GURL referrer("http://www.google.com/");
329 328
330 content::MockDownloadItem item; 329 content::MockDownloadItem item;
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 1169 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
1171 1170
1172 cert = ReadTestCertificate("test_c.pem"); 1171 cert = ReadTestCertificate("test_c.pem");
1173 ASSERT_TRUE(cert.get()); 1172 ASSERT_TRUE(cert.get());
1174 whitelist_strings.clear(); 1173 whitelist_strings.clear();
1175 GetCertificateWhitelistStrings( 1174 GetCertificateWhitelistStrings(
1176 *cert.get(), *issuer_cert.get(), &whitelist_strings); 1175 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1177 EXPECT_THAT(whitelist_strings, ElementsAre()); 1176 EXPECT_THAT(whitelist_strings, ElementsAre());
1178 } 1177 }
1179 } // namespace safe_browsing 1178 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater_unittest.cc ('k') | content/public/test/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698