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

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

Issue 2525743002: Make URLRequestContext a MemoryDumpProvider (Abandoned) (Closed)
Patch Set: rebased to 7f3d142161b15869f6bea58ac43c5f52ce5834ac Created 4 years 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 base::Closure url_request_destroyed_callback_; 294 base::Closure url_request_destroyed_callback_;
295 295
296 DISALLOW_COPY_AND_ASSIGN(TestExpectCTNetworkDelegate); 296 DISALLOW_COPY_AND_ASSIGN(TestExpectCTNetworkDelegate);
297 }; 297 };
298 298
299 // A test fixture that allows tests to send a report and wait until the 299 // A test fixture that allows tests to send a report and wait until the
300 // net::URLRequest that sent the report is destroyed. 300 // net::URLRequest that sent the report is destroyed.
301 class ChromeExpectCTReporterWaitTest : public ::testing::Test { 301 class ChromeExpectCTReporterWaitTest : public ::testing::Test {
302 public: 302 public:
303 ChromeExpectCTReporterWaitTest() 303 ChromeExpectCTReporterWaitTest()
304 : context_(true), 304 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
305 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 305
306 context_.set_network_delegate(&network_delegate_); 306 void SetUp() override {
307 context_.Init(); 307 context_.reset(new net::TestURLRequestContext(true));
308 context_->set_network_delegate(&network_delegate_);
309 context_->Init();
310 net::URLRequestFailedJob::AddUrlHandler();
308 } 311 }
309 312
310 void SetUp() override { net::URLRequestFailedJob::AddUrlHandler(); }
311
312 void TearDown() override { 313 void TearDown() override {
313 net::URLRequestFilter::GetInstance()->ClearHandlers(); 314 net::URLRequestFilter::GetInstance()->ClearHandlers();
314 } 315 }
315 316
316 net::TestURLRequestContext* context() { return &context_; } 317 net::TestURLRequestContext* context() { return context_.get(); }
317 318
318 protected: 319 protected:
319 void SendReport(ChromeExpectCTReporter* reporter, 320 void SendReport(ChromeExpectCTReporter* reporter,
320 const net::HostPortPair& host_port, 321 const net::HostPortPair& host_port,
321 const GURL& report_uri, 322 const GURL& report_uri,
322 const net::SSLInfo& ssl_info) { 323 const net::SSLInfo& ssl_info) {
323 base::RunLoop run_loop; 324 base::RunLoop run_loop;
324 network_delegate_.set_url_request_destroyed_callback( 325 network_delegate_.set_url_request_destroyed_callback(
325 run_loop.QuitClosure()); 326 run_loop.QuitClosure());
326 reporter->OnExpectCTFailed(host_port, report_uri, ssl_info); 327 reporter->OnExpectCTFailed(host_port, report_uri, ssl_info);
327 run_loop.Run(); 328 run_loop.Run();
328 } 329 }
329 330
330 private: 331 private:
331 TestExpectCTNetworkDelegate network_delegate_; 332 TestExpectCTNetworkDelegate network_delegate_;
332 net::TestURLRequestContext context_; 333 std::unique_ptr<net::TestURLRequestContext> context_;
333 content::TestBrowserThreadBundle thread_bundle_; 334 content::TestBrowserThreadBundle thread_bundle_;
334 335
335 DISALLOW_COPY_AND_ASSIGN(ChromeExpectCTReporterWaitTest); 336 DISALLOW_COPY_AND_ASSIGN(ChromeExpectCTReporterWaitTest);
336 }; 337 };
337 338
338 } // namespace 339 } // namespace
339 340
340 // Test that no report is sent when the feature is not enabled. 341 // Test that no report is sent when the feature is not enabled.
341 TEST(ChromeExpectCTReporterTest, FeatureDisabled) { 342 TEST(ChromeExpectCTReporterTest, FeatureDisabled) {
342 base::MessageLoop message_loop; 343 base::MessageLoop message_loop;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 EXPECT_EQ(report_uri, sender->latest_report_uri()); 492 EXPECT_EQ(report_uri, sender->latest_report_uri());
492 EXPECT_FALSE(sender->latest_serialized_report().empty()); 493 EXPECT_FALSE(sender->latest_serialized_report().empty());
493 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type()); 494 EXPECT_EQ("application/json; charset=utf-8", sender->latest_content_type());
494 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport( 495 ASSERT_NO_FATAL_FAILURE(CheckExpectCTReport(
495 sender->latest_serialized_report(), host_port, ssl_info)); 496 sender->latest_serialized_report(), host_port, ssl_info));
496 497
497 histograms.ExpectTotalCount(kFailureHistogramName, 0); 498 histograms.ExpectTotalCount(kFailureHistogramName, 0);
498 histograms.ExpectTotalCount(kSendHistogramName, 1); 499 histograms.ExpectTotalCount(kSendHistogramName, 1);
499 histograms.ExpectBucketCount(kSendHistogramName, true, 1); 500 histograms.ExpectBucketCount(kSendHistogramName, true, 1);
500 } 501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698