| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h" | 13 #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h" |
| 14 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 14 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 15 #include "net/base/net_errors.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" |
| 19 | 20 |
| 20 const char kAccountId[] = "user@gmail.com"; | 21 const char kAccountId[] = "user@gmail.com"; |
| 21 const char kDifferentAccountId[] = "some_other_user@gmail.com"; | 22 const char kDifferentAccountId[] = "some_other_user@gmail.com"; |
| 22 const int kFamilyInfoFetcherURLFetcherID = 0; | 23 const int kFamilyInfoFetcherURLFetcherID = 0; |
| 23 | 24 |
| 24 bool operator==(const FamilyInfoFetcher::FamilyProfile& family1, | 25 bool operator==(const FamilyInfoFetcher::FamilyProfile& family1, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 136 } |
| 136 | 137 |
| 137 net::TestURLFetcher* GetURLFetcher() { | 138 net::TestURLFetcher* GetURLFetcher() { |
| 138 net::TestURLFetcher* url_fetcher = | 139 net::TestURLFetcher* url_fetcher = |
| 139 url_fetcher_factory_.GetFetcherByID( | 140 url_fetcher_factory_.GetFetcherByID( |
| 140 kFamilyInfoFetcherURLFetcherID); | 141 kFamilyInfoFetcherURLFetcherID); |
| 141 EXPECT_TRUE(url_fetcher); | 142 EXPECT_TRUE(url_fetcher); |
| 142 return url_fetcher; | 143 return url_fetcher; |
| 143 } | 144 } |
| 144 | 145 |
| 145 void SendResponse(net::URLRequestStatus::Status status, | 146 void SendResponse(net::Error error, const std::string& response) { |
| 146 const std::string& response) { | |
| 147 net::TestURLFetcher* url_fetcher = GetURLFetcher(); | 147 net::TestURLFetcher* url_fetcher = GetURLFetcher(); |
| 148 url_fetcher->set_status(net::URLRequestStatus(status, 0)); | 148 url_fetcher->set_status(net::URLRequestStatus::FromError(error)); |
| 149 url_fetcher->set_response_code(net::HTTP_OK); | 149 url_fetcher->set_response_code(net::HTTP_OK); |
| 150 url_fetcher->SetResponseString(response); | 150 url_fetcher->SetResponseString(response); |
| 151 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); | 151 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void SendValidGetFamilyProfileResponse( | 154 void SendValidGetFamilyProfileResponse( |
| 155 const FamilyInfoFetcher::FamilyProfile& family) { | 155 const FamilyInfoFetcher::FamilyProfile& family) { |
| 156 SendResponse(net::URLRequestStatus::SUCCESS, | 156 SendResponse(net::OK, BuildGetFamilyProfileResponse(family)); |
| 157 BuildGetFamilyProfileResponse(family)); | |
| 158 } | 157 } |
| 159 | 158 |
| 160 void SendValidGetFamilyMembersResponse( | 159 void SendValidGetFamilyMembersResponse( |
| 161 const std::vector<FamilyInfoFetcher::FamilyMember>& members) { | 160 const std::vector<FamilyInfoFetcher::FamilyMember>& members) { |
| 162 SendResponse(net::URLRequestStatus::SUCCESS, | 161 SendResponse(net::OK, BuildGetFamilyMembersResponse(members)); |
| 163 BuildGetFamilyMembersResponse(members)); | |
| 164 } | 162 } |
| 165 | 163 |
| 166 void SendInvalidGetFamilyProfileResponse() { | 164 void SendInvalidGetFamilyProfileResponse() { |
| 167 SendResponse(net::URLRequestStatus::SUCCESS, | 165 SendResponse(net::OK, BuildEmptyGetFamilyProfileResponse()); |
| 168 BuildEmptyGetFamilyProfileResponse()); | |
| 169 } | 166 } |
| 170 | 167 |
| 171 void SendFailedResponse() { | 168 void SendFailedResponse() { |
| 172 SendResponse(net::URLRequestStatus::CANCELED, std::string()); | 169 SendResponse(net::ERR_ABORTED, std::string()); |
| 173 } | 170 } |
| 174 | 171 |
| 175 base::MessageLoop message_loop_; | 172 base::MessageLoop message_loop_; |
| 176 FakeProfileOAuth2TokenService token_service_; | 173 FakeProfileOAuth2TokenService token_service_; |
| 177 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 174 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
| 178 net::TestURLFetcherFactory url_fetcher_factory_; | 175 net::TestURLFetcherFactory url_fetcher_factory_; |
| 179 FamilyInfoFetcher fetcher_; | 176 FamilyInfoFetcher fetcher_; |
| 180 }; | 177 }; |
| 181 | 178 |
| 182 | 179 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 IssueRefreshToken(); | 309 IssueRefreshToken(); |
| 313 | 310 |
| 314 fetcher_.StartGetFamilyProfile(); | 311 fetcher_.StartGetFamilyProfile(); |
| 315 | 312 |
| 316 IssueAccessToken(); | 313 IssueAccessToken(); |
| 317 | 314 |
| 318 // Failed API call should result in a network error. | 315 // Failed API call should result in a network error. |
| 319 EXPECT_CALL(*this, OnFailure(FamilyInfoFetcher::NETWORK_ERROR)); | 316 EXPECT_CALL(*this, OnFailure(FamilyInfoFetcher::NETWORK_ERROR)); |
| 320 SendFailedResponse(); | 317 SendFailedResponse(); |
| 321 } | 318 } |
| OLD | NEW |