Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: sync/internal_api/syncapi_unittest.cc

Issue 10701046: sync: Remove SyncManager::TestingMode in favour of InternalComponentsFactory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: now with more scope Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Unit tests for the SyncApi. Note that a lot of the underlying 5 // Unit tests for the SyncApi. Note that a lot of the underlying
6 // functionality is provided by the Syncable layer, which has its own 6 // functionality is provided by the Syncable layer, which has its own
7 // unit tests. We'll test SyncApi specific things in this harness. 7 // unit tests. We'll test SyncApi specific things in this harness.
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 14 matching lines...) Expand all
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "sync/internal_api/public/base/model_type_test_util.h" 26 #include "sync/internal_api/public/base/model_type_test_util.h"
27 #include "sync/engine/sync_scheduler.h" 27 #include "sync/engine/sync_scheduler.h"
28 #include "sync/internal_api/public/change_record.h" 28 #include "sync/internal_api/public/change_record.h"
29 #include "sync/internal_api/public/engine/model_safe_worker.h" 29 #include "sync/internal_api/public/engine/model_safe_worker.h"
30 #include "sync/internal_api/public/engine/polling_constants.h" 30 #include "sync/internal_api/public/engine/polling_constants.h"
31 #include "sync/internal_api/public/http_post_provider_factory.h" 31 #include "sync/internal_api/public/http_post_provider_factory.h"
32 #include "sync/internal_api/public/http_post_provider_interface.h" 32 #include "sync/internal_api/public/http_post_provider_interface.h"
33 #include "sync/internal_api/public/read_node.h" 33 #include "sync/internal_api/public/read_node.h"
34 #include "sync/internal_api/public/read_transaction.h" 34 #include "sync/internal_api/public/read_transaction.h"
35 #include "sync/internal_api/public/test/test_internal_components_factory.h"
35 #include "sync/internal_api/public/test/test_user_share.h" 36 #include "sync/internal_api/public/test/test_user_share.h"
36 #include "sync/internal_api/public/write_node.h" 37 #include "sync/internal_api/public/write_node.h"
37 #include "sync/internal_api/public/write_transaction.h" 38 #include "sync/internal_api/public/write_transaction.h"
38 #include "sync/internal_api/syncapi_internal.h" 39 #include "sync/internal_api/syncapi_internal.h"
39 #include "sync/internal_api/sync_manager_impl.h" 40 #include "sync/internal_api/sync_manager_impl.h"
40 #include "sync/js/js_arg_list.h" 41 #include "sync/js/js_arg_list.h"
41 #include "sync/js/js_backend.h" 42 #include "sync/js/js_backend.h"
42 #include "sync/js/js_event_handler.h" 43 #include "sync/js/js_event_handler.h"
43 #include "sync/js/js_reply_handler.h" 44 #include "sync/js/js_reply_handler.h"
44 #include "sync/js/js_test_util.h" 45 #include "sync/js/js_test_util.h"
45 #include "sync/notifier/sync_notifier.h" 46 #include "sync/notifier/sync_notifier.h"
46 #include "sync/notifier/sync_notifier_observer.h" 47 #include "sync/notifier/sync_notifier_observer.h"
47 #include "sync/protocol/bookmark_specifics.pb.h" 48 #include "sync/protocol/bookmark_specifics.pb.h"
48 #include "sync/protocol/encryption.pb.h" 49 #include "sync/protocol/encryption.pb.h"
49 #include "sync/protocol/extension_specifics.pb.h" 50 #include "sync/protocol/extension_specifics.pb.h"
50 #include "sync/protocol/password_specifics.pb.h" 51 #include "sync/protocol/password_specifics.pb.h"
51 #include "sync/protocol/preference_specifics.pb.h" 52 #include "sync/protocol/preference_specifics.pb.h"
52 #include "sync/protocol/proto_value_conversions.h" 53 #include "sync/protocol/proto_value_conversions.h"
53 #include "sync/protocol/sync.pb.h" 54 #include "sync/protocol/sync.pb.h"
54 #include "sync/sessions/sync_session.h" 55 #include "sync/sessions/sync_session.h"
55 #include "sync/syncable/directory.h" 56 #include "sync/syncable/directory.h"
56 #include "sync/syncable/entry.h" 57 #include "sync/syncable/entry.h"
57 #include "sync/syncable/mutable_entry.h" 58 #include "sync/syncable/mutable_entry.h"
58 #include "sync/syncable/nigori_util.h" 59 #include "sync/syncable/nigori_util.h"
59 #include "sync/syncable/syncable_id.h" 60 #include "sync/syncable/syncable_id.h"
60 #include "sync/syncable/write_transaction.h" 61 #include "sync/syncable/write_transaction.h"
61 #include "sync/test/callback_counter.h" 62 #include "sync/test/callback_counter.h"
62 #include "sync/test/fake_encryptor.h" 63 #include "sync/test/fake_encryptor.h"
63 #include "sync/test/fake_extensions_activity_monitor.h" 64 #include "sync/test/fake_extensions_activity_monitor.h"
65 #include "sync/test/engine/fake_sync_scheduler.h"
64 #include "sync/util/cryptographer.h" 66 #include "sync/util/cryptographer.h"
65 #include "sync/util/extensions_activity_monitor.h" 67 #include "sync/util/extensions_activity_monitor.h"
66 #include "sync/util/test_unrecoverable_error_handler.h" 68 #include "sync/util/test_unrecoverable_error_handler.h"
67 #include "sync/util/time.h" 69 #include "sync/util/time.h"
68 #include "testing/gmock/include/gmock/gmock.h" 70 #include "testing/gmock/include/gmock/gmock.h"
69 #include "testing/gtest/include/gtest/gtest.h" 71 #include "testing/gtest/include/gtest/gtest.h"
70 72
71 using base::ExpectDictStringValue; 73 using base::ExpectDictStringValue;
72 using testing::_; 74 using testing::_;
73 using testing::AnyNumber; 75 using testing::AnyNumber;
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 WeakHandle<JsEventHandler>(), 770 WeakHandle<JsEventHandler>(),
769 "bogus", 0, false, 771 "bogus", 0, false,
770 base::MessageLoopProxy::current(), 772 base::MessageLoopProxy::current(),
771 scoped_ptr<HttpPostProviderFactory>( 773 scoped_ptr<HttpPostProviderFactory>(
772 new TestHttpPostProviderFactory()), 774 new TestHttpPostProviderFactory()),
773 routing_info, workers, 775 routing_info, workers,
774 &extensions_activity_monitor_, this, 776 &extensions_activity_monitor_, this,
775 credentials, 777 credentials,
776 scoped_ptr<SyncNotifier>(sync_notifier_mock_), 778 scoped_ptr<SyncNotifier>(sync_notifier_mock_),
777 "", 779 "",
778 syncer::SyncManager::TEST_IN_MEMORY, 780 scoped_ptr<InternalComponentsFactory>(GetFactory()),
779 &encryptor_, 781 &encryptor_,
780 &handler_, 782 &handler_,
781 NULL); 783 NULL);
782 784
783 EXPECT_TRUE(sync_notifier_observer_); 785 EXPECT_TRUE(sync_notifier_observer_);
784 EXPECT_TRUE(js_backend_.IsInitialized()); 786 EXPECT_TRUE(js_backend_.IsInitialized());
785 787
786 EXPECT_EQ(0, update_enabled_types_call_count_); 788 EXPECT_EQ(0, update_enabled_types_call_count_);
787 789
788 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 790 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 const std::string hash = BaseNode::GenerateSyncableHash(type, client_tag); 908 const std::string hash = BaseNode::GenerateSyncableHash(type, client_tag);
907 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, 909 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG,
908 hash); 910 hash);
909 EXPECT_TRUE(entry.good()); 911 EXPECT_TRUE(entry.good());
910 if (!entry.Get(IS_UNSYNCED)) 912 if (!entry.Get(IS_UNSYNCED))
911 return false; 913 return false;
912 entry.Put(IS_UNSYNCED, false); 914 entry.Put(IS_UNSYNCED, false);
913 return true; 915 return true;
914 } 916 }
915 917
916 void SetScheduler(scoped_ptr<SyncScheduler> scheduler) { 918 virtual InternalComponentsFactory* GetFactory() {
917 sync_manager_.SetSyncSchedulerForTest(scheduler.Pass()); 919 return new TestInternalComponentsFactory(
920 TestInternalComponentsFactory::IN_MEMORY);
918 } 921 }
919 922
920 private: 923 private:
921 // Needed by |sync_manager_|. 924 // Needed by |sync_manager_|.
922 MessageLoop message_loop_; 925 MessageLoop message_loop_;
923 // Needed by |sync_manager_|. 926 // Needed by |sync_manager_|.
924 ScopedTempDir temp_dir_; 927 ScopedTempDir temp_dir_;
925 // Sync Id's for the roots of the enabled datatypes. 928 // Sync Id's for the roots of the enabled datatypes.
926 std::map<ModelType, int64> type_roots_; 929 std::map<ModelType, int64> type_roots_;
927 FakeExtensionsActivityMonitor extensions_activity_monitor_; 930 FakeExtensionsActivityMonitor extensions_activity_monitor_;
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after
2489 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); 2492 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag));
2490 EXPECT_EQ(title, node.GetTitle()); 2493 EXPECT_EQ(title, node.GetTitle());
2491 EXPECT_EQ(GURL(url2), node.GetURL()); 2494 EXPECT_EQ(GURL(url2), node.GetURL());
2492 const syncable::Entry* node_entry = node.GetEntry(); 2495 const syncable::Entry* node_entry = node.GetEntry();
2493 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2496 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2494 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2497 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2495 EXPECT_TRUE(specifics.has_encrypted()); 2498 EXPECT_TRUE(specifics.has_encrypted());
2496 } 2499 }
2497 } 2500 }
2498 2501
2499 class MockSyncScheduler : public SyncScheduler { 2502 class MockSyncScheduler : public FakeSyncScheduler {
2500 public: 2503 public:
2501 MockSyncScheduler() : SyncScheduler("name", NULL, NULL) {} 2504 MockSyncScheduler() : FakeSyncScheduler() {}
2502 virtual ~MockSyncScheduler() {} 2505 virtual ~MockSyncScheduler() {}
2503 2506
2504 MOCK_METHOD1(Start, void(SyncScheduler::Mode)); 2507 MOCK_METHOD1(Start, void(SyncScheduler::Mode));
2505 MOCK_METHOD1(ScheduleConfiguration, bool(const ConfigurationParams&)); 2508 MOCK_METHOD1(ScheduleConfiguration, bool(const ConfigurationParams&));
2506 }; 2509 };
2507 2510
2511 class ComponentsFactory : public TestInternalComponentsFactory {
2512 public:
2513 ComponentsFactory(SyncScheduler* scheduler_to_use)
2514 : TestInternalComponentsFactory(
2515 TestInternalComponentsFactory::IN_MEMORY),
2516 scheduler_to_use_(scheduler_to_use) {}
2517 virtual ~ComponentsFactory() {}
2518
2519 virtual scoped_ptr<SyncScheduler> BuildScheduler(
2520 const std::string& name,
2521 sessions::SyncSessionContext* context) OVERRIDE {
2522 return scheduler_to_use_.Pass();
2523 }
2524 scoped_ptr<SyncScheduler> scheduler_to_use_;
2525 };
2526
2527 class SyncManagerTestWithMockScheduler : public SyncManagerTest {
2528 public:
2529 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {}
2530 virtual InternalComponentsFactory* GetFactory() OVERRIDE {
2531 scheduler_ = new MockSyncScheduler();
2532 return new ComponentsFactory(scheduler_);
2533 }
2534 MockSyncScheduler* scheduler_;
2535 };
2536
2508 // Test that the configuration params are properly created and sent to 2537 // Test that the configuration params are properly created and sent to
2509 // ScheduleConfigure. No callback should be invoked. 2538 // ScheduleConfigure. No callback should be invoked.
2510 TEST_F(SyncManagerTest, BasicConfiguration) { 2539 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) {
2511 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2540 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
2512 syncer::ModelTypeSet types_to_download(syncer::BOOKMARKS, 2541 syncer::ModelTypeSet types_to_download(syncer::BOOKMARKS,
2513 syncer::PREFERENCES); 2542 syncer::PREFERENCES);
2514 syncer::ModelSafeRoutingInfo new_routing_info; 2543 syncer::ModelSafeRoutingInfo new_routing_info;
2515 GetModelSafeRoutingInfo(&new_routing_info); 2544 GetModelSafeRoutingInfo(&new_routing_info);
2516 2545
2517 scoped_ptr<MockSyncScheduler> scheduler(new MockSyncScheduler());
2518 ConfigurationParams params; 2546 ConfigurationParams params;
2519 EXPECT_CALL(*scheduler, Start(SyncScheduler::CONFIGURATION_MODE)); 2547 EXPECT_CALL(*scheduler_, Start(SyncScheduler::CONFIGURATION_MODE));
2520 EXPECT_CALL(*scheduler, ScheduleConfiguration(_)). 2548 EXPECT_CALL(*scheduler_, ScheduleConfiguration(_)).
2521 WillOnce(DoAll(SaveArg<0>(&params), Return(true))); 2549 WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
2522 SetScheduler(scheduler.PassAs<SyncScheduler>());
2523 2550
2524 CallbackCounter ready_task_counter, retry_task_counter; 2551 CallbackCounter ready_task_counter, retry_task_counter;
2525 sync_manager_.ConfigureSyncer( 2552 sync_manager_.ConfigureSyncer(
2526 reason, 2553 reason,
2527 types_to_download, 2554 types_to_download,
2528 new_routing_info, 2555 new_routing_info,
2529 base::Bind(&CallbackCounter::Callback, 2556 base::Bind(&CallbackCounter::Callback,
2530 base::Unretained(&ready_task_counter)), 2557 base::Unretained(&ready_task_counter)),
2531 base::Bind(&CallbackCounter::Callback, 2558 base::Bind(&CallbackCounter::Callback,
2532 base::Unretained(&retry_task_counter))); 2559 base::Unretained(&retry_task_counter)));
2533 EXPECT_EQ(0, ready_task_counter.times_called()); 2560 EXPECT_EQ(0, ready_task_counter.times_called());
2534 EXPECT_EQ(0, retry_task_counter.times_called()); 2561 EXPECT_EQ(0, retry_task_counter.times_called());
2535 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 2562 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
2536 params.source); 2563 params.source);
2537 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); 2564 EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
2538 EXPECT_EQ(new_routing_info, params.routing_info); 2565 EXPECT_EQ(new_routing_info, params.routing_info);
2539 } 2566 }
2540 2567
2541 // Test that the retry callback is invoked on configuration failure. 2568 // Test that the retry callback is invoked on configuration failure.
2542 TEST_F(SyncManagerTest, ConfigurationRetry) { 2569 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) {
2543 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; 2570 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
2544 syncer::ModelTypeSet types_to_download(syncer::BOOKMARKS, 2571 syncer::ModelTypeSet types_to_download(syncer::BOOKMARKS,
2545 syncer::PREFERENCES); 2572 syncer::PREFERENCES);
2546 syncer::ModelSafeRoutingInfo new_routing_info; 2573 syncer::ModelSafeRoutingInfo new_routing_info;
2547 GetModelSafeRoutingInfo(&new_routing_info); 2574 GetModelSafeRoutingInfo(&new_routing_info);
2548 2575
2549 scoped_ptr<MockSyncScheduler> scheduler(new MockSyncScheduler());
2550 ConfigurationParams params; 2576 ConfigurationParams params;
2551 EXPECT_CALL(*scheduler, Start(SyncScheduler::CONFIGURATION_MODE)); 2577 EXPECT_CALL(*scheduler_, Start(SyncScheduler::CONFIGURATION_MODE));
2552 EXPECT_CALL(*scheduler, ScheduleConfiguration(_)). 2578 EXPECT_CALL(*scheduler_, ScheduleConfiguration(_)).
2553 WillOnce(DoAll(SaveArg<0>(&params), Return(false))); 2579 WillOnce(DoAll(SaveArg<0>(&params), Return(false)));
2554 SetScheduler(scheduler.PassAs<SyncScheduler>());
2555 2580
2556 CallbackCounter ready_task_counter, retry_task_counter; 2581 CallbackCounter ready_task_counter, retry_task_counter;
2557 sync_manager_.ConfigureSyncer( 2582 sync_manager_.ConfigureSyncer(
2558 reason, 2583 reason,
2559 types_to_download, 2584 types_to_download,
2560 new_routing_info, 2585 new_routing_info,
2561 base::Bind(&CallbackCounter::Callback, 2586 base::Bind(&CallbackCounter::Callback,
2562 base::Unretained(&ready_task_counter)), 2587 base::Unretained(&ready_task_counter)),
2563 base::Bind(&CallbackCounter::Callback, 2588 base::Bind(&CallbackCounter::Callback,
2564 base::Unretained(&retry_task_counter))); 2589 base::Unretained(&retry_task_counter)));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2606 // Ensure only bookmarks and nigori lost their progress marker. Preferences 2631 // Ensure only bookmarks and nigori lost their progress marker. Preferences
2607 // should still have it. 2632 // should still have it.
2608 partial_types = 2633 partial_types =
2609 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); 2634 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All());
2610 EXPECT_TRUE(partial_types.Has(NIGORI)); 2635 EXPECT_TRUE(partial_types.Has(NIGORI));
2611 EXPECT_TRUE(partial_types.Has(BOOKMARKS)); 2636 EXPECT_TRUE(partial_types.Has(BOOKMARKS));
2612 EXPECT_FALSE(partial_types.Has(PREFERENCES)); 2637 EXPECT_FALSE(partial_types.Has(PREFERENCES));
2613 } 2638 }
2614 2639
2615 } // namespace 2640 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698