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

Side by Side Diff: chrome/browser/sync/profile_sync_service_session_unittest.cc

Issue 16421003: [Sync] Add logic to reassociate tab nodes after restart. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit. Created 7 years, 6 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 #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 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 } 745 }
746 ASSERT_TRUE(notified_of_update_); 746 ASSERT_TRUE(notified_of_update_);
747 } 747 }
748 // Test the TabNodePool when it starts off empty. 748 // Test the TabNodePool when it starts off empty.
749 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) { 749 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) {
750 CreateRootHelper create_root(this); 750 CreateRootHelper create_root(this);
751 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 751 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
752 ASSERT_TRUE(create_root.success()); 752 ASSERT_TRUE(create_root.success());
753 753
754 std::vector<int64> node_ids; 754 std::vector<int64> node_ids;
755 ASSERT_EQ(0U, model_associator_->tab_pool_.capacity()); 755 ASSERT_EQ(0U, model_associator_->tab_pool_.Capacity());
756 ASSERT_TRUE(model_associator_->tab_pool_.empty()); 756 ASSERT_TRUE(model_associator_->tab_pool_.Empty());
757 ASSERT_TRUE(model_associator_->tab_pool_.full()); 757 ASSERT_TRUE(model_associator_->tab_pool_.Full());
758 const size_t num_ids = 10; 758 const size_t num_ids = 10;
759 for (size_t i = 0; i < num_ids; ++i) { 759 for (size_t i = 0; i < num_ids; ++i) {
760 int64 id = model_associator_->tab_pool_.GetFreeTabNode(); 760 int64 id = model_associator_->tab_pool_.GetFreeTabNode();
761 ASSERT_GT(id, -1); 761 ASSERT_GT(id, -1);
762 node_ids.push_back(id); 762 node_ids.push_back(id);
763 // Associate with a tab node.
764 model_associator_->tab_pool_.AssociateTabNode(id, i + 1);
763 } 765 }
764 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 766 ASSERT_EQ(num_ids, model_associator_->tab_pool_.Capacity());
765 ASSERT_TRUE(model_associator_->tab_pool_.empty()); 767 ASSERT_TRUE(model_associator_->tab_pool_.Empty());
766 ASSERT_FALSE(model_associator_->tab_pool_.full()); 768 ASSERT_FALSE(model_associator_->tab_pool_.Full());
767 for (size_t i = 0; i < num_ids; ++i) { 769 for (size_t i = 0; i < num_ids; ++i) {
768 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); 770 model_associator_->tab_pool_.FreeTabNode(node_ids[i]);
769 } 771 }
770 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 772 ASSERT_EQ(num_ids, model_associator_->tab_pool_.Capacity());
771 ASSERT_FALSE(model_associator_->tab_pool_.empty()); 773 ASSERT_FALSE(model_associator_->tab_pool_.Empty());
772 ASSERT_TRUE(model_associator_->tab_pool_.full()); 774 ASSERT_TRUE(model_associator_->tab_pool_.Full());
773 } 775 }
774 776
775 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed 777 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed
776 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty) { 778 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty) {
777 CreateRootHelper create_root(this); 779 CreateRootHelper create_root(this);
778 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 780 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
779 ASSERT_TRUE(create_root.success()); 781 ASSERT_TRUE(create_root.success());
780 782
781 const size_t num_starting_nodes = 3; 783 const size_t num_starting_nodes = 3;
784 SessionID session_id;
782 for (size_t i = 0; i < num_starting_nodes; ++i) { 785 for (size_t i = 0; i < num_starting_nodes; ++i) {
783 model_associator_->tab_pool_.AddTabNode(i); 786 session_id.set_id(i + 1);
787 model_associator_->tab_pool_.AddTabNode(i + 1, session_id, i);
784 } 788 }
785 789
790 model_associator_->tab_pool_.FreeUnusedTabNodes(std::set<int64>());
786 std::vector<int64> node_ids; 791 std::vector<int64> node_ids;
787 ASSERT_EQ(num_starting_nodes, model_associator_->tab_pool_.capacity()); 792 ASSERT_EQ(num_starting_nodes, model_associator_->tab_pool_.Capacity());
788 ASSERT_FALSE(model_associator_->tab_pool_.empty()); 793 ASSERT_FALSE(model_associator_->tab_pool_.Empty());
789 ASSERT_TRUE(model_associator_->tab_pool_.full()); 794 ASSERT_TRUE(model_associator_->tab_pool_.Full());
790 const size_t num_ids = 10; 795 const size_t num_ids = 10;
791 for (size_t i = 0; i < num_ids; ++i) { 796 for (size_t i = 0; i < num_ids; ++i) {
792 int64 id = model_associator_->tab_pool_.GetFreeTabNode(); 797 int64 id = model_associator_->tab_pool_.GetFreeTabNode();
793 ASSERT_GT(id, -1); 798 ASSERT_GT(id, -1);
794 node_ids.push_back(id); 799 node_ids.push_back(id);
800 // Associate with a tab node.
801 model_associator_->tab_pool_.AssociateTabNode(id, i + 1);
795 } 802 }
796 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 803 ASSERT_EQ(num_ids, model_associator_->tab_pool_.Capacity());
797 ASSERT_TRUE(model_associator_->tab_pool_.empty()); 804 ASSERT_TRUE(model_associator_->tab_pool_.Empty());
798 ASSERT_FALSE(model_associator_->tab_pool_.full()); 805 ASSERT_FALSE(model_associator_->tab_pool_.Full());
799 for (size_t i = 0; i < num_ids; ++i) { 806 for (size_t i = 0; i < num_ids; ++i) {
800 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); 807 model_associator_->tab_pool_.FreeTabNode(node_ids[i]);
801 } 808 }
802 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 809 ASSERT_EQ(num_ids, model_associator_->tab_pool_.Capacity());
803 ASSERT_FALSE(model_associator_->tab_pool_.empty()); 810 ASSERT_FALSE(model_associator_->tab_pool_.Empty());
804 ASSERT_TRUE(model_associator_->tab_pool_.full()); 811 ASSERT_TRUE(model_associator_->tab_pool_.Full());
805 } 812 }
806 813
807 // Write a foreign session to a node, and then delete it. 814 // Write a foreign session to a node, and then delete it.
808 TEST_F(ProfileSyncServiceSessionTest, DeleteForeignSession) { 815 TEST_F(ProfileSyncServiceSessionTest, DeleteForeignSession) {
809 CreateRootHelper create_root(this); 816 CreateRootHelper create_root(this);
810 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 817 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
811 ASSERT_TRUE(create_root.success()); 818 ASSERT_TRUE(create_root.success());
812 819
813 // Check that the DataTypeController associated the models. 820 // Check that the DataTypeController associated the models.
814 bool has_nodes; 821 bool has_nodes;
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 NavigateAndCommitActiveTab(GURL("http://bar2")); 1165 NavigateAndCommitActiveTab(GURL("http://bar2"));
1159 CreateRootHelper create_root(this); 1166 CreateRootHelper create_root(this);
1160 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 1167 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
1161 std::string local_tag = model_associator_->GetCurrentMachineTag(); 1168 std::string local_tag = model_associator_->GetCurrentMachineTag();
1162 syncer::SyncError error; 1169 syncer::SyncError error;
1163 1170
1164 error = model_associator_->DisassociateModels(); 1171 error = model_associator_->DisassociateModels();
1165 ASSERT_FALSE(error.IsSet()); 1172 ASSERT_FALSE(error.IsSet());
1166 { 1173 {
1167 // Delete the first sync tab node. 1174 // Delete the first sync tab node.
1168 std::string tab_tag = TabNodePool::TabIdToTag(local_tag, 0); 1175 std::string tab_tag = TabNodePool::TabIdToTag(local_tag, 1);
1169 1176
1170 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1177 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1171 syncer::ReadNode root(&trans); 1178 syncer::ReadNode root(&trans);
1172 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS)); 1179 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS));
1173 syncer::WriteNode tab_node(&trans); 1180 syncer::WriteNode tab_node(&trans);
1174 ASSERT_EQ(syncer::BaseNode::INIT_OK, 1181 ASSERT_EQ(syncer::BaseNode::INIT_OK,
1175 tab_node.InitByClientTagLookup(syncer::SESSIONS, tab_tag)); 1182 tab_node.InitByClientTagLookup(syncer::SESSIONS, tab_tag));
1176 tab_node.Tombstone(); 1183 tab_node.Tombstone();
1177 } 1184 }
1178 error = model_associator_->AssociateModels(NULL, NULL); 1185 error = model_associator_->AssociateModels(NULL, NULL);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 sync_pb::SessionSpecifics specifics; 1255 sync_pb::SessionSpecifics specifics;
1249 header.SetSessionSpecifics(specifics); 1256 header.SetSessionSpecifics(specifics);
1250 } 1257 }
1251 // Ensure we associate properly despite the pre-existing node with our local 1258 // Ensure we associate properly despite the pre-existing node with our local
1252 // tag. 1259 // tag.
1253 error = model_associator_->AssociateModels(NULL, NULL); 1260 error = model_associator_->AssociateModels(NULL, NULL);
1254 ASSERT_FALSE(error.IsSet()); 1261 ASSERT_FALSE(error.IsSet());
1255 } 1262 }
1256 1263
1257 } // namespace browser_sync 1264 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/tab_node_pool_unittest.cc ('k') | chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698