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

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

Issue 14667013: sync: Better iteration in GenericChangeProcessor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes Created 7 years, 7 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
« no previous file with comments | « chrome/browser/sync/glue/generic_change_processor.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/glue/generic_change_processor.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h"
10 #include "base/stringprintf.h"
11 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h"
12 #include "sync/api/fake_syncable_service.h"
13 #include "sync/api/sync_merge_result.h"
14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/read_node.h"
16 #include "sync/internal_api/public/test/test_user_share.h"
17 #include "sync/internal_api/public/user_share.h"
18 #include "sync/internal_api/public/write_node.h"
19 #include "sync/internal_api/public/write_transaction.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace browser_sync {
23
24 namespace {
25
26 class GenericChangeProcessorTest : public testing::Test {
27 public:
28 // It doesn't matter which type we use. Just pick one.
29 static const syncer::ModelType kType = syncer::PREFERENCES;
30
31 GenericChangeProcessorTest() :
32 loop(base::MessageLoop::TYPE_UI),
33 sync_merge_result_(kType),
34 merge_result_ptr_factory_(&sync_merge_result_),
35 syncable_service_ptr_factory_(&fake_syncable_service_) {
36 }
37
38 virtual void SetUp() OVERRIDE {
39 test_user_share_.SetUp();
40 syncer::TestUserShare::CreateRoot(kType, test_user_share_.user_share());
41 change_processor_.reset(
42 new GenericChangeProcessor(
43 &data_type_error_handler_,
44 syncable_service_ptr_factory_.GetWeakPtr(),
45 merge_result_ptr_factory_.GetWeakPtr(),
46 test_user_share_.user_share()));
47 }
48
49 virtual void TearDown() OVERRIDE {
50 test_user_share_.TearDown();
51 }
52
53 void BuildChildNodes(int n) {
54 syncer::WriteTransaction trans(FROM_HERE, user_share());
55 syncer::ReadNode root(&trans);
56 ASSERT_EQ(syncer::BaseNode::INIT_OK,
57 root.InitByTagLookup(syncer::ModelTypeToRootTag(kType)));
58 for (int i = 0; i < n; ++i) {
59 syncer::WriteNode node(&trans);
60 node.InitUniqueByCreation(kType, root, base::StringPrintf("node%05d", i));
61 }
62 }
63
64 GenericChangeProcessor* change_processor() {
65 return change_processor_.get();
66 }
67
68 syncer::UserShare* user_share() {
69 return test_user_share_.user_share();
70 }
71
72 private:
73 MessageLoop loop;
74
75 syncer::SyncMergeResult sync_merge_result_;
76 base::WeakPtrFactory<syncer::SyncMergeResult> merge_result_ptr_factory_;
77
78 syncer::FakeSyncableService fake_syncable_service_;
79 base::WeakPtrFactory<syncer::FakeSyncableService>
80 syncable_service_ptr_factory_;
81
82 DataTypeErrorHandlerMock data_type_error_handler_;
83 syncer::TestUserShare test_user_share_;
84
85 scoped_ptr<GenericChangeProcessor> change_processor_;
86 };
87
88 // This test exercises GenericChangeProcessor's GetSyncDataForType function.
89 // It's not a great test, but, by modifying some of the parameters, you could
90 // turn it into a micro-benchmark for model association.
91 TEST_F(GenericChangeProcessorTest, StressGetSyncDataForType) {
92 const int kNumChildNodes = 1000;
93 const int kRepeatCount = 1;
94
95 ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kNumChildNodes));
96
97 for (int i = 0; i < kRepeatCount; ++i) {
98 syncer::SyncDataList sync_data;
99 change_processor()->GetSyncDataForType(kType, &sync_data);
100
101 // Start with a simple test. We can add more in-depth testing later.
102 EXPECT_EQ(static_cast<size_t>(kNumChildNodes), sync_data.size());
103 }
104 }
105
106 } // namespace
107
108 } // namespace browser_sync
109
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/generic_change_processor.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698