| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync/one_click_signin_sync_starter.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.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_signin_manager.h" | 12 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 13 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 13 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
| 14 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 17 #include "components/signin/core/browser/account_tracker_service.h" | 19 #include "components/signin/core/browser/account_tracker_service.h" |
| 20 #include "components/signin/core/browser/fake_signin_manager.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 25 |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 const char* kTestingGaiaId = "gaia_id"; | 28 const char* kTestingGaiaId = "gaia_id"; |
| 26 const char* kTestingUsername = "fake_username"; | 29 const char* kTestingUsername = "fake_username"; |
| 27 | 30 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 OneClickSigninSyncStarter* sync_starter_; | 91 OneClickSigninSyncStarter* sync_starter_; |
| 89 | 92 |
| 90 // Number of times that the callback is called with SYNC_SETUP_FAILURE. | 93 // Number of times that the callback is called with SYNC_SETUP_FAILURE. |
| 91 int failed_count_; | 94 int failed_count_; |
| 92 | 95 |
| 93 // Number of times that the callback is called with SYNC_SETUP_SUCCESS. | 96 // Number of times that the callback is called with SYNC_SETUP_SUCCESS. |
| 94 int succeeded_count_; | 97 int succeeded_count_; |
| 95 | 98 |
| 96 private: | 99 private: |
| 97 static scoped_ptr<KeyedService> BuildSigninManager( | 100 static scoped_ptr<KeyedService> BuildSigninManager( |
| 98 content::BrowserContext* profile) { | 101 content::BrowserContext* context) { |
| 99 return make_scoped_ptr( | 102 Profile* profile = static_cast<Profile*>(context); |
| 100 new FakeSigninManager(static_cast<Profile*>(profile))); | 103 return make_scoped_ptr(new FakeSigninManager( |
| 104 ChromeSigninClientFactory::GetForProfile(profile), |
| 105 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 106 AccountTrackerServiceFactory::GetForProfile(profile), |
| 107 GaiaCookieManagerServiceFactory::GetForProfile(profile))); |
| 101 } | 108 } |
| 102 | 109 |
| 103 DISALLOW_COPY_AND_ASSIGN(OneClickSigninSyncStarterTest); | 110 DISALLOW_COPY_AND_ASSIGN(OneClickSigninSyncStarterTest); |
| 104 }; | 111 }; |
| 105 | 112 |
| 106 // Verifies that the callback is invoked when sync setup fails. | 113 // Verifies that the callback is invoked when sync setup fails. |
| 107 TEST_F(OneClickSigninSyncStarterTest, CallbackSigninFailed) { | 114 TEST_F(OneClickSigninSyncStarterTest, CallbackSigninFailed) { |
| 108 CreateSyncStarter(base::Bind(&OneClickSigninSyncStarterTest::Callback, | 115 CreateSyncStarter(base::Bind(&OneClickSigninSyncStarterTest::Callback, |
| 109 base::Unretained(this)), | 116 base::Unretained(this)), |
| 110 GURL()); | 117 GURL()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 130 | 137 |
| 131 const GURL kTestURL = GURL("http://www.example.com"); | 138 const GURL kTestURL = GURL("http://www.example.com"); |
| 132 CreateSyncStarter(base::Bind(&OneClickSigninSyncStarterTest::Callback, | 139 CreateSyncStarter(base::Bind(&OneClickSigninSyncStarterTest::Callback, |
| 133 base::Unretained(this)), | 140 base::Unretained(this)), |
| 134 kTestURL); | 141 kTestURL); |
| 135 sync_starter_->AccountAddedToCookie( | 142 sync_starter_->AccountAddedToCookie( |
| 136 GoogleServiceAuthError(GoogleServiceAuthError::NONE)); | 143 GoogleServiceAuthError(GoogleServiceAuthError::NONE)); |
| 137 EXPECT_EQ(1, succeeded_count_); | 144 EXPECT_EQ(1, succeeded_count_); |
| 138 EXPECT_EQ(kTestURL, controller.GetPendingEntry()->GetURL()); | 145 EXPECT_EQ(kTestURL, controller.GetPendingEntry()->GetURL()); |
| 139 } | 146 } |
| OLD | NEW |