Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 DiceResponseHandler dice_response_handler_; | 93 DiceResponseHandler dice_response_handler_; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // Checks that a SIGNIN action triggers a token exchange request. | 96 // Checks that a SIGNIN action triggers a token exchange request. |
| 97 TEST_F(DiceResponseHandlerTest, Signin) { | 97 TEST_F(DiceResponseHandlerTest, Signin) { |
| 98 DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN); | 98 DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN); |
| 99 ASSERT_FALSE( | 99 ASSERT_FALSE( |
| 100 token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id)); | 100 token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id)); |
| 101 dice_response_handler_.ProcessDiceHeader(dice_params); | 101 dice_response_handler_.ProcessDiceHeader(dice_params); |
| 102 // Check that a GaiaAuthFetcher has been created. | 102 // Check that a GaiaAuthFetcher has been created. |
| 103 ASSERT_TRUE(signin_client_.consumer_); | 103 ASSERT_THAT(signin_client_.consumer_, testing::NotNull()); |
| 104 // Simulate GaiaAuthFetcher success. | 104 // Simulate GaiaAuthFetcher success. |
| 105 signin_client_.consumer_->OnClientOAuthSuccess( | 105 signin_client_.consumer_->OnClientOAuthSuccess( |
| 106 GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10)); | 106 GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10)); |
| 107 // Check that the token has been inserted in the token service. | 107 // Check that the token has been inserted in the token service. |
| 108 EXPECT_TRUE( | 108 EXPECT_TRUE( |
| 109 token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id)); | 109 token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Checks that a second token for the same account is not requested when a | |
| 113 // request is already in flight. | |
| 114 TEST_F(DiceResponseHandlerTest, SigninRepeatedWithSameAccount) { | |
|
msarda
2017/06/22 09:51:32
This test will need to be updated if you implement
| |
| 115 DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN); | |
| 116 ASSERT_FALSE( | |
| 117 token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id)); | |
| 118 dice_response_handler_.ProcessDiceHeader(dice_params); | |
| 119 // Check that a GaiaAuthFetcher has been created. | |
| 120 GaiaAuthConsumer* consumer = signin_client_.consumer_; | |
| 121 ASSERT_THAT(consumer, testing::NotNull()); | |
| 122 // Start a second request for the same account. | |
| 123 signin_client_.consumer_ = nullptr; | |
| 124 dice_response_handler_.ProcessDiceHeader(dice_params); | |
| 125 // Check that there is no new request. | |
| 126 ASSERT_THAT(signin_client_.consumer_, testing::IsNull()); | |
| 127 // Simulate GaiaAuthFetcher success for the first request. | |
| 128 consumer->OnClientOAuthSuccess( | |
| 129 GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10)); | |
| 130 // Check that the token has been inserted in the token service. | |
| 131 EXPECT_TRUE( | |
| 132 token_service_.RefreshTokenIsAvailable(dice_params.obfuscated_gaia_id)); | |
| 133 } | |
| 134 | |
| 135 // Checks that two SIGNIN requests can happen concurrently. | |
| 136 TEST_F(DiceResponseHandlerTest, SigninWithTwoAccounts) { | |
| 137 DiceResponseParams dice_params_1 = MakeDiceParams(DiceAction::SIGNIN); | |
| 138 DiceResponseParams dice_params_2 = MakeDiceParams(DiceAction::SIGNIN); | |
| 139 dice_params_2.email = "other_email"; | |
| 140 dice_params_2.obfuscated_gaia_id = "other_gaia_id"; | |
| 141 ASSERT_FALSE( | |
| 142 token_service_.RefreshTokenIsAvailable(dice_params_1.obfuscated_gaia_id)); | |
| 143 ASSERT_FALSE( | |
| 144 token_service_.RefreshTokenIsAvailable(dice_params_2.obfuscated_gaia_id)); | |
| 145 // Start first request. | |
| 146 dice_response_handler_.ProcessDiceHeader(dice_params_1); | |
| 147 // Check that a GaiaAuthFetcher has been created. | |
| 148 GaiaAuthConsumer* consumer_1 = signin_client_.consumer_; | |
| 149 ASSERT_THAT(consumer_1, testing::NotNull()); | |
| 150 // Start second request. | |
| 151 signin_client_.consumer_ = nullptr; | |
| 152 dice_response_handler_.ProcessDiceHeader(dice_params_2); | |
| 153 GaiaAuthConsumer* consumer_2 = signin_client_.consumer_; | |
| 154 ASSERT_THAT(consumer_2, testing::NotNull()); | |
| 155 // Simulate GaiaAuthFetcher success for the first request. | |
| 156 consumer_1->OnClientOAuthSuccess( | |
| 157 GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10)); | |
| 158 // Check that the token has been inserted in the token service. | |
| 159 EXPECT_TRUE( | |
| 160 token_service_.RefreshTokenIsAvailable(dice_params_1.obfuscated_gaia_id)); | |
| 161 // Simulate GaiaAuthFetcher success for the second request. | |
| 162 consumer_2->OnClientOAuthSuccess( | |
| 163 GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10)); | |
| 164 // Check that the token has been inserted in the token service. | |
| 165 EXPECT_TRUE( | |
| 166 token_service_.RefreshTokenIsAvailable(dice_params_2.obfuscated_gaia_id)); | |
| 167 } | |
| 168 | |
| 112 // Tests that the DiceResponseHandler is created for a normal profile but not | 169 // Tests that the DiceResponseHandler is created for a normal profile but not |
| 113 // for an incognito profile. | 170 // for an incognito profile. |
| 114 TEST(DiceResponseHandlerFactoryTest, NotInIncognito) { | 171 TEST(DiceResponseHandlerFactoryTest, NotInIncognito) { |
| 115 content::TestBrowserThreadBundle thread_bundle; | 172 content::TestBrowserThreadBundle thread_bundle; |
| 116 TestingProfile profile; | 173 TestingProfile profile; |
| 117 EXPECT_THAT(DiceResponseHandler::GetForProfile(&profile), testing::NotNull()); | 174 EXPECT_THAT(DiceResponseHandler::GetForProfile(&profile), testing::NotNull()); |
| 118 EXPECT_THAT( | 175 EXPECT_THAT( |
| 119 DiceResponseHandler::GetForProfile(profile.GetOffTheRecordProfile()), | 176 DiceResponseHandler::GetForProfile(profile.GetOffTheRecordProfile()), |
| 120 testing::IsNull()); | 177 testing::IsNull()); |
| 121 } | 178 } |
| 122 | 179 |
| 123 } // namespace | 180 } // namespace |
| OLD | NEW |