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

Side by Side Diff: chrome/browser/sync/startup_controller_unittest.cc

Issue 195873020: [Sync] Move SyncPrefs into sync_driver component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rerererebase Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/startup_controller.cc ('k') | chrome/browser/sync/sync_policy_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/sync/startup_controller.h" 5 #include "chrome/browser/sync/startup_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/defaults.h" 11 #include "chrome/browser/defaults.h"
12 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" 12 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
13 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 13 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
14 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" 14 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
16 #include "chrome/browser/sync/sync_prefs.h"
17 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
18 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "components/sync_driver/sync_prefs.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 namespace browser_sync { 21 namespace browser_sync {
22 22
23 static const char kTestUser[] = "test@gmail.com"; 23 static const char kTestUser[] = "test@gmail.com";
24 static const char kTestToken[] = "testToken"; 24 static const char kTestToken[] = "testToken";
25 25
26 // These are coupled to the implementation of StartupController's 26 // These are coupled to the implementation of StartupController's
27 // GetBackendInitializationStateString which is used by about:sync. We use it 27 // GetBackendInitializationStateString which is used by about:sync. We use it
28 // as a convenient way to verify internal state and that the class is 28 // as a convenient way to verify internal state and that the class is
(...skipping 20 matching lines...) Expand all
49 private: 49 private:
50 std::string account_; 50 std::string account_;
51 }; 51 };
52 52
53 class StartupControllerTest : public testing::Test { 53 class StartupControllerTest : public testing::Test {
54 public: 54 public:
55 StartupControllerTest() : started_(false) {} 55 StartupControllerTest() : started_(false) {}
56 56
57 virtual void SetUp() OVERRIDE { 57 virtual void SetUp() OVERRIDE {
58 profile_.reset(new TestingProfile()); 58 profile_.reset(new TestingProfile());
59 sync_prefs_.reset(new SyncPrefs(profile_->GetPrefs())); 59 sync_prefs_.reset(new sync_driver::SyncPrefs(profile_->GetPrefs()));
60 token_service_.reset( 60 token_service_.reset(
61 static_cast<FakeProfileOAuth2TokenServiceWrapper*>( 61 static_cast<FakeProfileOAuth2TokenServiceWrapper*>(
62 FakeProfileOAuth2TokenServiceWrapper::Build(profile_.get()))); 62 FakeProfileOAuth2TokenServiceWrapper::Build(profile_.get())));
63 signin_.reset(new FakeManagedUserSigninManagerWrapper()); 63 signin_.reset(new FakeManagedUserSigninManagerWrapper());
64 64
65 ProfileSyncServiceStartBehavior behavior = 65 ProfileSyncServiceStartBehavior behavior =
66 browser_defaults::kSyncAutoStarts ? AUTO_START : MANUAL_START; 66 browser_defaults::kSyncAutoStarts ? AUTO_START : MANUAL_START;
67 base::Closure fake_start_backend = base::Bind( 67 base::Closure fake_start_backend = base::Bind(
68 &StartupControllerTest::FakeStartBackend, base::Unretained(this)); 68 &StartupControllerTest::FakeStartBackend, base::Unretained(this));
69 controller_.reset(new StartupController(behavior, token_service(), 69 controller_.reset(new StartupController(behavior, token_service(),
(...skipping 17 matching lines...) Expand all
87 } 87 }
88 88
89 bool started() const { return started_; } 89 bool started() const { return started_; }
90 void clear_started() { started_ = false; } 90 void clear_started() { started_ = false; }
91 StartupController* controller() { return controller_.get(); } 91 StartupController* controller() { return controller_.get(); }
92 FakeManagedUserSigninManagerWrapper* signin() { return signin_.get(); } 92 FakeManagedUserSigninManagerWrapper* signin() { return signin_.get(); }
93 FakeProfileOAuth2TokenService* token_service() { 93 FakeProfileOAuth2TokenService* token_service() {
94 return static_cast<FakeProfileOAuth2TokenService*>( 94 return static_cast<FakeProfileOAuth2TokenService*>(
95 token_service_->GetProfileOAuth2TokenService()); 95 token_service_->GetProfileOAuth2TokenService());
96 } 96 }
97 SyncPrefs* sync_prefs() { return sync_prefs_.get(); } 97 sync_driver::SyncPrefs* sync_prefs() { return sync_prefs_.get(); }
98 Profile* profile() { return profile_.get(); } 98 Profile* profile() { return profile_.get(); }
99 99
100 private: 100 private:
101 bool started_; 101 bool started_;
102 base::MessageLoop message_loop_; 102 base::MessageLoop message_loop_;
103 scoped_ptr<StartupController> controller_; 103 scoped_ptr<StartupController> controller_;
104 scoped_ptr<FakeManagedUserSigninManagerWrapper> signin_; 104 scoped_ptr<FakeManagedUserSigninManagerWrapper> signin_;
105 scoped_ptr<FakeProfileOAuth2TokenServiceWrapper> token_service_; 105 scoped_ptr<FakeProfileOAuth2TokenServiceWrapper> token_service_;
106 scoped_ptr<SyncPrefs> sync_prefs_; 106 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_;
107 scoped_ptr<TestingProfile> profile_; 107 scoped_ptr<TestingProfile> profile_;
108 }; 108 };
109 109
110 // Test that sync doesn't start until all conditions are met. 110 // Test that sync doesn't start until all conditions are met.
111 TEST_F(StartupControllerTest, Basic) { 111 TEST_F(StartupControllerTest, Basic) {
112 controller()->TryStart(); 112 controller()->TryStart();
113 EXPECT_FALSE(started()); 113 EXPECT_FALSE(started());
114 sync_prefs()->SetSyncSetupCompleted(); 114 sync_prefs()->SetSyncSetupCompleted();
115 controller()->TryStart(); 115 controller()->TryStart();
116 EXPECT_FALSE(started()); 116 EXPECT_FALSE(started());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 controller()->TryStart(); 258 controller()->TryStart();
259 259
260 if (!browser_defaults::kSyncAutoStarts) { 260 if (!browser_defaults::kSyncAutoStarts) {
261 EXPECT_FALSE(started()); 261 EXPECT_FALSE(started());
262 EXPECT_EQ(kStateStringNotStarted, 262 EXPECT_EQ(kStateStringNotStarted,
263 controller()->GetBackendInitializationStateString()); 263 controller()->GetBackendInitializationStateString());
264 } 264 }
265 } 265 }
266 266
267 } // namespace browser_sync 267 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/startup_controller.cc ('k') | chrome/browser/sync/sync_policy_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698