OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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/memory/ref_counted.h" | |
7 #include "chrome/browser/sync/engine/model_changing_syncer_command.h" | |
8 #include "chrome/browser/sync/sessions/sync_session.h" | |
9 #include "chrome/browser/sync/syncable/model_type.h" | |
10 #include "chrome/browser/sync/test/engine/fake_model_worker.h" | |
11 #include "chrome/browser/sync/test/engine/syncer_command_test.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace browser_sync { | |
15 | |
16 namespace { | |
17 | |
18 class FakeModelChangingSyncerCommand : public ModelChangingSyncerCommand { | |
19 public: | |
20 FakeModelChangingSyncerCommand() {} | |
21 virtual ~FakeModelChangingSyncerCommand() {} | |
22 | |
23 const std::set<ModelSafeGroup>& changed_groups() const { | |
24 return changed_groups_; | |
25 } | |
26 | |
27 protected: | |
28 virtual std::set<ModelSafeGroup> GetGroupsToChange( | |
29 const sessions::SyncSession& session) const { | |
30 return session.GetEnabledGroups(); | |
31 } | |
32 | |
33 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) { | |
34 changed_groups_.insert(session->status_controller().group_restriction()); | |
35 } | |
36 | |
37 private: | |
38 std::set<ModelSafeGroup> changed_groups_; | |
39 | |
40 DISALLOW_COPY_AND_ASSIGN(FakeModelChangingSyncerCommand); | |
41 }; | |
42 | |
43 class ModelChangingSyncerCommandTest : public SyncerCommandTest { | |
44 protected: | |
45 ModelChangingSyncerCommandTest() {} | |
46 virtual ~ModelChangingSyncerCommandTest() {} | |
47 | |
48 virtual void SetUp() { | |
49 workers()->push_back( | |
50 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | |
51 workers()->push_back( | |
52 make_scoped_refptr(new FakeModelWorker(GROUP_PASSWORD))); | |
53 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI; | |
54 (*mutable_routing_info())[syncable::PASSWORDS] = GROUP_PASSWORD; | |
55 SyncerCommandTest::SetUp(); | |
56 } | |
57 | |
58 FakeModelChangingSyncerCommand command_; | |
59 | |
60 private: | |
61 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommandTest); | |
62 }; | |
63 | |
64 TEST_F(ModelChangingSyncerCommandTest, Basic) { | |
65 ExpectGroupsToChange(command_, GROUP_UI, GROUP_PASSWORD, GROUP_PASSIVE); | |
66 EXPECT_TRUE(command_.changed_groups().empty()); | |
67 command_.ExecuteImpl(session()); | |
68 EXPECT_EQ(command_.GetGroupsToChangeForTest(*session()), | |
69 command_.changed_groups()); | |
70 } | |
71 | |
72 } // namespace | |
73 | |
74 } // namespace browser_sync | |
OLD | NEW |