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 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 TEST_F(ProfileSyncServiceSessionTest, MissingHeaderAndTab) { | 1019 TEST_F(ProfileSyncServiceSessionTest, MissingHeaderAndTab) { |
1020 AddTab(browser(), GURL("http://foo1")); | 1020 AddTab(browser(), GURL("http://foo1")); |
1021 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1021 NavigateAndCommitActiveTab(GURL("http://foo2")); |
1022 AddTab(browser(), GURL("http://bar1")); | 1022 AddTab(browser(), GURL("http://bar1")); |
1023 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1023 NavigateAndCommitActiveTab(GURL("http://bar2")); |
1024 CreateRootHelper create_root(this); | 1024 CreateRootHelper create_root(this); |
1025 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1025 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
1026 SyncError error; | 1026 SyncError error; |
1027 std::string local_tag = model_associator_->GetCurrentMachineTag(); | 1027 std::string local_tag = model_associator_->GetCurrentMachineTag(); |
1028 | 1028 |
1029 ASSERT_TRUE(model_associator_->DisassociateModels(&error)); | 1029 error = model_associator_->DisassociateModels(); |
| 1030 ASSERT_FALSE(error.IsSet()); |
1030 { | 1031 { |
1031 // Create a sync node with the local tag but neither header nor tab field. | 1032 // Create a sync node with the local tag but neither header nor tab field. |
1032 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1033 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1033 sync_api::ReadNode root(&trans); | 1034 sync_api::ReadNode root(&trans); |
1034 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); | 1035 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); |
1035 sync_api::WriteNode extra_header(&trans); | 1036 sync_api::WriteNode extra_header(&trans); |
1036 ASSERT_TRUE(extra_header.InitUniqueByCreation(syncable::SESSIONS, | 1037 ASSERT_TRUE(extra_header.InitUniqueByCreation(syncable::SESSIONS, |
1037 root, "new_tag")); | 1038 root, "new_tag")); |
1038 sync_pb::SessionSpecifics specifics; | 1039 sync_pb::SessionSpecifics specifics; |
1039 specifics.set_session_tag(local_tag); | 1040 specifics.set_session_tag(local_tag); |
1040 extra_header.SetSessionSpecifics(specifics); | 1041 extra_header.SetSessionSpecifics(specifics); |
1041 } | 1042 } |
1042 ASSERT_TRUE(model_associator_->AssociateModels(&error)); | 1043 |
| 1044 error = model_associator_->AssociateModels(); |
1043 ASSERT_FALSE(error.IsSet()); | 1045 ASSERT_FALSE(error.IsSet()); |
1044 } | 1046 } |
1045 | 1047 |
1046 TEST_F(ProfileSyncServiceSessionTest, MultipleHeaders) { | 1048 TEST_F(ProfileSyncServiceSessionTest, MultipleHeaders) { |
1047 AddTab(browser(), GURL("http://foo1")); | 1049 AddTab(browser(), GURL("http://foo1")); |
1048 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1050 NavigateAndCommitActiveTab(GURL("http://foo2")); |
1049 AddTab(browser(), GURL("http://bar1")); | 1051 AddTab(browser(), GURL("http://bar1")); |
1050 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1052 NavigateAndCommitActiveTab(GURL("http://bar2")); |
1051 CreateRootHelper create_root(this); | 1053 CreateRootHelper create_root(this); |
1052 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1054 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
1053 SyncError error; | 1055 SyncError error; |
1054 std::string local_tag = model_associator_->GetCurrentMachineTag(); | 1056 std::string local_tag = model_associator_->GetCurrentMachineTag(); |
1055 | 1057 |
1056 ASSERT_TRUE(model_associator_->DisassociateModels(&error)); | 1058 error = model_associator_->DisassociateModels(); |
| 1059 ASSERT_FALSE(error.IsSet()); |
1057 { | 1060 { |
1058 // Create another sync node with a header field and the local tag. | 1061 // Create another sync node with a header field and the local tag. |
1059 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1062 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1060 sync_api::ReadNode root(&trans); | 1063 sync_api::ReadNode root(&trans); |
1061 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); | 1064 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); |
1062 sync_api::WriteNode extra_header(&trans); | 1065 sync_api::WriteNode extra_header(&trans); |
1063 ASSERT_TRUE(extra_header.InitUniqueByCreation(syncable::SESSIONS, | 1066 ASSERT_TRUE(extra_header.InitUniqueByCreation(syncable::SESSIONS, |
1064 root, local_tag + "_")); | 1067 root, local_tag + "_")); |
1065 sync_pb::SessionSpecifics specifics; | 1068 sync_pb::SessionSpecifics specifics; |
1066 specifics.set_session_tag(local_tag); | 1069 specifics.set_session_tag(local_tag); |
1067 specifics.mutable_header(); | 1070 specifics.mutable_header(); |
1068 extra_header.SetSessionSpecifics(specifics); | 1071 extra_header.SetSessionSpecifics(specifics); |
1069 } | 1072 } |
1070 ASSERT_TRUE(model_associator_->AssociateModels(&error)); | 1073 error = model_associator_->AssociateModels(); |
1071 ASSERT_FALSE(error.IsSet()); | 1074 ASSERT_FALSE(error.IsSet()); |
1072 } | 1075 } |
1073 | 1076 |
1074 TEST_F(ProfileSyncServiceSessionTest, CorruptedForeign) { | 1077 TEST_F(ProfileSyncServiceSessionTest, CorruptedForeign) { |
1075 AddTab(browser(), GURL("http://foo1")); | 1078 AddTab(browser(), GURL("http://foo1")); |
1076 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1079 NavigateAndCommitActiveTab(GURL("http://foo2")); |
1077 AddTab(browser(), GURL("http://bar1")); | 1080 AddTab(browser(), GURL("http://bar1")); |
1078 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1081 NavigateAndCommitActiveTab(GURL("http://bar2")); |
1079 CreateRootHelper create_root(this); | 1082 CreateRootHelper create_root(this); |
1080 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1083 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
1081 SyncError error; | 1084 SyncError error; |
1082 | 1085 |
1083 ASSERT_TRUE(model_associator_->DisassociateModels(&error)); | 1086 error = model_associator_->DisassociateModels(); |
| 1087 ASSERT_FALSE(error.IsSet()); |
1084 { | 1088 { |
1085 // Create another sync node with neither header nor tab field and a foreign | 1089 // Create another sync node with neither header nor tab field and a foreign |
1086 // tag. | 1090 // tag. |
1087 std::string foreign_tag = "foreign_tag"; | 1091 std::string foreign_tag = "foreign_tag"; |
1088 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1092 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1089 sync_api::ReadNode root(&trans); | 1093 sync_api::ReadNode root(&trans); |
1090 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); | 1094 root.InitByTagLookup(syncable::ModelTypeToRootTag(syncable::SESSIONS)); |
1091 sync_api::WriteNode extra_header(&trans); | 1095 sync_api::WriteNode extra_header(&trans); |
1092 ASSERT_TRUE(extra_header.InitUniqueByCreation(syncable::SESSIONS, | 1096 ASSERT_TRUE(extra_header.InitUniqueByCreation(syncable::SESSIONS, |
1093 root, foreign_tag)); | 1097 root, foreign_tag)); |
1094 sync_pb::SessionSpecifics specifics; | 1098 sync_pb::SessionSpecifics specifics; |
1095 specifics.set_session_tag(foreign_tag); | 1099 specifics.set_session_tag(foreign_tag); |
1096 extra_header.SetSessionSpecifics(specifics); | 1100 extra_header.SetSessionSpecifics(specifics); |
1097 } | 1101 } |
1098 ASSERT_TRUE(model_associator_->AssociateModels(&error)); | 1102 error = model_associator_->AssociateModels(); |
1099 ASSERT_FALSE(error.IsSet()); | 1103 ASSERT_FALSE(error.IsSet()); |
1100 } | 1104 } |
1101 | 1105 |
1102 } // namespace browser_sync | 1106 } // namespace browser_sync |
OLD | NEW |