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

Side by Side Diff: remoting/protocol/third_party_authenticator_unittest.cc

Issue 1064863004: Use base::ResetAndReturn() in remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback_helpers.h"
6 #include "net/base/net_errors.h" 7 #include "net/base/net_errors.h"
7 #include "remoting/base/rsa_key_pair.h" 8 #include "remoting/base/rsa_key_pair.h"
8 #include "remoting/protocol/authenticator_test_base.h" 9 #include "remoting/protocol/authenticator_test_base.h"
9 #include "remoting/protocol/channel_authenticator.h" 10 #include "remoting/protocol/channel_authenticator.h"
10 #include "remoting/protocol/connection_tester.h" 11 #include "remoting/protocol/connection_tester.h"
11 #include "remoting/protocol/fake_authenticator.h" 12 #include "remoting/protocol/fake_authenticator.h"
12 #include "remoting/protocol/third_party_authenticator_base.h" 13 #include "remoting/protocol/third_party_authenticator_base.h"
13 #include "remoting/protocol/third_party_client_authenticator.h" 14 #include "remoting/protocol/third_party_client_authenticator.h"
14 #include "remoting/protocol/third_party_host_authenticator.h" 15 #include "remoting/protocol/third_party_host_authenticator.h"
15 #include "remoting/protocol/token_validator.h" 16 #include "remoting/protocol/token_validator.h"
(...skipping 30 matching lines...) Expand all
46 const TokenFetchedCallback& token_fetched_callback) override { 47 const TokenFetchedCallback& token_fetched_callback) override {
47 ASSERT_EQ(token_url.spec(), kTokenUrl); 48 ASSERT_EQ(token_url.spec(), kTokenUrl);
48 ASSERT_EQ(scope, kTokenScope); 49 ASSERT_EQ(scope, kTokenScope);
49 ASSERT_FALSE(token_fetched_callback.is_null()); 50 ASSERT_FALSE(token_fetched_callback.is_null());
50 on_token_fetched_ = token_fetched_callback; 51 on_token_fetched_ = token_fetched_callback;
51 } 52 }
52 53
53 void OnTokenFetched(const std::string& token, 54 void OnTokenFetched(const std::string& token,
54 const std::string& shared_secret) { 55 const std::string& shared_secret) {
55 ASSERT_FALSE(on_token_fetched_.is_null()); 56 ASSERT_FALSE(on_token_fetched_.is_null());
56 TokenFetchedCallback on_token_fetched = on_token_fetched_; 57 base::ResetAndReturn(&on_token_fetched_).Run(token, shared_secret);
57 on_token_fetched_.Reset();
58 on_token_fetched.Run(token, shared_secret);
59 } 58 }
60 59
61 private: 60 private:
62 TokenFetchedCallback on_token_fetched_; 61 TokenFetchedCallback on_token_fetched_;
63 }; 62 };
64 63
65 class FakeTokenValidator : public TokenValidator { 64 class FakeTokenValidator : public TokenValidator {
66 public: 65 public:
67 FakeTokenValidator() 66 FakeTokenValidator()
68 : token_url_(kTokenUrl), 67 : token_url_(kTokenUrl),
69 token_scope_(kTokenScope) {} 68 token_scope_(kTokenScope) {}
70 69
71 ~FakeTokenValidator() override {} 70 ~FakeTokenValidator() override {}
72 71
73 void ValidateThirdPartyToken( 72 void ValidateThirdPartyToken(
74 const std::string& token, 73 const std::string& token,
75 const TokenValidatedCallback& token_validated_callback) override { 74 const TokenValidatedCallback& token_validated_callback) override {
76 ASSERT_FALSE(token_validated_callback.is_null()); 75 ASSERT_FALSE(token_validated_callback.is_null());
77 on_token_validated_ = token_validated_callback; 76 on_token_validated_ = token_validated_callback;
78 } 77 }
79 78
80 void OnTokenValidated(const std::string& shared_secret) { 79 void OnTokenValidated(const std::string& shared_secret) {
81 ASSERT_FALSE(on_token_validated_.is_null()); 80 ASSERT_FALSE(on_token_validated_.is_null());
82 TokenValidatedCallback on_token_validated = on_token_validated_; 81 base::ResetAndReturn(&on_token_validated_).Run(shared_secret);
83 on_token_validated_.Reset();
84 on_token_validated.Run(shared_secret);
85 } 82 }
86 83
87 const GURL& token_url() const override { return token_url_; } 84 const GURL& token_url() const override { return token_url_; }
88 85
89 const std::string& token_scope() const override { return token_scope_; } 86 const std::string& token_scope() const override { return token_scope_; }
90 87
91 private: 88 private:
92 GURL token_url_; 89 GURL token_url_;
93 std::string token_scope_; 90 std::string token_scope_;
94 base::Callback<void(const std::string& shared_secret)> on_token_validated_; 91 base::Callback<void(const std::string& shared_secret)> on_token_validated_;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ASSERT_EQ(Authenticator::PROCESSING_MESSAGE, host_->state()); 202 ASSERT_EQ(Authenticator::PROCESSING_MESSAGE, host_->state());
206 ASSERT_NO_FATAL_FAILURE( 203 ASSERT_NO_FATAL_FAILURE(
207 token_validator_->OnTokenValidated(kSharedSecret)); 204 token_validator_->OnTokenValidated(kSharedSecret));
208 205
209 // The end result is that the host rejected the fake authentication. 206 // The end result is that the host rejected the fake authentication.
210 ASSERT_EQ(Authenticator::REJECTED, client_->state()); 207 ASSERT_EQ(Authenticator::REJECTED, client_->state());
211 } 208 }
212 209
213 } // namespace protocol 210 } // namespace protocol
214 } // namespace remoting 211 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698