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_client_impl.h" | 5 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" |
9 #include "base/test/null_task_runner.h" | 10 #include "base/test/null_task_runner.h" |
10 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" | 11 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" |
11 #include "components/proximity_auth/cryptauth/cryptauth_api_call_flow.h" | 12 #include "components/proximity_auth/cryptauth/cryptauth_api_call_flow.h" |
12 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" | 13 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" |
13 #include "components/proximity_auth/cryptauth/switches.h" | 14 #include "components/proximity_auth/cryptauth/switches.h" |
14 #include "google_apis/gaia/fake_oauth2_token_service.h" | 15 #include "google_apis/gaia/fake_oauth2_token_service.h" |
15 #include "net/url_request/test_url_fetcher_factory.h" | 16 #include "net/url_request/test_url_fetcher_factory.h" |
16 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 105 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
105 switches::kCryptAuthHTTPHost, kTestGoogleApisUrl); | 106 switches::kCryptAuthHTTPHost, kTestGoogleApisUrl); |
106 | 107 |
107 cryptauth::DeviceClassifier device_classifier; | 108 cryptauth::DeviceClassifier device_classifier; |
108 device_classifier.set_device_os_version_code(kDeviceOsVersionCode); | 109 device_classifier.set_device_os_version_code(kDeviceOsVersionCode); |
109 device_classifier.set_device_software_version_code( | 110 device_classifier.set_device_software_version_code( |
110 kDeviceSoftwareVersionCode); | 111 kDeviceSoftwareVersionCode); |
111 device_classifier.set_device_software_package(kDeviceSoftwarePackage); | 112 device_classifier.set_device_software_package(kDeviceSoftwarePackage); |
112 device_classifier.set_device_type(kDeviceType); | 113 device_classifier.set_device_type(kDeviceType); |
113 | 114 |
114 client_.reset(new CryptAuthClientImpl( | 115 client_.reset( |
115 make_scoped_ptr(api_call_flow_), make_scoped_ptr(access_token_fetcher_), | 116 new CryptAuthClientImpl(base::WrapUnique(api_call_flow_), |
116 url_request_context_, device_classifier)); | 117 base::WrapUnique(access_token_fetcher_), |
| 118 url_request_context_, device_classifier)); |
117 } | 119 } |
118 | 120 |
119 // Sets up an expectation and captures a CryptAuth API request to | 121 // Sets up an expectation and captures a CryptAuth API request to |
120 // |request_url|. | 122 // |request_url|. |
121 void ExpectRequest(const std::string& request_url) { | 123 void ExpectRequest(const std::string& request_url) { |
122 GURL url(request_url); | 124 GURL url(request_url); |
123 EXPECT_CALL(*api_call_flow_, | 125 EXPECT_CALL(*api_call_flow_, |
124 Start(url, url_request_context_.get(), kAccessToken, _, _, _)) | 126 Start(url, url_request_context_.get(), kAccessToken, _, _, _)) |
125 .WillOnce(DoAll(SaveArg<3>(&serialized_request_), | 127 .WillOnce(DoAll(SaveArg<3>(&serialized_request_), |
126 SaveArg<4>(&flow_result_callback_), | 128 SaveArg<4>(&flow_result_callback_), |
(...skipping 12 matching lines...) Expand all Loading... |
139 flow_error_callback_.Run(error_message); | 141 flow_error_callback_.Run(error_message); |
140 } | 142 } |
141 | 143 |
142 protected: | 144 protected: |
143 // Owned by |client_|. | 145 // Owned by |client_|. |
144 FakeCryptAuthAccessTokenFetcher* access_token_fetcher_; | 146 FakeCryptAuthAccessTokenFetcher* access_token_fetcher_; |
145 // Owned by |client_|. | 147 // Owned by |client_|. |
146 StrictMock<MockCryptAuthApiCallFlow>* api_call_flow_; | 148 StrictMock<MockCryptAuthApiCallFlow>* api_call_flow_; |
147 | 149 |
148 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | 150 scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
149 scoped_ptr<CryptAuthClient> client_; | 151 std::unique_ptr<CryptAuthClient> client_; |
150 | 152 |
151 std::string serialized_request_; | 153 std::string serialized_request_; |
152 CryptAuthApiCallFlow::ResultCallback flow_result_callback_; | 154 CryptAuthApiCallFlow::ResultCallback flow_result_callback_; |
153 CryptAuthApiCallFlow::ErrorCallback flow_error_callback_; | 155 CryptAuthApiCallFlow::ErrorCallback flow_error_callback_; |
154 }; | 156 }; |
155 | 157 |
156 TEST_F(ProximityAuthCryptAuthClientTest, GetMyDevicesSuccess) { | 158 TEST_F(ProximityAuthCryptAuthClientTest, GetMyDevicesSuccess) { |
157 ExpectRequest( | 159 ExpectRequest( |
158 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 160 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
159 "getmydevices?alt=proto"); | 161 "getmydevices?alt=proto"); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 cryptauth::GetMyDevicesRequest request_proto; | 553 cryptauth::GetMyDevicesRequest request_proto; |
552 request_proto.set_allow_stale_read(true); | 554 request_proto.set_allow_stale_read(true); |
553 client_->GetMyDevices( | 555 client_->GetMyDevices( |
554 request_proto, | 556 request_proto, |
555 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), | 557 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), |
556 base::Bind(&NotCalled<std::string>)); | 558 base::Bind(&NotCalled<std::string>)); |
557 EXPECT_EQ(kAccessToken, client_->GetAccessTokenUsed()); | 559 EXPECT_EQ(kAccessToken, client_->GetAccessTokenUsed()); |
558 } | 560 } |
559 | 561 |
560 } // namespace proximity_auth | 562 } // namespace proximity_auth |
OLD | NEW |