| OLD | NEW |
| 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 #include <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 281 } |
| 282 | 282 |
| 283 virtual ~CreateRootHelper() {} | 283 virtual ~CreateRootHelper() {} |
| 284 | 284 |
| 285 const base::Closure& callback() const { return callback_; } | 285 const base::Closure& callback() const { return callback_; } |
| 286 bool success() { return success_; } | 286 bool success() { return success_; } |
| 287 | 287 |
| 288 private: | 288 private: |
| 289 void CreateRootCallback(ProfileSyncServiceSessionTest* test) { | 289 void CreateRootCallback(ProfileSyncServiceSessionTest* test) { |
| 290 success_ = ProfileSyncServiceTestHelper::CreateRoot( | 290 success_ = ProfileSyncServiceTestHelper::CreateRoot( |
| 291 syncable::SESSIONS, test->sync_service()->GetUserShare(), test->ids()); | 291 syncer::SESSIONS, test->sync_service()->GetUserShare(), test->ids()); |
| 292 } | 292 } |
| 293 | 293 |
| 294 base::Closure callback_; | 294 base::Closure callback_; |
| 295 bool success_; | 295 bool success_; |
| 296 }; | 296 }; |
| 297 | 297 |
| 298 // Test that we can write this machine's session to a node and retrieve it. | 298 // Test that we can write this machine's session to a node and retrieve it. |
| 299 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { | 299 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { |
| 300 CreateRootHelper create_root(this); | 300 CreateRootHelper create_root(this); |
| 301 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 301 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| 302 ASSERT_TRUE(create_root.success()); | 302 ASSERT_TRUE(create_root.success()); |
| 303 | 303 |
| 304 // Check that the DataTypeController associated the models. | 304 // Check that the DataTypeController associated the models. |
| 305 bool has_nodes; | 305 bool has_nodes; |
| 306 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); | 306 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); |
| 307 ASSERT_TRUE(has_nodes); | 307 ASSERT_TRUE(has_nodes); |
| 308 std::string machine_tag = model_associator_->GetCurrentMachineTag(); | 308 std::string machine_tag = model_associator_->GetCurrentMachineTag(); |
| 309 int64 sync_id = model_associator_->GetSyncIdFromSessionTag(machine_tag); | 309 int64 sync_id = model_associator_->GetSyncIdFromSessionTag(machine_tag); |
| 310 ASSERT_NE(syncer::kInvalidId, sync_id); | 310 ASSERT_NE(syncer::kInvalidId, sync_id); |
| 311 | 311 |
| 312 // Check that we can get the correct session specifics back from the node. | 312 // Check that we can get the correct session specifics back from the node. |
| 313 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 313 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 314 syncer::ReadNode node(&trans); | 314 syncer::ReadNode node(&trans); |
| 315 ASSERT_EQ(syncer::BaseNode::INIT_OK, | 315 ASSERT_EQ(syncer::BaseNode::INIT_OK, |
| 316 node.InitByClientTagLookup(syncable::SESSIONS, machine_tag)); | 316 node.InitByClientTagLookup(syncer::SESSIONS, machine_tag)); |
| 317 const sync_pb::SessionSpecifics& specifics(node.GetSessionSpecifics()); | 317 const sync_pb::SessionSpecifics& specifics(node.GetSessionSpecifics()); |
| 318 ASSERT_EQ(machine_tag, specifics.session_tag()); | 318 ASSERT_EQ(machine_tag, specifics.session_tag()); |
| 319 ASSERT_TRUE(specifics.has_header()); | 319 ASSERT_TRUE(specifics.has_header()); |
| 320 const sync_pb::SessionHeader& header_s = specifics.header(); | 320 const sync_pb::SessionHeader& header_s = specifics.header(); |
| 321 ASSERT_TRUE(header_s.has_device_type()); | 321 ASSERT_TRUE(header_s.has_device_type()); |
| 322 ASSERT_EQ("TestSessionName", header_s.client_name()); | 322 ASSERT_EQ("TestSessionName", header_s.client_name()); |
| 323 ASSERT_EQ(0, header_s.window_size()); | 323 ASSERT_EQ(0, header_s.window_size()); |
| 324 } | 324 } |
| 325 | 325 |
| 326 // Test that we can fill this machine's session, write it to a node, | 326 // Test that we can fill this machine's session, write it to a node, |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1015 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| 1016 syncer::SyncError error; | 1016 syncer::SyncError error; |
| 1017 std::string local_tag = model_associator_->GetCurrentMachineTag(); | 1017 std::string local_tag = model_associator_->GetCurrentMachineTag(); |
| 1018 | 1018 |
| 1019 error = model_associator_->DisassociateModels(); | 1019 error = model_associator_->DisassociateModels(); |
| 1020 ASSERT_FALSE(error.IsSet()); | 1020 ASSERT_FALSE(error.IsSet()); |
| 1021 { | 1021 { |
| 1022 // Create a sync node with the local tag but neither header nor tab field. | 1022 // Create a sync node with the local tag but neither header nor tab field. |
| 1023 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1023 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1024 syncer::ReadNode root(&trans); | 1024 syncer::ReadNode root(&trans); |
| 1025 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); | 1025 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS)); |
| 1026 syncer::WriteNode extra_header(&trans); | 1026 syncer::WriteNode extra_header(&trans); |
| 1027 syncer::WriteNode::InitUniqueByCreationResult result = | 1027 syncer::WriteNode::InitUniqueByCreationResult result = |
| 1028 extra_header.InitUniqueByCreation(syncable::SESSIONS, root, "new_tag"); | 1028 extra_header.InitUniqueByCreation(syncer::SESSIONS, root, "new_tag"); |
| 1029 ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 1029 ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result); |
| 1030 sync_pb::SessionSpecifics specifics; | 1030 sync_pb::SessionSpecifics specifics; |
| 1031 specifics.set_session_tag(local_tag); | 1031 specifics.set_session_tag(local_tag); |
| 1032 extra_header.SetSessionSpecifics(specifics); | 1032 extra_header.SetSessionSpecifics(specifics); |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 error = model_associator_->AssociateModels(); | 1035 error = model_associator_->AssociateModels(); |
| 1036 ASSERT_FALSE(error.IsSet()); | 1036 ASSERT_FALSE(error.IsSet()); |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed | 1039 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed |
| 1040 TEST_F(ProfileSyncServiceSessionTest, DISABLED_MultipleHeaders) { | 1040 TEST_F(ProfileSyncServiceSessionTest, DISABLED_MultipleHeaders) { |
| 1041 AddTab(browser(), GURL("http://foo1")); | 1041 AddTab(browser(), GURL("http://foo1")); |
| 1042 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1042 NavigateAndCommitActiveTab(GURL("http://foo2")); |
| 1043 AddTab(browser(), GURL("http://bar1")); | 1043 AddTab(browser(), GURL("http://bar1")); |
| 1044 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1044 NavigateAndCommitActiveTab(GURL("http://bar2")); |
| 1045 CreateRootHelper create_root(this); | 1045 CreateRootHelper create_root(this); |
| 1046 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1046 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| 1047 syncer::SyncError error; | 1047 syncer::SyncError error; |
| 1048 std::string local_tag = model_associator_->GetCurrentMachineTag(); | 1048 std::string local_tag = model_associator_->GetCurrentMachineTag(); |
| 1049 | 1049 |
| 1050 error = model_associator_->DisassociateModels(); | 1050 error = model_associator_->DisassociateModels(); |
| 1051 ASSERT_FALSE(error.IsSet()); | 1051 ASSERT_FALSE(error.IsSet()); |
| 1052 { | 1052 { |
| 1053 // Create another sync node with a header field and the local tag. | 1053 // Create another sync node with a header field and the local tag. |
| 1054 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1054 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1055 syncer::ReadNode root(&trans); | 1055 syncer::ReadNode root(&trans); |
| 1056 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); | 1056 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS)); |
| 1057 syncer::WriteNode extra_header(&trans); | 1057 syncer::WriteNode extra_header(&trans); |
| 1058 syncer::WriteNode::InitUniqueByCreationResult result = | 1058 syncer::WriteNode::InitUniqueByCreationResult result = |
| 1059 extra_header.InitUniqueByCreation(syncable::SESSIONS, | 1059 extra_header.InitUniqueByCreation(syncer::SESSIONS, |
| 1060 root, local_tag + "_"); | 1060 root, local_tag + "_"); |
| 1061 ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 1061 ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result); |
| 1062 sync_pb::SessionSpecifics specifics; | 1062 sync_pb::SessionSpecifics specifics; |
| 1063 specifics.set_session_tag(local_tag); | 1063 specifics.set_session_tag(local_tag); |
| 1064 specifics.mutable_header(); | 1064 specifics.mutable_header(); |
| 1065 extra_header.SetSessionSpecifics(specifics); | 1065 extra_header.SetSessionSpecifics(specifics); |
| 1066 } | 1066 } |
| 1067 error = model_associator_->AssociateModels(); | 1067 error = model_associator_->AssociateModels(); |
| 1068 ASSERT_FALSE(error.IsSet()); | 1068 ASSERT_FALSE(error.IsSet()); |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed | 1071 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed |
| 1072 TEST_F(ProfileSyncServiceSessionTest, DISABLED_CorruptedForeign) { | 1072 TEST_F(ProfileSyncServiceSessionTest, DISABLED_CorruptedForeign) { |
| 1073 AddTab(browser(), GURL("http://foo1")); | 1073 AddTab(browser(), GURL("http://foo1")); |
| 1074 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1074 NavigateAndCommitActiveTab(GURL("http://foo2")); |
| 1075 AddTab(browser(), GURL("http://bar1")); | 1075 AddTab(browser(), GURL("http://bar1")); |
| 1076 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1076 NavigateAndCommitActiveTab(GURL("http://bar2")); |
| 1077 CreateRootHelper create_root(this); | 1077 CreateRootHelper create_root(this); |
| 1078 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1078 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| 1079 syncer::SyncError error; | 1079 syncer::SyncError error; |
| 1080 | 1080 |
| 1081 error = model_associator_->DisassociateModels(); | 1081 error = model_associator_->DisassociateModels(); |
| 1082 ASSERT_FALSE(error.IsSet()); | 1082 ASSERT_FALSE(error.IsSet()); |
| 1083 { | 1083 { |
| 1084 // Create another sync node with neither header nor tab field and a foreign | 1084 // Create another sync node with neither header nor tab field and a foreign |
| 1085 // tag. | 1085 // tag. |
| 1086 std::string foreign_tag = "foreign_tag"; | 1086 std::string foreign_tag = "foreign_tag"; |
| 1087 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1087 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1088 syncer::ReadNode root(&trans); | 1088 syncer::ReadNode root(&trans); |
| 1089 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); | 1089 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS)); |
| 1090 syncer::WriteNode extra_header(&trans); | 1090 syncer::WriteNode extra_header(&trans); |
| 1091 syncer::WriteNode::InitUniqueByCreationResult result = | 1091 syncer::WriteNode::InitUniqueByCreationResult result = |
| 1092 extra_header.InitUniqueByCreation(syncable::SESSIONS, | 1092 extra_header.InitUniqueByCreation(syncer::SESSIONS, |
| 1093 root, foreign_tag); | 1093 root, foreign_tag); |
| 1094 ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 1094 ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result); |
| 1095 sync_pb::SessionSpecifics specifics; | 1095 sync_pb::SessionSpecifics specifics; |
| 1096 specifics.set_session_tag(foreign_tag); | 1096 specifics.set_session_tag(foreign_tag); |
| 1097 extra_header.SetSessionSpecifics(specifics); | 1097 extra_header.SetSessionSpecifics(specifics); |
| 1098 } | 1098 } |
| 1099 error = model_associator_->AssociateModels(); | 1099 error = model_associator_->AssociateModels(); |
| 1100 ASSERT_FALSE(error.IsSet()); | 1100 ASSERT_FALSE(error.IsSet()); |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed | 1103 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed |
| 1104 TEST_F(ProfileSyncServiceSessionTest, DISABLED_MissingLocalTabNode) { | 1104 TEST_F(ProfileSyncServiceSessionTest, DISABLED_MissingLocalTabNode) { |
| 1105 AddTab(browser(), GURL("http://foo1")); | 1105 AddTab(browser(), GURL("http://foo1")); |
| 1106 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1106 NavigateAndCommitActiveTab(GURL("http://foo2")); |
| 1107 AddTab(browser(), GURL("http://bar1")); | 1107 AddTab(browser(), GURL("http://bar1")); |
| 1108 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1108 NavigateAndCommitActiveTab(GURL("http://bar2")); |
| 1109 CreateRootHelper create_root(this); | 1109 CreateRootHelper create_root(this); |
| 1110 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1110 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| 1111 std::string local_tag = model_associator_->GetCurrentMachineTag(); | 1111 std::string local_tag = model_associator_->GetCurrentMachineTag(); |
| 1112 syncer::SyncError error; | 1112 syncer::SyncError error; |
| 1113 | 1113 |
| 1114 error = model_associator_->DisassociateModels(); | 1114 error = model_associator_->DisassociateModels(); |
| 1115 ASSERT_FALSE(error.IsSet()); | 1115 ASSERT_FALSE(error.IsSet()); |
| 1116 { | 1116 { |
| 1117 // Delete the first sync tab node. | 1117 // Delete the first sync tab node. |
| 1118 std::string tab_tag = SessionModelAssociator::TabIdToTag(local_tag, 0); | 1118 std::string tab_tag = SessionModelAssociator::TabIdToTag(local_tag, 0); |
| 1119 | 1119 |
| 1120 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1120 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1121 syncer::ReadNode root(&trans); | 1121 syncer::ReadNode root(&trans); |
| 1122 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); | 1122 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS)); |
| 1123 syncer::WriteNode tab_node(&trans); | 1123 syncer::WriteNode tab_node(&trans); |
| 1124 ASSERT_TRUE(tab_node.InitByClientTagLookup(syncable::SESSIONS, tab_tag)); | 1124 ASSERT_TRUE(tab_node.InitByClientTagLookup(syncer::SESSIONS, tab_tag)); |
| 1125 tab_node.Remove(); | 1125 tab_node.Remove(); |
| 1126 } | 1126 } |
| 1127 error = model_associator_->AssociateModels(); | 1127 error = model_associator_->AssociateModels(); |
| 1128 ASSERT_FALSE(error.IsSet()); | 1128 ASSERT_FALSE(error.IsSet()); |
| 1129 | 1129 |
| 1130 // Add some more tabs to ensure we don't conflict with the pre-existing tab | 1130 // Add some more tabs to ensure we don't conflict with the pre-existing tab |
| 1131 // node. | 1131 // node. |
| 1132 AddTab(browser(), GURL("http://baz1")); | 1132 AddTab(browser(), GURL("http://baz1")); |
| 1133 AddTab(browser(), GURL("http://baz2")); | 1133 AddTab(browser(), GURL("http://baz2")); |
| 1134 } | 1134 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 std::string local_tag = model_associator_->GetCurrentMachineTag(); | 1184 std::string local_tag = model_associator_->GetCurrentMachineTag(); |
| 1185 syncer::SyncError error; | 1185 syncer::SyncError error; |
| 1186 | 1186 |
| 1187 error = model_associator_->DisassociateModels(); | 1187 error = model_associator_->DisassociateModels(); |
| 1188 ASSERT_FALSE(error.IsSet()); | 1188 ASSERT_FALSE(error.IsSet()); |
| 1189 { | 1189 { |
| 1190 // Load the header node and clear it. | 1190 // Load the header node and clear it. |
| 1191 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1191 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1192 syncer::WriteNode header(&trans); | 1192 syncer::WriteNode header(&trans); |
| 1193 ASSERT_EQ(syncer::BaseNode::INIT_OK, | 1193 ASSERT_EQ(syncer::BaseNode::INIT_OK, |
| 1194 header.InitByClientTagLookup(syncable::SESSIONS, local_tag)); | 1194 header.InitByClientTagLookup(syncer::SESSIONS, local_tag)); |
| 1195 sync_pb::SessionSpecifics specifics; | 1195 sync_pb::SessionSpecifics specifics; |
| 1196 header.SetSessionSpecifics(specifics); | 1196 header.SetSessionSpecifics(specifics); |
| 1197 } | 1197 } |
| 1198 // Ensure we associate properly despite the pre-existing node with our local | 1198 // Ensure we associate properly despite the pre-existing node with our local |
| 1199 // tag. | 1199 // tag. |
| 1200 error = model_associator_->AssociateModels(); | 1200 error = model_associator_->AssociateModels(); |
| 1201 ASSERT_FALSE(error.IsSet()); | 1201 ASSERT_FALSE(error.IsSet()); |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 } // namespace browser_sync | 1204 } // namespace browser_sync |
| OLD | NEW |