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

Side by Side Diff: components/sync_driver/local_device_info_provider_unittest.cc

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "components/sync/base/get_session_name.h"
9 #include "components/sync_driver/local_device_info_provider_impl.h"
10 #include "components/version_info/version_info.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using sync_driver::DeviceInfo;
14 using sync_driver::LocalDeviceInfoProvider;
15
16 namespace browser_sync {
17
18 const char kLocalDeviceGuid[] = "foo";
19 const char kSigninScopedDeviceId[] = "device_id";
20
21 class LocalDeviceInfoProviderTest : public testing::Test {
22 public:
23 LocalDeviceInfoProviderTest() : called_back_(false) {}
24 ~LocalDeviceInfoProviderTest() override {}
25
26 void SetUp() override {
27 provider_.reset(new LocalDeviceInfoProviderImpl(
28 version_info::Channel::UNKNOWN,
29 version_info::GetVersionStringWithModifier("UNKNOWN"), false));
30 }
31
32 void TearDown() override {
33 provider_.reset();
34 called_back_ = false;
35 }
36
37 protected:
38 void StartInitializeProvider() { StartInitializeProvider(kLocalDeviceGuid); }
39
40 void StartInitializeProvider(const std::string& guid) {
41 provider_->Initialize(guid, kSigninScopedDeviceId,
42 message_loop_.task_runner());
43 }
44
45 void FinishInitializeProvider() {
46 // Subscribe to the notification and wait until the callback
47 // is called. The callback will quit the loop.
48 base::RunLoop run_loop;
49 std::unique_ptr<LocalDeviceInfoProvider::Subscription> subscription =
50 provider_->RegisterOnInitializedCallback(
51 base::Bind(&LocalDeviceInfoProviderTest::QuitLoopOnInitialized,
52 base::Unretained(this), &run_loop));
53 run_loop.Run();
54 }
55
56 void InitializeProvider() {
57 StartInitializeProvider();
58 FinishInitializeProvider();
59 }
60
61 void QuitLoopOnInitialized(base::RunLoop* loop) {
62 called_back_ = true;
63 loop->Quit();
64 }
65
66 std::unique_ptr<LocalDeviceInfoProviderImpl> provider_;
67
68 bool called_back_;
69
70 private:
71 base::MessageLoop message_loop_;
72 };
73
74 TEST_F(LocalDeviceInfoProviderTest, OnInitializedCallback) {
75 ASSERT_FALSE(called_back_);
76 StartInitializeProvider();
77 ASSERT_FALSE(called_back_);
78 FinishInitializeProvider();
79 EXPECT_TRUE(called_back_);
80 }
81
82 TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) {
83 ASSERT_EQ(nullptr, provider_->GetLocalDeviceInfo());
84 StartInitializeProvider();
85 ASSERT_EQ(nullptr, provider_->GetLocalDeviceInfo());
86 FinishInitializeProvider();
87
88 const DeviceInfo* local_device_info = provider_->GetLocalDeviceInfo();
89 ASSERT_NE(nullptr, local_device_info);
90 EXPECT_EQ(std::string(kLocalDeviceGuid), local_device_info->guid());
91 EXPECT_EQ(std::string(kSigninScopedDeviceId),
92 local_device_info->signin_scoped_device_id());
93 EXPECT_EQ(syncer::GetSessionNameSynchronouslyForTesting(),
94 local_device_info->client_name());
95
96 EXPECT_EQ(provider_->GetSyncUserAgent(),
97 local_device_info->sync_user_agent());
98
99 provider_->Clear();
100 ASSERT_EQ(nullptr, provider_->GetLocalDeviceInfo());
101 }
102
103 TEST_F(LocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) {
104 EXPECT_TRUE(provider_->GetLocalSyncCacheGUID().empty());
105
106 StartInitializeProvider();
107 EXPECT_EQ(std::string(kLocalDeviceGuid), provider_->GetLocalSyncCacheGUID());
108
109 FinishInitializeProvider();
110 EXPECT_EQ(std::string(kLocalDeviceGuid), provider_->GetLocalSyncCacheGUID());
111
112 provider_->Clear();
113 EXPECT_TRUE(provider_->GetLocalSyncCacheGUID().empty());
114 }
115
116 TEST_F(LocalDeviceInfoProviderTest, InitClearRace) {
117 EXPECT_TRUE(provider_->GetLocalSyncCacheGUID().empty());
118 StartInitializeProvider();
119
120 provider_->Clear();
121 ASSERT_EQ(nullptr, provider_->GetLocalDeviceInfo());
122 EXPECT_TRUE(provider_->GetLocalSyncCacheGUID().empty());
123
124 base::RunLoop().RunUntilIdle();
125 ASSERT_EQ(nullptr, provider_->GetLocalDeviceInfo());
126 EXPECT_TRUE(provider_->GetLocalSyncCacheGUID().empty());
127 }
128
129 TEST_F(LocalDeviceInfoProviderTest, InitClearInitRace) {
130 EXPECT_TRUE(provider_->GetLocalSyncCacheGUID().empty());
131 StartInitializeProvider();
132 provider_->Clear();
133
134 const std::string guid2 = "guid2";
135 StartInitializeProvider(guid2);
136 ASSERT_EQ(nullptr, provider_->GetLocalDeviceInfo());
137 EXPECT_EQ(guid2, provider_->GetLocalSyncCacheGUID());
138
139 FinishInitializeProvider();
140 const DeviceInfo* local_device_info = provider_->GetLocalDeviceInfo();
141 ASSERT_NE(nullptr, local_device_info);
142 EXPECT_EQ(guid2, local_device_info->guid());
143 EXPECT_EQ(guid2, provider_->GetLocalSyncCacheGUID());
144 }
145
146 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_driver/local_device_info_provider_mock.cc ('k') | components/sync_driver/model_association_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698