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

Side by Side Diff: blimp/client/core/session/identity_source_unittest.cc

Issue 2391263005: Propagate error messages to UI for blimp. (Closed)
Patch Set: Minor fixes. Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "blimp/client/core/session/identity_source.h" 5 #include "blimp/client/core/session/identity_source.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "blimp/client/test/test_blimp_client_context_delegate.h" 14 #include "blimp/client/test/test_blimp_client_context_delegate.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using ::testing::_;
18 using ::testing::Return;
19
17 namespace blimp { 20 namespace blimp {
18 namespace client { 21 namespace client {
19 namespace { 22 namespace {
20 23
21 class MockIdentitySource : public IdentitySource { 24 class MockIdentitySource : public IdentitySource {
22 public: 25 public:
23 explicit MockIdentitySource(BlimpClientContextDelegate* delegate, 26 explicit MockIdentitySource(BlimpClientContextDelegate* delegate,
24 const IdentitySource::TokenCallback& callback) 27 const IdentitySource::TokenCallback& callback)
25 : IdentitySource(delegate, callback), 28 : IdentitySource(delegate, callback),
26 success_(0), 29 success_(0),
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 217
215 // Trigger the second request without calling connect. 218 // Trigger the second request without calling connect.
216 base::Time time; 219 base::Time time;
217 token_service->IssueAllTokensForAccount(account, mock_access_token, time); 220 token_service->IssueAllTokensForAccount(account, mock_access_token, time);
218 DCHECK_EQ(auth.Succeeded(), 1); 221 DCHECK_EQ(auth.Succeeded(), 1);
219 DCHECK_EQ(auth.Token(), mock_access_token); 222 DCHECK_EQ(auth.Token(), mock_access_token);
220 DCHECK_EQ(auth.TokenCallbackCount(), 1); 223 DCHECK_EQ(auth.TokenCallbackCount(), 1);
221 DCHECK_EQ(auth.CallbackToken(), mock_access_token); 224 DCHECK_EQ(auth.CallbackToken(), mock_access_token);
222 } 225 }
223 226
227 TEST_F(IdentitySourceTest, TestConnectFailDelegateCallback) {
228 TestBlimpClientContextDelegate mock_blimp_delegate;
229 MockIdentitySource auth(
230 &mock_blimp_delegate,
231 base::Bind(&MockIdentitySource::MockTokenCall, base::Unretained(&auth)));
232 FakeOAuth2TokenService* token_service = mock_blimp_delegate.GetTokenService();
233 FakeIdentityProvider* id_provider =
234 static_cast<FakeIdentityProvider*>(auth.GetIdentityProvider());
235
236 std::string account = "mock_account";
237 std::string mock_access_token = "mock_token";
238 id_provider->LogIn(account);
239
240 // Prepare refresh token.
241 FakeOAuth2TokenServiceDelegate* mock_token_service_delegate =
242 token_service->GetFakeOAuth2TokenServiceDelegate();
243 mock_token_service_delegate->UpdateCredentials(account, "mock_refresh_token");
244
245 // Expect delegate to show error message on non REQUEST_CANCELED errors.
246 auth.Connect();
247 GoogleServiceAuthError error(
248 GoogleServiceAuthError::State::CONNECTION_FAILED);
249
250 EXPECT_CALL(mock_blimp_delegate, OnAuthenticationError(error))
251 .WillOnce(Return());
252 token_service->IssueErrorForAllPendingRequestsForAccount(account, error);
253
254 DCHECK_EQ(auth.Failed(), 1);
255 }
256
224 } // namespace 257 } // namespace
225 } // namespace client 258 } // namespace client
226 } // namespace blimp 259 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/core/session/identity_source.cc ('k') | blimp/client/public/blimp_client_context_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698