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

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

Issue 2483993002: Add report_id to ErrorReporter interface. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
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 5
6 #include "base/base64.h" 6 #include "base/base64.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
8 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/test/histogram_tester.h"
9 #include "base/time/time.h" 12 #include "base/time/time.h"
10 #include "base/values.h" 13 #include "base/values.h"
11 #include "chrome/browser/safe_browsing/ping_manager.h" 14 #include "chrome/browser/safe_browsing/ping_manager.h"
15 #include "components/certificate_reporting/error_reporter.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_thread.h"
12 #include "google_apis/google_api_keys.h" 18 #include "google_apis/google_api_keys.h"
13 #include "net/base/escape.h" 19 #include "net/base/escape.h"
14 #include "net/log/net_log.h" 20 #include "net/log/net_log.h"
15 #include "net/log/net_log_source_type.h" 21 #include "net/log/net_log_source_type.h"
16 #include "net/log/test_net_log.h" 22 #include "net/log/test_net_log.h"
17 #include "net/log/test_net_log_entry.h" 23 #include "net/log/test_net_log_entry.h"
24 #include "net/test/url_request/url_request_failed_job.h"
25 #include "net/url_request/report_sender.h"
18 #include "net/url_request/test_url_fetcher_factory.h" 26 #include "net/url_request/test_url_fetcher_factory.h"
27 #include "net/url_request/url_request_context_getter.h"
28 #include "net/url_request/url_request_test_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
20 30
21 using base::Time; 31 using base::Time;
22 using base::TimeDelta; 32 using base::TimeDelta;
23 using safe_browsing::HitReport; 33 using safe_browsing::HitReport;
24 using safe_browsing::ThreatSource; 34 using safe_browsing::ThreatSource;
25 35
26 static const char kUrlPrefix[] = "https://prefix.com/foo"; 36 static const char kUrlPrefix[] = "https://prefix.com/foo";
27 static const char kClient[] = "unittest"; 37 static const char kClient[] = "unittest";
28 static const char kAppVer[] = "1.0"; 38 static const char kAppVer[] = "1.0";
39 // Histogram for certificate reporting failures:
40 static const char kFailureHistogramName[] = "SSL.CertificateErrorReportFailure";
29 41
30 namespace safe_browsing { 42 namespace safe_browsing {
31 43
32 class SafeBrowsingPingManagerTest : public testing::Test { 44 class SafeBrowsingPingManagerTest : public testing::Test {
33 public: 45 public:
34 SafeBrowsingPingManagerTest() 46 SafeBrowsingPingManagerTest()
35 : net_log_(new net::TestNetLog()) { 47 : net_log_(new net::TestNetLog()) {
36 net_log_with_source_ = net::NetLogWithSource::Make( 48 net_log_with_source_ = net::NetLogWithSource::Make(
37 net_log_.get(), net::NetLogSourceType::SAFE_BROWSING); 49 net_log_.get(), net::NetLogSourceType::SAFE_BROWSING);
38 } 50 }
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 EXPECT_EQ(net::URLRequestStatus::FAILED, int_value); 315 EXPECT_EQ(net::URLRequestStatus::FAILED, int_value);
304 316
305 EXPECT_TRUE(end_entry.GetIntegerValue("error", &int_value)); 317 EXPECT_TRUE(end_entry.GetIntegerValue("error", &int_value));
306 EXPECT_EQ(kRequestErrorCode, int_value); 318 EXPECT_EQ(kRequestErrorCode, int_value);
307 319
308 // We don't really care what the source_dependency value is, just making sure 320 // We don't really care what the source_dependency value is, just making sure
309 // it's there. 321 // it's there.
310 EXPECT_TRUE(end_entry.params->HasKey("source_dependency")); 322 EXPECT_TRUE(end_entry.params->HasKey("source_dependency"));
311 } 323 }
312 324
325 class SafeBrowsingPingManagerCertReportingTest : public testing::Test {
326 public:
327 SafeBrowsingPingManagerCertReportingTest() {}
328
329 protected:
330 void SetUp() override {
331 message_loop_.reset(new base::MessageLoopForIO());
332 io_thread_.reset(new content::TestBrowserThread(content::BrowserThread::IO,
333 message_loop_.get()));
334 url_request_context_getter_ =
335 new net::TestURLRequestContextGetter(message_loop_->task_runner());
336 net::URLRequestFailedJob::AddUrlHandler();
337 }
338
339 net::URLRequestContextGetter* url_request_context_getter() {
340 return url_request_context_getter_.get();
341 }
342
343 private:
344 std::unique_ptr<base::MessageLoopForIO> message_loop_;
345 std::unique_ptr<content::TestBrowserThread> io_thread_;
346
347 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
348 };
349
350 TEST_F(SafeBrowsingPingManagerCertReportingTest, UMAOnFailure) {
351 base::HistogramTester histograms;
352 histograms.ExpectTotalCount(kFailureHistogramName, 0);
353
354 SafeBrowsingProtocolConfig config;
355 config.client_name = kClient;
356 config.url_prefix = kUrlPrefix;
357 std::unique_ptr<SafeBrowsingPingManager> ping_manager(
358 new SafeBrowsingPingManager(url_request_context_getter(), config));
359 const GURL kReportURL =
360 net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_CONNECTION_FAILED);
361
362 ping_manager->certificate_error_reporter_->set_upload_url_for_testing(
363 kReportURL);
364 ping_manager->ReportInvalidCertificateChain("report");
365 base::RunLoop().RunUntilIdle();
366
367 histograms.ExpectTotalCount(kFailureHistogramName, 1);
368 histograms.ExpectBucketCount(kFailureHistogramName,
369 -net::ERR_CONNECTION_FAILED, 1);
370 }
371
313 } // namespace safe_browsing 372 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/ping_manager.cc ('k') | chrome/browser/ssl/certificate_reporting_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698