Home | History | Annotate | Download | only in engine
      1 // Copyright (c) 2010 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 <vector>
      6 
      7 #include "chrome/browser/sync/engine/cleanup_disabled_types_command.h"
      8 
      9 #include "chrome/browser/sync/engine/syncer_end_command.h"
     10 #include "chrome/browser/sync/sessions/sync_session.h"
     11 #include "chrome/test/sync/engine/syncer_command_test.h"
     12 #include "testing/gtest/include/gtest/gtest.h"
     13 #include "testing/gmock/include/gmock/gmock.h"
     14 
     15 using testing::_;
     16 
     17 namespace browser_sync {
     18 
     19 class CleanupDisabledTypesCommandTest : public MockDirectorySyncerCommandTest {
     20  public:
     21   CleanupDisabledTypesCommandTest() {
     22     for (int i = syncable::FIRST_REAL_MODEL_TYPE;
     23          i < syncable::MODEL_TYPE_COUNT; i++) {
     24       all_types_.insert(syncable::ModelTypeFromInt(i));
     25     }
     26   }
     27   virtual void SetUp() {
     28     mutable_routing_info()->clear();
     29     (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_PASSIVE;
     30     MockDirectorySyncerCommandTest::SetUp();
     31   }
     32 
     33   // Overridden to allow SyncerEndCommand Execute to work.
     34   virtual bool IsSyncingCurrentlySilenced() {
     35     return false;
     36   }
     37 
     38   const syncable::ModelTypeSet& all_types() { return all_types_; }
     39 
     40  private:
     41   syncable::ModelTypeSet all_types_;
     42 };
     43 
     44 // TODO(tim): Add syncer test to verify previous routing info is set.
     45 TEST_F(CleanupDisabledTypesCommandTest, NoPreviousRoutingInfo) {
     46   CleanupDisabledTypesCommand command;
     47   syncable::ModelTypeSet expected(all_types());
     48   expected.erase(syncable::BOOKMARKS);
     49   EXPECT_CALL(*mock_directory(), PurgeEntriesWithTypeIn(expected));
     50   command.ExecuteImpl(session());
     51 }
     52 
     53 TEST_F(CleanupDisabledTypesCommandTest, NoPurge) {
     54   CleanupDisabledTypesCommand command;
     55   EXPECT_CALL(*mock_directory(), PurgeEntriesWithTypeIn(_)).Times(0);
     56 
     57   ModelSafeRoutingInfo prev(routing_info());
     58   session()->context()->set_previous_session_routing_info(prev);
     59   (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_PASSIVE;
     60   command.ExecuteImpl(session());
     61 
     62   prev = routing_info();
     63   command.ExecuteImpl(session());
     64 }
     65 
     66 TEST_F(CleanupDisabledTypesCommandTest, TypeDisabled) {
     67   CleanupDisabledTypesCommand command;
     68   syncable::ModelTypeSet expected;
     69   expected.insert(syncable::PASSWORDS);
     70   expected.insert(syncable::PREFERENCES);
     71 
     72   (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_PASSIVE;
     73   (*mutable_routing_info())[syncable::THEMES] = GROUP_PASSIVE;
     74   (*mutable_routing_info())[syncable::EXTENSIONS] = GROUP_PASSIVE;
     75 
     76   ModelSafeRoutingInfo prev(routing_info());
     77   prev[syncable::PASSWORDS] = GROUP_PASSIVE;
     78   prev[syncable::PREFERENCES] = GROUP_PASSIVE;
     79   session()->context()->set_previous_session_routing_info(prev);
     80 
     81   EXPECT_CALL(*mock_directory(), PurgeEntriesWithTypeIn(expected));
     82   command.ExecuteImpl(session());
     83 }
     84 
     85 }  // namespace browser_sync
     86 
     87