OLD | NEW |
| (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 "base/basictypes.h" | |
6 #include "base/compiler_specific.h" | |
7 #include "base/memory/ref_counted.h" | |
8 #include "chrome/browser/sync/engine/model_changing_syncer_command.h" | |
9 #include "chrome/browser/sync/sessions/sync_session.h" | |
10 #include "chrome/browser/sync/syncable/model_type.h" | |
11 #include "chrome/browser/sync/test/engine/fake_model_worker.h" | |
12 #include "chrome/browser/sync/test/engine/syncer_command_test.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace browser_sync { | |
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 return session.GetEnabledGroups(); | |
32 } | |
33 | |
34 virtual SyncerError ModelChangingExecuteImpl( | |
35 sessions::SyncSession* session) OVERRIDE { | |
36 changed_groups_.insert(session->status_controller().group_restriction()); | |
37 return SYNCER_OK; | |
38 } | |
39 | |
40 private: | |
41 std::set<ModelSafeGroup> changed_groups_; | |
42 | |
43 DISALLOW_COPY_AND_ASSIGN(FakeModelChangingSyncerCommand); | |
44 }; | |
45 | |
46 class ModelChangingSyncerCommandTest : public SyncerCommandTest { | |
47 protected: | |
48 ModelChangingSyncerCommandTest() {} | |
49 virtual ~ModelChangingSyncerCommandTest() {} | |
50 | |
51 virtual void SetUp() { | |
52 workers()->push_back( | |
53 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | |
54 workers()->push_back( | |
55 make_scoped_refptr(new FakeModelWorker(GROUP_PASSWORD))); | |
56 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI; | |
57 (*mutable_routing_info())[syncable::PASSWORDS] = GROUP_PASSWORD; | |
58 SyncerCommandTest::SetUp(); | |
59 } | |
60 | |
61 FakeModelChangingSyncerCommand command_; | |
62 | |
63 private: | |
64 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommandTest); | |
65 }; | |
66 | |
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()); | |
73 } | |
74 | |
75 } // namespace | |
76 | |
77 } // namespace browser_sync | |
OLD | NEW |