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 "base/basictypes.h" 6 #include "base/compiler_specific.h" 7 #include "base/memory/ref_counted.h" 8 #include "sync/engine/model_changing_syncer_command.h" 9 #include "sync/internal_api/public/base/model_type.h" 10 #include "sync/sessions/sync_session.h" 11 #include "sync/test/engine/fake_model_worker.h" 12 #include "sync/test/engine/syncer_command_test.h" 13 #include "testing/gtest/include/gtest/gtest.h" 14 15 namespace syncer { 16 17 namespace { 18 19 class FakeModelChangingSyncerCommand : public ModelChangingSyncerCommand { 20 public: 21 FakeModelChangingSyncerCommand() {} 22 virtual ~FakeModelChangingSyncerCommand() {} 23 24 const std::set<ModelSafeGroup>& changed_groups() const { 25 return changed_groups_; 26 } 27 28 protected: 29 virtual std::set<ModelSafeGroup> GetGroupsToChange( 30 const sessions::SyncSession& session) const OVERRIDE { 31 // This command doesn't actually make changes, so the empty set might be an 32 // appropriate response. That would not be very interesting, so instead we 33 // return the set of groups with active types. 34 std::set<ModelSafeGroup> enabled_groups; 35 const ModelSafeRoutingInfo& routing_info = 36 session.context()->routing_info(); 37 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); 38 it != routing_info.end(); ++it) { 39 enabled_groups.insert(it->second); 40 } 41 enabled_groups.insert(GROUP_PASSIVE); 42 return enabled_groups; 43 } 44 45 virtual SyncerError ModelChangingExecuteImpl( 46 sessions::SyncSession* session) OVERRIDE { 47 changed_groups_.insert(session->status_controller().group_restriction()); 48 return SYNCER_OK; 49 } 50 51 private: 52 std::set<ModelSafeGroup> changed_groups_; 53 54 DISALLOW_COPY_AND_ASSIGN(FakeModelChangingSyncerCommand); 55 }; 56 57 class ModelChangingSyncerCommandTest : public SyncerCommandTest { 58 protected: 59 ModelChangingSyncerCommandTest() {} 60 virtual ~ModelChangingSyncerCommandTest() {} 61 62 virtual void SetUp() { 63 workers()->push_back( 64 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); 65 workers()->push_back( 66 make_scoped_refptr(new FakeModelWorker(GROUP_PASSWORD))); 67 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; 68 (*mutable_routing_info())[PASSWORDS] = GROUP_PASSWORD; 69 SyncerCommandTest::SetUp(); 70 } 71 72 FakeModelChangingSyncerCommand command_; 73 74 private: 75 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommandTest); 76 }; 77 78 TEST_F(ModelChangingSyncerCommandTest, Basic) { 79 ExpectGroupsToChange(command_, GROUP_UI, GROUP_PASSWORD, GROUP_PASSIVE); 80 EXPECT_TRUE(command_.changed_groups().empty()); 81 command_.ExecuteImpl(session()); 82 EXPECT_EQ(command_.GetGroupsToChangeForTest(*session()), 83 command_.changed_groups()); 84 } 85 86 } // namespace 87 88 } // namespace syncer 89