OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/proximity_auth/cryptauth/cryptauth_api_call_flow.h" | 5 #include "components/proximity_auth/cryptauth/cryptauth_api_call_flow.h" |
6 | 6 |
7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
8 #include "net/url_request/test_url_fetcher_factory.h" | 8 #include "net/url_request/test_url_fetcher_factory.h" |
9 #include "net/url_request/url_request_test_util.h" | 9 #include "net/url_request/url_request_test_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 void OnRequestEnd(int fetcher_id) override {} | 95 void OnRequestEnd(int fetcher_id) override {} |
96 | 96 |
97 net::TestURLFetcher* url_fetcher_; | 97 net::TestURLFetcher* url_fetcher_; |
98 scoped_ptr<std::string> result_; | 98 scoped_ptr<std::string> result_; |
99 scoped_ptr<std::string> error_message_; | 99 scoped_ptr<std::string> error_message_; |
100 | 100 |
101 private: | 101 private: |
102 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 102 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
103 scoped_ptr<net::TestURLFetcherFactory> url_fetcher_factory_; | 103 scoped_ptr<net::TestURLFetcherFactory> url_fetcher_factory_; |
104 CryptAuthApiCallFlow flow_; | 104 CryptAuthApiCallFlow flow_; |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(ProximityAuthCryptAuthApiCallFlowTest); | |
105 }; | 107 }; |
106 | 108 |
107 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, RequestSuccess) { | 109 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, RequestSuccess) { |
108 StartApiCallFlow(); | 110 StartApiCallFlow(); |
109 CompleteCurrentRequest( | 111 CompleteCurrentRequest( |
110 net::URLRequestStatus::SUCCESS, net::HTTP_OK, kSerializedResponseProto); | 112 net::URLRequestStatus::SUCCESS, net::HTTP_OK, kSerializedResponseProto); |
111 EXPECT_EQ(kSerializedResponseProto, *result_); | 113 EXPECT_EQ(kSerializedResponseProto, *result_); |
112 EXPECT_FALSE(error_message_); | 114 EXPECT_FALSE(error_message_); |
113 } | 115 } |
114 | 116 |
115 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, RequestFailure) { | 117 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, RequestFailure) { |
116 StartApiCallFlow(); | 118 StartApiCallFlow(); |
117 CompleteCurrentRequest(net::URLRequestStatus::FAILED, 0, std::string()); | 119 CompleteCurrentRequest(net::URLRequestStatus::FAILED, 0, std::string()); |
118 EXPECT_FALSE(result_); | 120 EXPECT_FALSE(result_); |
119 EXPECT_EQ("Request failed", *error_message_); | 121 EXPECT_EQ("Request failed", *error_message_); |
120 } | 122 } |
121 | 123 |
122 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, RequestStatus500) { | 124 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, RequestStatus500) { |
123 StartApiCallFlow(); | 125 StartApiCallFlow(); |
124 CompleteCurrentRequest(net::URLRequestStatus::SUCCESS, | 126 CompleteCurrentRequest(net::URLRequestStatus::SUCCESS, |
125 net::HTTP_INTERNAL_SERVER_ERROR, | 127 net::HTTP_INTERNAL_SERVER_ERROR, |
126 "CryptAuth Meltdown."); | 128 "CryptAuth Meltdown."); |
127 EXPECT_FALSE(result_); | 129 EXPECT_FALSE(result_); |
128 EXPECT_EQ("HTTP status: 500", *error_message_); | 130 EXPECT_EQ("HTTP status: 500", *error_message_); |
129 } | 131 } |
130 | 132 |
133 // The empty string is a valid protocol buffer message serialization. | |
131 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, ResponseWithNoBody) { | 134 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, ResponseWithNoBody) { |
132 StartApiCallFlow(); | 135 StartApiCallFlow(); |
133 CompleteCurrentRequest( | 136 CompleteCurrentRequest( |
134 net::URLRequestStatus::SUCCESS, net::HTTP_OK, std::string()); | 137 net::URLRequestStatus::SUCCESS, net::HTTP_OK, std::string()); |
135 EXPECT_FALSE(result_); | 138 EXPECT_EQ(std::string(), *result_); |
136 EXPECT_EQ("No response body", *error_message_); | 139 EXPECT_FALSE(error_message_); |
137 } | 140 } |
Ilya Sherman
2014/12/10 23:38:29
Please add a new test to provide coverage for the
Tim Song
2014/12/11 00:12:55
Hmm... I'm note sure how to force this error, as t
| |
138 | 141 |
139 } // namespace proximity_auth | 142 } // namespace proximity_auth |
OLD | NEW |