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

Side by Side Diff: chrome/browser/sync/glue/synced_device_tracker_unittest.cc

Issue 332923002: [sync] Add backup time in synced device info so that server can flag device (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check db on DB thread Created 6 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "chrome/browser/sync/glue/device_info.h" 12 #include "chrome/browser/sync/glue/device_info.h"
13 #include "chrome/browser/sync/glue/synced_device_tracker.h" 13 #include "chrome/browser/sync/glue/synced_device_tracker.h"
14 #include "sync/internal_api/public/base/model_type.h" 14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/test/test_user_share.h" 15 #include "sync/internal_api/public/test/test_user_share.h"
16 #include "sync/protocol/sync.pb.h" 16 #include "sync/protocol/sync.pb.h"
17 #include "sync/syncable/directory.h" 17 #include "sync/syncable/directory.h"
18 #include "sync/test/test_transaction_observer.h" 18 #include "sync/test/test_transaction_observer.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 namespace {
24
25 void ConvertDeviceInfoSpecifics(
26 const DeviceInfo& device_info,
27 sync_pb::DeviceInfoSpecifics* specifics) {
28 specifics->set_cache_guid(device_info.guid());
29 specifics->set_client_name(device_info.client_name());
30 specifics->set_chrome_version(device_info.chrome_version());
31 specifics->set_sync_user_agent(device_info.sync_user_agent());
32 specifics->set_device_type(device_info.device_type());
33 }
34
35 } // namespace
36
37 class SyncedDeviceTrackerTest : public ::testing::Test { 23 class SyncedDeviceTrackerTest : public ::testing::Test {
38 protected: 24 protected:
39 SyncedDeviceTrackerTest() : transaction_count_baseline_(0) { } 25 SyncedDeviceTrackerTest() : transaction_count_baseline_(0) { }
40 virtual ~SyncedDeviceTrackerTest() { } 26 virtual ~SyncedDeviceTrackerTest() { }
41 27
42 virtual void SetUp() { 28 virtual void SetUp() {
43 test_user_share_.SetUp(); 29 test_user_share_.SetUp();
44 syncer::TestUserShare::CreateRoot(syncer::DEVICE_INFO, user_share()); 30 syncer::TestUserShare::CreateRoot(syncer::DEVICE_INFO, user_share());
45 31
46 synced_device_tracker_.reset( 32 synced_device_tracker_.reset(
(...skipping 15 matching lines...) Expand all
62 syncer::UserShare* user_share() { 48 syncer::UserShare* user_share() {
63 return test_user_share_.user_share(); 49 return test_user_share_.user_share();
64 } 50 }
65 51
66 // Expose the private method to our tests. 52 // Expose the private method to our tests.
67 void WriteLocalDeviceInfo(const DeviceInfo& info) { 53 void WriteLocalDeviceInfo(const DeviceInfo& info) {
68 synced_device_tracker_->WriteLocalDeviceInfo(info); 54 synced_device_tracker_->WriteLocalDeviceInfo(info);
69 } 55 }
70 56
71 void WriteDeviceInfo(const DeviceInfo& device_info) { 57 void WriteDeviceInfo(const DeviceInfo& device_info) {
72 sync_pb::DeviceInfoSpecifics specifics; 58 synced_device_tracker_->WriteDeviceInfo(device_info, device_info.guid());
73 ConvertDeviceInfoSpecifics(device_info, &specifics);
74 synced_device_tracker_->WriteDeviceInfo(specifics, device_info.guid());
75 } 59 }
76 60
77 void ResetObservedChangesCounter() { 61 void ResetObservedChangesCounter() {
78 transaction_count_baseline_ = GetTotalTransactionsCount(); 62 transaction_count_baseline_ = GetTotalTransactionsCount();
79 } 63 }
80 64
81 int GetObservedChangesCounter() { 65 int GetObservedChangesCounter() {
82 return GetTotalTransactionsCount() - transaction_count_baseline_; 66 return GetTotalTransactionsCount() - transaction_count_baseline_;
83 } 67 }
84 68
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 WriteDeviceInfo(device_info2); 185 WriteDeviceInfo(device_info2);
202 186
203 ScopedVector<DeviceInfo> device_info; 187 ScopedVector<DeviceInfo> device_info;
204 synced_device_tracker_->GetAllSyncedDeviceInfo(&device_info); 188 synced_device_tracker_->GetAllSyncedDeviceInfo(&device_info);
205 189
206 EXPECT_EQ(device_info.size(), 2U); 190 EXPECT_EQ(device_info.size(), 2U);
207 EXPECT_TRUE(device_info[0]->Equals(device_info1)); 191 EXPECT_TRUE(device_info[0]->Equals(device_info1));
208 EXPECT_TRUE(device_info[1]->Equals(device_info2)); 192 EXPECT_TRUE(device_info[1]->Equals(device_info2));
209 } 193 }
210 194
195 TEST_F(SyncedDeviceTrackerTest, DeviceBackupTime) {
196 DeviceInfo device_info(
197 user_share()->directory->cache_guid(),
198 "John’s Device", "XYZ v1", "XYZ SyncAgent v1",
199 sync_pb::SyncEnums_DeviceType_TYPE_LINUX);
200 const base::Time test_backup_time =
201 base::Time::UnixEpoch() + base::TimeDelta::FromDays(10000);
202
203 WriteLocalDeviceInfo(device_info);
204 synced_device_tracker_->UpdateLocalDeviceBackupTime(test_backup_time);
205
206 // Verify read of device info and backup time.
207 EXPECT_EQ(test_backup_time,
208 synced_device_tracker_->GetLocalDeviceBackupTime());
209 scoped_ptr<DeviceInfo> device_info_out(
210 synced_device_tracker_->ReadLocalDeviceInfo());
211 ASSERT_TRUE(device_info_out);
212 EXPECT_TRUE(device_info.Equals(*device_info_out.get()));
213
214 // Verify backup time is not lost after updating device info.
215 DeviceInfo device_info2(
216 user_share()->directory->cache_guid(),
217 "def Device", "XYZ v2", "XYZ SyncAgent v2",
218 sync_pb::SyncEnums_DeviceType_TYPE_LINUX);
219 WriteLocalDeviceInfo(device_info2);
220 EXPECT_EQ(test_backup_time,
221 synced_device_tracker_->GetLocalDeviceBackupTime());
222 }
223
211 } // namespace 224 } // namespace
212 225
213 } // namespace browser_sync 226 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/synced_device_tracker.cc ('k') | chrome/browser/sync/profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698