| OLD | NEW |
| 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 "chrome/browser/ui/webui/signin/sync_confirmation_handler.h" | 5 #include "chrome/browser/ui/webui/signin/sync_confirmation_handler.h" |
| 6 | 6 |
| 7 #include "base/test/user_action_tester.h" | 7 #include "base/test/user_action_tester.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 9 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 10 #include "chrome/browser/signin/account_fetcher_service_factory.h" | 10 #include "chrome/browser/signin/account_fetcher_service_factory.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 "gaia", | 136 "gaia", |
| 137 "", | 137 "", |
| 138 "full_name", | 138 "full_name", |
| 139 "given_name", | 139 "given_name", |
| 140 "locale", | 140 "locale", |
| 141 "http://picture.example.com/picture.jpg"); | 141 "http://picture.example.com/picture.jpg"); |
| 142 | 142 |
| 143 base::ListValue args; | 143 base::ListValue args; |
| 144 args.Set(0, new base::FundamentalValue(kDefaultDialogHeight)); | 144 args.Set(0, new base::FundamentalValue(kDefaultDialogHeight)); |
| 145 handler()->HandleInitializedWithSize(&args); | 145 handler()->HandleInitializedWithSize(&args); |
| 146 EXPECT_EQ(1U, web_ui()->call_data().size()); | 146 EXPECT_EQ(2U, web_ui()->call_data().size()); |
| 147 |
| 148 // When the primary account is ready, setUserImageURL happens before |
| 149 // clearFocus since the image URL is known before showing the dialog. |
| 147 EXPECT_EQ("sync.confirmation.setUserImageURL", | 150 EXPECT_EQ("sync.confirmation.setUserImageURL", |
| 148 web_ui()->call_data()[0]->function_name()); | 151 web_ui()->call_data()[0]->function_name()); |
| 149 EXPECT_TRUE( | 152 EXPECT_TRUE( |
| 150 web_ui()->call_data()[0]->arg1()->IsType(base::Value::TYPE_STRING)); | 153 web_ui()->call_data()[0]->arg1()->IsType(base::Value::TYPE_STRING)); |
| 151 std::string passed_picture_url; | 154 std::string passed_picture_url; |
| 152 EXPECT_TRUE( | 155 EXPECT_TRUE( |
| 153 web_ui()->call_data()[0]->arg1()->GetAsString(&passed_picture_url)); | 156 web_ui()->call_data()[0]->arg1()->GetAsString(&passed_picture_url)); |
| 154 | 157 |
| 158 EXPECT_EQ("sync.confirmation.clearFocus", |
| 159 web_ui()->call_data()[1]->function_name()); |
| 160 |
| 155 std::string original_picture_url = | 161 std::string original_picture_url = |
| 156 AccountTrackerServiceFactory::GetForProfile(profile())-> | 162 AccountTrackerServiceFactory::GetForProfile(profile())-> |
| 157 GetAccountInfo("gaia").picture_url; | 163 GetAccountInfo("gaia").picture_url; |
| 158 GURL picture_url_with_size; | 164 GURL picture_url_with_size; |
| 159 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(GURL(original_picture_url), | 165 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(GURL(original_picture_url), |
| 160 kExpectedProfileImageSize, | 166 kExpectedProfileImageSize, |
| 161 &picture_url_with_size)); | 167 &picture_url_with_size)); |
| 162 EXPECT_EQ(picture_url_with_size.spec(), passed_picture_url); | 168 EXPECT_EQ(picture_url_with_size.spec(), passed_picture_url); |
| 163 handler()->HandleUndo(nullptr); | 169 handler()->HandleUndo(nullptr); |
| 164 } | 170 } |
| 165 | 171 |
| 166 TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReadyLater) { | 172 TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReadyLater) { |
| 167 browser()->ShowModalSyncConfirmationWindow(); | 173 browser()->ShowModalSyncConfirmationWindow(); |
| 168 | 174 |
| 169 base::ListValue args; | 175 base::ListValue args; |
| 170 args.Set(0, new base::FundamentalValue(kDefaultDialogHeight)); | 176 args.Set(0, new base::FundamentalValue(kDefaultDialogHeight)); |
| 171 handler()->HandleInitializedWithSize(&args); | 177 handler()->HandleInitializedWithSize(&args); |
| 172 EXPECT_EQ(0U, web_ui()->call_data().size()); | 178 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 173 | 179 |
| 174 account_fetcher_service()->FakeUserInfoFetchSuccess( | 180 account_fetcher_service()->FakeUserInfoFetchSuccess( |
| 175 "gaia", | 181 "gaia", |
| 176 "foo@example.com", | 182 "foo@example.com", |
| 177 "gaia", | 183 "gaia", |
| 178 "", | 184 "", |
| 179 "full_name", | 185 "full_name", |
| 180 "given_name", | 186 "given_name", |
| 181 "locale", | 187 "locale", |
| 182 "http://picture.example.com/picture.jpg"); | 188 "http://picture.example.com/picture.jpg"); |
| 183 | 189 |
| 184 EXPECT_EQ(1U, web_ui()->call_data().size()); | 190 EXPECT_EQ(2U, web_ui()->call_data().size()); |
| 191 |
| 192 // When the primary account isn't yet ready when the dialog is shown, |
| 193 // clearFocus is called before setUserImageURL. |
| 194 EXPECT_EQ("sync.confirmation.clearFocus", |
| 195 web_ui()->call_data()[0]->function_name()); |
| 196 |
| 185 EXPECT_EQ("sync.confirmation.setUserImageURL", | 197 EXPECT_EQ("sync.confirmation.setUserImageURL", |
| 186 web_ui()->call_data()[0]->function_name()); | 198 web_ui()->call_data()[1]->function_name()); |
| 187 EXPECT_TRUE( | 199 EXPECT_TRUE( |
| 188 web_ui()->call_data()[0]->arg1()->IsType(base::Value::TYPE_STRING)); | 200 web_ui()->call_data()[1]->arg1()->IsType(base::Value::TYPE_STRING)); |
| 189 std::string passed_picture_url; | 201 std::string passed_picture_url; |
| 190 EXPECT_TRUE( | 202 EXPECT_TRUE( |
| 191 web_ui()->call_data()[0]->arg1()->GetAsString(&passed_picture_url)); | 203 web_ui()->call_data()[1]->arg1()->GetAsString(&passed_picture_url)); |
| 192 | 204 |
| 193 std::string original_picture_url = | 205 std::string original_picture_url = |
| 194 AccountTrackerServiceFactory::GetForProfile(profile())-> | 206 AccountTrackerServiceFactory::GetForProfile(profile())-> |
| 195 GetAccountInfo("gaia").picture_url; | 207 GetAccountInfo("gaia").picture_url; |
| 196 GURL picture_url_with_size; | 208 GURL picture_url_with_size; |
| 197 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(GURL(original_picture_url), | 209 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(GURL(original_picture_url), |
| 198 kExpectedProfileImageSize, | 210 kExpectedProfileImageSize, |
| 199 &picture_url_with_size)); | 211 &picture_url_with_size)); |
| 200 EXPECT_EQ(picture_url_with_size.spec(), passed_picture_url); | 212 EXPECT_EQ(picture_url_with_size.spec(), passed_picture_url); |
| 201 handler()->HandleUndo(nullptr); | 213 handler()->HandleUndo(nullptr); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 227 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); | 239 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); |
| 228 EXPECT_TRUE(sync()->IsFirstSetupComplete()); | 240 EXPECT_TRUE(sync()->IsFirstSetupComplete()); |
| 229 EXPECT_TRUE( | 241 EXPECT_TRUE( |
| 230 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); | 242 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); |
| 231 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); | 243 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); |
| 232 EXPECT_EQ(1, user_action_tester()->GetActionCount( | 244 EXPECT_EQ(1, user_action_tester()->GetActionCount( |
| 233 "Signin_Signin_WithDefaultSyncSettings")); | 245 "Signin_Signin_WithDefaultSyncSettings")); |
| 234 EXPECT_EQ(0, user_action_tester()->GetActionCount( | 246 EXPECT_EQ(0, user_action_tester()->GetActionCount( |
| 235 "Signin_Signin_WithAdvancedSyncSettings")); | 247 "Signin_Signin_WithAdvancedSyncSettings")); |
| 236 } | 248 } |
| OLD | NEW |