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

Unified Diff: chrome/browser/signin/dice_response_handler_unittest.cc

Issue 2950073002: [Signin] Handle multiple concurrent Dice responses (Closed)
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/signin/dice_response_handler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/signin/dice_response_handler_unittest.cc
diff --git a/chrome/browser/signin/dice_response_handler_unittest.cc b/chrome/browser/signin/dice_response_handler_unittest.cc
index aed6afdb35a659f74b8c417035588c379607eaa1..43ca48a485603f60de4997313c1db4a1384b20d6 100644
--- a/chrome/browser/signin/dice_response_handler_unittest.cc
+++ b/chrome/browser/signin/dice_response_handler_unittest.cc
@@ -100,7 +100,7 @@ TEST_F(DiceResponseHandlerTest, Signin) {
token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id));
dice_response_handler_.ProcessDiceHeader(dice_params);
// Check that a GaiaAuthFetcher has been created.
- ASSERT_TRUE(signin_client_.consumer_);
+ ASSERT_THAT(signin_client_.consumer_, testing::NotNull());
// Simulate GaiaAuthFetcher success.
signin_client_.consumer_->OnClientOAuthSuccess(
GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10));
@@ -109,6 +109,63 @@ TEST_F(DiceResponseHandlerTest, Signin) {
token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id));
}
+// Checks that a second token for the same account is not requested when a
+// request is already in flight.
+TEST_F(DiceResponseHandlerTest, SigninRepeatedWithSameAccount) {
+ DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN);
+ ASSERT_FALSE(
+ token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id));
+ dice_response_handler_.ProcessDiceHeader(dice_params);
+ // Check that a GaiaAuthFetcher has been created.
+ GaiaAuthConsumer* consumer = signin_client_.consumer_;
+ ASSERT_THAT(consumer, testing::NotNull());
+ // Start a second request for the same account.
+ signin_client_.consumer_ = nullptr;
+ dice_response_handler_.ProcessDiceHeader(dice_params);
+ // Check that there is no new request.
+ ASSERT_THAT(signin_client_.consumer_, testing::IsNull());
+ // Simulate GaiaAuthFetcher success for the first request.
+ consumer->OnClientOAuthSuccess(
+ GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10));
+ // Check that the token has been inserted in the token service.
+ EXPECT_TRUE(
+ token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id));
+}
+
+// Checks that two SIGNIN requests can happen concurrently.
+TEST_F(DiceResponseHandlerTest, SigninWithTwoAccounts) {
+ DiceResponseParams dice_params_1 = MakeDiceParams(DiceAction::SIGNIN);
+ DiceResponseParams dice_params_2 = MakeDiceParams(DiceAction::SIGNIN);
+ dice_params_2.email = "other_email";
+ dice_params_2.obfuscated_gaia_id = "other_gaia_id";
+ ASSERT_FALSE(
+ token_service_.RefreshTokenIsAvailable(dice_params_1.obfuscated_gaia_id));
+ ASSERT_FALSE(
+ token_service_.RefreshTokenIsAvailable(dice_params_2.obfuscated_gaia_id));
+ // Start first request.
+ dice_response_handler_.ProcessDiceHeader(dice_params_1);
+ // Check that a GaiaAuthFetcher has been created.
+ GaiaAuthConsumer* consumer_1 = signin_client_.consumer_;
+ ASSERT_THAT(consumer_1, testing::NotNull());
+ // Start second request.
+ signin_client_.consumer_ = nullptr;
+ dice_response_handler_.ProcessDiceHeader(dice_params_2);
+ GaiaAuthConsumer* consumer_2 = signin_client_.consumer_;
+ ASSERT_THAT(consumer_2, testing::NotNull());
+ // Simulate GaiaAuthFetcher success for the first request.
+ consumer_1->OnClientOAuthSuccess(
+ GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10));
+ // Check that the token has been inserted in the token service.
+ EXPECT_TRUE(
+ token_service_.RefreshTokenIsAvailable(dice_params_1.obfuscated_gaia_id));
+ // Simulate GaiaAuthFetcher success for the second request.
+ consumer_2->OnClientOAuthSuccess(
+ GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10));
+ // Check that the token has been inserted in the token service.
+ EXPECT_TRUE(
+ token_service_.RefreshTokenIsAvailable(dice_params_2.obfuscated_gaia_id));
+}
+
// Tests that the DiceResponseHandler is created for a normal profile but not
// for an incognito profile.
TEST(DiceResponseHandlerFactoryTest, NotInIncognito) {
« no previous file with comments | « chrome/browser/signin/dice_response_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698