OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/sync/engine/download_updates_command.h" | 5 #include "chrome/browser/sync/engine/download_updates_command.h" |
6 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 6 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
7 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 7 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
8 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 8 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
9 #include "chrome/browser/sync/protocol/sync.pb.h" | 9 #include "chrome/browser/sync/protocol/sync.pb.h" |
10 #include "chrome/browser/sync/syncable/directory_manager.h" | 10 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 11 #include "chrome/browser/sync/test/engine/fake_model_worker.h" |
11 #include "chrome/browser/sync/test/engine/proto_extension_validator.h" | 12 #include "chrome/browser/sync/test/engine/proto_extension_validator.h" |
12 #include "chrome/browser/sync/test/engine/syncer_command_test.h" | 13 #include "chrome/browser/sync/test/engine/syncer_command_test.h" |
13 | 14 |
14 using ::testing::_; | 15 using ::testing::_; |
15 namespace browser_sync { | 16 namespace browser_sync { |
16 | 17 |
17 using syncable::FIRST_REAL_MODEL_TYPE; | 18 using syncable::FIRST_REAL_MODEL_TYPE; |
18 using syncable::MODEL_TYPE_COUNT; | 19 using syncable::MODEL_TYPE_COUNT; |
19 | 20 |
20 // A test fixture for tests exercising DownloadUpdatesCommandTest. | 21 // A test fixture for tests exercising DownloadUpdatesCommandTest. |
21 class DownloadUpdatesCommandTest : public SyncerCommandTest { | 22 class DownloadUpdatesCommandTest : public SyncerCommandTest { |
22 protected: | 23 protected: |
23 DownloadUpdatesCommandTest() {} | 24 DownloadUpdatesCommandTest() {} |
24 | 25 |
25 virtual void SetUp() { | 26 virtual void SetUp() { |
26 workers()->clear(); | 27 workers()->clear(); |
27 mutable_routing_info()->clear(); | 28 mutable_routing_info()->clear(); |
28 // GROUP_PASSIVE worker. | 29 workers()->push_back( |
29 workers()->push_back(make_scoped_refptr(new ModelSafeWorker())); | 30 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 31 workers()->push_back( |
| 32 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 33 (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_DB; |
| 34 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI; |
| 35 (*mutable_routing_info())[syncable::PREFERENCES] = GROUP_UI; |
30 SyncerCommandTest::SetUp(); | 36 SyncerCommandTest::SetUp(); |
31 } | 37 } |
32 | 38 |
33 virtual void SetRoutingInfo(const syncable::ModelTypeSet& types) { | 39 DownloadUpdatesCommand command_; |
34 for (syncable::ModelTypeSet::const_iterator iter = types.begin(); | |
35 iter != types.end(); ++iter) { | |
36 (*mutable_routing_info())[*iter] = GROUP_PASSIVE; | |
37 } | |
38 } | |
39 | 40 |
40 DownloadUpdatesCommand command_; | |
41 private: | 41 private: |
42 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesCommandTest); | 42 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesCommandTest); |
43 }; | 43 }; |
44 | 44 |
45 TEST_F(DownloadUpdatesCommandTest, SetRequestedTypes) { | 45 TEST_F(DownloadUpdatesCommandTest, SetRequestedTypes) { |
46 { | 46 { |
47 SCOPED_TRACE("Several enabled datatypes, spread out across groups."); | 47 SCOPED_TRACE("Several enabled datatypes, spread out across groups."); |
48 syncable::ModelTypeBitSet enabled_types; | 48 syncable::ModelTypeBitSet enabled_types; |
49 enabled_types[syncable::BOOKMARKS] = true; | 49 enabled_types[syncable::BOOKMARKS] = true; |
50 enabled_types[syncable::AUTOFILL] = true; | 50 enabled_types[syncable::AUTOFILL] = true; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 sync_pb::EntitySpecifics get_updates_filter; | 99 sync_pb::EntitySpecifics get_updates_filter; |
100 command_.SetRequestedTypes(enabled_types, &get_updates_filter); | 100 command_.SetRequestedTypes(enabled_types, &get_updates_filter); |
101 ProtoExtensionValidator<sync_pb::EntitySpecifics> v(get_updates_filter); | 101 ProtoExtensionValidator<sync_pb::EntitySpecifics> v(get_updates_filter); |
102 v.ExpectHasExtension(sync_pb::preference); | 102 v.ExpectHasExtension(sync_pb::preference); |
103 v.ExpectNoOtherFieldsOrExtensions(); | 103 v.ExpectNoOtherFieldsOrExtensions(); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 TEST_F(DownloadUpdatesCommandTest, ExecuteNoPayloads) { | 107 TEST_F(DownloadUpdatesCommandTest, ExecuteNoPayloads) { |
108 ConfigureMockServerConnection(); | 108 ConfigureMockServerConnection(); |
109 | 109 mock_server()->ExpectGetUpdatesRequestTypes( |
110 syncable::ModelTypeSet types; | 110 ModelTypeBitSetFromSet(GetRoutingInfoTypes(routing_info()))); |
111 types.insert(syncable::AUTOFILL); | |
112 types.insert(syncable::BOOKMARKS); | |
113 types.insert(syncable::PREFERENCES); | |
114 SetRoutingInfo(types); | |
115 mock_server()->ExpectGetUpdatesRequestTypes(ModelTypeBitSetFromSet(types)); | |
116 command_.ExecuteImpl(session()); | 111 command_.ExecuteImpl(session()); |
117 } | 112 } |
118 | 113 |
119 TEST_F(DownloadUpdatesCommandTest, ExecuteWithPayloads) { | 114 TEST_F(DownloadUpdatesCommandTest, ExecuteWithPayloads) { |
120 ConfigureMockServerConnection(); | 115 ConfigureMockServerConnection(); |
121 | |
122 syncable::ModelTypeSet types; | |
123 types.insert(syncable::AUTOFILL); | |
124 types.insert(syncable::BOOKMARKS); | |
125 types.insert(syncable::PREFERENCES); | |
126 SetRoutingInfo(types); | |
127 sessions::SyncSourceInfo source; | 116 sessions::SyncSourceInfo source; |
128 source.types[syncable::AUTOFILL] = "autofill_payload"; | 117 source.types[syncable::AUTOFILL] = "autofill_payload"; |
129 source.types[syncable::BOOKMARKS] = "bookmark_payload"; | 118 source.types[syncable::BOOKMARKS] = "bookmark_payload"; |
130 source.types[syncable::PREFERENCES] = "preferences_payload"; | 119 source.types[syncable::PREFERENCES] = "preferences_payload"; |
131 mock_server()->ExpectGetUpdatesRequestTypes(ModelTypeBitSetFromSet(types)); | 120 mock_server()->ExpectGetUpdatesRequestTypes( |
| 121 ModelTypeBitSetFromSet(GetRoutingInfoTypes(routing_info()))); |
132 mock_server()->ExpectGetUpdatesRequestPayloads(source.types); | 122 mock_server()->ExpectGetUpdatesRequestPayloads(source.types); |
133 command_.ExecuteImpl(session(source)); | 123 command_.ExecuteImpl(session(source)); |
134 } | 124 } |
135 | 125 |
136 TEST_F(DownloadUpdatesCommandTest, VerifyAppendDebugInfo) { | 126 TEST_F(DownloadUpdatesCommandTest, VerifyAppendDebugInfo) { |
137 sync_pb::DebugInfo debug_info; | 127 sync_pb::DebugInfo debug_info; |
138 EXPECT_CALL(*(mock_debug_info_getter()), GetAndClearDebugInfo(_)) | 128 EXPECT_CALL(*(mock_debug_info_getter()), GetAndClearDebugInfo(_)) |
139 .Times(1); | 129 .Times(1); |
140 command_.AppendClientDebugInfoIfNeeded(session(), &debug_info); | 130 command_.AppendClientDebugInfoIfNeeded(session(), &debug_info); |
141 | 131 |
142 // Now try to add it once more and make sure |GetAndClearDebugInfo| is not | 132 // Now try to add it once more and make sure |GetAndClearDebugInfo| is not |
143 // called. | 133 // called. |
144 command_.AppendClientDebugInfoIfNeeded(session(), &debug_info); | 134 command_.AppendClientDebugInfoIfNeeded(session(), &debug_info); |
145 } | 135 } |
146 | 136 |
147 } // namespace browser_sync | 137 } // namespace browser_sync |
OLD | NEW |