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

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

Issue 2484323002: Add a NetworkQualityEstimator to TestURLRequestContext. (Closed)
Patch Set: Fix 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
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"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 const GURL& report_uri, 315 const GURL& report_uri,
316 const net::SSLInfo& ssl_info) { 316 const net::SSLInfo& ssl_info) {
317 base::RunLoop run_loop; 317 base::RunLoop run_loop;
318 network_delegate_.set_url_request_destroyed_callback( 318 network_delegate_.set_url_request_destroyed_callback(
319 run_loop.QuitClosure()); 319 run_loop.QuitClosure());
320 reporter->OnExpectCTFailed(host_port, report_uri, ssl_info); 320 reporter->OnExpectCTFailed(host_port, report_uri, ssl_info);
321 run_loop.Run(); 321 run_loop.Run();
322 } 322 }
323 323
324 private: 324 private:
325 content::TestBrowserThreadBundle thread_bundle_;
325 TestExpectCTNetworkDelegate network_delegate_; 326 TestExpectCTNetworkDelegate network_delegate_;
326 net::TestURLRequestContext context_; 327 net::TestURLRequestContext context_;
327 content::TestBrowserThreadBundle thread_bundle_;
328 328
329 DISALLOW_COPY_AND_ASSIGN(ChromeExpectCTReporterWaitTest); 329 DISALLOW_COPY_AND_ASSIGN(ChromeExpectCTReporterWaitTest);
330 }; 330 };
331 331
332 } // namespace 332 } // namespace
333 333
334 // Test that no report is sent when the feature is not enabled. 334 // Test that no report is sent when the feature is not enabled.
335 TEST(ChromeExpectCTReporterTest, FeatureDisabled) { 335 TEST(ChromeExpectCTReporterTest, FeatureDisabled) {
336 base::HistogramTester histograms; 336 base::HistogramTester histograms;
337 histograms.ExpectTotalCount(kSendHistogramName, 0); 337 histograms.ExpectTotalCount(kSendHistogramName, 0);
338 338
339 TestCertificateReportSender* sender = new TestCertificateReportSender(); 339 TestCertificateReportSender* sender = new TestCertificateReportSender();
340 content::TestBrowserThreadBundle thread_bundle(
341 content::TestBrowserThreadBundle::IO_MAINLOOP);
mmenke 2016/11/14 20:16:38 These are because the NQE expects a MessageLoop on
340 net::TestURLRequestContext context; 342 net::TestURLRequestContext context;
341 ChromeExpectCTReporter reporter(&context); 343 ChromeExpectCTReporter reporter(&context);
342 reporter.report_sender_.reset(sender); 344 reporter.report_sender_.reset(sender);
343 EXPECT_TRUE(sender->latest_report_uri().is_empty()); 345 EXPECT_TRUE(sender->latest_report_uri().is_empty());
344 EXPECT_TRUE(sender->latest_serialized_report().empty()); 346 EXPECT_TRUE(sender->latest_serialized_report().empty());
345 347
346 net::SSLInfo ssl_info; 348 net::SSLInfo ssl_info;
347 ssl_info.cert = 349 ssl_info.cert =
348 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 350 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
349 ssl_info.unverified_cert = net::ImportCertFromFile( 351 ssl_info.unverified_cert = net::ImportCertFromFile(
(...skipping 11 matching lines...) Expand all
361 363
362 // Test that no report is sent if the report URI is empty. 364 // Test that no report is sent if the report URI is empty.
363 TEST(ChromeExpectCTReporterTest, EmptyReportURI) { 365 TEST(ChromeExpectCTReporterTest, EmptyReportURI) {
364 base::HistogramTester histograms; 366 base::HistogramTester histograms;
365 histograms.ExpectTotalCount(kSendHistogramName, 0); 367 histograms.ExpectTotalCount(kSendHistogramName, 0);
366 368
367 base::test::ScopedFeatureList scoped_feature_list; 369 base::test::ScopedFeatureList scoped_feature_list;
368 scoped_feature_list.InitAndEnableFeature(features::kExpectCTReporting); 370 scoped_feature_list.InitAndEnableFeature(features::kExpectCTReporting);
369 371
370 TestCertificateReportSender* sender = new TestCertificateReportSender(); 372 TestCertificateReportSender* sender = new TestCertificateReportSender();
373 content::TestBrowserThreadBundle thread_bundle(
374 content::TestBrowserThreadBundle::IO_MAINLOOP);
371 net::TestURLRequestContext context; 375 net::TestURLRequestContext context;
372 ChromeExpectCTReporter reporter(&context); 376 ChromeExpectCTReporter reporter(&context);
373 reporter.report_sender_.reset(sender); 377 reporter.report_sender_.reset(sender);
374 EXPECT_TRUE(sender->latest_report_uri().is_empty()); 378 EXPECT_TRUE(sender->latest_report_uri().is_empty());
375 EXPECT_TRUE(sender->latest_serialized_report().empty()); 379 EXPECT_TRUE(sender->latest_serialized_report().empty());
376 380
377 reporter.OnExpectCTFailed(net::HostPortPair("example.test", 443), GURL(), 381 reporter.OnExpectCTFailed(net::HostPortPair("example.test", 443), GURL(),
378 net::SSLInfo()); 382 net::SSLInfo());
379 EXPECT_TRUE(sender->latest_report_uri().is_empty()); 383 EXPECT_TRUE(sender->latest_report_uri().is_empty());
380 EXPECT_TRUE(sender->latest_serialized_report().empty()); 384 EXPECT_TRUE(sender->latest_serialized_report().empty());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // Test that a sent report has the right format. 419 // Test that a sent report has the right format.
416 TEST(ChromeExpectCTReporterTest, SendReport) { 420 TEST(ChromeExpectCTReporterTest, SendReport) {
417 base::HistogramTester histograms; 421 base::HistogramTester histograms;
418 histograms.ExpectTotalCount(kFailureHistogramName, 0); 422 histograms.ExpectTotalCount(kFailureHistogramName, 0);
419 histograms.ExpectTotalCount(kSendHistogramName, 0); 423 histograms.ExpectTotalCount(kSendHistogramName, 0);
420 424
421 base::test::ScopedFeatureList scoped_feature_list; 425 base::test::ScopedFeatureList scoped_feature_list;
422 scoped_feature_list.InitAndEnableFeature(features::kExpectCTReporting); 426 scoped_feature_list.InitAndEnableFeature(features::kExpectCTReporting);
423 427
424 TestCertificateReportSender* sender = new TestCertificateReportSender(); 428 TestCertificateReportSender* sender = new TestCertificateReportSender();
429 content::TestBrowserThreadBundle thread_bundle(
430 content::TestBrowserThreadBundle::IO_MAINLOOP);
425 net::TestURLRequestContext context; 431 net::TestURLRequestContext context;
426 ChromeExpectCTReporter reporter(&context); 432 ChromeExpectCTReporter reporter(&context);
427 reporter.report_sender_.reset(sender); 433 reporter.report_sender_.reset(sender);
428 EXPECT_TRUE(sender->latest_report_uri().is_empty()); 434 EXPECT_TRUE(sender->latest_report_uri().is_empty());
429 EXPECT_TRUE(sender->latest_serialized_report().empty()); 435 EXPECT_TRUE(sender->latest_serialized_report().empty());
430 436
431 net::SSLInfo ssl_info; 437 net::SSLInfo ssl_info;
432 ssl_info.cert = 438 ssl_info.cert =
433 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 439 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
434 ssl_info.unverified_cert = net::ImportCertFromFile( 440 ssl_info.unverified_cert = net::ImportCertFromFile(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 EXPECT_EQ(report_uri, sender->latest_report_uri()); 488 EXPECT_EQ(report_uri, sender->latest_report_uri());
483 EXPECT_FALSE(sender->latest_serialized_report().empty()); 489 EXPECT_FALSE(sender->latest_serialized_report().empty());
484 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type()); 490 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type());
485 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( 491 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport(
486 sender->latest_serialized_report(), host_port, ssl_info)); 492 sender->latest_serialized_report(), host_port, ssl_info));
487 493
488 histograms.ExpectTotalCount(kFailureHistogramName, 0); 494 histograms.ExpectTotalCount(kFailureHistogramName, 0);
489 histograms.ExpectTotalCount(kSendHistogramName, 1); 495 histograms.ExpectTotalCount(kSendHistogramName, 1);
490 histograms.ExpectBucketCount(kSendHistogramName, true, 1); 496 histograms.ExpectBucketCount(kSendHistogramName, true, 1);
491 } 497 }
OLDNEW
« no previous file with comments | « no previous file | net/http/http_transaction_test_util.h » ('j') | net/nqe/network_quality_estimator_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698