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 19 matching lines...) Expand all Loading... |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 class ProximityAuthCryptAuthApiCallFlowTest | 32 class ProximityAuthCryptAuthApiCallFlowTest |
33 : public testing::Test, | 33 : public testing::Test, |
34 public net::TestURLFetcherDelegateForTests { | 34 public net::TestURLFetcherDelegateForTests { |
35 protected: | 35 protected: |
36 ProximityAuthCryptAuthApiCallFlowTest() | 36 ProximityAuthCryptAuthApiCallFlowTest() |
37 : url_request_context_getter_(new net::TestURLRequestContextGetter( | 37 : url_request_context_getter_(new net::TestURLRequestContextGetter( |
38 new base::TestSimpleTaskRunner())) {} | 38 new base::TestSimpleTaskRunner())) {} |
39 | 39 |
40 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() override { |
41 // The TestURLFetcherFactory will override the global URLFetcherFactory for | 41 // The TestURLFetcherFactory will override the global URLFetcherFactory for |
42 // the entire test. | 42 // the entire test. |
43 url_fetcher_factory_.reset(new net::TestURLFetcherFactory()); | 43 url_fetcher_factory_.reset(new net::TestURLFetcherFactory()); |
44 url_fetcher_factory_->SetDelegateForTests(this); | 44 url_fetcher_factory_->SetDelegateForTests(this); |
45 | 45 |
46 flow_.reset(new CryptAuthApiCallFlow(url_request_context_getter_.get(), | 46 flow_.reset(new CryptAuthApiCallFlow(url_request_context_getter_.get(), |
47 "refresh_token", | 47 "refresh_token", |
48 "access_token", | 48 "access_token", |
49 GURL(kRequestUrl))); | 49 GURL(kRequestUrl))); |
50 } | 50 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 url_fetcher_ = NULL; | 91 url_fetcher_ = NULL; |
92 url_fetcher->set_status(net::URLRequestStatus(request_status, 0)); | 92 url_fetcher->set_status(net::URLRequestStatus(request_status, 0)); |
93 if (request_status == net::URLRequestStatus::SUCCESS) { | 93 if (request_status == net::URLRequestStatus::SUCCESS) { |
94 url_fetcher->set_response_code(response_code); | 94 url_fetcher->set_response_code(response_code); |
95 url_fetcher->SetResponseString(response_string); | 95 url_fetcher->SetResponseString(response_string); |
96 } | 96 } |
97 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); | 97 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); |
98 } | 98 } |
99 | 99 |
100 // net::TestURLFetcherDelegateForTests overrides. | 100 // net::TestURLFetcherDelegateForTests overrides. |
101 virtual void OnRequestStart(int fetcher_id) OVERRIDE { | 101 virtual void OnRequestStart(int fetcher_id) override { |
102 url_fetcher_ = url_fetcher_factory_->GetFetcherByID(fetcher_id); | 102 url_fetcher_ = url_fetcher_factory_->GetFetcherByID(fetcher_id); |
103 } | 103 } |
104 | 104 |
105 virtual void OnChunkUpload(int fetcher_id) OVERRIDE {} | 105 virtual void OnChunkUpload(int fetcher_id) override {} |
106 | 106 |
107 virtual void OnRequestEnd(int fetcher_id) OVERRIDE {} | 107 virtual void OnRequestEnd(int fetcher_id) override {} |
108 | 108 |
109 net::TestURLFetcher* url_fetcher_; | 109 net::TestURLFetcher* url_fetcher_; |
110 scoped_ptr<std::string> result_; | 110 scoped_ptr<std::string> result_; |
111 scoped_ptr<std::string> error_message_; | 111 scoped_ptr<std::string> error_message_; |
112 | 112 |
113 private: | 113 private: |
114 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 114 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
115 scoped_ptr<net::TestURLFetcherFactory> url_fetcher_factory_; | 115 scoped_ptr<net::TestURLFetcherFactory> url_fetcher_factory_; |
116 scoped_ptr<CryptAuthApiCallFlow> flow_; | 116 scoped_ptr<CryptAuthApiCallFlow> flow_; |
117 }; | 117 }; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 net::URLRequestStatus::SUCCESS, net::HTTP_UNAUTHORIZED, std::string()); | 191 net::URLRequestStatus::SUCCESS, net::HTTP_UNAUTHORIZED, std::string()); |
192 | 192 |
193 CompleteCurrentRequest( | 193 CompleteCurrentRequest( |
194 net::URLRequestStatus::SUCCESS, net::HTTP_UNAUTHORIZED, std::string()); | 194 net::URLRequestStatus::SUCCESS, net::HTTP_UNAUTHORIZED, std::string()); |
195 | 195 |
196 EXPECT_FALSE(result_); | 196 EXPECT_FALSE(result_); |
197 EXPECT_EQ("Could not mint access token", *error_message_); | 197 EXPECT_EQ("Could not mint access token", *error_message_); |
198 } | 198 } |
199 | 199 |
200 } // namespace proximity_auth | 200 } // namespace proximity_auth |
OLD | NEW |