| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/signin/signin_global_error.h" | 5 #include "chrome/browser/signin/signin_global_error.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 9 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 11 #include "chrome/browser/signin/fake_signin_manager.h" | 11 #include "chrome/browser/signin/fake_signin_manager.h" |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 13 #include "chrome/browser/signin/signin_global_error_factory.h" | 13 #include "chrome/browser/signin/signin_global_error_factory.h" |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
| 15 #include "chrome/browser/ui/global_error/global_error_service.h" | 15 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 16 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 16 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "components/signin/core/browser/fake_auth_status_provider.h" | 19 #include "components/signin/core/browser/fake_auth_status_provider.h" |
| 20 #include "components/signin/core/browser/signin_error_controller.h" | 20 #include "components/signin/core/browser/signin_error_controller.h" |
| 21 #include "components/signin/core/browser/signin_manager.h" | 21 #include "components/signin/core/browser/signin_manager.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 static const char kTestAccountId[] = "testuser@test.com"; | 25 static const char kTestAccountId[] = "testuser@test.com"; |
| 26 static const char kTestUsername[] = "testuser@test.com"; |
| 26 | 27 |
| 27 class SigninGlobalErrorTest : public testing::Test { | 28 class SigninGlobalErrorTest : public testing::Test { |
| 28 public: | 29 public: |
| 29 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() OVERRIDE { |
| 30 // Create a signed-in profile. | 31 // Create a signed-in profile. |
| 31 TestingProfile::Builder builder; | 32 TestingProfile::Builder builder; |
| 32 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | 33 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 33 BuildFakeProfileOAuth2TokenService); | 34 BuildFakeProfileOAuth2TokenService); |
| 34 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 35 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
| 35 FakeSigninManagerBase::Build); | 36 FakeSigninManagerBase::Build); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 66 } | 67 } |
| 67 | 68 |
| 68 TEST_F(SigninGlobalErrorTest, ErrorAuthStatusProvider) { | 69 TEST_F(SigninGlobalErrorTest, ErrorAuthStatusProvider) { |
| 69 scoped_ptr<FakeAuthStatusProvider> provider; | 70 scoped_ptr<FakeAuthStatusProvider> provider; |
| 70 scoped_ptr<FakeAuthStatusProvider> error_provider; | 71 scoped_ptr<FakeAuthStatusProvider> error_provider; |
| 71 | 72 |
| 72 provider.reset(new FakeAuthStatusProvider(error_controller_)); | 73 provider.reset(new FakeAuthStatusProvider(error_controller_)); |
| 73 ASSERT_FALSE(global_error_->HasMenuItem()); | 74 ASSERT_FALSE(global_error_->HasMenuItem()); |
| 74 | 75 |
| 75 error_provider.reset(new FakeAuthStatusProvider(error_controller_)); | 76 error_provider.reset(new FakeAuthStatusProvider(error_controller_)); |
| 76 error_provider->SetAuthError(kTestAccountId, GoogleServiceAuthError( | 77 error_provider->SetAuthError( |
| 77 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | 78 kTestAccountId, |
| 79 kTestUsername, |
| 80 GoogleServiceAuthError( |
| 81 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
| 78 ASSERT_TRUE(global_error_->HasMenuItem()); | 82 ASSERT_TRUE(global_error_->HasMenuItem()); |
| 79 | 83 |
| 80 error_provider.reset(); | 84 error_provider.reset(); |
| 81 ASSERT_FALSE(global_error_->HasMenuItem()); | 85 ASSERT_FALSE(global_error_->HasMenuItem()); |
| 82 | 86 |
| 83 provider.reset(); | 87 provider.reset(); |
| 84 error_provider.reset(); | 88 error_provider.reset(); |
| 85 ASSERT_FALSE(global_error_->HasMenuItem()); | 89 ASSERT_FALSE(global_error_->HasMenuItem()); |
| 86 } | 90 } |
| 87 | 91 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 106 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, | 110 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, |
| 107 { GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, true }, | 111 { GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, true }, |
| 108 { GoogleServiceAuthError::SERVICE_ERROR, true }, | 112 { GoogleServiceAuthError::SERVICE_ERROR, true }, |
| 109 }; | 113 }; |
| 110 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(table) == GoogleServiceAuthError::NUM_STATES, | 114 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(table) == GoogleServiceAuthError::NUM_STATES, |
| 111 kTable_size_does_not_match_number_of_auth_error_types); | 115 kTable_size_does_not_match_number_of_auth_error_types); |
| 112 | 116 |
| 113 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(table); ++i) { | 117 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(table); ++i) { |
| 114 FakeAuthStatusProvider provider(error_controller_); | 118 FakeAuthStatusProvider provider(error_controller_); |
| 115 provider.SetAuthError(kTestAccountId, | 119 provider.SetAuthError(kTestAccountId, |
| 120 kTestUsername, |
| 116 GoogleServiceAuthError(table[i].error_state)); | 121 GoogleServiceAuthError(table[i].error_state)); |
| 117 | 122 |
| 118 EXPECT_EQ(global_error_->HasMenuItem(), table[i].is_error); | 123 EXPECT_EQ(global_error_->HasMenuItem(), table[i].is_error); |
| 119 EXPECT_EQ(global_error_->MenuItemLabel().empty(), !table[i].is_error); | 124 EXPECT_EQ(global_error_->MenuItemLabel().empty(), !table[i].is_error); |
| 120 EXPECT_EQ(global_error_->GetBubbleViewMessages().empty(), | 125 EXPECT_EQ(global_error_->GetBubbleViewMessages().empty(), |
| 121 !table[i].is_error); | 126 !table[i].is_error); |
| 122 EXPECT_FALSE(global_error_->GetBubbleViewTitle().empty()); | 127 EXPECT_FALSE(global_error_->GetBubbleViewTitle().empty()); |
| 123 EXPECT_FALSE(global_error_->GetBubbleViewAcceptButtonLabel().empty()); | 128 EXPECT_FALSE(global_error_->GetBubbleViewAcceptButtonLabel().empty()); |
| 124 EXPECT_TRUE(global_error_->GetBubbleViewCancelButtonLabel().empty()); | 129 EXPECT_TRUE(global_error_->GetBubbleViewCancelButtonLabel().empty()); |
| 125 } | 130 } |
| 126 } | 131 } |
| OLD | NEW |