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

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

Issue 224563004: sync: Re-implement getAllNodes WebUI function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix Created 6 years, 8 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
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/internal_api/test/fake_sync_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 24 matching lines...) Expand all
35 #include "sync/internal_api/public/read_node.h" 35 #include "sync/internal_api/public/read_node.h"
36 #include "sync/internal_api/public/read_transaction.h" 36 #include "sync/internal_api/public/read_transaction.h"
37 #include "sync/internal_api/public/test/test_entry_factory.h" 37 #include "sync/internal_api/public/test/test_entry_factory.h"
38 #include "sync/internal_api/public/test/test_internal_components_factory.h" 38 #include "sync/internal_api/public/test/test_internal_components_factory.h"
39 #include "sync/internal_api/public/test/test_user_share.h" 39 #include "sync/internal_api/public/test/test_user_share.h"
40 #include "sync/internal_api/public/write_node.h" 40 #include "sync/internal_api/public/write_node.h"
41 #include "sync/internal_api/public/write_transaction.h" 41 #include "sync/internal_api/public/write_transaction.h"
42 #include "sync/internal_api/sync_encryption_handler_impl.h" 42 #include "sync/internal_api/sync_encryption_handler_impl.h"
43 #include "sync/internal_api/sync_manager_impl.h" 43 #include "sync/internal_api/sync_manager_impl.h"
44 #include "sync/internal_api/syncapi_internal.h" 44 #include "sync/internal_api/syncapi_internal.h"
45 #include "sync/js/js_arg_list.h"
46 #include "sync/js/js_backend.h" 45 #include "sync/js/js_backend.h"
47 #include "sync/js/js_event_handler.h" 46 #include "sync/js/js_event_handler.h"
48 #include "sync/js/js_reply_handler.h"
49 #include "sync/js/js_test_util.h" 47 #include "sync/js/js_test_util.h"
50 #include "sync/notifier/fake_invalidation_handler.h" 48 #include "sync/notifier/fake_invalidation_handler.h"
51 #include "sync/notifier/invalidation_handler.h" 49 #include "sync/notifier/invalidation_handler.h"
52 #include "sync/notifier/invalidator.h" 50 #include "sync/notifier/invalidator.h"
53 #include "sync/protocol/bookmark_specifics.pb.h" 51 #include "sync/protocol/bookmark_specifics.pb.h"
54 #include "sync/protocol/encryption.pb.h" 52 #include "sync/protocol/encryption.pb.h"
55 #include "sync/protocol/extension_specifics.pb.h" 53 #include "sync/protocol/extension_specifics.pb.h"
56 #include "sync/protocol/password_specifics.pb.h" 54 #include "sync/protocol/password_specifics.pb.h"
57 #include "sync/protocol/preference_specifics.pb.h" 55 #include "sync/protocol/preference_specifics.pb.h"
58 #include "sync/protocol/proto_value_conversions.h" 56 #include "sync/protocol/proto_value_conversions.h"
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 745
748 EXPECT_TRUE(js_backend_.IsInitialized()); 746 EXPECT_TRUE(js_backend_.IsInitialized());
749 747
750 if (initialization_succeeded_) { 748 if (initialization_succeeded_) {
751 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 749 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
752 i != routing_info.end(); ++i) { 750 i != routing_info.end(); ++i) {
753 type_roots_[i->first] = MakeServerNodeForType( 751 type_roots_[i->first] = MakeServerNodeForType(
754 sync_manager_.GetUserShare(), i->first); 752 sync_manager_.GetUserShare(), i->first);
755 } 753 }
756 } 754 }
755
757 PumpLoop(); 756 PumpLoop();
758 } 757 }
759 758
760 void TearDown() { 759 void TearDown() {
761 sync_manager_.RemoveObserver(&manager_observer_); 760 sync_manager_.RemoveObserver(&manager_observer_);
762 sync_manager_.ShutdownOnSyncThread(); 761 sync_manager_.ShutdownOnSyncThread();
763 PumpLoop(); 762 PumpLoop();
764 } 763 }
765 764
766 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { 765 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 int64 GetIdForDataType(ModelType type) { 828 int64 GetIdForDataType(ModelType type) {
830 if (type_roots_.count(type) == 0) 829 if (type_roots_.count(type) == 0)
831 return 0; 830 return 0;
832 return type_roots_[type]; 831 return type_roots_[type];
833 } 832 }
834 833
835 void PumpLoop() { 834 void PumpLoop() {
836 message_loop_.RunUntilIdle(); 835 message_loop_.RunUntilIdle();
837 } 836 }
838 837
839 void SendJsMessage(const std::string& name, const JsArgList& args,
840 const WeakHandle<JsReplyHandler>& reply_handler) {
841 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage,
842 name, args, reply_handler);
843 PumpLoop();
844 }
845
846 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler) { 838 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler) {
847 js_backend_.Call(FROM_HERE, &JsBackend::SetJsEventHandler, 839 js_backend_.Call(FROM_HERE, &JsBackend::SetJsEventHandler,
848 event_handler); 840 event_handler);
849 PumpLoop(); 841 PumpLoop();
850 } 842 }
851 843
852 // Looks up an entry by client tag and resets IS_UNSYNCED value to false. 844 // Looks up an entry by client tag and resets IS_UNSYNCED value to false.
853 // Returns true if entry was previously unsynced, false if IS_UNSYNCED was 845 // Returns true if entry was previously unsynced, false if IS_UNSYNCED was
854 // already false. 846 // already false.
855 bool ResetUnsyncedEntry(ModelType type, 847 bool ResetUnsyncedEntry(ModelType type,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 FakeEncryptor encryptor_; 923 FakeEncryptor encryptor_;
932 SyncManagerImpl sync_manager_; 924 SyncManagerImpl sync_manager_;
933 CancelationSignal cancelation_signal_; 925 CancelationSignal cancelation_signal_;
934 WeakHandle<JsBackend> js_backend_; 926 WeakHandle<JsBackend> js_backend_;
935 bool initialization_succeeded_; 927 bool initialization_succeeded_;
936 StrictMock<SyncManagerObserverMock> manager_observer_; 928 StrictMock<SyncManagerObserverMock> manager_observer_;
937 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; 929 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_;
938 InternalComponentsFactory::Switches switches_; 930 InternalComponentsFactory::Switches switches_;
939 }; 931 };
940 932
941 TEST_F(SyncManagerTest, GetAllNodesTest) { 933 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) {
942 StrictMock<MockJsReplyHandler> reply_handler; 934 ModelSafeRoutingInfo routing_info;
943 JsArgList return_args; 935 GetModelSafeRoutingInfo(&routing_info);
936 sync_manager_.StartSyncingNormally(routing_info);
944 937
945 EXPECT_CALL(reply_handler, 938 scoped_ptr<base::ListValue> node_list(
946 HandleJsReply("getAllNodes", _)) 939 sync_manager_.GetAllNodesForType(syncer::PREFERENCES));
947 .Times(1).WillRepeatedly(SaveArg<1>(&return_args));
948 940
949 { 941 // Should have one node: the type root node.
950 base::ListValue args; 942 ASSERT_EQ(1U, node_list->GetSize());
951 SendJsMessage("getAllNodes",
952 JsArgList(&args), reply_handler.AsWeakHandle());
953 }
954 943
955 // There's not much value in verifying every attribute on every node here.
956 // Most of the value of this test has already been achieved: we've verified we
957 // can call the above function without crashing or leaking memory.
958 //
959 // Let's just check the list size and a few of its elements. Anything more
960 // would make this test brittle without greatly increasing our chances of
961 // catching real bugs.
962
963 const base::ListValue* node_list;
964 const base::DictionaryValue* first_result; 944 const base::DictionaryValue* first_result;
965
966 // The resulting argument list should have one argument, a list of nodes.
967 ASSERT_EQ(1U, return_args.Get().GetSize());
968 ASSERT_TRUE(return_args.Get().GetList(0, &node_list));
969
970 // The database creation logic depends on the routing info.
971 // Refer to setup methods for more information.
972 ModelSafeRoutingInfo routes;
973 GetModelSafeRoutingInfo(&routes);
974 size_t directory_size = routes.size() + 1;
975
976 ASSERT_EQ(directory_size, node_list->GetSize());
977 ASSERT_TRUE(node_list->GetDictionary(0, &first_result)); 945 ASSERT_TRUE(node_list->GetDictionary(0, &first_result));
978 EXPECT_TRUE(first_result->HasKey("ID")); 946 EXPECT_TRUE(first_result->HasKey("ID"));
979 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME")); 947 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME"));
980 } 948 }
981 949
982 TEST_F(SyncManagerTest, RefreshEncryptionReady) { 950 TEST_F(SyncManagerTest, RefreshEncryptionReady) {
983 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 951 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
984 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 952 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
985 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 953 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
986 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); 954 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false));
(...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 // SyncManagerInitInvalidStorageTest::GetFactory will return 3041 // SyncManagerInitInvalidStorageTest::GetFactory will return
3074 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. 3042 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails.
3075 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's 3043 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's
3076 // task is to ensure that SyncManagerImpl reported initialization failure in 3044 // task is to ensure that SyncManagerImpl reported initialization failure in
3077 // OnInitializationComplete callback. 3045 // OnInitializationComplete callback.
3078 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { 3046 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) {
3079 EXPECT_FALSE(initialization_succeeded_); 3047 EXPECT_FALSE(initialization_succeeded_);
3080 } 3048 }
3081 3049
3082 } // namespace 3050 } // namespace
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/internal_api/test/fake_sync_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698