Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/proximity_auth/cryptauth/cryptauth_account_token_fetcher.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
|
Ilya Sherman
2014/12/11 02:53:21
nit: If you keep the scoped_ptr, please #include t
Tim Song
2014/12/12 20:48:45
Done.
| |
| 8 #include "google_apis/gaia/fake_oauth2_token_service.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace proximity_auth { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const char kAccountId[] = "account_id"; | |
| 16 const char kAccessToken[] = "access_token"; | |
| 17 const char kInvalidResult[] = "invalid_result"; | |
| 18 | |
| 19 // Callback that saves the fetched access token to the first argument. | |
| 20 void SaveAccessToken(std::string* out_token, const std::string& in_token) { | |
|
Ilya Sherman
2014/12/11 02:53:21
nit: Please #include the header for std::string.
Tim Song
2014/12/12 20:48:45
Done.
| |
| 21 *out_token = in_token; | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 class ProximityAuthCryptAuthAccountTokenFetcherTest : public testing::Test { | |
| 27 protected: | |
| 28 ProximityAuthCryptAuthAccountTokenFetcherTest() {} | |
| 29 virtual ~ProximityAuthCryptAuthAccountTokenFetcherTest() {} | |
| 30 | |
| 31 void SetUp() override { | |
| 32 token_service_.AddAccount(kAccountId); | |
| 33 fetcher_.reset( | |
| 34 new CryptAuthAccountTokenFetcher(&token_service_, kAccountId)); | |
|
Ilya Sherman
2014/12/11 02:53:22
Can this be done in the constructor, rather than i
Tim Song
2014/12/12 20:48:44
Done. From a simulation perspective, the token ser
| |
| 35 } | |
| 36 | |
| 37 FakeOAuth2TokenService token_service_; | |
| 38 scoped_ptr<CryptAuthAccessTokenFetcher> fetcher_; | |
| 39 | |
| 40 DISALLOW_COPY_AND_ASSIGN(ProximityAuthCryptAuthAccountTokenFetcherTest); | |
| 41 }; | |
| 42 | |
| 43 TEST_F(ProximityAuthCryptAuthAccountTokenFetcherTest, FetchSuccess) { | |
| 44 std::string result; | |
| 45 fetcher_->FetchAccessToken(base::Bind(SaveAccessToken, &result)); | |
| 46 token_service_.IssueAllTokensForAccount(kAccountId, kAccessToken, | |
| 47 base::Time::Max()); | |
| 48 | |
| 49 EXPECT_EQ(kAccessToken, result); | |
| 50 } | |
| 51 | |
| 52 TEST_F(ProximityAuthCryptAuthAccountTokenFetcherTest, FetchFailure) { | |
| 53 std::string result(kInvalidResult); | |
| 54 fetcher_->FetchAccessToken(base::Bind(SaveAccessToken, &result)); | |
| 55 token_service_.IssueErrorForAllPendingRequestsForAccount( | |
| 56 kAccountId, | |
| 57 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR)); | |
| 58 | |
| 59 EXPECT_EQ(std::string(), result); | |
| 60 } | |
| 61 | |
| 62 TEST_F(ProximityAuthCryptAuthAccountTokenFetcherTest, FetcherReuse) { | |
| 63 std::string result; | |
| 64 fetcher_->FetchAccessToken(base::Bind(SaveAccessToken, &result)); | |
| 65 | |
| 66 { | |
| 67 std::string result(kInvalidResult); | |
|
Ilya Sherman
2014/12/11 02:53:21
I think there's actually a clang warning being add
Tim Song
2014/12/12 20:48:45
Done. However, I kind of like scoping the same var
| |
| 68 fetcher_->FetchAccessToken(base::Bind(SaveAccessToken, &result)); | |
| 69 EXPECT_EQ(std::string(), result); | |
| 70 } | |
| 71 | |
| 72 token_service_.IssueAllTokensForAccount(kAccountId, kAccessToken, | |
| 73 base::Time::Max()); | |
| 74 EXPECT_EQ(kAccessToken, result); | |
| 75 } | |
| 76 | |
| 77 } // namespace proximity_auth | |
| OLD | NEW |