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

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

Issue 23189021: sync: Gracefully handle very early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix sync_client compile Created 7 years, 3 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/format_macros.h" 16 #include "base/format_macros.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/message_loop/message_loop_proxy.h" 20 #include "base/message_loop/message_loop_proxy.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/test/values_test_util.h" 24 #include "base/test/values_test_util.h"
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "sync/engine/sync_scheduler.h" 26 #include "sync/engine/sync_scheduler.h"
27 #include "sync/internal_api/public/base/cancellation_signal.h"
27 #include "sync/internal_api/public/base/model_type_test_util.h" 28 #include "sync/internal_api/public/base/model_type_test_util.h"
28 #include "sync/internal_api/public/change_record.h" 29 #include "sync/internal_api/public/change_record.h"
29 #include "sync/internal_api/public/engine/model_safe_worker.h" 30 #include "sync/internal_api/public/engine/model_safe_worker.h"
30 #include "sync/internal_api/public/engine/polling_constants.h" 31 #include "sync/internal_api/public/engine/polling_constants.h"
31 #include "sync/internal_api/public/http_post_provider_factory.h" 32 #include "sync/internal_api/public/http_post_provider_factory.h"
32 #include "sync/internal_api/public/http_post_provider_interface.h" 33 #include "sync/internal_api/public/http_post_provider_interface.h"
33 #include "sync/internal_api/public/read_node.h" 34 #include "sync/internal_api/public/read_node.h"
34 #include "sync/internal_api/public/read_transaction.h" 35 #include "sync/internal_api/public/read_transaction.h"
35 #include "sync/internal_api/public/test/test_entry_factory.h" 36 #include "sync/internal_api/public/test/test_entry_factory.h"
36 #include "sync/internal_api/public/test/test_internal_components_factory.h" 37 #include "sync/internal_api/public/test/test_internal_components_factory.h"
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 this, 829 this,
829 credentials, 830 credentials,
830 "fake_invalidator_client_id", 831 "fake_invalidator_client_id",
831 std::string(), 832 std::string(),
832 std::string(), // bootstrap tokens 833 std::string(), // bootstrap tokens
833 scoped_ptr<InternalComponentsFactory>(GetFactory()).get(), 834 scoped_ptr<InternalComponentsFactory>(GetFactory()).get(),
834 &encryptor_, 835 &encryptor_,
835 scoped_ptr<UnrecoverableErrorHandler>( 836 scoped_ptr<UnrecoverableErrorHandler>(
836 new TestUnrecoverableErrorHandler).Pass(), 837 new TestUnrecoverableErrorHandler).Pass(),
837 NULL, 838 NULL,
838 false); 839 false,
840 &cancellation_signal_);
839 841
840 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); 842 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_);
841 843
842 EXPECT_TRUE(js_backend_.IsInitialized()); 844 EXPECT_TRUE(js_backend_.IsInitialized());
843 845
844 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 846 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
845 i != routing_info.end(); ++i) { 847 i != routing_info.end(); ++i) {
846 type_roots_[i->first] = MakeServerNodeForType( 848 type_roots_[i->first] = MakeServerNodeForType(
847 sync_manager_.GetUserShare(), i->first); 849 sync_manager_.GetUserShare(), i->first);
848 } 850 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 base::MessageLoop message_loop_; 1012 base::MessageLoop message_loop_;
1011 // Needed by |sync_manager_|. 1013 // Needed by |sync_manager_|.
1012 base::ScopedTempDir temp_dir_; 1014 base::ScopedTempDir temp_dir_;
1013 // Sync Id's for the roots of the enabled datatypes. 1015 // Sync Id's for the roots of the enabled datatypes.
1014 std::map<ModelType, int64> type_roots_; 1016 std::map<ModelType, int64> type_roots_;
1015 scoped_refptr<ExtensionsActivity> extensions_activity_; 1017 scoped_refptr<ExtensionsActivity> extensions_activity_;
1016 1018
1017 protected: 1019 protected:
1018 FakeEncryptor encryptor_; 1020 FakeEncryptor encryptor_;
1019 SyncManagerImpl sync_manager_; 1021 SyncManagerImpl sync_manager_;
1022 CancellationSignal cancellation_signal_;
1020 WeakHandle<JsBackend> js_backend_; 1023 WeakHandle<JsBackend> js_backend_;
1021 StrictMock<SyncManagerObserverMock> manager_observer_; 1024 StrictMock<SyncManagerObserverMock> manager_observer_;
1022 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; 1025 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_;
1023 InternalComponentsFactory::Switches switches_; 1026 InternalComponentsFactory::Switches switches_;
1024 }; 1027 };
1025 1028
1026 TEST_F(SyncManagerTest, ProcessJsMessage) { 1029 TEST_F(SyncManagerTest, ProcessJsMessage) {
1027 const JsArgList kNoArgs; 1030 const JsArgList kNoArgs;
1028 1031
1029 StrictMock<MockJsReplyHandler> reply_handler; 1032 StrictMock<MockJsReplyHandler> reply_handler;
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
2788 ComponentsFactory(const Switches& switches, 2791 ComponentsFactory(const Switches& switches,
2789 SyncScheduler* scheduler_to_use, 2792 SyncScheduler* scheduler_to_use,
2790 sessions::SyncSessionContext** session_context) 2793 sessions::SyncSessionContext** session_context)
2791 : TestInternalComponentsFactory(switches, syncer::STORAGE_IN_MEMORY), 2794 : TestInternalComponentsFactory(switches, syncer::STORAGE_IN_MEMORY),
2792 scheduler_to_use_(scheduler_to_use), 2795 scheduler_to_use_(scheduler_to_use),
2793 session_context_(session_context) {} 2796 session_context_(session_context) {}
2794 virtual ~ComponentsFactory() {} 2797 virtual ~ComponentsFactory() {}
2795 2798
2796 virtual scoped_ptr<SyncScheduler> BuildScheduler( 2799 virtual scoped_ptr<SyncScheduler> BuildScheduler(
2797 const std::string& name, 2800 const std::string& name,
2798 sessions::SyncSessionContext* context) OVERRIDE { 2801 sessions::SyncSessionContext* context,
2802 CancellationSignal* stop_handle) OVERRIDE {
2799 *session_context_ = context; 2803 *session_context_ = context;
2800 return scheduler_to_use_.Pass(); 2804 return scheduler_to_use_.Pass();
2801 } 2805 }
2802 2806
2803 private: 2807 private:
2804 scoped_ptr<SyncScheduler> scheduler_to_use_; 2808 scoped_ptr<SyncScheduler> scheduler_to_use_;
2805 sessions::SyncSessionContext** session_context_; 2809 sessions::SyncSessionContext** session_context_;
2806 }; 2810 };
2807 2811
2808 class SyncManagerTestWithMockScheduler : public SyncManagerTest { 2812 class SyncManagerTestWithMockScheduler : public SyncManagerTest {
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
3507 size_t folder_b_pos = 3511 size_t folder_b_pos =
3508 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); 3512 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE);
3509 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); 3513 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE);
3510 3514
3511 // Deletes should appear before updates. 3515 // Deletes should appear before updates.
3512 EXPECT_LT(child_pos, folder_a_pos); 3516 EXPECT_LT(child_pos, folder_a_pos);
3513 EXPECT_LT(folder_b_pos, folder_a_pos); 3517 EXPECT_LT(folder_b_pos, folder_a_pos);
3514 } 3518 }
3515 3519
3516 } // namespace 3520 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698