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

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

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 10 #include "chrome/browser/chromeos/cros/cros_library.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 EXPECT_CALL(*(resolver_.get()), Resolve()) 51 EXPECT_CALL(*(resolver_.get()), Resolve())
52 .Times(1) 52 .Times(1)
53 .RetiresOnSaturation(); 53 .RetiresOnSaturation();
54 54
55 BrowserThread::PostTask( 55 BrowserThread::PostTask(
56 BrowserThread::UI, FROM_HERE, 56 BrowserThread::UI, FROM_HERE,
57 base::Bind(&OnlineAttempt::OnClientLoginFailure, 57 base::Bind(&OnlineAttempt::OnClientLoginFailure,
58 attempt_->weak_factory_.GetWeakPtr(), 58 attempt_->weak_factory_.GetWeakPtr(),
59 error)); 59 error));
60 // Force UI thread to finish tasks so I can verify |state_|. 60 // Force UI thread to finish tasks so I can verify |state_|.
61 message_loop_.RunAllPending(); 61 message_loop_.RunUntilIdle();
62 EXPECT_TRUE(error == state_.online_outcome().error()); 62 EXPECT_TRUE(error == state_.online_outcome().error());
63 } 63 }
64 64
65 void CancelLogin(OnlineAttempt* auth) { 65 void CancelLogin(OnlineAttempt* auth) {
66 BrowserThread::PostTask( 66 BrowserThread::PostTask(
67 BrowserThread::UI, FROM_HERE, 67 BrowserThread::UI, FROM_HERE,
68 base::Bind(&OnlineAttempt::CancelClientLogin, 68 base::Bind(&OnlineAttempt::CancelClientLogin,
69 auth->weak_factory_.GetWeakPtr())); 69 auth->weak_factory_.GetWeakPtr()));
70 } 70 }
71 71
72 static void Quit() { 72 static void Quit() {
73 BrowserThread::PostTask( 73 BrowserThread::PostTask(
74 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); 74 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure());
75 } 75 }
76 76
77 static void RunThreadTest() { 77 static void RunThreadTest() {
78 MessageLoop::current()->RunAllPending(); 78 MessageLoop::current()->RunUntilIdle();
79 } 79 }
80 80
81 MessageLoop message_loop_; 81 MessageLoop message_loop_;
82 content::TestBrowserThread ui_thread_; 82 content::TestBrowserThread ui_thread_;
83 TestAttemptState state_; 83 TestAttemptState state_;
84 scoped_ptr<MockAuthAttemptStateResolver> resolver_; 84 scoped_ptr<MockAuthAttemptStateResolver> resolver_;
85 scoped_ptr<OnlineAttempt> attempt_; 85 scoped_ptr<OnlineAttempt> attempt_;
86 86
87 // Initializes / shuts down a stub CrosLibrary. 87 // Initializes / shuts down a stub CrosLibrary.
88 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; 88 chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
89 }; 89 };
90 90
91 TEST_F(OnlineAttemptTest, LoginSuccess) { 91 TEST_F(OnlineAttemptTest, LoginSuccess) {
92 EXPECT_CALL(*(resolver_.get()), Resolve()) 92 EXPECT_CALL(*(resolver_.get()), Resolve())
93 .Times(1) 93 .Times(1)
94 .RetiresOnSaturation(); 94 .RetiresOnSaturation();
95 95
96 BrowserThread::PostTask( 96 BrowserThread::PostTask(
97 BrowserThread::UI, FROM_HERE, 97 BrowserThread::UI, FROM_HERE,
98 base::Bind(&OnlineAttempt::OnClientLoginSuccess, 98 base::Bind(&OnlineAttempt::OnClientLoginSuccess,
99 attempt_->weak_factory_.GetWeakPtr(), 99 attempt_->weak_factory_.GetWeakPtr(),
100 GaiaAuthConsumer::ClientLoginResult())); 100 GaiaAuthConsumer::ClientLoginResult()));
101 // Force UI thread to finish tasks so I can verify |state_|. 101 // Force UI thread to finish tasks so I can verify |state_|.
102 message_loop_.RunAllPending(); 102 message_loop_.RunUntilIdle();
103 } 103 }
104 104
105 TEST_F(OnlineAttemptTest, LoginCancelRetry) { 105 TEST_F(OnlineAttemptTest, LoginCancelRetry) {
106 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 106 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
107 TestingProfile profile; 107 TestingProfile profile;
108 108
109 EXPECT_CALL(*(resolver_.get()), Resolve()) 109 EXPECT_CALL(*(resolver_.get()), Resolve())
110 .WillOnce(Invoke(OnlineAttemptTest::Quit)) 110 .WillOnce(Invoke(OnlineAttemptTest::Quit))
111 .RetiresOnSaturation(); 111 .RetiresOnSaturation();
112 112
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 .Times(1) 242 .Times(1)
243 .RetiresOnSaturation(); 243 .RetiresOnSaturation();
244 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); 244 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
245 BrowserThread::PostTask( 245 BrowserThread::PostTask(
246 BrowserThread::UI, FROM_HERE, 246 BrowserThread::UI, FROM_HERE,
247 base::Bind(&OnlineAttempt::OnClientLoginFailure, 247 base::Bind(&OnlineAttempt::OnClientLoginFailure,
248 attempt_->weak_factory_.GetWeakPtr(), 248 attempt_->weak_factory_.GetWeakPtr(),
249 error)); 249 error));
250 250
251 // Force UI thread to finish tasks so I can verify |state_|. 251 // Force UI thread to finish tasks so I can verify |state_|.
252 message_loop_.RunAllPending(); 252 message_loop_.RunUntilIdle();
253 EXPECT_TRUE(GoogleServiceAuthError::None() == 253 EXPECT_TRUE(GoogleServiceAuthError::None() ==
254 state_.online_outcome().error()); 254 state_.online_outcome().error());
255 } 255 }
256 256
257 } // namespace chromeos 257 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698