Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_sync_observer_unittest.cc

Issue 2354613002: [Sync] Fix namespaces for the browser_sync component. (Closed)
Patch Set: Address comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 virtual ~MockWebContentsObserver() {} 42 virtual ~MockWebContentsObserver() {}
43 43
44 // A hook to verify that the OneClickSigninSyncObserver initiated a redirect 44 // A hook to verify that the OneClickSigninSyncObserver initiated a redirect
45 // to the continue URL. Navigations in unit_tests never complete, but a 45 // to the continue URL. Navigations in unit_tests never complete, but a
46 // navigation start is a sufficient signal for the purposes of this test. 46 // navigation start is a sufficient signal for the purposes of this test.
47 // Listening for this call also has the advantage of being synchronous. 47 // Listening for this call also has the advantage of being synchronous.
48 MOCK_METHOD2(DidStartNavigationToPendingEntry, 48 MOCK_METHOD2(DidStartNavigationToPendingEntry,
49 void(const GURL&, content::ReloadType)); 49 void(const GURL&, content::ReloadType));
50 }; 50 };
51 51
52 class OneClickTestProfileSyncService : public TestProfileSyncService { 52 class OneClickTestProfileSyncService
53 : public browser_sync::TestProfileSyncService {
53 public: 54 public:
54 ~OneClickTestProfileSyncService() override {} 55 ~OneClickTestProfileSyncService() override {}
55 56
56 // Helper routine to be used in conjunction with 57 // Helper routine to be used in conjunction with
57 // BrowserContextKeyedServiceFactory::SetTestingFactory(). 58 // BrowserContextKeyedServiceFactory::SetTestingFactory().
58 static std::unique_ptr<KeyedService> Build(content::BrowserContext* profile) { 59 static std::unique_ptr<KeyedService> Build(content::BrowserContext* profile) {
59 return base::WrapUnique(new OneClickTestProfileSyncService( 60 return base::WrapUnique(new OneClickTestProfileSyncService(
60 CreateProfileSyncServiceParamsForTest( 61 CreateProfileSyncServiceParamsForTest(
61 Profile::FromBrowserContext(profile)))); 62 Profile::FromBrowserContext(profile))));
62 } 63 }
63 64
64 bool IsFirstSetupInProgress() const override { 65 bool IsFirstSetupInProgress() const override {
65 return first_setup_in_progress_; 66 return first_setup_in_progress_;
66 } 67 }
67 68
68 bool IsSyncActive() const override { return sync_active_; } 69 bool IsSyncActive() const override { return sync_active_; }
69 70
70 void set_first_setup_in_progress(bool in_progress) { 71 void set_first_setup_in_progress(bool in_progress) {
71 first_setup_in_progress_ = in_progress; 72 first_setup_in_progress_ = in_progress;
72 } 73 }
73 74
74 void set_sync_active(bool active) { 75 void set_sync_active(bool active) {
75 sync_active_ = active; 76 sync_active_ = active;
76 } 77 }
77 78
78 private: 79 private:
79 explicit OneClickTestProfileSyncService( 80 explicit OneClickTestProfileSyncService(InitParams init_params)
80 ProfileSyncService::InitParams init_params) 81 : browser_sync::TestProfileSyncService(std::move(init_params)),
81 : TestProfileSyncService(std::move(init_params)),
82 first_setup_in_progress_(false), 82 first_setup_in_progress_(false),
83 sync_active_(false) {} 83 sync_active_(false) {}
84 84
85 bool first_setup_in_progress_; 85 bool first_setup_in_progress_;
86 bool sync_active_; 86 bool sync_active_;
87 87
88 DISALLOW_COPY_AND_ASSIGN(OneClickTestProfileSyncService); 88 DISALLOW_COPY_AND_ASSIGN(OneClickTestProfileSyncService);
89 }; 89 };
90 90
91 class TestOneClickSigninSyncObserver : public OneClickSigninSyncObserver { 91 class TestOneClickSigninSyncObserver : public OneClickSigninSyncObserver {
(...skipping 27 matching lines...) Expand all
119 class OneClickSigninSyncObserverTest : public ChromeRenderViewHostTestHarness { 119 class OneClickSigninSyncObserverTest : public ChromeRenderViewHostTestHarness {
120 public: 120 public:
121 OneClickSigninSyncObserverTest() 121 OneClickSigninSyncObserverTest()
122 : sync_service_(NULL), 122 : sync_service_(NULL),
123 sync_observer_(NULL), 123 sync_observer_(NULL),
124 sync_observer_destroyed_(true) {} 124 sync_observer_destroyed_(true) {}
125 125
126 void SetUp() override { 126 void SetUp() override {
127 ChromeRenderViewHostTestHarness::SetUp(); 127 ChromeRenderViewHostTestHarness::SetUp();
128 web_contents_observer_.reset(new MockWebContentsObserver(web_contents())); 128 web_contents_observer_.reset(new MockWebContentsObserver(web_contents()));
129 sync_service_ = 129 sync_service_ = static_cast<OneClickTestProfileSyncService*>(
130 static_cast<OneClickTestProfileSyncService*>( 130 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
131 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 131 profile(), OneClickTestProfileSyncService::Build));
132 profile(), OneClickTestProfileSyncService::Build));
133 } 132 }
134 133
135 void TearDown() override { 134 void TearDown() override {
136 // Verify that the |sync_observer_| unregistered as an observer from the 135 // Verify that the |sync_observer_| unregistered as an observer from the
137 // sync service and freed its memory. 136 // sync service and freed its memory.
138 EXPECT_TRUE(sync_observer_destroyed_); 137 EXPECT_TRUE(sync_observer_destroyed_);
139 if (sync_service_) 138 if (sync_service_)
140 EXPECT_FALSE(sync_service_->HasObserver(sync_observer_)); 139 EXPECT_FALSE(sync_service_->HasObserver(sync_observer_));
141 ChromeRenderViewHostTestHarness::TearDown(); 140 ChromeRenderViewHostTestHarness::TearDown();
142 } 141 }
(...skipping 23 matching lines...) Expand all
166 TestOneClickSigninSyncObserver* sync_observer_; 165 TestOneClickSigninSyncObserver* sync_observer_;
167 bool sync_observer_destroyed_; 166 bool sync_observer_destroyed_;
168 167
169 DISALLOW_COPY_AND_ASSIGN(OneClickSigninSyncObserverTest); 168 DISALLOW_COPY_AND_ASSIGN(OneClickSigninSyncObserverTest);
170 }; 169 };
171 170
172 // Verify that if no Sync service is present, e.g. because Sync is disabled, the 171 // Verify that if no Sync service is present, e.g. because Sync is disabled, the
173 // observer immediately loads the continue URL. 172 // observer immediately loads the continue URL.
174 TEST_F(OneClickSigninSyncObserverTest, NoSyncService_RedirectsImmediately) { 173 TEST_F(OneClickSigninSyncObserverTest, NoSyncService_RedirectsImmediately) {
175 // Simulate disabling Sync. 174 // Simulate disabling Sync.
176 sync_service_ = 175 sync_service_ = static_cast<OneClickTestProfileSyncService*>(
177 static_cast<OneClickTestProfileSyncService*>( 176 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
178 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 177 profile(), BuildNullService));
179 profile(), BuildNullService));
180 178
181 // The observer should immediately redirect to the continue URL. 179 // The observer should immediately redirect to the continue URL.
182 EXPECT_CALL(*web_contents_observer_, DidStartNavigationToPendingEntry(_, _)); 180 EXPECT_CALL(*web_contents_observer_, DidStartNavigationToPendingEntry(_, _));
183 CreateSyncObserver(kContinueUrl); 181 CreateSyncObserver(kContinueUrl);
184 EXPECT_EQ(GURL(kContinueUrl), web_contents()->GetVisibleURL()); 182 EXPECT_EQ(GURL(kContinueUrl), web_contents()->GetVisibleURL());
185 183
186 // The |sync_observer_| will be destroyed asynchronously, so manually pump 184 // The |sync_observer_| will be destroyed asynchronously, so manually pump
187 // the message loop to wait for the destruction. 185 // the message loop to wait for the destruction.
188 content::RunAllPendingInMessageLoop(); 186 content::RunAllPendingInMessageLoop();
189 } 187 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, false); 248 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, false);
251 CreateSyncObserver(continue_url.spec()); 249 CreateSyncObserver(continue_url.spec());
252 sync_service_->set_first_setup_in_progress(false); 250 sync_service_->set_first_setup_in_progress(false);
253 sync_service_->set_sync_active(true); 251 sync_service_->set_sync_active(true);
254 252
255 EXPECT_CALL(*web_contents_observer_, 253 EXPECT_CALL(*web_contents_observer_,
256 DidStartNavigationToPendingEntry(_, _)).Times(0); 254 DidStartNavigationToPendingEntry(_, _)).Times(0);
257 sync_service_->NotifyObservers(); 255 sync_service_->NotifyObservers();
258 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL()); 256 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL());
259 } 257 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_sync_observer.cc ('k') | chrome/browser/ui/sync/one_click_signin_sync_starter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698