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" |
11 | 11 |
12 namespace proximity_auth { | 12 namespace proximity_auth { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 const char kSerializedRequestProto[] = "serialized_request_proto"; | 16 const char kSerializedRequestProto[] = "serialized_request_proto"; |
17 const char kSerializedResponseProto[] = "result_proto"; | 17 const char kSerializedResponseProto[] = "result_proto"; |
18 const char kRequestUrl[] = "https://googleapis.com/cryptauth/test"; | 18 const char kRequestUrl[] = "https://googleapis.com/cryptauth/test"; |
19 | 19 |
20 } // namespace | 20 } // namespace |
21 | 21 |
22 class ProximityAuthCryptAuthApiCallFlowTest | 22 class ProximityAuthCryptAuthApiCallFlowTest |
23 : public testing::Test, | 23 : public testing::Test, |
24 public net::TestURLFetcherDelegateForTests { | 24 public net::TestURLFetcherDelegateForTests { |
25 protected: | 25 protected: |
26 ProximityAuthCryptAuthApiCallFlowTest() | 26 ProximityAuthCryptAuthApiCallFlowTest() |
27 : url_request_context_getter_(new net::TestURLRequestContextGetter( | 27 : url_request_context_getter_(new net::TestURLRequestContextGetter( |
28 new base::TestSimpleTaskRunner())), | 28 new base::TestSimpleTaskRunner())) {} |
29 flow_(GURL(kRequestUrl)) {} | |
30 | 29 |
31 void SetUp() override { | 30 void SetUp() override { |
32 // The TestURLFetcherFactory will override the global URLFetcherFactory for | 31 // The TestURLFetcherFactory will override the global URLFetcherFactory for |
33 // the entire test. | 32 // the entire test. |
34 url_fetcher_factory_.reset(new net::TestURLFetcherFactory()); | 33 url_fetcher_factory_.reset(new net::TestURLFetcherFactory()); |
35 url_fetcher_factory_->SetDelegateForTests(this); | 34 url_fetcher_factory_->SetDelegateForTests(this); |
36 } | 35 } |
37 | 36 |
38 void StartApiCallFlow() { | 37 void StartApiCallFlow() { |
39 flow_.Start(url_request_context_getter_.get(), | 38 flow_.Start(GURL(kRequestUrl), url_request_context_getter_.get(), |
40 "access_token", | 39 "access_token", kSerializedRequestProto, |
41 kSerializedRequestProto, | |
42 base::Bind(&ProximityAuthCryptAuthApiCallFlowTest::OnResult, | 40 base::Bind(&ProximityAuthCryptAuthApiCallFlowTest::OnResult, |
43 base::Unretained(this)), | 41 base::Unretained(this)), |
44 base::Bind(&ProximityAuthCryptAuthApiCallFlowTest::OnError, | 42 base::Bind(&ProximityAuthCryptAuthApiCallFlowTest::OnError, |
45 base::Unretained(this))); | 43 base::Unretained(this))); |
46 // URLFetcher object for the API request should be created. | 44 // URLFetcher object for the API request should be created. |
47 CheckCryptAuthHttpRequest(); | 45 CheckCryptAuthHttpRequest(); |
48 } | 46 } |
49 | 47 |
50 void OnResult(const std::string& result) { | 48 void OnResult(const std::string& result) { |
51 EXPECT_FALSE(result_); | 49 EXPECT_FALSE(result_); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // The empty string is a valid protocol buffer message serialization. | 131 // The empty string is a valid protocol buffer message serialization. |
134 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, ResponseWithNoBody) { | 132 TEST_F(ProximityAuthCryptAuthApiCallFlowTest, ResponseWithNoBody) { |
135 StartApiCallFlow(); | 133 StartApiCallFlow(); |
136 CompleteCurrentRequest( | 134 CompleteCurrentRequest( |
137 net::URLRequestStatus::SUCCESS, net::HTTP_OK, std::string()); | 135 net::URLRequestStatus::SUCCESS, net::HTTP_OK, std::string()); |
138 EXPECT_EQ(std::string(), *result_); | 136 EXPECT_EQ(std::string(), *result_); |
139 EXPECT_FALSE(error_message_); | 137 EXPECT_FALSE(error_message_); |
140 } | 138 } |
141 | 139 |
142 } // namespace proximity_auth | 140 } // namespace proximity_auth |
OLD | NEW |