| 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 16 matching lines...) Expand all Loading... |
| 27 #include "content/public/test/test_web_ui.h" | 27 #include "content/public/test/test_web_ui.h" |
| 28 | 28 |
| 29 const int kExpectedProfileImageSize = 128; | 29 const int kExpectedProfileImageSize = 128; |
| 30 | 30 |
| 31 // The dialog needs to be initialized with a height but the actual value doesn't | 31 // The dialog needs to be initialized with a height but the actual value doesn't |
| 32 // really matter in unit tests. | 32 // really matter in unit tests. |
| 33 const double kDefaultDialogHeight = 350.0; | 33 const double kDefaultDialogHeight = 350.0; |
| 34 | 34 |
| 35 class TestingSyncConfirmationHandler : public SyncConfirmationHandler { | 35 class TestingSyncConfirmationHandler : public SyncConfirmationHandler { |
| 36 public: | 36 public: |
| 37 explicit TestingSyncConfirmationHandler(Browser* browser, | 37 explicit TestingSyncConfirmationHandler(content::WebUI* web_ui) { |
| 38 content::WebUI* web_ui) | |
| 39 : SyncConfirmationHandler(browser) { | |
| 40 set_web_ui(web_ui); | 38 set_web_ui(web_ui); |
| 41 } | 39 } |
| 42 | 40 |
| 43 using SyncConfirmationHandler::HandleConfirm; | 41 using SyncConfirmationHandler::HandleConfirm; |
| 44 using SyncConfirmationHandler::HandleUndo; | 42 using SyncConfirmationHandler::HandleUndo; |
| 45 using SyncConfirmationHandler::HandleInitializedWithSize; | 43 using SyncConfirmationHandler::HandleInitializedWithSize; |
| 46 using SyncConfirmationHandler::HandleGoToSettings; | 44 using SyncConfirmationHandler::HandleGoToSettings; |
| 47 using SyncConfirmationHandler::SetUserImageURL; | 45 using SyncConfirmationHandler::SetUserImageURL; |
| 48 }; | 46 }; |
| 49 | 47 |
| 50 class SyncConfirmationHandlerTest : public BrowserWithTestWindowTest { | 48 class SyncConfirmationHandlerTest : public BrowserWithTestWindowTest { |
| 51 public: | 49 public: |
| 52 SyncConfirmationHandlerTest() : did_user_explicitly_interact(false), | 50 SyncConfirmationHandlerTest() : did_user_explicitly_interact(false), |
| 53 web_ui_(new content::TestWebUI) {} | 51 web_ui_(new content::TestWebUI) {} |
| 54 void SetUp() override { | 52 void SetUp() override { |
| 55 BrowserWithTestWindowTest::SetUp(); | 53 BrowserWithTestWindowTest::SetUp(); |
| 56 chrome::NewTab(browser()); | 54 chrome::NewTab(browser()); |
| 57 web_ui()->set_web_contents( | 55 web_ui()->set_web_contents( |
| 58 browser()->tab_strip_model()->GetActiveWebContents()); | 56 browser()->tab_strip_model()->GetActiveWebContents()); |
| 59 | 57 |
| 60 auto handler = | 58 auto handler = base::MakeUnique<TestingSyncConfirmationHandler>(web_ui()); |
| 61 base::MakeUnique<TestingSyncConfirmationHandler>(browser(), web_ui()); | |
| 62 handler_ = handler.get(); | 59 handler_ = handler.get(); |
| 63 sync_confirmation_ui_.reset(new SyncConfirmationUI(web_ui())); | 60 sync_confirmation_ui_.reset( |
| 64 web_ui()->AddMessageHandler(std::move(handler)); | 61 new SyncConfirmationUI(web_ui(), std::move(handler))); |
| 65 | 62 |
| 66 // This dialog assumes the signin flow was completed, which kicks off the | 63 // This dialog assumes the signin flow was completed, which kicks off the |
| 67 // SigninManager. | 64 // SigninManager. |
| 68 new OneClickSigninSyncStarter( | 65 new OneClickSigninSyncStarter( |
| 69 profile(), browser(), "gaia", "foo@example.com", "password", | 66 profile(), browser(), "gaia", "foo@example.com", "password", |
| 70 "refresh_token", OneClickSigninSyncStarter::CURRENT_PROFILE, | 67 "refresh_token", OneClickSigninSyncStarter::CURRENT_PROFILE, |
| 71 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, nullptr, | 68 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, nullptr, |
| 72 OneClickSigninSyncStarter::NO_CONFIRMATION, GURL(), GURL(), | 69 OneClickSigninSyncStarter::NO_CONFIRMATION, GURL(), GURL(), |
| 73 OneClickSigninSyncStarter::Callback()); | 70 OneClickSigninSyncStarter::Callback()); |
| 74 } | 71 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); | 279 EXPECT_FALSE(sync()->IsFirstSetupInProgress()); |
| 283 EXPECT_TRUE(sync()->IsFirstSetupComplete()); | 280 EXPECT_TRUE(sync()->IsFirstSetupComplete()); |
| 284 EXPECT_TRUE( | 281 EXPECT_TRUE( |
| 285 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); | 282 SigninManagerFactory::GetForProfile(profile())->IsAuthenticated()); |
| 286 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); | 283 EXPECT_EQ(0, user_action_tester()->GetActionCount("Signin_Undo_Signin")); |
| 287 EXPECT_EQ(1, user_action_tester()->GetActionCount( | 284 EXPECT_EQ(1, user_action_tester()->GetActionCount( |
| 288 "Signin_Signin_WithDefaultSyncSettings")); | 285 "Signin_Signin_WithDefaultSyncSettings")); |
| 289 EXPECT_EQ(0, user_action_tester()->GetActionCount( | 286 EXPECT_EQ(0, user_action_tester()->GetActionCount( |
| 290 "Signin_Signin_WithAdvancedSyncSettings")); | 287 "Signin_Signin_WithAdvancedSyncSettings")); |
| 291 } | 288 } |
| OLD | NEW |