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

Side by Side Diff: components/sync/model_impl/processor_entity_tracker_unittest.cc

Issue 2915763005: [Sync] Implement support for updating storage key for new entities (Closed)
Patch Set: Rebase. Fix recommit for encryption scenario. Created 3 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
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 "components/sync/model_impl/processor_entity_tracker.h" 5 #include "components/sync/model_impl/processor_entity_tracker.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/sync/base/model_type.h" 10 #include "components/sync/base/model_type.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // properly intialized and flags properly set. Anything more complicated would 100 // properly intialized and flags properly set. Anything more complicated would
101 // be a redundant and incomplete version of the SharedModelTypeProcessor tests. 101 // be a redundant and incomplete version of the SharedModelTypeProcessor tests.
102 class ProcessorEntityTrackerTest : public ::testing::Test { 102 class ProcessorEntityTrackerTest : public ::testing::Test {
103 public: 103 public:
104 ProcessorEntityTrackerTest() 104 ProcessorEntityTrackerTest()
105 : ctime_(base::Time::Now() - base::TimeDelta::FromSeconds(1)) {} 105 : ctime_(base::Time::Now() - base::TimeDelta::FromSeconds(1)) {}
106 106
107 std::unique_ptr<ProcessorEntityTracker> CreateNew() { 107 std::unique_ptr<ProcessorEntityTracker> CreateNew() {
108 return ProcessorEntityTracker::CreateNew(kKey, kHash, "", ctime_); 108 return ProcessorEntityTracker::CreateNew(kKey, kHash, "", ctime_);
109 } 109 }
110 std::unique_ptr<ProcessorEntityTracker> CreateNewWithEmptyStorageKey() {
111 return ProcessorEntityTracker::CreateNew("", kHash, "", ctime_);
112 }
110 113
111 std::unique_ptr<ProcessorEntityTracker> CreateSynced() { 114 std::unique_ptr<ProcessorEntityTracker> CreateSynced() {
112 std::unique_ptr<ProcessorEntityTracker> entity = CreateNew(); 115 std::unique_ptr<ProcessorEntityTracker> entity = CreateNew();
113 entity->RecordAcceptedUpdate( 116 entity->RecordAcceptedUpdate(
114 GenerateUpdate(*entity, kHash, kId, kName, kValue1, ctime_, 1)); 117 GenerateUpdate(*entity, kHash, kId, kName, kValue1, ctime_, 1));
115 DCHECK(!entity->IsUnsynced()); 118 DCHECK(!entity->IsUnsynced());
116 return entity; 119 return entity;
117 } 120 }
118 121
119 const base::Time ctime_; 122 const base::Time ctime_;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 EXPECT_FALSE(entity->IsUnsynced()); 238 EXPECT_FALSE(entity->IsUnsynced());
236 EXPECT_FALSE(entity->RequiresCommitRequest()); 239 EXPECT_FALSE(entity->RequiresCommitRequest());
237 EXPECT_FALSE(entity->RequiresCommitData()); 240 EXPECT_FALSE(entity->RequiresCommitData());
238 EXPECT_FALSE(entity->CanClearMetadata()); 241 EXPECT_FALSE(entity->CanClearMetadata());
239 EXPECT_TRUE(entity->UpdateIsReflection(9)); 242 EXPECT_TRUE(entity->UpdateIsReflection(9));
240 EXPECT_TRUE(entity->UpdateIsReflection(10)); 243 EXPECT_TRUE(entity->UpdateIsReflection(10));
241 EXPECT_FALSE(entity->UpdateIsReflection(11)); 244 EXPECT_FALSE(entity->UpdateIsReflection(11));
242 EXPECT_FALSE(entity->HasCommitData()); 245 EXPECT_FALSE(entity->HasCommitData());
243 } 246 }
244 247
248 // Test creating tracker for new server item with empty storage key, applying
249 // update and updating storage key.
250 TEST_F(ProcessorEntityTrackerTest, NewServerItem_EmptyStorageKey) {
251 std::unique_ptr<ProcessorEntityTracker> entity =
252 CreateNewWithEmptyStorageKey();
253
254 EXPECT_EQ("", entity->storage_key());
255
256 const base::Time mtime = base::Time::Now();
257 entity->RecordAcceptedUpdate(
258 GenerateUpdate(*entity, kHash, kId, kName, kValue1, mtime, 10));
259 entity->SetStorageKey(kKey);
260 EXPECT_EQ(kKey, entity->storage_key());
261 }
262
245 // Test state for a tombstone received for a previously unknown item. 263 // Test state for a tombstone received for a previously unknown item.
246 TEST_F(ProcessorEntityTrackerTest, NewServerTombstone) { 264 TEST_F(ProcessorEntityTrackerTest, NewServerTombstone) {
247 std::unique_ptr<ProcessorEntityTracker> entity = CreateNew(); 265 std::unique_ptr<ProcessorEntityTracker> entity = CreateNew();
248 266
249 const base::Time mtime = base::Time::Now(); 267 const base::Time mtime = base::Time::Now();
250 entity->RecordAcceptedUpdate( 268 entity->RecordAcceptedUpdate(
251 GenerateTombstone(*entity, kHash, kId, kName, mtime, 1)); 269 GenerateTombstone(*entity, kHash, kId, kName, mtime, 1));
252 270
253 EXPECT_EQ(kId, entity->metadata().server_id()); 271 EXPECT_EQ(kId, entity->metadata().server_id());
254 EXPECT_TRUE(entity->metadata().is_deleted()); 272 EXPECT_TRUE(entity->metadata().is_deleted());
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 EXPECT_EQ("", entity->metadata().base_specifics_hash()); 492 EXPECT_EQ("", entity->metadata().base_specifics_hash());
475 493
476 EXPECT_FALSE(entity->IsUnsynced()); 494 EXPECT_FALSE(entity->IsUnsynced());
477 EXPECT_FALSE(entity->RequiresCommitRequest()); 495 EXPECT_FALSE(entity->RequiresCommitRequest());
478 EXPECT_FALSE(entity->RequiresCommitData()); 496 EXPECT_FALSE(entity->RequiresCommitData());
479 EXPECT_FALSE(entity->CanClearMetadata()); 497 EXPECT_FALSE(entity->CanClearMetadata());
480 EXPECT_FALSE(entity->HasCommitData()); 498 EXPECT_FALSE(entity->HasCommitData());
481 } 499 }
482 500
483 } // namespace syncer 501 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/model_impl/processor_entity_tracker.cc ('k') | components/sync/model_impl/shared_model_type_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698