| 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 18 matching lines...) Expand all Loading... |
| 29 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
| 30 #include "ui/gfx/screen_type_delegate.h" | 30 #include "ui/gfx/screen_type_delegate.h" |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 namespace ash { | 33 namespace ash { |
| 34 namespace test { | 34 namespace test { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 static const char kTestAccountId[] = "testuser@test.com"; | 38 static const char kTestAccountId[] = "testuser@test.com"; |
| 39 static const char kTestUsername[] = "testuser@test.com"; | |
| 40 | 39 |
| 41 // Notification ID corresponding to kProfileSigninNotificationId + | 40 // Notification ID corresponding to kProfileSigninNotificationId + |
| 42 // kTestAccountId. | 41 // kTestAccountId. |
| 43 static const std::string kNotificationId = | 42 static const std::string kNotificationId = |
| 44 "chrome://settings/signin/testuser@test.com"; | 43 "chrome://settings/signin/testuser@test.com"; |
| 45 } | 44 } |
| 46 | 45 |
| 47 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
| 48 class ScreenTypeDelegateDesktop : public gfx::ScreenTypeDelegate { | 47 class ScreenTypeDelegateDesktop : public gfx::ScreenTypeDelegate { |
| 49 public: | 48 public: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // Disabled on Win due to flake. http://crbug.com/372236 | 136 // Disabled on Win due to flake. http://crbug.com/372236 |
| 138 TEST_F(SigninErrorNotifierTest, ErrorAuthStatusProvider) { | 137 TEST_F(SigninErrorNotifierTest, ErrorAuthStatusProvider) { |
| 139 { | 138 { |
| 140 FakeAuthStatusProvider provider(error_controller_); | 139 FakeAuthStatusProvider provider(error_controller_); |
| 141 ASSERT_FALSE(notification_ui_manager_->FindById( | 140 ASSERT_FALSE(notification_ui_manager_->FindById( |
| 142 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); | 141 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); |
| 143 { | 142 { |
| 144 FakeAuthStatusProvider error_provider(error_controller_); | 143 FakeAuthStatusProvider error_provider(error_controller_); |
| 145 error_provider.SetAuthError( | 144 error_provider.SetAuthError( |
| 146 kTestAccountId, | 145 kTestAccountId, |
| 147 kTestUsername, | |
| 148 GoogleServiceAuthError( | 146 GoogleServiceAuthError( |
| 149 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | 147 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
| 150 ASSERT_TRUE(notification_ui_manager_->FindById( | 148 ASSERT_TRUE(notification_ui_manager_->FindById( |
| 151 kNotificationId, | 149 kNotificationId, |
| 152 NotificationUIManager::GetProfileID(profile_.get()))); | 150 NotificationUIManager::GetProfileID(profile_.get()))); |
| 153 } | 151 } |
| 154 // error_provider is removed now that we've left that scope. | 152 // error_provider is removed now that we've left that scope. |
| 155 ASSERT_FALSE(notification_ui_manager_->FindById( | 153 ASSERT_FALSE(notification_ui_manager_->FindById( |
| 156 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); | 154 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); |
| 157 } | 155 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 168 #else | 166 #else |
| 169 #define MAYBE_AuthStatusProviderErrorTransition \ | 167 #define MAYBE_AuthStatusProviderErrorTransition \ |
| 170 AuthStatusProviderErrorTransition | 168 AuthStatusProviderErrorTransition |
| 171 #endif | 169 #endif |
| 172 TEST_F(SigninErrorNotifierTest, MAYBE_AuthStatusProviderErrorTransition) { | 170 TEST_F(SigninErrorNotifierTest, MAYBE_AuthStatusProviderErrorTransition) { |
| 173 { | 171 { |
| 174 FakeAuthStatusProvider provider0(error_controller_); | 172 FakeAuthStatusProvider provider0(error_controller_); |
| 175 FakeAuthStatusProvider provider1(error_controller_); | 173 FakeAuthStatusProvider provider1(error_controller_); |
| 176 provider0.SetAuthError( | 174 provider0.SetAuthError( |
| 177 kTestAccountId, | 175 kTestAccountId, |
| 178 kTestUsername, | |
| 179 GoogleServiceAuthError( | 176 GoogleServiceAuthError( |
| 180 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | 177 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
| 181 ASSERT_TRUE(notification_ui_manager_->FindById( | 178 ASSERT_TRUE(notification_ui_manager_->FindById( |
| 182 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); | 179 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); |
| 183 | 180 |
| 184 base::string16 message; | 181 base::string16 message; |
| 185 GetMessage(&message); | 182 GetMessage(&message); |
| 186 ASSERT_FALSE(message.empty()); | 183 ASSERT_FALSE(message.empty()); |
| 187 | 184 |
| 188 // Now set another auth error and clear the original. | 185 // Now set another auth error and clear the original. |
| 189 provider1.SetAuthError( | 186 provider1.SetAuthError( |
| 190 kTestAccountId, | 187 kTestAccountId, |
| 191 kTestUsername, | |
| 192 GoogleServiceAuthError( | 188 GoogleServiceAuthError( |
| 193 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); | 189 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); |
| 194 provider0.SetAuthError( | 190 provider0.SetAuthError( |
| 195 kTestAccountId, | 191 kTestAccountId, |
| 196 kTestUsername, | |
| 197 GoogleServiceAuthError::AuthErrorNone()); | 192 GoogleServiceAuthError::AuthErrorNone()); |
| 198 | 193 |
| 199 ASSERT_TRUE(notification_ui_manager_->FindById( | 194 ASSERT_TRUE(notification_ui_manager_->FindById( |
| 200 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); | 195 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); |
| 201 | 196 |
| 202 base::string16 new_message; | 197 base::string16 new_message; |
| 203 GetMessage(&new_message); | 198 GetMessage(&new_message); |
| 204 ASSERT_FALSE(new_message.empty()); | 199 ASSERT_FALSE(new_message.empty()); |
| 205 | 200 |
| 206 ASSERT_NE(new_message, message); | 201 ASSERT_NE(new_message, message); |
| 207 | 202 |
| 208 provider1.SetAuthError( | 203 provider1.SetAuthError( |
| 209 kTestAccountId, kTestUsername, GoogleServiceAuthError::AuthErrorNone()); | 204 kTestAccountId, GoogleServiceAuthError::AuthErrorNone()); |
| 210 ASSERT_FALSE(notification_ui_manager_->FindById( | 205 ASSERT_FALSE(notification_ui_manager_->FindById( |
| 211 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); | 206 kNotificationId, NotificationUIManager::GetProfileID(profile_.get()))); |
| 212 } | 207 } |
| 213 } | 208 } |
| 214 | 209 |
| 215 #if !defined(OS_WIN) | 210 #if !defined(OS_WIN) |
| 216 // Disabled on Win due to flake. http://crbug.com/372236 | 211 // Disabled on Win due to flake. http://crbug.com/372236 |
| 217 // Verify that SigninErrorNotifier ignores certain errors. | 212 // Verify that SigninErrorNotifier ignores certain errors. |
| 218 TEST_F(SigninErrorNotifierTest, AuthStatusEnumerateAllErrors) { | 213 TEST_F(SigninErrorNotifierTest, AuthStatusEnumerateAllErrors) { |
| 219 typedef struct { | 214 typedef struct { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 236 { GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, true }, | 231 { GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, true }, |
| 237 { GoogleServiceAuthError::SERVICE_ERROR, true }, | 232 { GoogleServiceAuthError::SERVICE_ERROR, true }, |
| 238 { GoogleServiceAuthError::WEB_LOGIN_REQUIRED, true }, | 233 { GoogleServiceAuthError::WEB_LOGIN_REQUIRED, true }, |
| 239 }; | 234 }; |
| 240 static_assert(arraysize(table) == GoogleServiceAuthError::NUM_STATES, | 235 static_assert(arraysize(table) == GoogleServiceAuthError::NUM_STATES, |
| 241 "table size should match number of auth error types"); | 236 "table size should match number of auth error types"); |
| 242 | 237 |
| 243 for (size_t i = 0; i < arraysize(table); ++i) { | 238 for (size_t i = 0; i < arraysize(table); ++i) { |
| 244 FakeAuthStatusProvider provider(error_controller_); | 239 FakeAuthStatusProvider provider(error_controller_); |
| 245 provider.SetAuthError(kTestAccountId, | 240 provider.SetAuthError(kTestAccountId, |
| 246 kTestUsername, | |
| 247 GoogleServiceAuthError(table[i].error_state)); | 241 GoogleServiceAuthError(table[i].error_state)); |
| 248 const Notification* notification = notification_ui_manager_->FindById( | 242 const Notification* notification = notification_ui_manager_->FindById( |
| 249 kNotificationId, NotificationUIManager::GetProfileID(profile_.get())); | 243 kNotificationId, NotificationUIManager::GetProfileID(profile_.get())); |
| 250 ASSERT_EQ(table[i].is_error, notification != NULL); | 244 ASSERT_EQ(table[i].is_error, notification != NULL); |
| 251 if (table[i].is_error) { | 245 if (table[i].is_error) { |
| 252 EXPECT_FALSE(notification->title().empty()); | 246 EXPECT_FALSE(notification->title().empty()); |
| 253 EXPECT_FALSE(notification->message().empty()); | 247 EXPECT_FALSE(notification->message().empty()); |
| 254 EXPECT_EQ((size_t)1, notification->buttons().size()); | 248 EXPECT_EQ((size_t)1, notification->buttons().size()); |
| 255 } | 249 } |
| 256 } | 250 } |
| 257 } | 251 } |
| 258 #endif | 252 #endif |
| 259 | 253 |
| 260 } // namespace test | 254 } // namespace test |
| 261 } // namespace ash | 255 } // namespace ash |
| OLD | NEW |