1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file. 4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/signin_error_controller.h" 6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <functional> 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/fake_auth_status_provider.h" 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)static const char kTestAccountId[] = "testuser@test.com"; 14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)static const char kTestUsername[] = "testuser@test.com"; 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)static const char kOtherTestAccountId[] = "otheruser@test.com"; 16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)static const char kOtherTestUsername[] = "otheruser@test.com"; 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SigninErrorControllerTest : public testing::Test { 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void SetUp() OVERRIDE { 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_.reset(new SigninErrorController()); 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<SigninErrorController> error_controller_; 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}; 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(SigninErrorControllerTest, NoErrorAuthStatusProviders) { 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> provider; 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // No providers. 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Add a provider. 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider.reset(new FakeAuthStatusProvider(error_controller_.get())); 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Remove the provider. 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider.reset(); 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(SigninErrorControllerTest, ErrorAuthStatusProvider) { 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> provider; 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> error_provider; 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider.reset(new FakeAuthStatusProvider(error_controller_.get())); 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_provider.reset(new FakeAuthStatusProvider(error_controller_.get())); 50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) error_provider->SetAuthError( 51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestAccountId, 52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) GoogleServiceAuthError( 54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(error_controller_->HasError()); 56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_provider.reset(); 58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider.reset(); 61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // All providers should be removed now. 62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(SigninErrorControllerTest, AuthStatusProviderErrorTransition) { 66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> provider0( 67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) new FakeAuthStatusProvider(error_controller_.get())); 68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> provider1( 69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) new FakeAuthStatusProvider(error_controller_.get())); 70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0->SetAuthError( 73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kTestAccountId, 74cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError( 76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(error_controller_->HasError()); 78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1->SetAuthError( 79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kTestAccountId, 80cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED)); 82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(error_controller_->HasError()); 83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Now resolve the auth errors - the menu item should go away. 85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0->SetAuthError(kTestAccountId, 86cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::AuthErrorNone()); 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(error_controller_->HasError()); 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1->SetAuthError(kTestAccountId, 90cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 91cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) GoogleServiceAuthError::AuthErrorNone()); 92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0.reset(); 95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1.reset(); 96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(SigninErrorControllerTest, AuthStatusProviderAccountTransition) { 100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> provider0( 101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) new FakeAuthStatusProvider(error_controller_.get())); 102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> provider1( 103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) new FakeAuthStatusProvider(error_controller_.get())); 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0->SetAuthError( 108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kTestAccountId, 109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError( 111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1->SetAuthError( 113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kOtherTestAccountId, 114cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kOtherTestUsername, 115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError(GoogleServiceAuthError::NONE)); 116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(error_controller_->HasError()); 117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_STREQ(kTestAccountId, 118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->error_account_id().c_str()); 119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Swap providers reporting errors. 121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1->set_error_without_status_change( 122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError( 123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0->set_error_without_status_change( 125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError(GoogleServiceAuthError::NONE)); 126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->AuthStatusChanged(); 127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(error_controller_->HasError()); 128a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_STREQ(kOtherTestAccountId, 129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->error_account_id().c_str()); 130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Now resolve the auth errors - the menu item should go away. 132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0->set_error_without_status_change( 133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::AuthErrorNone()); 134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1->set_error_without_status_change( 135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::AuthErrorNone()); 136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->AuthStatusChanged(); 137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0.reset(); 140a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1.reset(); 141a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 142a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 143a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 144a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Verify that SigninErrorController handles errors properly. 145a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(SigninErrorControllerTest, AuthStatusEnumerateAllErrors) { 146a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) typedef struct { 147a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::State error_state; 148a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool is_error; 149a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } ErrorTableEntry; 150a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ErrorTableEntry table[] = { 152a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::NONE, false }, 153a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true }, 154a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true }, 155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::CONNECTION_FAILED, false }, 156a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::CAPTCHA_REQUIRED, true }, 157a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::ACCOUNT_DELETED, true }, 158a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::ACCOUNT_DISABLED, true }, 159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true }, 160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::TWO_FACTOR, true }, 161a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::REQUEST_CANCELED, true }, 162a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, 163a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, true }, 164a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { GoogleServiceAuthError::SERVICE_ERROR, true }, 165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) }; 166a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) COMPILE_ASSERT(ARRAYSIZE_UNSAFE(table) == GoogleServiceAuthError::NUM_STATES, 167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kTable_size_does_not_match_number_of_auth_error_types); 168a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 169a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) for (size_t i = 0; i < ARRAYSIZE_UNSAFE(table); ++i) { 170a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FakeAuthStatusProvider provider(error_controller_.get()); 171a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider.SetAuthError(kTestAccountId, 172cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 173a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError(table[i].error_state)); 174a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 175a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(error_controller_->HasError(), table[i].is_error); 176a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 177a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (table[i].is_error) { 178a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(table[i].error_state, 179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->auth_error().state()); 180a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_STREQ(kTestAccountId, 181a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->error_account_id().c_str()); 182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } else { 183a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(GoogleServiceAuthError::NONE, 184a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->auth_error().state()); 185a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_STREQ("", 186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->error_account_id().c_str()); 187a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 188a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 189a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 190a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 191a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Verify that existing error is not replaced by new error. 192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(SigninErrorControllerTest, AuthStatusChange) { 193a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> fake_provider0( 194a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) new FakeAuthStatusProvider(error_controller_.get())); 195a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<FakeAuthStatusProvider> fake_provider1( 196a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) new FakeAuthStatusProvider(error_controller_.get())); 197a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 198a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If there are multiple providers in the provider set... 199a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 200a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // | provider0 | provider1 | ... 201a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // | NONE | INVALID_GAIA_CREDENTIALS | ... 202a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // SigninErrorController picks the first error found when iterating through 204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // the set. But if another error crops up... 205a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 206a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // | provider0 | provider1 | ... 207a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // | SERVICE_UNAVAILABLE | INVALID_GAIA_CREDENTIALS | ... 208a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 209a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // we want the controller to still use the original error. 210a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 211a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The provider pointers are stored in a set, which is sorted by std::less. 212a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::less<SigninErrorController::AuthStatusProvider*> compare; 213a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FakeAuthStatusProvider* provider0 = 214a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) compare(fake_provider0.get(), fake_provider1.get()) ? 215a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) fake_provider0.get() : fake_provider1.get(); 216a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FakeAuthStatusProvider* provider1 = 217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0 == fake_provider0.get() ? 218a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) fake_provider1.get() : fake_provider0.get(); 219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0->SetAuthError( 221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kTestAccountId, 222cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 223a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError( 224a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::NONE)); 225a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1->SetAuthError( 226a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kOtherTestAccountId, 227cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kOtherTestUsername, 228a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError( 229a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 230a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_EQ(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, 231a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->auth_error().state()); 232a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_STREQ(kOtherTestAccountId, 233a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->error_account_id().c_str()); 234a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 235a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Change the 1st provider's error. 236a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1->SetAuthError( 237a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kOtherTestAccountId, 238cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kOtherTestUsername, 239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError( 240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::SERVICE_UNAVAILABLE)); 241a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_EQ(GoogleServiceAuthError::SERVICE_UNAVAILABLE, 242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->auth_error().state()); 243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_STREQ(kOtherTestAccountId, 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->error_account_id().c_str()); 245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Set the 0th provider's error -- nothing should change. 247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider0->SetAuthError( 248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kTestAccountId, 249cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kTestUsername, 250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError( 251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); 252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_EQ(GoogleServiceAuthError::SERVICE_UNAVAILABLE, 253a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->auth_error().state()); 254a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_STREQ(kOtherTestAccountId, 255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->error_account_id().c_str()); 256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 257a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Clear the 1st provider's error, so the 0th provider's error is used. 258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) provider1->SetAuthError( 259a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kOtherTestAccountId, 260cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) kOtherTestUsername, 261a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError( 262a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GoogleServiceAuthError::NONE)); 263a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_EQ(GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, 264a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->auth_error().state()); 265a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_STREQ(kTestAccountId, 266a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) error_controller_->error_account_id().c_str()); 267a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 268a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) fake_provider0.reset(); 269a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) fake_provider1.reset(); 270a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_FALSE(error_controller_->HasError()); 271a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 272