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.
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"
19 class FakeModelChangingSyncerCommand
: public ModelChangingSyncerCommand
{
21 FakeModelChangingSyncerCommand() {}
22 virtual ~FakeModelChangingSyncerCommand() {}
24 const std::set
<ModelSafeGroup
>& changed_groups() const {
25 return changed_groups_
;
29 virtual std::set
<ModelSafeGroup
> GetGroupsToChange(
30 const sessions::SyncSession
& session
) const OVERRIDE
{
31 return session
.GetEnabledGroups();
34 virtual SyncerError
ModelChangingExecuteImpl(
35 sessions::SyncSession
* session
) OVERRIDE
{
36 changed_groups_
.insert(session
->status_controller().group_restriction());
41 std::set
<ModelSafeGroup
> changed_groups_
;
43 DISALLOW_COPY_AND_ASSIGN(FakeModelChangingSyncerCommand
);
46 class ModelChangingSyncerCommandTest
: public SyncerCommandTest
{
48 ModelChangingSyncerCommandTest() {}
49 virtual ~ModelChangingSyncerCommandTest() {}
51 virtual void SetUp() {
53 make_scoped_refptr(new FakeModelWorker(GROUP_UI
)));
55 make_scoped_refptr(new FakeModelWorker(GROUP_PASSWORD
)));
56 (*mutable_routing_info())[BOOKMARKS
] = GROUP_UI
;
57 (*mutable_routing_info())[PASSWORDS
] = GROUP_PASSWORD
;
58 SyncerCommandTest::SetUp();
61 FakeModelChangingSyncerCommand command_
;
64 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommandTest
);
67 TEST_F(ModelChangingSyncerCommandTest
, Basic
) {
68 ExpectGroupsToChange(command_
, GROUP_UI
, GROUP_PASSWORD
, GROUP_PASSIVE
);
69 EXPECT_TRUE(command_
.changed_groups().empty());
70 command_
.ExecuteImpl(session());
71 EXPECT_EQ(command_
.GetGroupsToChangeForTest(*session()),
72 command_
.changed_groups());