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

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

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