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

Side by Side Diff: net/cert_net/cert_net_fetcher_impl_unittest.cc

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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
« no previous file with comments | « net/cert/test_root_certs_unittest.cc ('k') | net/cert_net/nss_ocsp_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "net/cert_net/cert_net_fetcher_impl.h" 5 #include "net/cert_net/cert_net_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "net/cert/ct_policy_enforcer.h" 13 #include "net/cert/ct_policy_enforcer.h"
14 #include "net/cert/mock_cert_verifier.h" 14 #include "net/cert/mock_cert_verifier.h"
15 #include "net/cert/multi_log_ct_verifier.h" 15 #include "net/cert/multi_log_ct_verifier.h"
16 #include "net/dns/mock_host_resolver.h" 16 #include "net/dns/mock_host_resolver.h"
17 #include "net/http/http_server_properties_impl.h" 17 #include "net/http/http_server_properties_impl.h"
18 #include "net/test/embedded_test_server/embedded_test_server.h" 18 #include "net/test/embedded_test_server/embedded_test_server.h"
19 #include "net/test/gtest_util.h"
19 #include "net/url_request/url_request_job_factory_impl.h" 20 #include "net/url_request/url_request_job_factory_impl.h"
20 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
22 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 #include "testing/platform_test.h" 24 #include "testing/platform_test.h"
23 25
26 using net::test::IsOk;
27
24 // TODO(eroman): Test that cookies aren't sent. 28 // TODO(eroman): Test that cookies aren't sent.
25 29
26 using base::ASCIIToUTF16; 30 using base::ASCIIToUTF16;
27 31
28 namespace net { 32 namespace net {
29 33
30 namespace { 34 namespace {
31 35
32 const base::FilePath::CharType kDocRoot[] = 36 const base::FilePath::CharType kDocRoot[] =
33 FILE_PATH_LITERAL("net/data/cert_net_fetcher_impl_unittest"); 37 FILE_PATH_LITERAL("net/data/cert_net_fetcher_impl_unittest");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 private: 76 private:
73 URLRequestContextStorage storage_; 77 URLRequestContextStorage storage_;
74 }; 78 };
75 79
76 class FetchResult { 80 class FetchResult {
77 public: 81 public:
78 FetchResult(Error net_error, const std::vector<uint8_t>& response_body) 82 FetchResult(Error net_error, const std::vector<uint8_t>& response_body)
79 : net_error_(net_error), response_body_(response_body) {} 83 : net_error_(net_error), response_body_(response_body) {}
80 84
81 void VerifySuccess(const std::string& expected_body) { 85 void VerifySuccess(const std::string& expected_body) {
82 EXPECT_EQ(OK, net_error_); 86 EXPECT_THAT(net_error_, IsOk());
83 EXPECT_EQ(expected_body, 87 EXPECT_EQ(expected_body,
84 std::string(response_body_.begin(), response_body_.end())); 88 std::string(response_body_.begin(), response_body_.end()));
85 } 89 }
86 90
87 void VerifyFailure(Error expected_error) { 91 void VerifyFailure(Error expected_error) {
88 EXPECT_EQ(expected_error, net_error_); 92 EXPECT_EQ(expected_error, net_error_);
89 EXPECT_EQ(0u, response_body_.size()); 93 EXPECT_EQ(0u, response_body_.size());
90 } 94 }
91 95
92 private: 96 private:
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 EXPECT_EQ(1, network_delegate_.created_requests()); 763 EXPECT_EQ(1, network_delegate_.created_requests());
760 764
761 std::unique_ptr<FetchResult> result = callback1.WaitForResult(); 765 std::unique_ptr<FetchResult> result = callback1.WaitForResult();
762 result->VerifySuccess("-cert.crt-\n"); 766 result->VerifySuccess("-cert.crt-\n");
763 767
764 // request2 was cancelled. 768 // request2 was cancelled.
765 EXPECT_FALSE(callback2.HasResult()); 769 EXPECT_FALSE(callback2.HasResult());
766 } 770 }
767 771
768 } // namespace net 772 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/test_root_certs_unittest.cc ('k') | net/cert_net/nss_ocsp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698