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

Side by Side Diff: components/sync/engine_impl/model_type_worker_unittest.cc

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 years, 2 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/engine_impl/model_type_worker.h" 5 #include "components/sync/engine_impl/model_type_worker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "components/sync/base/fake_encryptor.h" 15 #include "components/sync/base/fake_encryptor.h"
16 #include "components/sync/base/model_type.h" 16 #include "components/sync/base/model_type.h"
17 #include "components/sync/core/model_type_processor.h" 17 #include "components/sync/core/model_type_processor.h"
18 #include "components/sync/core/non_blocking_sync_common.h" 18 #include "components/sync/core/non_blocking_sync_common.h"
19 #include "components/sync/engine_impl/commit_contribution.h" 19 #include "components/sync/engine_impl/commit_contribution.h"
20 #include "components/sync/engine_impl/cycle/status_controller.h" 20 #include "components/sync/engine_impl/cycle/status_controller.h"
21 #include "components/sync/protocol/data_type_state.pb.h" 21 #include "components/sync/protocol/data_type_state.pb.h"
22 #include "components/sync/protocol/sync.pb.h" 22 #include "components/sync/protocol/sync.pb.h"
23 #include "components/sync/syncable/syncable_util.h" 23 #include "components/sync/syncable/syncable_util.h"
24 #include "components/sync/test/engine/mock_model_type_processor.h" 24 #include "components/sync/test/engine/mock_model_type_processor.h"
25 #include "components/sync/test/engine/mock_nudge_handler.h" 25 #include "components/sync/test/engine/mock_nudge_handler.h"
26 #include "components/sync/test/engine/single_type_mock_server.h" 26 #include "components/sync/test/engine/single_type_mock_server.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 namespace syncer { 29 using syncer::Cryptographer;
30 using syncer::CommitContribution;
31 using syncer::KeyParams;
32 using syncer::Nigori;
33 using syncer::StatusController;
34
35 namespace syncer_v2 {
30 36
31 namespace { 37 namespace {
32 38
33 // Special constant value taken from cryptographer.cc. 39 // Special constant value taken from cryptographer.cc.
34 const char kNigoriKeyName[] = "nigori-key"; 40 const char kNigoriKeyName[] = "nigori-key";
35 41
36 const ModelType kModelType = PREFERENCES; 42 const syncer::ModelType kModelType = syncer::PREFERENCES;
37 43
38 std::string GenerateTagHash(const std::string& tag) { 44 std::string GenerateTagHash(const std::string& tag) {
39 return syncable::GenerateSyncableHash(kModelType, tag); 45 return syncer::syncable::GenerateSyncableHash(kModelType, tag);
40 } 46 }
41 47
42 const char kTag1[] = "tag1"; 48 const char kTag1[] = "tag1";
43 const char kTag2[] = "tag2"; 49 const char kTag2[] = "tag2";
44 const char kTag3[] = "tag3"; 50 const char kTag3[] = "tag3";
45 const char kValue1[] = "value1"; 51 const char kValue1[] = "value1";
46 const char kValue2[] = "value2"; 52 const char kValue2[] = "value2";
47 const char kValue3[] = "value3"; 53 const char kValue3[] = "value3";
48 const std::string kHash1(GenerateTagHash(kTag1)); 54 const std::string kHash1(GenerateTagHash(kTag1));
49 const std::string kHash2(GenerateTagHash(kTag2)); 55 const std::string kHash2(GenerateTagHash(kTag2));
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // in use. See also: UpdateLocalCryptographer(). 426 // in use. See also: UpdateLocalCryptographer().
421 std::string GetLocalCryptographerKeyName() const { 427 std::string GetLocalCryptographerKeyName() const {
422 if (!cryptographer_) { 428 if (!cryptographer_) {
423 return std::string(); 429 return std::string();
424 } 430 }
425 return cryptographer_->GetDefaultNigoriKeyName(); 431 return cryptographer_->GetDefaultNigoriKeyName();
426 } 432 }
427 433
428 MockModelTypeProcessor* processor() { return mock_type_processor_; } 434 MockModelTypeProcessor* processor() { return mock_type_processor_; }
429 ModelTypeWorker* worker() { return worker_.get(); } 435 ModelTypeWorker* worker() { return worker_.get(); }
430 SingleTypeMockServer* server() { return &mock_server_; } 436 syncer::SingleTypeMockServer* server() { return &mock_server_; }
431 437
432 private: 438 private:
433 // An encryptor for our cryptographer. 439 // An encryptor for our cryptographer.
434 FakeEncryptor fake_encryptor_; 440 syncer::FakeEncryptor fake_encryptor_;
435 441
436 // The cryptographer itself. Null if we're not encrypting the type. 442 // The cryptographer itself. Null if we're not encrypting the type.
437 std::unique_ptr<Cryptographer> cryptographer_; 443 std::unique_ptr<Cryptographer> cryptographer_;
438 444
439 // The number of the most recent foreign encryption key known to our 445 // The number of the most recent foreign encryption key known to our
440 // cryptographer. Note that not all of these will be decryptable. 446 // cryptographer. Note that not all of these will be decryptable.
441 int foreign_encryption_key_index_; 447 int foreign_encryption_key_index_;
442 448
443 // The number of the encryption key used to encrypt incoming updates. A zero 449 // The number of the encryption key used to encrypt incoming updates. A zero
444 // value implies no encryption. 450 // value implies no encryption.
445 int update_encryption_filter_index_; 451 int update_encryption_filter_index_;
446 452
447 // The ModelTypeWorker being tested. 453 // The ModelTypeWorker being tested.
448 std::unique_ptr<ModelTypeWorker> worker_; 454 std::unique_ptr<ModelTypeWorker> worker_;
449 455
450 // Non-owned, possibly null pointer. This object belongs to the 456 // Non-owned, possibly null pointer. This object belongs to the
451 // ModelTypeWorker under test. 457 // ModelTypeWorker under test.
452 MockModelTypeProcessor* mock_type_processor_; 458 MockModelTypeProcessor* mock_type_processor_;
453 459
454 // A mock that emulates enough of the sync server that it can be used 460 // A mock that emulates enough of the sync server that it can be used
455 // a single UpdateHandler and CommitContributor pair. In this test 461 // a single UpdateHandler and CommitContributor pair. In this test
456 // harness, the |worker_| is both of them. 462 // harness, the |worker_| is both of them.
457 SingleTypeMockServer mock_server_; 463 syncer::SingleTypeMockServer mock_server_;
458 464
459 // A mock to track the number of times the CommitQueue requests to 465 // A mock to track the number of times the CommitQueue requests to
460 // sync. 466 // sync.
461 MockNudgeHandler mock_nudge_handler_; 467 syncer::MockNudgeHandler mock_nudge_handler_;
462 468
463 bool is_processor_disconnected_; 469 bool is_processor_disconnected_;
464 }; 470 };
465 471
466 // Requests a commit and verifies the messages sent to the client and server as 472 // Requests a commit and verifies the messages sent to the client and server as
467 // a result. 473 // a result.
468 // 474 //
469 // This test performs sanity checks on most of the fields in these messages. 475 // This test performs sanity checks on most of the fields in these messages.
470 // For the most part this is checking that the test code behaves as expected 476 // For the most part this is checking that the test code behaves as expected
471 // and the |worker_| doesn't mess up its simple task of moving around these 477 // and the |worker_| doesn't mess up its simple task of moving around these
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 EXPECT_EQ(1, server()->GetNthCommitMessage(1).commit().entries_size()); 550 EXPECT_EQ(1, server()->GetNthCommitMessage(1).commit().entries_size());
545 ASSERT_TRUE(server()->HasCommitEntity(kHash1)); 551 ASSERT_TRUE(server()->HasCommitEntity(kHash1));
546 const sync_pb::SyncEntity& entity = server()->GetLastCommittedEntity(kHash1); 552 const sync_pb::SyncEntity& entity = server()->GetLastCommittedEntity(kHash1);
547 EXPECT_FALSE(entity.id_string().empty()); 553 EXPECT_FALSE(entity.id_string().empty());
548 EXPECT_EQ(GenerateTagHash(kTag1), entity.client_defined_unique_tag()); 554 EXPECT_EQ(GenerateTagHash(kTag1), entity.client_defined_unique_tag());
549 EXPECT_EQ(base_version, entity.version()); 555 EXPECT_EQ(base_version, entity.version());
550 EXPECT_TRUE(entity.deleted()); 556 EXPECT_TRUE(entity.deleted());
551 557
552 // Deletions should contain enough specifics to identify the type. 558 // Deletions should contain enough specifics to identify the type.
553 EXPECT_TRUE(entity.has_specifics()); 559 EXPECT_TRUE(entity.has_specifics());
554 EXPECT_EQ(kModelType, GetModelTypeFromSpecifics(entity.specifics())); 560 EXPECT_EQ(kModelType, syncer::GetModelTypeFromSpecifics(entity.specifics()));
555 561
556 // Verify the commit response returned to the model thread. 562 // Verify the commit response returned to the model thread.
557 ASSERT_EQ(2U, processor()->GetNumCommitResponses()); 563 ASSERT_EQ(2U, processor()->GetNumCommitResponses());
558 EXPECT_EQ(1U, processor()->GetNthCommitResponse(1).size()); 564 EXPECT_EQ(1U, processor()->GetNthCommitResponse(1).size());
559 ASSERT_TRUE(processor()->HasCommitResponse(kHash1)); 565 ASSERT_TRUE(processor()->HasCommitResponse(kHash1));
560 const CommitResponseData& commit_response = 566 const CommitResponseData& commit_response =
561 processor()->GetCommitResponse(kHash1); 567 processor()->GetCommitResponse(kHash1);
562 568
563 EXPECT_EQ(entity.id_string(), commit_response.id); 569 EXPECT_EQ(entity.id_string(), commit_response.id);
564 EXPECT_EQ(entity.client_defined_unique_tag(), 570 EXPECT_EQ(entity.client_defined_unique_tag(),
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 // Test that processor has been disconnected from Sync when worker got 1028 // Test that processor has been disconnected from Sync when worker got
1023 // disconnected. 1029 // disconnected.
1024 TEST_F(ModelTypeWorkerTest, DisconnectProcessorFromSyncTest) { 1030 TEST_F(ModelTypeWorkerTest, DisconnectProcessorFromSyncTest) {
1025 // Initialize the worker with basic state. 1031 // Initialize the worker with basic state.
1026 NormalInitialize(); 1032 NormalInitialize();
1027 EXPECT_FALSE(IsProcessorDisconnected()); 1033 EXPECT_FALSE(IsProcessorDisconnected());
1028 ResetWorker(); 1034 ResetWorker();
1029 EXPECT_TRUE(IsProcessorDisconnected()); 1035 EXPECT_TRUE(IsProcessorDisconnected());
1030 } 1036 }
1031 1037
1032 } // namespace syncer 1038 } // namespace syncer_v2
OLDNEW
« no previous file with comments | « components/sync/engine_impl/model_type_worker.cc ('k') | components/sync/engine_impl/non_blocking_type_commit_contribution.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698