| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_observer.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "chrome/browser/signin/signin_promo.h" | 17 #include "chrome/browser/signin/signin_promo.h" |
| 17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 18 #include "chrome/browser/sync/profile_sync_test_util.h" | 19 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 21 #include "components/browser_sync/browser/test_profile_sync_service.h" | 22 #include "components/browser_sync/browser/test_profile_sync_service.h" |
| 22 #include "components/signin/core/browser/signin_manager.h" | 23 #include "components/signin/core/browser/signin_manager.h" |
| 23 #include "components/sync_driver/startup_controller.h" | 24 #include "components/sync_driver/startup_controller.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 46 MOCK_METHOD2(DidStartNavigationToPendingEntry, | 47 MOCK_METHOD2(DidStartNavigationToPendingEntry, |
| 47 void(const GURL&, content::NavigationController::ReloadType)); | 48 void(const GURL&, content::NavigationController::ReloadType)); |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 class OneClickTestProfileSyncService : public TestProfileSyncService { | 51 class OneClickTestProfileSyncService : public TestProfileSyncService { |
| 51 public: | 52 public: |
| 52 ~OneClickTestProfileSyncService() override {} | 53 ~OneClickTestProfileSyncService() override {} |
| 53 | 54 |
| 54 // Helper routine to be used in conjunction with | 55 // Helper routine to be used in conjunction with |
| 55 // BrowserContextKeyedServiceFactory::SetTestingFactory(). | 56 // BrowserContextKeyedServiceFactory::SetTestingFactory(). |
| 56 static scoped_ptr<KeyedService> Build(content::BrowserContext* profile) { | 57 static std::unique_ptr<KeyedService> Build(content::BrowserContext* profile) { |
| 57 return make_scoped_ptr(new OneClickTestProfileSyncService( | 58 return base::WrapUnique(new OneClickTestProfileSyncService( |
| 58 CreateProfileSyncServiceParamsForTest( | 59 CreateProfileSyncServiceParamsForTest( |
| 59 Profile::FromBrowserContext(profile)))); | 60 Profile::FromBrowserContext(profile)))); |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool IsFirstSetupInProgress() const override { | 63 bool IsFirstSetupInProgress() const override { |
| 63 return first_setup_in_progress_; | 64 return first_setup_in_progress_; |
| 64 } | 65 } |
| 65 | 66 |
| 66 bool IsSyncActive() const override { return sync_active_; } | 67 bool IsSyncActive() const override { return sync_active_; } |
| 67 | 68 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 destruction_callback_.Run(this); | 101 destruction_callback_.Run(this); |
| 101 } | 102 } |
| 102 | 103 |
| 103 private: | 104 private: |
| 104 DestructionCallback destruction_callback_; | 105 DestructionCallback destruction_callback_; |
| 105 | 106 |
| 106 DISALLOW_COPY_AND_ASSIGN(TestOneClickSigninSyncObserver); | 107 DISALLOW_COPY_AND_ASSIGN(TestOneClickSigninSyncObserver); |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 // A trivial factory to build a null service. | 110 // A trivial factory to build a null service. |
| 110 scoped_ptr<KeyedService> BuildNullService(content::BrowserContext* context) { | 111 std::unique_ptr<KeyedService> BuildNullService( |
| 112 content::BrowserContext* context) { |
| 111 return nullptr; | 113 return nullptr; |
| 112 } | 114 } |
| 113 | 115 |
| 114 } // namespace | 116 } // namespace |
| 115 | 117 |
| 116 class OneClickSigninSyncObserverTest : public ChromeRenderViewHostTestHarness { | 118 class OneClickSigninSyncObserverTest : public ChromeRenderViewHostTestHarness { |
| 117 public: | 119 public: |
| 118 OneClickSigninSyncObserverTest() | 120 OneClickSigninSyncObserverTest() |
| 119 : sync_service_(NULL), | 121 : sync_service_(NULL), |
| 120 sync_observer_(NULL), | 122 sync_observer_(NULL), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 144 web_contents(), GURL(url), | 146 web_contents(), GURL(url), |
| 145 base::Bind(&OneClickSigninSyncObserverTest::OnSyncObserverDestroyed, | 147 base::Bind(&OneClickSigninSyncObserverTest::OnSyncObserverDestroyed, |
| 146 base::Unretained(this))); | 148 base::Unretained(this))); |
| 147 if (sync_service_) | 149 if (sync_service_) |
| 148 EXPECT_TRUE(sync_service_->HasObserver(sync_observer_)); | 150 EXPECT_TRUE(sync_service_->HasObserver(sync_observer_)); |
| 149 EXPECT_TRUE(sync_observer_destroyed_); | 151 EXPECT_TRUE(sync_observer_destroyed_); |
| 150 sync_observer_destroyed_ = false; | 152 sync_observer_destroyed_ = false; |
| 151 } | 153 } |
| 152 | 154 |
| 153 OneClickTestProfileSyncService* sync_service_; | 155 OneClickTestProfileSyncService* sync_service_; |
| 154 scoped_ptr<MockWebContentsObserver> web_contents_observer_; | 156 std::unique_ptr<MockWebContentsObserver> web_contents_observer_; |
| 155 | 157 |
| 156 private: | 158 private: |
| 157 void OnSyncObserverDestroyed(TestOneClickSigninSyncObserver* observer) { | 159 void OnSyncObserverDestroyed(TestOneClickSigninSyncObserver* observer) { |
| 158 EXPECT_EQ(sync_observer_, observer); | 160 EXPECT_EQ(sync_observer_, observer); |
| 159 EXPECT_FALSE(sync_observer_destroyed_); | 161 EXPECT_FALSE(sync_observer_destroyed_); |
| 160 sync_observer_destroyed_ = true; | 162 sync_observer_destroyed_ = true; |
| 161 } | 163 } |
| 162 | 164 |
| 163 TestOneClickSigninSyncObserver* sync_observer_; | 165 TestOneClickSigninSyncObserver* sync_observer_; |
| 164 bool sync_observer_destroyed_; | 166 bool sync_observer_destroyed_; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, false); | 249 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, false); |
| 248 CreateSyncObserver(continue_url.spec()); | 250 CreateSyncObserver(continue_url.spec()); |
| 249 sync_service_->set_first_setup_in_progress(false); | 251 sync_service_->set_first_setup_in_progress(false); |
| 250 sync_service_->set_sync_active(true); | 252 sync_service_->set_sync_active(true); |
| 251 | 253 |
| 252 EXPECT_CALL(*web_contents_observer_, | 254 EXPECT_CALL(*web_contents_observer_, |
| 253 DidStartNavigationToPendingEntry(_, _)).Times(0); | 255 DidStartNavigationToPendingEntry(_, _)).Times(0); |
| 254 sync_service_->NotifyObservers(); | 256 sync_service_->NotifyObservers(); |
| 255 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL()); | 257 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL()); |
| 256 } | 258 } |
| OLD | NEW |