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

Side by Side Diff: chrome/browser/ssl/chrome_expect_ct_reporter_unittest.cc

Issue 2130493002: Implement THROTTLED priority semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NetworkStreamThrottler
Patch Set: Fix use of message_loop_ in Android tests. 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
« no previous file with comments | « no previous file | components/cronet/url_request_context_config_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ssl/chrome_expect_ct_reporter.h" 5 #include "chrome/browser/ssl/chrome_expect_ct_reporter.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
14 #include "base/test/scoped_feature_list.h" 15 #include "base/test/scoped_feature_list.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/common/chrome_features.h" 17 #include "chrome/common/chrome_features.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "net/cert/signed_certificate_timestamp_and_status.h" 19 #include "net/cert/signed_certificate_timestamp_and_status.h"
19 #include "net/test/cert_test_util.h" 20 #include "net/test/cert_test_util.h"
20 #include "net/test/test_data_directory.h" 21 #include "net/test/test_data_directory.h"
21 #include "net/test/url_request/url_request_failed_job.h" 22 #include "net/test/url_request/url_request_failed_job.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 net::TestURLRequestContext context_; 332 net::TestURLRequestContext context_;
332 content::TestBrowserThreadBundle thread_bundle_; 333 content::TestBrowserThreadBundle thread_bundle_;
333 334
334 DISALLOW_COPY_AND_ASSIGN(ChromeExpectCTReporterWaitTest); 335 DISALLOW_COPY_AND_ASSIGN(ChromeExpectCTReporterWaitTest);
335 }; 336 };
336 337
337 } // namespace 338 } // namespace
338 339
339 // Test that no report is sent when the feature is not enabled. 340 // Test that no report is sent when the feature is not enabled.
340 TEST(ChromeExpectCTReporterTest, FeatureDisabled) { 341 TEST(ChromeExpectCTReporterTest, FeatureDisabled) {
342 base::MessageLoop message_loop;
341 base::HistogramTester histograms; 343 base::HistogramTester histograms;
342 histograms.ExpectTotalCount(kSendHistogramName, 0); 344 histograms.ExpectTotalCount(kSendHistogramName, 0);
343 345
344 TestCertificateReportSender* sender = new TestCertificateReportSender(); 346 TestCertificateReportSender* sender = new TestCertificateReportSender();
345 net::TestURLRequestContext context; 347 net::TestURLRequestContext context;
346 ChromeExpectCTReporter reporter(&context); 348 ChromeExpectCTReporter reporter(&context);
347 reporter.report_sender_.reset(sender); 349 reporter.report_sender_.reset(sender);
348 EXPECT_TRUE(sender->latest_report_uri().is_empty()); 350 EXPECT_TRUE(sender->latest_report_uri().is_empty());
349 EXPECT_TRUE(sender->latest_serialized_report().empty()); 351 EXPECT_TRUE(sender->latest_serialized_report().empty());
350 352
351 net::SSLInfo ssl_info; 353 net::SSLInfo ssl_info;
352 ssl_info.cert = 354 ssl_info.cert =
353 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 355 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
354 ssl_info.unverified_cert = net::ImportCertFromFile( 356 ssl_info.unverified_cert = net::ImportCertFromFile(
355 net::GetTestCertsDirectory(), "localhost_cert.pem"); 357 net::GetTestCertsDirectory(), "localhost_cert.pem");
356 358
357 net::HostPortPair host_port("example.test", 443); 359 net::HostPortPair host_port("example.test", 443);
358 GURL report_uri("http://example-report.test"); 360 GURL report_uri("http://example-report.test");
359 361
360 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info); 362 reporter.OnExpectCTFailed(host_port, report_uri, ssl_info);
361 EXPECT_TRUE(sender->latest_report_uri().is_empty()); 363 EXPECT_TRUE(sender->latest_report_uri().is_empty());
362 EXPECT_TRUE(sender->latest_serialized_report().empty()); 364 EXPECT_TRUE(sender->latest_serialized_report().empty());
363 365
364 histograms.ExpectTotalCount(kSendHistogramName, 0); 366 histograms.ExpectTotalCount(kSendHistogramName, 0);
365 } 367 }
366 368
367 // Test that no report is sent if the report URI is empty. 369 // Test that no report is sent if the report URI is empty.
368 TEST(ChromeExpectCTReporterTest, EmptyReportURI) { 370 TEST(ChromeExpectCTReporterTest, EmptyReportURI) {
371 base::MessageLoop message_loop;
369 base::HistogramTester histograms; 372 base::HistogramTester histograms;
370 histograms.ExpectTotalCount(kSendHistogramName, 0); 373 histograms.ExpectTotalCount(kSendHistogramName, 0);
371 374
372 base::test::ScopedFeatureList scoped_feature_list; 375 base::test::ScopedFeatureList scoped_feature_list;
373 scoped_feature_list.InitAndEnableFeature(features::kExpectCTReporting); 376 scoped_feature_list.InitAndEnableFeature(features::kExpectCTReporting);
374 377
375 TestCertificateReportSender* sender = new TestCertificateReportSender(); 378 TestCertificateReportSender* sender = new TestCertificateReportSender();
376 net::TestURLRequestContext context; 379 net::TestURLRequestContext context;
377 ChromeExpectCTReporter reporter(&context); 380 ChromeExpectCTReporter reporter(&context);
378 reporter.report_sender_.reset(sender); 381 reporter.report_sender_.reset(sender);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 415
413 histograms.ExpectTotalCount(kFailureHistogramName, 1); 416 histograms.ExpectTotalCount(kFailureHistogramName, 1);
414 histograms.ExpectBucketCount(kFailureHistogramName, 417 histograms.ExpectBucketCount(kFailureHistogramName,
415 -net::ERR_CONNECTION_FAILED, 1); 418 -net::ERR_CONNECTION_FAILED, 1);
416 histograms.ExpectTotalCount(kSendHistogramName, 1); 419 histograms.ExpectTotalCount(kSendHistogramName, 1);
417 histograms.ExpectBucketCount(kSendHistogramName, true, 1); 420 histograms.ExpectBucketCount(kSendHistogramName, true, 1);
418 } 421 }
419 422
420 // Test that a sent report has the right format. 423 // Test that a sent report has the right format.
421 TEST(ChromeExpectCTReporterTest, SendReport) { 424 TEST(ChromeExpectCTReporterTest, SendReport) {
425 base::MessageLoop message_loop;
422 base::HistogramTester histograms; 426 base::HistogramTester histograms;
423 histograms.ExpectTotalCount(kFailureHistogramName, 0); 427 histograms.ExpectTotalCount(kFailureHistogramName, 0);
424 histograms.ExpectTotalCount(kSendHistogramName, 0); 428 histograms.ExpectTotalCount(kSendHistogramName, 0);
425 429
426 base::test::ScopedFeatureList scoped_feature_list; 430 base::test::ScopedFeatureList scoped_feature_list;
427 scoped_feature_list.InitAndEnableFeature(features::kExpectCTReporting); 431 scoped_feature_list.InitAndEnableFeature(features::kExpectCTReporting);
428 432
429 TestCertificateReportSender* sender = new TestCertificateReportSender(); 433 TestCertificateReportSender* sender = new TestCertificateReportSender();
430 net::TestURLRequestContext context; 434 net::TestURLRequestContext context;
431 ChromeExpectCTReporter reporter(&context); 435 ChromeExpectCTReporter reporter(&context);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 EXPECT_EQ(report_uri, sender->latest_report_uri()); 491 EXPECT_EQ(report_uri, sender->latest_report_uri());
488 EXPECT_FALSE(sender->latest_serialized_report().empty()); 492 EXPECT_FALSE(sender->latest_serialized_report().empty());
489 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type()); 493 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type());
490 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( 494 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport(
491 sender->latest_serialized_report(), host_port, ssl_info)); 495 sender->latest_serialized_report(), host_port, ssl_info));
492 496
493 histograms.ExpectTotalCount(kFailureHistogramName, 0); 497 histograms.ExpectTotalCount(kFailureHistogramName, 0);
494 histograms.ExpectTotalCount(kSendHistogramName, 1); 498 histograms.ExpectTotalCount(kSendHistogramName, 1);
495 histograms.ExpectBucketCount(kSendHistogramName, true, 1); 499 histograms.ExpectBucketCount(kSendHistogramName, true, 1);
496 } 500 }
OLDNEW
« no previous file with comments | « no previous file | components/cronet/url_request_context_config_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698