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

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: Undo unnecessary change 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
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 class GenericChangeProcessorTest : public testing::Test {
Nicolas Zea 2013/05/22 22:34:02 put in anon namespace?
rlarocque 2013/05/23 00:39:39 Done.
25 public:
26 // It doesn't matter which type we use. Just pick one.
27 static const syncer::ModelType kType = syncer::PREFERENCES;
28
29 GenericChangeProcessorTest() :
30 loop(base::MessageLoop::TYPE_UI),
31 sync_merge_result_(kType),
32 merge_result_ptr_factory_(&sync_merge_result_),
33 syncable_service_ptr_factory_(&fake_syncable_service_) {
34 }
35
36 virtual void SetUp() OVERRIDE {
37 test_user_share_.SetUp();
38 syncer::TestUserShare::CreateRoot(kType, test_user_share_.user_share());
39 change_processor_.reset(
40 new GenericChangeProcessor(
41 &data_type_error_handler_,
42 syncable_service_ptr_factory_.GetWeakPtr(),
43 merge_result_ptr_factory_.GetWeakPtr(),
44 test_user_share_.user_share()));
45 }
46
47 virtual void TearDown() OVERRIDE {
48 test_user_share_.TearDown();
49 }
50
51 void BuildChildNodes(int n) {
52 syncer::WriteTransaction trans(FROM_HERE, user_share());
53 syncer::ReadNode root(&trans);
54 EXPECT_EQ(syncer::BaseNode::INIT_OK,
Nicolas Zea 2013/05/22 22:34:02 ASSERT_EQ?
rlarocque 2013/05/23 00:39:39 Done.
55 root.InitByTagLookup(syncer::ModelTypeToRootTag(kType)));
56 for (int i = 0; i < n; ++i) {
57 syncer::WriteNode node(&trans);
58 node.InitUniqueByCreation(kType, root, base::StringPrintf("node%05d", i));
59 }
60 }
61
62 GenericChangeProcessor* change_processor() {
63 return change_processor_.get();
64 }
65
66 syncer::UserShare* user_share() {
67 return test_user_share_.user_share();
68 }
69
70 private:
71 MessageLoop loop;
72
73 syncer::SyncMergeResult sync_merge_result_;
74 base::WeakPtrFactory<syncer::SyncMergeResult> merge_result_ptr_factory_;
75
76 syncer::FakeSyncableService fake_syncable_service_;
77 base::WeakPtrFactory<syncer::FakeSyncableService>
78 syncable_service_ptr_factory_;
79
80 DataTypeErrorHandlerMock data_type_error_handler_;
81 syncer::TestUserShare test_user_share_;
82
83 scoped_ptr<GenericChangeProcessor> change_processor_;
84 };
85
86 // This test exercises GenericChangeProcessor's GetSyncDataForType function.
87 // It's not a great test, but, by modifying some of the parameters, you could
88 // turn it into a micro-benchmark for model association.
89 TEST_F(GenericChangeProcessorTest, StressGetSyncDataForType) {
90 const int kNumChildNodes = 1000;
91 const int kRepeatCount = 1;
92
93 BuildChildNodes(kNumChildNodes);
94
95 for (int i = 0; i < kRepeatCount; ++i) {
96 syncer::SyncDataList sync_data;
97 change_processor()->GetSyncDataForType(kType, &sync_data);
98
99 // Start with a simple test. We can add more in-depth testing later.
100 EXPECT_EQ(static_cast<size_t>(kNumChildNodes), sync_data.size());
101 }
102 }
103
104 } // namespace browser_sync
105
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698