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

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

Issue 335273005: Rename "managed (mode|user)" to "supervised user" (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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
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/signin/fake_profile_oauth2_token_service.h" 12 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
13 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 13 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/sync/managed_user_signin_manager_wrapper.h" 15 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "components/sync_driver/sync_prefs.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
29 // outputting the correct values for the debug string. 29 // outputting the correct values for the debug string.
30 static const char kStateStringStarted[] = "Started"; 30 static const char kStateStringStarted[] = "Started";
31 static const char kStateStringDeferred[] = "Deferred"; 31 static const char kStateStringDeferred[] = "Deferred";
32 static const char kStateStringNotStarted[] = "Not started"; 32 static const char kStateStringNotStarted[] = "Not started";
33 33
34 class FakeManagedUserSigninManagerWrapper 34 class FakeSupervisedUserSigninManagerWrapper
35 : public ManagedUserSigninManagerWrapper { 35 : public SupervisedUserSigninManagerWrapper {
36 public: 36 public:
37 FakeManagedUserSigninManagerWrapper() 37 FakeSupervisedUserSigninManagerWrapper()
38 : ManagedUserSigninManagerWrapper(NULL, NULL) {} 38 : SupervisedUserSigninManagerWrapper(NULL, NULL) {}
39 virtual std::string GetEffectiveUsername() const OVERRIDE { 39 virtual std::string GetEffectiveUsername() const OVERRIDE {
40 return account_; 40 return account_;
41 } 41 }
42 42
43 virtual std::string GetAccountIdToUse() const OVERRIDE { 43 virtual std::string GetAccountIdToUse() const OVERRIDE {
44 return account_; 44 return account_;
45 } 45 }
46 46
47 void set_account(const std::string& account) { account_ = account; } 47 void set_account(const std::string& account) { account_ = account; }
48 48
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 sync_driver::SyncPrefs(profile_->GetPrefs())); 59 sync_prefs_.reset(new sync_driver::SyncPrefs(profile_->GetPrefs()));
60 token_service_.reset(static_cast<FakeProfileOAuth2TokenService*>( 60 token_service_.reset(static_cast<FakeProfileOAuth2TokenService*>(
61 BuildFakeProfileOAuth2TokenService(profile_.get()))); 61 BuildFakeProfileOAuth2TokenService(profile_.get())));
62 signin_.reset(new FakeManagedUserSigninManagerWrapper()); 62 signin_.reset(new FakeSupervisedUserSigninManagerWrapper());
63 63
64 ProfileSyncServiceStartBehavior behavior = 64 ProfileSyncServiceStartBehavior behavior =
65 browser_defaults::kSyncAutoStarts ? AUTO_START : MANUAL_START; 65 browser_defaults::kSyncAutoStarts ? AUTO_START : MANUAL_START;
66 base::Closure fake_start_backend = base::Bind( 66 base::Closure fake_start_backend = base::Bind(
67 &StartupControllerTest::FakeStartBackend, base::Unretained(this)); 67 &StartupControllerTest::FakeStartBackend, base::Unretained(this));
68 controller_.reset(new StartupController(behavior, token_service(), 68 controller_.reset(new StartupController(behavior, token_service(),
69 sync_prefs_.get(), signin_.get(), 69 sync_prefs_.get(), signin_.get(),
70 fake_start_backend)); 70 fake_start_backend));
71 controller_->Reset(syncer::UserTypes()); 71 controller_->Reset(syncer::UserTypes());
72 controller_->OverrideFallbackTimeoutForTest( 72 controller_->OverrideFallbackTimeoutForTest(
73 base::TimeDelta::FromSeconds(0)); 73 base::TimeDelta::FromSeconds(0));
74 } 74 }
75 75
76 virtual void TearDown() OVERRIDE { 76 virtual void TearDown() OVERRIDE {
77 controller_.reset(); 77 controller_.reset();
78 signin_.reset(); 78 signin_.reset();
79 token_service_->Shutdown(); 79 token_service_->Shutdown();
80 token_service_.reset(); 80 token_service_.reset();
81 sync_prefs_.reset(); 81 sync_prefs_.reset();
82 started_ = false; 82 started_ = false;
83 } 83 }
84 84
85 void FakeStartBackend() { 85 void FakeStartBackend() {
86 started_ = true; 86 started_ = true;
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 FakeSupervisedUserSigninManagerWrapper* signin() { return signin_.get(); }
93 FakeProfileOAuth2TokenService* token_service() { 93 FakeProfileOAuth2TokenService* token_service() {
94 return token_service_.get(); 94 return token_service_.get();
95 } 95 }
96 sync_driver::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } 96 sync_driver::SyncPrefs* sync_prefs() { return sync_prefs_.get(); }
97 Profile* profile() { return profile_.get(); } 97 Profile* profile() { return profile_.get(); }
98 98
99 private: 99 private:
100 bool started_; 100 bool started_;
101 base::MessageLoop message_loop_; 101 base::MessageLoop message_loop_;
102 scoped_ptr<StartupController> controller_; 102 scoped_ptr<StartupController> controller_;
103 scoped_ptr<FakeManagedUserSigninManagerWrapper> signin_; 103 scoped_ptr<FakeSupervisedUserSigninManagerWrapper> signin_;
104 scoped_ptr<FakeProfileOAuth2TokenService> token_service_; 104 scoped_ptr<FakeProfileOAuth2TokenService> token_service_;
105 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_; 105 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_;
106 scoped_ptr<TestingProfile> profile_; 106 scoped_ptr<TestingProfile> profile_;
107 }; 107 };
108 108
109 // Test that sync doesn't start until all conditions are met. 109 // Test that sync doesn't start until all conditions are met.
110 TEST_F(StartupControllerTest, Basic) { 110 TEST_F(StartupControllerTest, Basic) {
111 controller()->TryStart(); 111 controller()->TryStart();
112 EXPECT_FALSE(started()); 112 EXPECT_FALSE(started());
113 sync_prefs()->SetSyncSetupCompleted(); 113 sync_prefs()->SetSyncSetupCompleted();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 controller()->set_setup_in_progress(true); 256 controller()->set_setup_in_progress(true);
257 257
258 // This could happen if the UI triggers a stop-syncing permanently call. 258 // This could happen if the UI triggers a stop-syncing permanently call.
259 controller()->Reset(syncer::UserTypes()); 259 controller()->Reset(syncer::UserTypes());
260 260
261 // From the UI's point of view, setup is still in progress. 261 // From the UI's point of view, setup is still in progress.
262 EXPECT_TRUE(controller()->setup_in_progress()); 262 EXPECT_TRUE(controller()->setup_in_progress());
263 } 263 }
264 264
265 } // namespace browser_sync 265 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/startup_controller.cc ('k') | chrome/browser/sync/supervised_user_signin_manager_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698