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

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: Fix win compile, rename uint -> size_t. 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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 749
750 std::vector<int64> node_ids; 750 std::vector<int64> node_ids;
751 ASSERT_EQ(0U, model_associator_->tab_pool_.capacity()); 751 ASSERT_EQ(0U, model_associator_->tab_pool_.capacity());
752 ASSERT_TRUE(model_associator_->tab_pool_.empty()); 752 ASSERT_TRUE(model_associator_->tab_pool_.empty());
753 ASSERT_TRUE(model_associator_->tab_pool_.full()); 753 ASSERT_TRUE(model_associator_->tab_pool_.full());
754 const size_t num_ids = 10; 754 const size_t num_ids = 10;
755 for (size_t i = 0; i < num_ids; ++i) { 755 for (size_t i = 0; i < num_ids; ++i) {
756 int64 id = model_associator_->tab_pool_.GetFreeTabNode(); 756 int64 id = model_associator_->tab_pool_.GetFreeTabNode();
757 ASSERT_GT(id, -1); 757 ASSERT_GT(id, -1);
758 node_ids.push_back(id); 758 node_ids.push_back(id);
759 // Associate with a tab node.
760 model_associator_->tab_pool_.AssociateTabNode(id, i + 1);
759 } 761 }
760 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 762 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
761 ASSERT_TRUE(model_associator_->tab_pool_.empty()); 763 ASSERT_TRUE(model_associator_->tab_pool_.empty());
762 ASSERT_FALSE(model_associator_->tab_pool_.full()); 764 ASSERT_FALSE(model_associator_->tab_pool_.full());
763 for (size_t i = 0; i < num_ids; ++i) { 765 for (size_t i = 0; i < num_ids; ++i) {
764 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); 766 model_associator_->tab_pool_.FreeTabNode(node_ids[i]);
765 } 767 }
766 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 768 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
767 ASSERT_FALSE(model_associator_->tab_pool_.empty()); 769 ASSERT_FALSE(model_associator_->tab_pool_.empty());
768 ASSERT_TRUE(model_associator_->tab_pool_.full()); 770 ASSERT_TRUE(model_associator_->tab_pool_.full());
769 } 771 }
770 772
771 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed 773 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed
772 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty) { 774 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty) {
773 CreateRootHelper create_root(this); 775 CreateRootHelper create_root(this);
774 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 776 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
775 ASSERT_TRUE(create_root.success()); 777 ASSERT_TRUE(create_root.success());
776 778
777 const size_t num_starting_nodes = 3; 779 const size_t num_starting_nodes = 3;
780 SessionID session_id;
778 for (size_t i = 0; i < num_starting_nodes; ++i) { 781 for (size_t i = 0; i < num_starting_nodes; ++i) {
779 model_associator_->tab_pool_.AddTabNode(i); 782 session_id.set_id(i + 1);
783 model_associator_->tab_pool_.AddTabNode(i + 1, session_id, i);
780 } 784 }
781 785
786 model_associator_->tab_pool_.FreeUnusedTabNodes(std::set<int64>());
782 std::vector<int64> node_ids; 787 std::vector<int64> node_ids;
783 ASSERT_EQ(num_starting_nodes, model_associator_->tab_pool_.capacity()); 788 ASSERT_EQ(num_starting_nodes, model_associator_->tab_pool_.capacity());
784 ASSERT_FALSE(model_associator_->tab_pool_.empty()); 789 ASSERT_FALSE(model_associator_->tab_pool_.empty());
785 ASSERT_TRUE(model_associator_->tab_pool_.full()); 790 ASSERT_TRUE(model_associator_->tab_pool_.full());
786 const size_t num_ids = 10; 791 const size_t num_ids = 10;
787 for (size_t i = 0; i < num_ids; ++i) { 792 for (size_t i = 0; i < num_ids; ++i) {
788 int64 id = model_associator_->tab_pool_.GetFreeTabNode(); 793 int64 id = model_associator_->tab_pool_.GetFreeTabNode();
789 ASSERT_GT(id, -1); 794 ASSERT_GT(id, -1);
790 node_ids.push_back(id); 795 node_ids.push_back(id);
796 // Associate with a tab node.
797 model_associator_->tab_pool_.AssociateTabNode(id, i + 1);
791 } 798 }
792 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 799 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
793 ASSERT_TRUE(model_associator_->tab_pool_.empty()); 800 ASSERT_TRUE(model_associator_->tab_pool_.empty());
794 ASSERT_FALSE(model_associator_->tab_pool_.full()); 801 ASSERT_FALSE(model_associator_->tab_pool_.full());
795 for (size_t i = 0; i < num_ids; ++i) { 802 for (size_t i = 0; i < num_ids; ++i) {
796 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); 803 model_associator_->tab_pool_.FreeTabNode(node_ids[i]);
797 } 804 }
798 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 805 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
799 ASSERT_FALSE(model_associator_->tab_pool_.empty()); 806 ASSERT_FALSE(model_associator_->tab_pool_.empty());
800 ASSERT_TRUE(model_associator_->tab_pool_.full()); 807 ASSERT_TRUE(model_associator_->tab_pool_.full());
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 NavigateAndCommitActiveTab(GURL("http://bar2")); 1161 NavigateAndCommitActiveTab(GURL("http://bar2"));
1155 CreateRootHelper create_root(this); 1162 CreateRootHelper create_root(this);
1156 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 1163 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
1157 std::string local_tag = model_associator_->GetCurrentMachineTag(); 1164 std::string local_tag = model_associator_->GetCurrentMachineTag();
1158 syncer::SyncError error; 1165 syncer::SyncError error;
1159 1166
1160 error = model_associator_->DisassociateModels(); 1167 error = model_associator_->DisassociateModels();
1161 ASSERT_FALSE(error.IsSet()); 1168 ASSERT_FALSE(error.IsSet());
1162 { 1169 {
1163 // Delete the first sync tab node. 1170 // Delete the first sync tab node.
1164 std::string tab_tag = TabNodePool::TabIdToTag(local_tag, 0); 1171 std::string tab_tag = TabNodePool::TabIdToTag(local_tag, 1);
1165 1172
1166 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1173 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1167 syncer::ReadNode root(&trans); 1174 syncer::ReadNode root(&trans);
1168 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS)); 1175 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS));
1169 syncer::WriteNode tab_node(&trans); 1176 syncer::WriteNode tab_node(&trans);
1170 ASSERT_EQ(syncer::BaseNode::INIT_OK, 1177 ASSERT_EQ(syncer::BaseNode::INIT_OK,
1171 tab_node.InitByClientTagLookup(syncer::SESSIONS, tab_tag)); 1178 tab_node.InitByClientTagLookup(syncer::SESSIONS, tab_tag));
1172 tab_node.Tombstone(); 1179 tab_node.Tombstone();
1173 } 1180 }
1174 error = model_associator_->AssociateModels(NULL, NULL); 1181 error = model_associator_->AssociateModels(NULL, NULL);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 sync_pb::SessionSpecifics specifics; 1251 sync_pb::SessionSpecifics specifics;
1245 header.SetSessionSpecifics(specifics); 1252 header.SetSessionSpecifics(specifics);
1246 } 1253 }
1247 // Ensure we associate properly despite the pre-existing node with our local 1254 // Ensure we associate properly despite the pre-existing node with our local
1248 // tag. 1255 // tag.
1249 error = model_associator_->AssociateModels(NULL, NULL); 1256 error = model_associator_->AssociateModels(NULL, NULL);
1250 ASSERT_FALSE(error.IsSet()); 1257 ASSERT_FALSE(error.IsSet());
1251 } 1258 }
1252 1259
1253 } // namespace browser_sync 1260 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698