summaryrefslogtreecommitdiffstats
path: root/sync/engine/cleanup_disabled_types_command_unittest.cc
blob: 665c68cd9cf7bd362ec78b3bc24c00f0cbee87e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <vector>

#include "sync/engine/cleanup_disabled_types_command.h"

#include "sync/internal_api/public/syncable/model_type_test_util.h"
#include "sync/sessions/sync_session.h"
#include "sync/test/engine/syncer_command_test.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace browser_sync {

namespace {

using syncable::HasModelTypes;
using syncable::ModelTypeSet;
using testing::_;

class CleanupDisabledTypesCommandTest : public MockDirectorySyncerCommandTest {
 public:
  CleanupDisabledTypesCommandTest() {}

  virtual void SetUp() {
    mutable_routing_info()->clear();
    (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_PASSIVE;
    MockDirectorySyncerCommandTest::SetUp();
  }
};

// TODO(tim): Add syncer test to verify previous routing info is set.
TEST_F(CleanupDisabledTypesCommandTest, NoPreviousRoutingInfo) {
  CleanupDisabledTypesCommand command;
  ModelTypeSet expected = ModelTypeSet::All();
  expected.Remove(syncable::BOOKMARKS);
  EXPECT_CALL(*mock_directory(),
              PurgeEntriesWithTypeIn(HasModelTypes(expected)));
  command.ExecuteImpl(session());
}

TEST_F(CleanupDisabledTypesCommandTest, NoPurge) {
  CleanupDisabledTypesCommand command;
  EXPECT_CALL(*mock_directory(), PurgeEntriesWithTypeIn(_)).Times(0);

  ModelSafeRoutingInfo prev(routing_info());
  session()->context()->set_previous_session_routing_info(prev);
  (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_PASSIVE;
  command.ExecuteImpl(session());

  prev = routing_info();
  command.ExecuteImpl(session());
}

TEST_F(CleanupDisabledTypesCommandTest, TypeDisabled) {
  CleanupDisabledTypesCommand command;

  (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_PASSIVE;
  (*mutable_routing_info())[syncable::THEMES] = GROUP_PASSIVE;
  (*mutable_routing_info())[syncable::EXTENSIONS] = GROUP_PASSIVE;

  ModelSafeRoutingInfo prev(routing_info());
  prev[syncable::PASSWORDS] = GROUP_PASSIVE;
  prev[syncable::PREFERENCES] = GROUP_PASSIVE;
  session()->context()->set_previous_session_routing_info(prev);

  const ModelTypeSet expected(syncable::PASSWORDS, syncable::PREFERENCES);
  EXPECT_CALL(*mock_directory(),
              PurgeEntriesWithTypeIn(HasModelTypes(expected)));
  command.ExecuteImpl(session());
}

}  // namespace

}  // namespace browser_sync