Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / proximity_auth / cryptauth / cryptauth_access_token_fetcher_impl_unittest.cc
blob3fa70a5e3bf3a44b7fb16d4ae5c27b4d57f49c39
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.
5 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher_impl.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "google_apis/gaia/fake_oauth2_token_service.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace proximity_auth {
15 namespace {
17 const char kAccountId[] = "account_id";
18 const char kAccessToken[] = "access_token";
19 const char kInvalidResult[] = "invalid_result";
21 // Callback that saves the fetched access token to the first argument.
22 void SaveAccessToken(std::string* out_token, const std::string& in_token) {
23 *out_token = in_token;
26 } // namespace
28 class ProximityAuthCryptAuthAccessTokenFetcherTest : public testing::Test {
29 protected:
30 ProximityAuthCryptAuthAccessTokenFetcherTest()
31 : fetcher_(&token_service_, kAccountId) {
32 token_service_.AddAccount(kAccountId);
35 FakeOAuth2TokenService token_service_;
36 CryptAuthAccessTokenFetcherImpl fetcher_;
38 DISALLOW_COPY_AND_ASSIGN(ProximityAuthCryptAuthAccessTokenFetcherTest);
41 TEST_F(ProximityAuthCryptAuthAccessTokenFetcherTest, FetchSuccess) {
42 std::string result;
43 fetcher_.FetchAccessToken(base::Bind(SaveAccessToken, &result));
44 token_service_.IssueAllTokensForAccount(kAccountId, kAccessToken,
45 base::Time::Max());
47 EXPECT_EQ(kAccessToken, result);
50 TEST_F(ProximityAuthCryptAuthAccessTokenFetcherTest, FetchFailure) {
51 std::string result(kInvalidResult);
52 fetcher_.FetchAccessToken(base::Bind(SaveAccessToken, &result));
53 token_service_.IssueErrorForAllPendingRequestsForAccount(
54 kAccountId,
55 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR));
57 EXPECT_EQ(std::string(), result);
60 TEST_F(ProximityAuthCryptAuthAccessTokenFetcherTest, FetcherReuse) {
61 std::string result1;
62 fetcher_.FetchAccessToken(base::Bind(SaveAccessToken, &result1));
65 std::string result2(kInvalidResult);
66 fetcher_.FetchAccessToken(base::Bind(SaveAccessToken, &result2));
67 EXPECT_EQ(std::string(), result2);
70 token_service_.IssueAllTokensForAccount(kAccountId, kAccessToken,
71 base::Time::Max());
72 EXPECT_EQ(kAccessToken, result1);
75 } // namespace proximity_auth