1 // Copyright 2013 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 "sync/engine/download.h" 6 #include "sync/protocol/sync.pb.h" 7 #include "sync/sessions/nudge_tracker.h" 8 #include "sync/test/engine/fake_model_worker.h" 9 #include "sync/test/engine/syncer_command_test.h" 10 11 using ::testing::_; 12 13 namespace syncer { 14 15 // A test fixture for tests exercising download updates functions. 16 class DownloadUpdatesTest : public SyncerCommandTest { 17 protected: 18 DownloadUpdatesTest() { 19 } 20 21 virtual void SetUp() { 22 workers()->clear(); 23 mutable_routing_info()->clear(); 24 workers()->push_back( 25 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); 26 workers()->push_back( 27 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); 28 (*mutable_routing_info())[AUTOFILL] = GROUP_DB; 29 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; 30 (*mutable_routing_info())[PREFERENCES] = GROUP_UI; 31 SyncerCommandTest::SetUp(); 32 } 33 34 private: 35 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesTest); 36 }; 37 38 TEST_F(DownloadUpdatesTest, ExecuteNoStates) { 39 ConfigureMockServerConnection(); 40 41 sessions::NudgeTracker nudge_tracker; 42 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); 43 44 mock_server()->ExpectGetUpdatesRequestTypes( 45 GetRoutingInfoTypes(routing_info())); 46 scoped_ptr<sessions::SyncSession> session( 47 sessions::SyncSession::Build(context(), 48 delegate())); 49 NormalDownloadUpdates(session.get(), 50 false, 51 GetRoutingInfoTypes(routing_info()), 52 nudge_tracker); 53 } 54 55 TEST_F(DownloadUpdatesTest, ExecuteWithStates) { 56 ConfigureMockServerConnection(); 57 58 sessions::NudgeTracker nudge_tracker; 59 nudge_tracker.RecordRemoteInvalidation( 60 ModelTypeSetToInvalidationMap(ModelTypeSet(AUTOFILL), 61 "autofill_payload")); 62 nudge_tracker.RecordRemoteInvalidation( 63 ModelTypeSetToInvalidationMap(ModelTypeSet(BOOKMARKS), 64 "bookmark_payload")); 65 nudge_tracker.RecordRemoteInvalidation( 66 ModelTypeSetToInvalidationMap(ModelTypeSet(PREFERENCES), 67 "preferences_payload")); 68 69 ModelTypeInvalidationMap invalidation_map; 70 Invalidation i1; 71 i1.payload = "autofill_payload"; 72 invalidation_map.insert(std::make_pair(AUTOFILL, i1)); 73 Invalidation i2; 74 i2.payload = "bookmark_payload"; 75 invalidation_map.insert(std::make_pair(BOOKMARKS, i2)); 76 Invalidation i3; 77 i3.payload = "preferences_payload"; 78 invalidation_map.insert(std::make_pair(PREFERENCES, i3)); 79 80 mock_server()->ExpectGetUpdatesRequestTypes( 81 GetRoutingInfoTypes(routing_info())); 82 mock_server()->ExpectGetUpdatesRequestStates( 83 invalidation_map); 84 scoped_ptr<sessions::SyncSession> session( 85 sessions::SyncSession::Build(context(), delegate())); 86 NormalDownloadUpdates(session.get(), 87 false, 88 GetRoutingInfoTypes(routing_info()), 89 nudge_tracker); 90 } 91 92 TEST_F(DownloadUpdatesTest, VerifyAppendDebugInfo) { 93 sync_pb::DebugInfo debug_info; 94 EXPECT_CALL(*(mock_debug_info_getter()), GetAndClearDebugInfo(_)) 95 .Times(1); 96 // The first of a set of repeated GUs will set it. 97 AppendClientDebugInfoIfNeeded(session(), &debug_info); 98 99 // Subsequent GUs will not. 100 // Verify by checking that GetAndClearDebugInfo() is not called again. 101 AppendClientDebugInfoIfNeeded(session(), &debug_info); 102 } 103 104 } // namespace syncer 105