google_service_auth_error_unittest.cc 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (c) 2012 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. #include "google_apis/gaia/google_service_auth_error.h"
  5. #include <memory>
  6. #include <string>
  7. #include "net/base/net_errors.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. namespace {
  10. TEST(GoogleServiceAuthErrorTest, State) {
  11. for (GoogleServiceAuthError::State i = GoogleServiceAuthError::NONE;
  12. i < GoogleServiceAuthError::NUM_STATES;
  13. i = GoogleServiceAuthError::State(i + 1)) {
  14. if (!GoogleServiceAuthError::IsValid(i))
  15. continue;
  16. GoogleServiceAuthError error(i);
  17. EXPECT_EQ(i, error.state());
  18. EXPECT_TRUE(error.error_message().empty());
  19. if (i == GoogleServiceAuthError::CONNECTION_FAILED)
  20. EXPECT_EQ(net::ERR_FAILED, error.network_error());
  21. else
  22. EXPECT_EQ(net::OK, error.network_error());
  23. if (i == GoogleServiceAuthError::NONE) {
  24. EXPECT_FALSE(error.IsTransientError());
  25. EXPECT_FALSE(error.IsPersistentError());
  26. } else if ((i == GoogleServiceAuthError::CONNECTION_FAILED) ||
  27. (i == GoogleServiceAuthError::SERVICE_UNAVAILABLE) ||
  28. (i == GoogleServiceAuthError::REQUEST_CANCELED)) {
  29. EXPECT_TRUE(error.IsTransientError());
  30. EXPECT_FALSE(error.IsPersistentError());
  31. } else {
  32. EXPECT_FALSE(error.IsTransientError());
  33. EXPECT_TRUE(error.IsPersistentError());
  34. }
  35. if (i == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) {
  36. EXPECT_EQ(GoogleServiceAuthError::InvalidGaiaCredentialsReason::UNKNOWN,
  37. error.GetInvalidGaiaCredentialsReason());
  38. }
  39. }
  40. }
  41. TEST(GoogleServiceAuthErrorTest, FromConnectionError) {
  42. GoogleServiceAuthError error =
  43. GoogleServiceAuthError::FromConnectionError(net::ERR_TIMED_OUT);
  44. EXPECT_EQ(GoogleServiceAuthError::CONNECTION_FAILED, error.state());
  45. EXPECT_EQ(net::ERR_TIMED_OUT, error.network_error());
  46. }
  47. TEST(GoogleServiceAuthErrorTest, FromServiceError) {
  48. GoogleServiceAuthError error =
  49. GoogleServiceAuthError::FromServiceError("Foo");
  50. EXPECT_EQ(GoogleServiceAuthError::SERVICE_ERROR, error.state());
  51. EXPECT_EQ("Foo", error.error_message());
  52. }
  53. TEST(GoogleServiceAuthErrorTest, FromInvalidGaiaCredentialsReason) {
  54. GoogleServiceAuthError error =
  55. GoogleServiceAuthError::FromInvalidGaiaCredentialsReason(
  56. GoogleServiceAuthError::InvalidGaiaCredentialsReason::
  57. CREDENTIALS_REJECTED_BY_SERVER);
  58. EXPECT_EQ(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, error.state());
  59. EXPECT_EQ(GoogleServiceAuthError::InvalidGaiaCredentialsReason::
  60. CREDENTIALS_REJECTED_BY_SERVER,
  61. error.GetInvalidGaiaCredentialsReason());
  62. EXPECT_EQ("Invalid credentials (credentials rejected by server).",
  63. error.ToString());
  64. }
  65. TEST(GoogleServiceAuthErrorTest, AuthErrorNone) {
  66. EXPECT_EQ(GoogleServiceAuthError(GoogleServiceAuthError::NONE),
  67. GoogleServiceAuthError::AuthErrorNone());
  68. }
  69. } // namespace