| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_error_notifier_ash.h" | 5 #include "chrome/browser/signin/signin_error_notifier_ash.h" |
| 6 | 6 |
| 7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "ui/gfx/screen.h" | 31 #include "ui/gfx/screen.h" |
| 32 #include "ui/gfx/screen_type_delegate.h" | 32 #include "ui/gfx/screen_type_delegate.h" |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 namespace ash { | 35 namespace ash { |
| 36 namespace test { | 36 namespace test { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 static const char kTestAccountId[] = "testuser@test.com"; | 40 static const char kTestAccountId[] = "testuser@test.com"; |
| 41 static const char kTestUsername[] = "testuser@test.com"; |
| 41 | 42 |
| 42 // Notification ID corresponding to kProfileSigninNotificationId + | 43 // Notification ID corresponding to kProfileSigninNotificationId + |
| 43 // kTestAccountId. | 44 // kTestAccountId. |
| 44 static const std::string kNotificationId = | 45 static const std::string kNotificationId = |
| 45 "chrome://settings/signin/testuser@test.com"; | 46 "chrome://settings/signin/testuser@test.com"; |
| 46 } | 47 } |
| 47 | 48 |
| 48 #if !defined(OS_CHROMEOS) | 49 #if !defined(OS_CHROMEOS) |
| 49 class ScreenTypeDelegateDesktop : public gfx::ScreenTypeDelegate { | 50 class ScreenTypeDelegateDesktop : public gfx::ScreenTypeDelegate { |
| 50 public: | 51 public: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 124 } |
| 124 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); | 125 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); |
| 125 } | 126 } |
| 126 | 127 |
| 127 TEST_F(SigninErrorNotifierTest, ErrorAuthStatusProvider) { | 128 TEST_F(SigninErrorNotifierTest, ErrorAuthStatusProvider) { |
| 128 { | 129 { |
| 129 FakeAuthStatusProvider provider(error_controller_); | 130 FakeAuthStatusProvider provider(error_controller_); |
| 130 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); | 131 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); |
| 131 { | 132 { |
| 132 FakeAuthStatusProvider error_provider(error_controller_); | 133 FakeAuthStatusProvider error_provider(error_controller_); |
| 133 error_provider.SetAuthError(kTestAccountId, GoogleServiceAuthError( | 134 error_provider.SetAuthError( |
| 134 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | 135 kTestAccountId, |
| 136 kTestUsername, |
| 137 GoogleServiceAuthError( |
| 138 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
| 135 ASSERT_TRUE(notification_ui_manager_->FindById(kNotificationId)); | 139 ASSERT_TRUE(notification_ui_manager_->FindById(kNotificationId)); |
| 136 } | 140 } |
| 137 // error_provider is removed now that we've left that scope. | 141 // error_provider is removed now that we've left that scope. |
| 138 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); | 142 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); |
| 139 } | 143 } |
| 140 // All providers should be removed now. | 144 // All providers should be removed now. |
| 141 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); | 145 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); |
| 142 } | 146 } |
| 143 | 147 |
| 144 TEST_F(SigninErrorNotifierTest, AuthStatusProviderErrorTransition) { | 148 TEST_F(SigninErrorNotifierTest, AuthStatusProviderErrorTransition) { |
| 145 { | 149 { |
| 146 FakeAuthStatusProvider provider0(error_controller_); | 150 FakeAuthStatusProvider provider0(error_controller_); |
| 147 FakeAuthStatusProvider provider1(error_controller_); | 151 FakeAuthStatusProvider provider1(error_controller_); |
| 148 provider0.SetAuthError( | 152 provider0.SetAuthError( |
| 149 kTestAccountId, | 153 kTestAccountId, |
| 154 kTestUsername, |
| 150 GoogleServiceAuthError( | 155 GoogleServiceAuthError( |
| 151 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | 156 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
| 152 ASSERT_TRUE(notification_ui_manager_->FindById(kNotificationId)); | 157 ASSERT_TRUE(notification_ui_manager_->FindById(kNotificationId)); |
| 153 | 158 |
| 154 base::string16 message; | 159 base::string16 message; |
| 155 GetMessage(&message); | 160 GetMessage(&message); |
| 156 ASSERT_FALSE(message.empty()); | 161 ASSERT_FALSE(message.empty()); |
| 157 | 162 |
| 158 // Now set another auth error and clear the original. | 163 // Now set another auth error and clear the original. |
| 159 provider1.SetAuthError( | 164 provider1.SetAuthError( |
| 160 kTestAccountId, | 165 kTestAccountId, |
| 166 kTestUsername, |
| 161 GoogleServiceAuthError( | 167 GoogleServiceAuthError( |
| 162 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); | 168 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); |
| 163 provider0.SetAuthError( | 169 provider0.SetAuthError( |
| 164 kTestAccountId, GoogleServiceAuthError::AuthErrorNone()); | 170 kTestAccountId, |
| 171 kTestUsername, |
| 172 GoogleServiceAuthError::AuthErrorNone()); |
| 165 | 173 |
| 166 ASSERT_TRUE(notification_ui_manager_->FindById(kNotificationId)); | 174 ASSERT_TRUE(notification_ui_manager_->FindById(kNotificationId)); |
| 167 | 175 |
| 168 base::string16 new_message; | 176 base::string16 new_message; |
| 169 GetMessage(&new_message); | 177 GetMessage(&new_message); |
| 170 ASSERT_FALSE(new_message.empty()); | 178 ASSERT_FALSE(new_message.empty()); |
| 171 | 179 |
| 172 ASSERT_NE(new_message, message); | 180 ASSERT_NE(new_message, message); |
| 173 | 181 |
| 174 provider1.SetAuthError( | 182 provider1.SetAuthError( |
| 175 kTestAccountId, GoogleServiceAuthError::AuthErrorNone()); | 183 kTestAccountId, kTestUsername, GoogleServiceAuthError::AuthErrorNone()); |
| 176 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); | 184 ASSERT_FALSE(notification_ui_manager_->FindById(kNotificationId)); |
| 177 } | 185 } |
| 178 } | 186 } |
| 179 | 187 |
| 180 // Verify that SigninErrorNotifier ignores certain errors. | 188 // Verify that SigninErrorNotifier ignores certain errors. |
| 181 TEST_F(SigninErrorNotifierTest, AuthStatusEnumerateAllErrors) { | 189 TEST_F(SigninErrorNotifierTest, AuthStatusEnumerateAllErrors) { |
| 182 typedef struct { | 190 typedef struct { |
| 183 GoogleServiceAuthError::State error_state; | 191 GoogleServiceAuthError::State error_state; |
| 184 bool is_error; | 192 bool is_error; |
| 185 } ErrorTableEntry; | 193 } ErrorTableEntry; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 198 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, | 206 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, |
| 199 { GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, true }, | 207 { GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, true }, |
| 200 { GoogleServiceAuthError::SERVICE_ERROR, true }, | 208 { GoogleServiceAuthError::SERVICE_ERROR, true }, |
| 201 }; | 209 }; |
| 202 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(table) == GoogleServiceAuthError::NUM_STATES, | 210 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(table) == GoogleServiceAuthError::NUM_STATES, |
| 203 kTable_size_does_not_match_number_of_auth_error_types); | 211 kTable_size_does_not_match_number_of_auth_error_types); |
| 204 | 212 |
| 205 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(table); ++i) { | 213 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(table); ++i) { |
| 206 FakeAuthStatusProvider provider(error_controller_); | 214 FakeAuthStatusProvider provider(error_controller_); |
| 207 provider.SetAuthError(kTestAccountId, | 215 provider.SetAuthError(kTestAccountId, |
| 216 kTestUsername, |
| 208 GoogleServiceAuthError(table[i].error_state)); | 217 GoogleServiceAuthError(table[i].error_state)); |
| 209 const Notification* notification = notification_ui_manager_-> | 218 const Notification* notification = notification_ui_manager_-> |
| 210 FindById(kNotificationId); | 219 FindById(kNotificationId); |
| 211 ASSERT_EQ(table[i].is_error, notification != NULL); | 220 ASSERT_EQ(table[i].is_error, notification != NULL); |
| 212 if (table[i].is_error) { | 221 if (table[i].is_error) { |
| 213 EXPECT_FALSE(notification->title().empty()); | 222 EXPECT_FALSE(notification->title().empty()); |
| 214 EXPECT_FALSE(notification->message().empty()); | 223 EXPECT_FALSE(notification->message().empty()); |
| 215 EXPECT_EQ((size_t)1, notification->buttons().size()); | 224 EXPECT_EQ((size_t)1, notification->buttons().size()); |
| 216 } | 225 } |
| 217 } | 226 } |
| 218 } | 227 } |
| 219 | 228 |
| 220 } // namespace test | 229 } // namespace test |
| 221 } // namespace ash | 230 } // namespace ash |
| OLD | NEW |