| 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 25 matching lines...) Expand all Loading... |
| 36 public: | 36 public: |
| 37 explicit TestingSyncConfirmationHandler(Browser* browser, | 37 explicit TestingSyncConfirmationHandler(Browser* browser, |
| 38 content::WebUI* web_ui) | 38 content::WebUI* web_ui) |
| 39 : SyncConfirmationHandler(browser) { | 39 : SyncConfirmationHandler(browser) { |
| 40 set_web_ui(web_ui); | 40 set_web_ui(web_ui); |
| 41 } | 41 } |
| 42 | 42 |
| 43 using SyncConfirmationHandler::HandleConfirm; | 43 using SyncConfirmationHandler::HandleConfirm; |
| 44 using SyncConfirmationHandler::HandleUndo; | 44 using SyncConfirmationHandler::HandleUndo; |
| 45 using SyncConfirmationHandler::HandleInitializedWithSize; | 45 using SyncConfirmationHandler::HandleInitializedWithSize; |
| 46 using SyncConfirmationHandler::HandleGoToSettings; | |
| 47 using SyncConfirmationHandler::SetUserImageURL; | 46 using SyncConfirmationHandler::SetUserImageURL; |
| 47 |
| 48 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(TestingSyncConfirmationHandler); |
| 50 }; |
| 51 |
| 52 class TestingOneClickSigninSyncStarter : public OneClickSigninSyncStarter { |
| 53 public: |
| 54 TestingOneClickSigninSyncStarter(Profile* profile, |
| 55 Browser* browser, |
| 56 const std::string& gaia_id, |
| 57 const std::string& email, |
| 58 const std::string& password, |
| 59 const std::string& refresh_token, |
| 60 ProfileMode profile_mode, |
| 61 StartSyncMode start_mode, |
| 62 content::WebContents* web_contents, |
| 63 ConfirmationRequired display_confirmation, |
| 64 const GURL& current_url, |
| 65 const GURL& continue_url, |
| 66 Callback callback) |
| 67 : OneClickSigninSyncStarter(profile, |
| 68 browser, |
| 69 gaia_id, |
| 70 email, |
| 71 password, |
| 72 refresh_token, |
| 73 profile_mode, |
| 74 start_mode, |
| 75 web_contents, |
| 76 display_confirmation, |
| 77 current_url, |
| 78 continue_url, |
| 79 callback) {} |
| 80 |
| 81 protected: |
| 82 void ShowSyncSetupSettingsSubpage() override { |
| 83 // Intentionally don't open a tab to settings. |
| 84 } |
| 85 |
| 86 private: |
| 87 DISALLOW_COPY_AND_ASSIGN(TestingOneClickSigninSyncStarter); |
| 48 }; | 88 }; |
| 49 | 89 |
| 50 class SyncConfirmationHandlerTest : public BrowserWithTestWindowTest { | 90 class SyncConfirmationHandlerTest : public BrowserWithTestWindowTest { |
| 51 public: | 91 public: |
| 52 SyncConfirmationHandlerTest() : did_user_explicitly_interact(false), | 92 SyncConfirmationHandlerTest() |
| 53 web_ui_(new content::TestWebUI) {} | 93 : did_user_explicitly_interact(false), web_ui_(new content::TestWebUI) {} |
| 94 |
| 54 void SetUp() override { | 95 void SetUp() override { |
| 55 BrowserWithTestWindowTest::SetUp(); | 96 BrowserWithTestWindowTest::SetUp(); |
| 56 chrome::NewTab(browser()); | 97 chrome::NewTab(browser()); |
| 57 web_ui()->set_web_contents( | 98 web_ui()->set_web_contents( |
| 58 browser()->tab_strip_model()->GetActiveWebContents()); | 99 browser()->tab_strip_model()->GetActiveWebContents()); |
| 59 | 100 |
| 60 auto handler = | 101 auto handler = |
| 61 base::MakeUnique<TestingSyncConfirmationHandler>(browser(), web_ui()); | 102 base::MakeUnique<TestingSyncConfirmationHandler>(browser(), web_ui()); |
| 62 handler_ = handler.get(); | 103 handler_ = handler.get(); |
| 63 sync_confirmation_ui_.reset(new SyncConfirmationUI(web_ui())); | 104 sync_confirmation_ui_.reset(new SyncConfirmationUI(web_ui())); |
| 64 web_ui()->AddMessageHandler(std::move(handler)); | 105 web_ui()->AddMessageHandler(std::move(handler)); |
| 65 | 106 |
| 66 // This dialog assumes the signin flow was completed, which kicks off the | 107 // This dialog assumes the signin flow was completed, which kicks off the |
| 67 // SigninManager. | 108 // SigninManager. |
| 68 new OneClickSigninSyncStarter( | 109 new TestingOneClickSigninSyncStarter( |
| 69 profile(), browser(), "gaia", "foo@example.com", "password", | 110 profile(), browser(), "gaia", "foo@example.com", "password", |
| 70 "refresh_token", OneClickSigninSyncStarter::CURRENT_PROFILE, | 111 "refresh_token", OneClickSigninSyncStarter::CURRENT_PROFILE, |
| 71 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, nullptr, | 112 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, nullptr, |
| 72 OneClickSigninSyncStarter::NO_CONFIRMATION, GURL(), GURL(), | 113 OneClickSigninSyncStarter::NO_CONFIRMATION, GURL(), GURL(), |
| 73 OneClickSigninSyncStarter::Callback()); | 114 OneClickSigninSyncStarter::Callback()); |
| 74 } | 115 } |
| 75 | 116 |
| 76 void TearDown() override { | 117 void TearDown() override { |
| 77 sync_confirmation_ui_.reset(); | 118 sync_confirmation_ui_.reset(); |
| 78 web_ui_.reset(); | 119 web_ui_.reset(); |
| 79 BrowserWithTestWindowTest::TearDown(); | 120 BrowserWithTestWindowTest::TearDown(); |
| 80 | 121 |
| 81 if (did_user_explicitly_interact) { | 122 if (did_user_explicitly_interact) |
| 82 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Abort_Signin")); | 123 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Abort_Signin")); |
| 83 } else { | 124 else |
| 84 EXPECT_EQ(1, user_action_tester()->GetActionCount("Signin_Abort_Signin")); | 125 EXPECT_EQ(1, user_action_tester()->GetActionCount("Signin_Abort_Signin")); |
| 85 } | |
| 86 } | 126 } |
| 87 | 127 |
| 88 TestingSyncConfirmationHandler* handler() { | 128 TestingSyncConfirmationHandler* handler() { |
| 89 return handler_; | 129 return handler_; |
| 90 } | 130 } |
| 91 | 131 |
| 92 content::TestWebUI* web_ui() { | 132 content::TestWebUI* web_ui() { |
| 93 return web_ui_.get(); | 133 return web_ui_.get(); |
| 94 } | 134 } |
| 95 | 135 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 118 | 158 |
| 119 TestingProfile* CreateProfile() override { | 159 TestingProfile* CreateProfile() override { |
| 120 TestingProfile::Builder builder; | 160 TestingProfile::Builder builder; |
| 121 builder.AddTestingFactory(AccountFetcherServiceFactory::GetInstance(), | 161 builder.AddTestingFactory(AccountFetcherServiceFactory::GetInstance(), |
| 122 FakeAccountFetcherServiceBuilder::BuildForTests); | 162 FakeAccountFetcherServiceBuilder::BuildForTests); |
| 123 builder.AddTestingFactory( | 163 builder.AddTestingFactory( |
| 124 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase); | 164 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase); |
| 125 return builder.Build().release(); | 165 return builder.Build().release(); |
| 126 } | 166 } |
| 127 | 167 |
| 128 protected: | 168 protected: |
| 129 bool did_user_explicitly_interact; | 169 bool did_user_explicitly_interact; |
| 130 | 170 |
| 131 private: | 171 private: |
| 132 std::unique_ptr<content::TestWebUI> web_ui_; | 172 std::unique_ptr<content::TestWebUI> web_ui_; |
| 133 std::unique_ptr<SyncConfirmationUI> sync_confirmation_ui_; | 173 std::unique_ptr<SyncConfirmationUI> sync_confirmation_ui_; |
| 134 TestingSyncConfirmationHandler* handler_; // Not owned. | 174 TestingSyncConfirmationHandler* handler_; // Not owned. |
| 135 base::UserActionTester user_action_tester_; | 175 base::UserActionTester user_action_tester_; |
| 176 |
| 177 DISALLOW_COPY_AND_ASSIGN(SyncConfirmationHandlerTest); |
| 136 }; | 178 }; |
| 137 | 179 |
| 138 TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReady) { | 180 TEST_F(SyncConfirmationHandlerTest, TestSetImageIfPrimaryAccountReady) { |
| 139 account_fetcher_service()->FakeUserInfoFetchSuccess( | 181 account_fetcher_service()->FakeUserInfoFetchSuccess( |
| 140 "gaia", | 182 "gaia", |
| 141 "foo@example.com", | 183 "foo@example.com", |
| 142 "gaia", | 184 "gaia", |
| 143 "", | 185 "", |
| 144 "full_name", | 186 "full_name", |
| 145 "given_name", | 187 "given_name", |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 EXPECT_EQ(0, user_action_tester()->GetActionCount( | 311 EXPECT_EQ(0, user_action_tester()->GetActionCount( |
| 270 "Signin_Signin_WithDefaultSyncSettings")); | 312 "Signin_Signin_WithDefaultSyncSettings")); |
| 271 EXPECT_EQ(0, user_action_tester()->GetActionCount( | 313 EXPECT_EQ(0, user_action_tester()->GetActionCount( |
| 272 "Signin_Signin_WithAdvancedSyncSettings")); | 314 "Signin_Signin_WithAdvancedSyncSettings")); |
| 273 } | 315 } |
| 274 | 316 |
| 275 TEST_F(SyncConfirmationHandlerTest, TestHandleConfirm) { | 317 TEST_F(SyncConfirmationHandlerTest, TestHandleConfirm) { |
| 276 EXPECT_FALSE(sync()->IsFirstSetupComplete()); | 318 EXPECT_FALSE(sync()->IsFirstSetupComplete()); |
| 277 EXPECT_TRUE(sync()->IsFirstSetupInProgress()); | 319 EXPECT_TRUE(sync()->IsFirstSetupInProgress()); |
| 278 | 320 |
| 279 handler()->HandleConfirm(nullptr); | 321 base::ListValue args; |
| 322 args.AppendBoolean(false /* show advanced */); |
| 323 handler()->HandleConfirm(&args); |
| 280 did_user_explicitly_interact = true; | 324 did_user_explicitly_interact = true; |
| 281 | 325 |
| 282 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); | 326 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); |
| 283 EXPECT_TRUE(sync()->IsFirstSetupComplete()); | 327 EXPECT_TRUE(sync()->IsFirstSetupComplete()); |
| 284 EXPECT_TRUE( | 328 EXPECT_TRUE( |
| 285 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); | 329 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); |
| 286 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); | 330 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); |
| 287 EXPECT_EQ(1, user_action_tester()->GetActionCount( | 331 EXPECT_EQ(1, user_action_tester()->GetActionCount( |
| 288 "Signin_Signin_WithDefaultSyncSettings")); | 332 "Signin_Signin_WithDefaultSyncSettings")); |
| 289 EXPECT_EQ(0, user_action_tester()->GetActionCount( | 333 EXPECT_EQ(0, user_action_tester()->GetActionCount( |
| 290 "Signin_Signin_WithAdvancedSyncSettings")); | 334 "Signin_Signin_WithAdvancedSyncSettings")); |
| 291 } | 335 } |
| 336 |
| 337 TEST_F(SyncConfirmationHandlerTest, TestHandleConfirmWithAdvancedSyncSettings) { |
| 338 EXPECT_FALSE(sync()->IsFirstSetupComplete()); |
| 339 EXPECT_TRUE(sync()->IsFirstSetupInProgress()); |
| 340 |
| 341 base::ListValue args; |
| 342 args.AppendBoolean(true /* show advanced */); |
| 343 handler()->HandleConfirm(&args); |
| 344 did_user_explicitly_interact = true; |
| 345 |
| 346 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); |
| 347 EXPECT_FALSE(sync()->IsFirstSetupComplete()); |
| 348 EXPECT_TRUE( |
| 349 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); |
| 350 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); |
| 351 EXPECT_EQ(0, user_action_tester()->GetActionCount( |
| 352 "Signin_Signin_WithDefaultSyncSettings")); |
| 353 EXPECT_EQ(1, user_action_tester()->GetActionCount( |
| 354 "Signin_Signin_WithAdvancedSyncSettings")); |
| 355 } |
| OLD | NEW |