#include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
#include <memory>
#include <string>
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/chromeos_buildflags.h"
#include "google_apis/gaia/gaia_access_token_fetcher.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
_;
namespace {
ScopeList;
constexpr char kValidTokenResponse[] = …;
constexpr char kTokenResponseNoAccessToken[] = …;
constexpr char kValidFailureTokenResponse[] = …;
constexpr char kRaptRequiredErrorResponse[] = …;
constexpr char kInvalidRaptErrorResponse[] = …;
class MockOAuth2AccessTokenConsumer : public OAuth2AccessTokenConsumer { … };
class URLLoaderFactoryInterceptor { … };
MATCHER_P(resourceRequestUrlEquals, url, "") { … }
}
class OAuth2AccessTokenFetcherImplTest : public testing::Test { … };
TEST_F(OAuth2AccessTokenFetcherImplTest, GetAccessTokenRequestFailure) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, GetAccessTokenResponseCodeFailure) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, ProxyFailure) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, Success) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, SuccessUnexpectedFormat) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, CancelOngoingRequest) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(OAuth2AccessTokenFetcherImplTest, GetAccessTokenRaptRequiredFailure) {
SetupGetAccessToken(net::OK, net::HTTP_BAD_REQUEST,
kRaptRequiredErrorResponse);
EXPECT_CALL(consumer_,
OnGetTokenFailure(
GoogleServiceAuthError::FromScopeLimitedUnrecoverableError(
"reauth related error")))
.Times(1);
fetcher_->Start("client_id", "client_secret", ScopeList());
base::RunLoop().RunUntilIdle();
}
#endif
TEST_F(OAuth2AccessTokenFetcherImplTest, MakeGetAccessTokenBodyNoScope) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, MakeGetAccessTokenBodyOneScope) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, MakeGetAccessTokenBodyMultipleScopes) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, ParseGetAccessTokenResponseNoBody) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, ParseGetAccessTokenResponseBadJson) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest,
ParseGetAccessTokenResponseNoAccessToken) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, ParseGetAccessTokenResponseSuccess) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest,
ParseGetAccessTokenFailureInvalidError) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest, ParseGetAccessTokenFailure) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest,
ParseGetAccessTokenFailureForMissingRaptError) { … }
TEST_F(OAuth2AccessTokenFetcherImplTest,
ParseGetAccessTokenFailureForInvalidRaptError) { … }
struct OAuth2ErrorCodesTestParam { … };
class OAuth2ErrorCodesTest
: public OAuth2AccessTokenFetcherImplTest,
public ::testing::WithParamInterface<OAuth2ErrorCodesTestParam> { … };
const OAuth2ErrorCodesTestParam kOAuth2ErrorCodesTable[] = …;
TEST_P(OAuth2ErrorCodesTest, TableRowTest) { … }
INSTANTIATE_TEST_SUITE_P(…);