Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: chrome/browser/chromeos/login/auth/online_attempt_unittest.cc

Issue 1086733002: Ensure tests have an active task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/test/null_task_runner.h" 11 #include "base/test/null_task_runner.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "chromeos/login/auth/auth_attempt_state.h" 13 #include "chromeos/login/auth/auth_attempt_state.h"
14 #include "chromeos/login/auth/mock_auth_attempt_state_resolver.h" 14 #include "chromeos/login/auth/mock_auth_attempt_state_resolver.h"
15 #include "chromeos/login/auth/mock_url_fetchers.h" 15 #include "chromeos/login/auth/mock_url_fetchers.h"
16 #include "chromeos/login/auth/online_attempt.h" 16 #include "chromeos/login/auth/online_attempt.h"
17 #include "chromeos/login/auth/test_attempt_state.h" 17 #include "chromeos/login/auth/test_attempt_state.h"
18 #include "chromeos/login/auth/user_context.h" 18 #include "chromeos/login/auth/user_context.h"
19 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "google_apis/gaia/gaia_auth_consumer.h" 20 #include "google_apis/gaia/gaia_auth_consumer.h"
20 #include "google_apis/gaia/mock_url_fetcher_factory.h" 21 #include "google_apis/gaia/mock_url_fetcher_factory.h"
21 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
22 #include "net/url_request/url_request_context_getter.h" 23 #include "net/url_request/url_request_context_getter.h"
23 #include "net/url_request/url_request_test_util.h" 24 #include "net/url_request/url_request_test_util.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "url/gurl.h" 27 #include "url/gurl.h"
27 28
28 using ::testing::AnyNumber; 29 using ::testing::AnyNumber;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 base::RunLoop().RunUntilIdle(); 78 base::RunLoop().RunUntilIdle();
78 EXPECT_TRUE(error == state_.online_outcome().error()); 79 EXPECT_TRUE(error == state_.online_outcome().error());
79 } 80 }
80 81
81 void CancelLogin(OnlineAttempt* auth) { 82 void CancelLogin(OnlineAttempt* auth) {
82 message_loop_->PostTask(FROM_HERE, 83 message_loop_->PostTask(FROM_HERE,
83 base::Bind(&OnlineAttempt::CancelClientLogin, 84 base::Bind(&OnlineAttempt::CancelClientLogin,
84 auth->weak_factory_.GetWeakPtr())); 85 auth->weak_factory_.GetWeakPtr()));
85 } 86 }
86 87
88 content::TestBrowserThreadBundle thread_bundle_;
87 scoped_refptr<base::MessageLoopProxy> message_loop_; 89 scoped_refptr<base::MessageLoopProxy> message_loop_;
88 scoped_refptr<net::URLRequestContextGetter> request_context_; 90 scoped_refptr<net::URLRequestContextGetter> request_context_;
89 base::MessageLoop loop_;
90 TestAttemptState state_; 91 TestAttemptState state_;
91 MockAuthAttemptStateResolver resolver_; 92 MockAuthAttemptStateResolver resolver_;
92 scoped_ptr<OnlineAttempt> attempt_; 93 scoped_ptr<OnlineAttempt> attempt_;
93 }; 94 };
94 95
95 TEST_F(OnlineAttemptTest, LoginSuccess) { 96 TEST_F(OnlineAttemptTest, LoginSuccess) {
96 EXPECT_CALL(resolver_, Resolve()).Times(1).RetiresOnSaturation(); 97 EXPECT_CALL(resolver_, Resolve()).Times(1).RetiresOnSaturation();
97 98
98 message_loop_->PostTask(FROM_HERE, 99 message_loop_->PostTask(FROM_HERE,
99 base::Bind(&OnlineAttempt::OnClientLoginSuccess, 100 base::Bind(&OnlineAttempt::OnClientLoginSuccess,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 attempt_->weak_factory_.GetWeakPtr(), 236 attempt_->weak_factory_.GetWeakPtr(),
236 error)); 237 error));
237 238
238 // Force UI thread to finish tasks so I can verify |state_|. 239 // Force UI thread to finish tasks so I can verify |state_|.
239 base::RunLoop().RunUntilIdle(); 240 base::RunLoop().RunUntilIdle();
240 EXPECT_TRUE(GoogleServiceAuthError::AuthErrorNone() == 241 EXPECT_TRUE(GoogleServiceAuthError::AuthErrorNone() ==
241 state_.online_outcome().error()); 242 state_.online_outcome().error());
242 } 243 }
243 244
244 } // namespace chromeos 245 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698