| 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" |
| 11 #include "chrome/browser/signin/account_tracker_service_factory.h" | 11 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 12 #include "chrome/browser/signin/fake_account_fetcher_service_builder.h" | 12 #include "chrome/browser/signin/fake_account_fetcher_service_builder.h" |
| 13 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 13 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" | 15 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 16 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/browser/ui/webui/signin/sync_confirmation_ui.h" | 18 #include "chrome/browser/ui/webui/signin/sync_confirmation_ui.h" |
| 19 #include "chrome/test/base/browser_with_test_window_test.h" | 19 #include "chrome/test/base/browser_with_test_window_test.h" |
| 20 #include "chrome/test/base/dialog_test_browser_window.h" | 20 #include "chrome/test/base/dialog_test_browser_window.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/browser_sync/browser/profile_sync_service.h" | 22 #include "components/browser_sync/browser/profile_sync_service.h" |
| 23 #include "components/signin/core/browser/account_fetcher_service.h" | 23 #include "components/signin/core/browser/account_fetcher_service.h" |
| 24 #include "components/signin/core/browser/fake_account_fetcher_service.h" | 24 #include "components/signin/core/browser/fake_account_fetcher_service.h" |
| 25 #include "components/signin/core/browser/fake_signin_manager.h" | 25 #include "components/signin/core/browser/fake_signin_manager.h" |
| 26 #include "content/public/test/test_web_ui.h" | 26 #include "content/public/test/test_web_ui.h" |
| 27 | 27 |
| 28 const int kExpectedProfileImageSize = 128; | 28 const int kExpectedProfileImageSize = 128; |
| 29 | 29 |
| 30 // The dialog needs to be initialized with a height but the actual value doesn't |
| 31 // really matter in unit tests. |
| 32 const double kDefaultDialogHeight = 350.0; |
| 33 |
| 30 class TestingSyncConfirmationHandler : public SyncConfirmationHandler { | 34 class TestingSyncConfirmationHandler : public SyncConfirmationHandler { |
| 31 public: | 35 public: |
| 32 explicit TestingSyncConfirmationHandler(content::WebUI* web_ui) { | 36 explicit TestingSyncConfirmationHandler(content::WebUI* web_ui) { |
| 33 set_web_ui(web_ui); | 37 set_web_ui(web_ui); |
| 34 } | 38 } |
| 35 | 39 |
| 36 using SyncConfirmationHandler::HandleConfirm; | 40 using SyncConfirmationHandler::HandleConfirm; |
| 37 using SyncConfirmationHandler::HandleUndo; | 41 using SyncConfirmationHandler::HandleUndo; |
| 38 using SyncConfirmationHandler::HandleInitialized; | 42 using SyncConfirmationHandler::HandleInitializedWithSize; |
| 39 using SyncConfirmationHandler::HandleGoToSettings; | 43 using SyncConfirmationHandler::HandleGoToSettings; |
| 40 using SyncConfirmationHandler::SetUserImageURL; | 44 using SyncConfirmationHandler::SetUserImageURL; |
| 41 }; | 45 }; |
| 42 | 46 |
| 43 class SyncConfirmationHandlerTest : public BrowserWithTestWindowTest { | 47 class SyncConfirmationHandlerTest : public BrowserWithTestWindowTest { |
| 44 public: | 48 public: |
| 45 SyncConfirmationHandlerTest() : web_ui_(new content::TestWebUI) {} | 49 SyncConfirmationHandlerTest() : web_ui_(new content::TestWebUI) {} |
| 46 void SetUp() override { | 50 void SetUp() override { |
| 47 BrowserWithTestWindowTest::SetUp(); | 51 BrowserWithTestWindowTest::SetUp(); |
| 48 chrome::NewTab(browser()); | 52 chrome::NewTab(browser()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 122 } |
| 119 | 123 |
| 120 private: | 124 private: |
| 121 scoped_ptr<content::TestWebUI> web_ui_; | 125 scoped_ptr<content::TestWebUI> web_ui_; |
| 122 scoped_ptr<SyncConfirmationUI> sync_confirmation_ui_; | 126 scoped_ptr<SyncConfirmationUI> sync_confirmation_ui_; |
| 123 TestingSyncConfirmationHandler* handler_; // Not owned. | 127 TestingSyncConfirmationHandler* handler_; // Not owned. |
| 124 base::UserActionTester user_action_tester_; | 128 base::UserActionTester user_action_tester_; |
| 125 }; | 129 }; |
| 126 | 130 |
| 127 TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReady) { | 131 TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReady) { |
| 132 browser()->ShowModalSyncConfirmationWindow(); |
| 128 account_fetcher_service()->FakeUserInfoFetchSuccess( | 133 account_fetcher_service()->FakeUserInfoFetchSuccess( |
| 129 "gaia", | 134 "gaia", |
| 130 "foo@example.com", | 135 "foo@example.com", |
| 131 "gaia", | 136 "gaia", |
| 132 "", | 137 "", |
| 133 "full_name", | 138 "full_name", |
| 134 "given_name", | 139 "given_name", |
| 135 "locale", | 140 "locale", |
| 136 "http://picture.example.com/picture.jpg"); | 141 "http://picture.example.com/picture.jpg"); |
| 137 | 142 |
| 138 handler()->HandleInitialized(nullptr); | 143 base::ListValue args; |
| 144 args.Set(0, new base::FundamentalValue(kDefaultDialogHeight)); |
| 145 handler()->HandleInitializedWithSize(&args); |
| 139 EXPECT_EQ(1U, web_ui()->call_data().size()); | 146 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 140 EXPECT_EQ("sync.confirmation.setUserImageURL", | 147 EXPECT_EQ("sync.confirmation.setUserImageURL", |
| 141 web_ui()->call_data()[0]->function_name()); | 148 web_ui()->call_data()[0]->function_name()); |
| 142 EXPECT_TRUE( | 149 EXPECT_TRUE( |
| 143 web_ui()->call_data()[0]->arg1()->IsType(base::Value::TYPE_STRING)); | 150 web_ui()->call_data()[0]->arg1()->IsType(base::Value::TYPE_STRING)); |
| 144 std::string passed_picture_url; | 151 std::string passed_picture_url; |
| 145 EXPECT_TRUE( | 152 EXPECT_TRUE( |
| 146 web_ui()->call_data()[0]->arg1()->GetAsString(&passed_picture_url)); | 153 web_ui()->call_data()[0]->arg1()->GetAsString(&passed_picture_url)); |
| 147 | 154 |
| 148 std::string original_picture_url = | 155 std::string original_picture_url = |
| 149 AccountTrackerServiceFactory::GetForProfile(profile())-> | 156 AccountTrackerServiceFactory::GetForProfile(profile())-> |
| 150 GetAccountInfo("gaia").picture_url; | 157 GetAccountInfo("gaia").picture_url; |
| 151 GURL picture_url_with_size; | 158 GURL picture_url_with_size; |
| 152 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(GURL(original_picture_url), | 159 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(GURL(original_picture_url), |
| 153 kExpectedProfileImageSize, | 160 kExpectedProfileImageSize, |
| 154 &picture_url_with_size)); | 161 &picture_url_with_size)); |
| 155 EXPECT_EQ(picture_url_with_size.spec(), passed_picture_url); | 162 EXPECT_EQ(picture_url_with_size.spec(), passed_picture_url); |
| 156 handler()->HandleUndo(nullptr); | 163 handler()->HandleUndo(nullptr); |
| 157 } | 164 } |
| 158 | 165 |
| 159 TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReadyLater) { | 166 TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReadyLater) { |
| 160 handler()->HandleInitialized(nullptr); | 167 browser()->ShowModalSyncConfirmationWindow(); |
| 168 |
| 169 base::ListValue args; |
| 170 args.Set(0, new base::FundamentalValue(kDefaultDialogHeight)); |
| 171 handler()->HandleInitializedWithSize(&args); |
| 161 EXPECT_EQ(0U, web_ui()->call_data().size()); | 172 EXPECT_EQ(0U, web_ui()->call_data().size()); |
| 162 | 173 |
| 163 account_fetcher_service()->FakeUserInfoFetchSuccess( | 174 account_fetcher_service()->FakeUserInfoFetchSuccess( |
| 164 "gaia", | 175 "gaia", |
| 165 "foo@example.com", | 176 "foo@example.com", |
| 166 "gaia", | 177 "gaia", |
| 167 "", | 178 "", |
| 168 "full_name", | 179 "full_name", |
| 169 "given_name", | 180 "given_name", |
| 170 "locale", | 181 "locale", |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); | 227 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); |
| 217 EXPECT_TRUE(sync()->IsFirstSetupComplete()); | 228 EXPECT_TRUE(sync()->IsFirstSetupComplete()); |
| 218 EXPECT_TRUE( | 229 EXPECT_TRUE( |
| 219 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); | 230 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); |
| 220 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); | 231 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); |
| 221 EXPECT_EQ(1, user_action_tester()->GetActionCount( | 232 EXPECT_EQ(1, user_action_tester()->GetActionCount( |
| 222 "Signin_Signin_WithDefaultSyncSettings")); | 233 "Signin_Signin_WithDefaultSyncSettings")); |
| 223 EXPECT_EQ(0, user_action_tester()->GetActionCount( | 234 EXPECT_EQ(0, user_action_tester()->GetActionCount( |
| 224 "Signin_Signin_WithAdvancedSyncSettings")); | 235 "Signin_Signin_WithAdvancedSyncSettings")); |
| 225 } | 236 } |
| OLD | NEW |