Chromium Code Reviews| Index: chromeos/login/auth/online_attempt_unittest.cc |
| diff --git a/chrome/browser/chromeos/login/auth/online_attempt_unittest.cc b/chromeos/login/auth/online_attempt_unittest.cc |
| similarity index 75% |
| rename from chrome/browser/chromeos/login/auth/online_attempt_unittest.cc |
| rename to chromeos/login/auth/online_attempt_unittest.cc |
| index bb5502eb459d30a639ff06ad77afe2a92c6999b7..05ac2bb4aedf77e37d8d59f5b3fc428bd44ce91c 100644 |
| --- a/chrome/browser/chromeos/login/auth/online_attempt_unittest.cc |
| +++ b/chromeos/login/auth/online_attempt_unittest.cc |
| @@ -7,14 +7,14 @@ |
| #include "base/bind.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/run_loop.h" |
| -#include "chrome/browser/chromeos/login/auth/mock_url_fetchers.h" |
| -#include "chrome/browser/chromeos/login/auth/online_attempt.h" |
| -#include "chrome/test/base/testing_profile.h" |
| #include "chromeos/login/auth/auth_attempt_state.h" |
| #include "chromeos/login/auth/mock_auth_attempt_state_resolver.h" |
| +#include "chromeos/login/auth/mock_url_fetchers.h" |
| +#include "chromeos/login/auth/online_attempt.h" |
| #include "chromeos/login/auth/test_attempt_state.h" |
| #include "chromeos/login/auth/user_context.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/test/test_browser_context.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
|
stevenjb
2014/07/22 16:35:37
Layering violation.
Denis Kuznetsov (DE-MUC)
2014/07/24 15:22:13
Done.
|
| #include "google_apis/gaia/gaia_auth_consumer.h" |
| #include "google_apis/gaia/mock_url_fetcher_factory.h" |
| @@ -27,6 +27,7 @@ using ::testing::Invoke; |
| using ::testing::Return; |
| using ::testing::_; |
| using content::BrowserThread; |
| +using content::TestBrowserContext; |
| namespace chromeos { |
| @@ -34,29 +35,26 @@ class OnlineAttemptTest : public testing::Test { |
| public: |
| OnlineAttemptTest() |
| : state_(UserContext(), false), |
| - attempt_(new OnlineAttempt(&state_, &resolver_)) { |
| - } |
| + attempt_(new OnlineAttempt(&state_, &resolver_)) {} |
| void RunFailureTest(const GoogleServiceAuthError& error) { |
| - EXPECT_CALL(resolver_, Resolve()) |
| - .Times(1) |
| - .RetiresOnSaturation(); |
| - |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind(&OnlineAttempt::OnClientLoginFailure, |
| - attempt_->weak_factory_.GetWeakPtr(), |
| - error)); |
| + EXPECT_CALL(resolver_, Resolve()).Times(1).RetiresOnSaturation(); |
| + |
| + BrowserThread::PostTask(BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&OnlineAttempt::OnClientLoginFailure, |
| + attempt_->weak_factory_.GetWeakPtr(), |
| + error)); |
| // Force UI thread to finish tasks so I can verify |state_|. |
| base::RunLoop().RunUntilIdle(); |
| EXPECT_TRUE(error == state_.online_outcome().error()); |
| } |
| void CancelLogin(OnlineAttempt* auth) { |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind(&OnlineAttempt::CancelClientLogin, |
| - auth->weak_factory_.GetWeakPtr())); |
| + BrowserThread::PostTask(BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&OnlineAttempt::CancelClientLogin, |
| + auth->weak_factory_.GetWeakPtr())); |
| } |
| content::TestBrowserThreadBundle thread_bundle_; |
| @@ -66,22 +64,20 @@ class OnlineAttemptTest : public testing::Test { |
| }; |
| TEST_F(OnlineAttemptTest, LoginSuccess) { |
| - EXPECT_CALL(resolver_, Resolve()) |
| - .Times(1) |
| - .RetiresOnSaturation(); |
| + EXPECT_CALL(resolver_, Resolve()).Times(1).RetiresOnSaturation(); |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind(&OnlineAttempt::OnClientLoginSuccess, |
| - attempt_->weak_factory_.GetWeakPtr(), |
| - GaiaAuthConsumer::ClientLoginResult())); |
| + BrowserThread::PostTask(BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&OnlineAttempt::OnClientLoginSuccess, |
| + attempt_->weak_factory_.GetWeakPtr(), |
| + GaiaAuthConsumer::ClientLoginResult())); |
| // Force UI thread to finish tasks so I can verify |state_|. |
| base::RunLoop().RunUntilIdle(); |
| } |
| TEST_F(OnlineAttemptTest, LoginCancelRetry) { |
| GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); |
| - TestingProfile profile; |
| + TestBrowserContext context; |
| base::RunLoop run_loop; |
| EXPECT_CALL(resolver_, Resolve()) |
| @@ -93,7 +89,7 @@ TEST_F(OnlineAttemptTest, LoginCancelRetry) { |
| // and then come back on the UI thread saying they've been canceled. |
| MockURLFetcherFactory<GotCanceledFetcher> factory; |
| - attempt_->Initiate(&profile); |
| + attempt_->Initiate(&context); |
| run_loop.Run(); |
| @@ -103,7 +99,7 @@ TEST_F(OnlineAttemptTest, LoginCancelRetry) { |
| TEST_F(OnlineAttemptTest, LoginTimeout) { |
| AuthFailure error(AuthFailure::LOGIN_TIMED_OUT); |
| - TestingProfile profile; |
| + TestBrowserContext context; |
| base::RunLoop run_loop; |
| EXPECT_CALL(resolver_, Resolve()) |
| @@ -115,7 +111,7 @@ TEST_F(OnlineAttemptTest, LoginTimeout) { |
| // and then come back on the UI thread saying they've been canceled. |
| MockURLFetcherFactory<ExpectCanceledFetcher> factory; |
| - attempt_->Initiate(&profile); |
| + attempt_->Initiate(&context); |
| // Post a task to cancel the login attempt. |
| CancelLogin(attempt_.get()); |
| @@ -128,7 +124,7 @@ TEST_F(OnlineAttemptTest, LoginTimeout) { |
| TEST_F(OnlineAttemptTest, HostedLoginRejected) { |
| AuthFailure error(AuthFailure::FromNetworkAuthFailure( |
| GoogleServiceAuthError(GoogleServiceAuthError::HOSTED_NOT_ALLOWED))); |
| - TestingProfile profile; |
| + TestBrowserContext context; |
| base::RunLoop run_loop; |
| EXPECT_CALL(resolver_, Resolve()) |
| @@ -140,7 +136,7 @@ TEST_F(OnlineAttemptTest, HostedLoginRejected) { |
| TestAttemptState local_state(UserContext(), true); |
| attempt_.reset(new OnlineAttempt(&local_state, &resolver_)); |
| - attempt_->Initiate(&profile); |
| + attempt_->Initiate(&context); |
| run_loop.Run(); |
| @@ -150,7 +146,7 @@ TEST_F(OnlineAttemptTest, HostedLoginRejected) { |
| } |
| TEST_F(OnlineAttemptTest, FullLogin) { |
| - TestingProfile profile; |
| + TestBrowserContext context; |
| base::RunLoop run_loop; |
| EXPECT_CALL(resolver_, Resolve()) |
| @@ -162,7 +158,7 @@ TEST_F(OnlineAttemptTest, FullLogin) { |
| TestAttemptState local_state(UserContext(), true); |
| attempt_.reset(new OnlineAttempt(&local_state, &resolver_)); |
| - attempt_->Initiate(&profile); |
| + attempt_->Initiate(&context); |
| run_loop.Run(); |
| @@ -204,15 +200,13 @@ TEST_F(OnlineAttemptTest, CaptchaErrorOutputted) { |
| } |
| TEST_F(OnlineAttemptTest, TwoFactorSuccess) { |
| - EXPECT_CALL(resolver_, Resolve()) |
| - .Times(1) |
| - .RetiresOnSaturation(); |
| + EXPECT_CALL(resolver_, Resolve()).Times(1).RetiresOnSaturation(); |
| GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind(&OnlineAttempt::OnClientLoginFailure, |
| - attempt_->weak_factory_.GetWeakPtr(), |
| - error)); |
| + BrowserThread::PostTask(BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&OnlineAttempt::OnClientLoginFailure, |
| + attempt_->weak_factory_.GetWeakPtr(), |
| + error)); |
| // Force UI thread to finish tasks so I can verify |state_|. |
| base::RunLoop().RunUntilIdle(); |