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

Side by Side Diff: chrome/browser/signin/dice_response_handler_unittest.cc

Issue 2953673003: [signin] Add unit test for Gaia error in DiceResponseHandler (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/signin/dice_response_handler.h" 5 #include "chrome/browser/signin/dice_response_handler.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/test/test_mock_time_task_runner.h" 10 #include "base/test/test_mock_time_task_runner.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 dice_response_handler_.ProcessDiceHeader(dice_params); 105 dice_response_handler_.ProcessDiceHeader(dice_params);
106 // Check that a GaiaAuthFetcher has been created. 106 // Check that a GaiaAuthFetcher has been created.
107 ASSERT_THAT(signin_client_.consumer_, testing::NotNull()); 107 ASSERT_THAT(signin_client_.consumer_, testing::NotNull());
108 // Simulate GaiaAuthFetcher success. 108 // Simulate GaiaAuthFetcher success.
109 signin_client_.consumer_->OnClientOAuthSuccess( 109 signin_client_.consumer_->OnClientOAuthSuccess(
110 GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10)); 110 GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10));
111 // Check that the token has been inserted in the token service. 111 // Check that the token has been inserted in the token service.
112 EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(dice_params.gaia_id)); 112 EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(dice_params.gaia_id));
113 } 113 }
114 114
115 // Checks that a GaiaAuthFetcher failure is handled correctly.
116 TEST_F(DiceResponseHandlerTest, SigninFailure) {
117 DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN);
118 ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(dice_params.gaia_id));
119 dice_response_handler_.ProcessDiceHeader(dice_params);
120 // Check that a GaiaAuthFetcher has been created.
121 ASSERT_THAT(signin_client_.consumer_, testing::NotNull());
122 EXPECT_EQ(
123 1u, dice_response_handler_.GetPendingDiceTokenFetchersCountForTesting());
124 // Simulate GaiaAuthFetcher failure.
125 signin_client_.consumer_->OnClientOAuthFailure(
126 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
127 EXPECT_EQ(
128 0u, dice_response_handler_.GetPendingDiceTokenFetchersCountForTesting());
129 // Check that the token has not been inserted in the token service.
130 EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(dice_params.gaia_id));
131 }
132
115 // Checks that a second token for the same account is not requested when a 133 // Checks that a second token for the same account is not requested when a
116 // request is already in flight. 134 // request is already in flight.
117 TEST_F(DiceResponseHandlerTest, SigninRepeatedWithSameAccount) { 135 TEST_F(DiceResponseHandlerTest, SigninRepeatedWithSameAccount) {
118 DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN); 136 DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN);
119 ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(dice_params.gaia_id)); 137 ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(dice_params.gaia_id));
120 dice_response_handler_.ProcessDiceHeader(dice_params); 138 dice_response_handler_.ProcessDiceHeader(dice_params);
121 // Check that a GaiaAuthFetcher has been created. 139 // Check that a GaiaAuthFetcher has been created.
122 GaiaAuthConsumer* consumer = signin_client_.consumer_; 140 GaiaAuthConsumer* consumer = signin_client_.consumer_;
123 ASSERT_THAT(consumer, testing::NotNull()); 141 ASSERT_THAT(consumer, testing::NotNull());
124 // Start a second request for the same account. 142 // Start a second request for the same account.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 dice_response_handler_.ProcessDiceHeader(dice_params); 187 dice_response_handler_.ProcessDiceHeader(dice_params);
170 // Check that a GaiaAuthFetcher has been created. 188 // Check that a GaiaAuthFetcher has been created.
171 ASSERT_THAT(signin_client_.consumer_, testing::NotNull()); 189 ASSERT_THAT(signin_client_.consumer_, testing::NotNull());
172 EXPECT_EQ( 190 EXPECT_EQ(
173 1u, dice_response_handler_.GetPendingDiceTokenFetchersCountForTesting()); 191 1u, dice_response_handler_.GetPendingDiceTokenFetchersCountForTesting());
174 // Force a timeout. 192 // Force a timeout.
175 task_runner_->FastForwardBy( 193 task_runner_->FastForwardBy(
176 base::TimeDelta::FromSeconds(kDiceTokenFetchTimeoutSeconds + 1)); 194 base::TimeDelta::FromSeconds(kDiceTokenFetchTimeoutSeconds + 1));
177 EXPECT_EQ( 195 EXPECT_EQ(
178 0u, dice_response_handler_.GetPendingDiceTokenFetchersCountForTesting()); 196 0u, dice_response_handler_.GetPendingDiceTokenFetchersCountForTesting());
197 // Check that the token has not been inserted in the token service.
198 EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(dice_params.gaia_id));
179 } 199 }
180 200
181 // Tests that the DiceResponseHandler is created for a normal profile but not 201 // Tests that the DiceResponseHandler is created for a normal profile but not
182 // for an incognito profile. 202 // for an incognito profile.
183 TEST(DiceResponseHandlerFactoryTest, NotInIncognito) { 203 TEST(DiceResponseHandlerFactoryTest, NotInIncognito) {
184 content::TestBrowserThreadBundle thread_bundle; 204 content::TestBrowserThreadBundle thread_bundle;
185 TestingProfile profile; 205 TestingProfile profile;
186 EXPECT_THAT(DiceResponseHandler::GetForProfile(&profile), testing::NotNull()); 206 EXPECT_THAT(DiceResponseHandler::GetForProfile(&profile), testing::NotNull());
187 EXPECT_THAT( 207 EXPECT_THAT(
188 DiceResponseHandler::GetForProfile(profile.GetOffTheRecordProfile()), 208 DiceResponseHandler::GetForProfile(profile.GetOffTheRecordProfile()),
189 testing::IsNull()); 209 testing::IsNull());
190 } 210 }
191 211
192 } // namespace 212 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698