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

Unified Diff: components/sync_driver/startup_controller_unittest.cc

Issue 1858673002: [Sync] Inject startup dependencies into StartupController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/sync_driver/startup_controller.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync_driver/startup_controller_unittest.cc
diff --git a/components/sync_driver/startup_controller_unittest.cc b/components/sync_driver/startup_controller_unittest.cc
index c6de60f1180d37cae812d768e8386ffd79c540ed..2c2207664c565c5ce47b26ec6f5fd6dac137dfa6 100644
--- a/components/sync_driver/startup_controller_unittest.cc
+++ b/components/sync_driver/startup_controller_unittest.cc
@@ -10,8 +10,6 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/time/time.h"
-#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
-#include "components/sync_driver/signin_manager_wrapper.h"
#include "components/sync_driver/sync_driver_switches.h"
#include "components/sync_driver/sync_prefs.h"
#include "components/syncable_prefs/testing_pref_service_syncable.h"
@@ -19,9 +17,6 @@
namespace browser_sync {
-static const char kTestUser[] = "test@gmail.com";
-static const char kTestToken[] = "testToken";
-
// These are coupled to the implementation of StartupController's
// GetBackendInitializationStateString which is used by about:sync. We use it
// as a convenient way to verify internal state and that the class is
@@ -30,54 +25,27 @@ static const char kStateStringStarted[] = "Started";
static const char kStateStringDeferred[] = "Deferred";
static const char kStateStringNotStarted[] = "Not started";
-class FakeSigninManagerWrapper : public SigninManagerWrapper {
- public:
- FakeSigninManagerWrapper() : SigninManagerWrapper(NULL) {}
- std::string GetEffectiveUsername() const override { return std::string(); }
-
- std::string GetAccountIdToUse() const override { return account_id_; }
-
- void set_account_id(const std::string& account_id) {
- account_id_ = account_id;
- }
-
- private:
- std::string account_id_;
-};
-
class StartupControllerTest : public testing::Test {
public:
- StartupControllerTest() : started_(false) {}
+ StartupControllerTest() : can_start_(false), started_(false) {}
void SetUp() override {
sync_driver::SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
sync_prefs_.reset(new sync_driver::SyncPrefs(&pref_service_));
- token_service_.reset(new FakeProfileOAuth2TokenService());
- signin_.reset(new FakeSigninManagerWrapper());
-
- SetUpController();
- }
-
- void TearDown() override {
- controller_.reset();
- signin_.reset();
- token_service_->Shutdown();
- token_service_.reset();
- sync_prefs_.reset();
- started_ = false;
- }
-
- void SetUpController() {
- started_ = false;
- base::Closure fake_start_backend = base::Bind(
- &StartupControllerTest::FakeStartBackend, base::Unretained(this));
- controller_.reset(new StartupController(token_service(), sync_prefs_.get(),
- signin_.get(), fake_start_backend));
+ controller_.reset(new StartupController(
+ sync_prefs_.get(),
+ base::Bind(&StartupControllerTest::CanStart, base::Unretained(this)),
+ base::Bind(&StartupControllerTest::FakeStartBackend,
+ base::Unretained(this))));
controller_->Reset(syncer::UserTypes());
controller_->OverrideFallbackTimeoutForTest(
base::TimeDelta::FromSeconds(0));
}
+ bool CanStart() { return can_start_; }
+
+ void SetCanStart(bool can_start) { can_start_ = can_start; }
+
void FakeStartBackend() {
started_ = true;
sync_prefs()->SetFirstSetupComplete();
@@ -107,20 +75,15 @@ class StartupControllerTest : public testing::Test {
bool started() const { return started_; }
void clear_started() { started_ = false; }
StartupController* controller() { return controller_.get(); }
- FakeSigninManagerWrapper* signin() { return signin_.get(); }
- FakeProfileOAuth2TokenService* token_service() {
- return token_service_.get();
- }
sync_driver::SyncPrefs* sync_prefs() { return sync_prefs_.get(); }
private:
+ bool can_start_;
bool started_;
base::MessageLoop message_loop_;
syncable_prefs::TestingPrefServiceSyncable pref_service_;
- scoped_ptr<StartupController> controller_;
- scoped_ptr<FakeSigninManagerWrapper> signin_;
- scoped_ptr<FakeProfileOAuth2TokenService> token_service_;
scoped_ptr<sync_driver::SyncPrefs> sync_prefs_;
+ scoped_ptr<StartupController> controller_;
};
// Test that sync doesn't start until all conditions are met.
@@ -128,45 +91,23 @@ TEST_F(StartupControllerTest, Basic) {
controller()->TryStart();
ExpectNotStarted();
- sync_prefs()->SetFirstSetupComplete();
- controller()->TryStart();
- ExpectNotStarted();
-
- signin()->set_account_id(kTestUser);
- controller()->TryStart();
- ExpectNotStarted();
-
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ SetCanStart(true);
controller()->TryStart();
- ExpectStartDeferred();
-}
-
-// Test that sync doesn't start when not requested even if all other
-// conditons are met.
-TEST_F(StartupControllerTest, NotRequested) {
- sync_prefs()->SetFirstSetupComplete();
- sync_prefs()->SetSyncRequested(false);
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
- controller()->TryStart();
- ExpectNotStarted();
+ ExpectStarted();
}
-// Test that sync doesn't when managed even if all other conditons are met.
-TEST_F(StartupControllerTest, Managed) {
+// Test that sync defers if first setup is complete.
+TEST_F(StartupControllerTest, DefersAfterFirstSetupComplete) {
sync_prefs()->SetFirstSetupComplete();
- sync_prefs()->SetManagedForTest(true);
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ SetCanStart(true);
controller()->TryStart();
- ExpectNotStarted();
+ ExpectStartDeferred();
}
// Test that a data type triggering startup starts sync immediately.
TEST_F(StartupControllerTest, NoDeferralDataTypeTrigger) {
sync_prefs()->SetFirstSetupComplete();
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ SetCanStart(true);
controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS);
ExpectStarted();
}
@@ -175,8 +116,7 @@ TEST_F(StartupControllerTest, NoDeferralDataTypeTrigger) {
// sync immediately.
TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) {
sync_prefs()->SetFirstSetupComplete();
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ SetCanStart(true);
controller()->TryStart();
ExpectStartDeferred();
@@ -194,8 +134,7 @@ TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) {
// conditions are met and no data type requests sync.
TEST_F(StartupControllerTest, FallbackTimer) {
sync_prefs()->SetFirstSetupComplete();
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ SetCanStart(true);
controller()->TryStart();
ExpectStartDeferred();
@@ -214,10 +153,9 @@ TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) {
sync_prefs()->SetKeepEverythingSynced(false);
sync_prefs()->SetPreferredDataTypes(syncer::UserTypes(), types);
controller()->Reset(syncer::UserTypes());
- sync_prefs()->SetFirstSetupComplete();
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ sync_prefs()->SetFirstSetupComplete();
+ SetCanStart(true);
controller()->TryStart();
ExpectStarted();
}
@@ -234,9 +172,7 @@ TEST_F(StartupControllerTest, FallbackTimerWaits) {
// Test that sync starts immediately when setup in progress is true.
TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) {
sync_prefs()->SetFirstSetupComplete();
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
-
+ SetCanStart(true);
controller()->SetSetupInProgress(true);
ExpectStarted();
}
@@ -245,8 +181,7 @@ TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) {
// and starts sync immediately.
TEST_F(StartupControllerTest, SetupInProgressTriggerInterruptsDeferral) {
sync_prefs()->SetFirstSetupComplete();
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ SetCanStart(true);
controller()->TryStart();
ExpectStartDeferred();
@@ -256,8 +191,7 @@ TEST_F(StartupControllerTest, SetupInProgressTriggerInterruptsDeferral) {
// Test that start isn't deferred on the first start but is on restarts.
TEST_F(StartupControllerTest, DeferralOnRestart) {
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ SetCanStart(true);
controller()->TryStart();
ExpectStarted();
@@ -270,8 +204,7 @@ TEST_F(StartupControllerTest, DeferralOnRestart) {
// Test that setup-in-progress tracking is persistent across a Reset.
TEST_F(StartupControllerTest, ResetDuringSetup) {
- signin()->set_account_id(kTestUser);
- token_service()->UpdateCredentials(kTestUser, kTestToken);
+ SetCanStart(true);
// Simulate UI telling us setup is in progress.
controller()->SetSetupInProgress(true);
« no previous file with comments | « components/sync_driver/startup_controller.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698