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

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

Issue 15055003: Do not submit: high level overview patch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build. Created 7 years, 7 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"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/time.h" 17 #include "base/time.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19
19 #include "chrome/browser/signin/signin_manager.h" 20 #include "chrome/browser/signin/signin_manager.h"
20 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/signin/token_service_factory.h" 22 #include "chrome/browser/signin/token_service_factory.h"
22 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 23 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
24 #include "chrome/browser/sync/glue/change_processor.h"
23 #include "chrome/browser/sync/glue/device_info.h" 25 #include "chrome/browser/sync/glue/device_info.h"
24 #include "chrome/browser/sync/glue/session_change_processor.h" 26 #include "chrome/browser/sync/glue/session_change_processor.h"
25 #include "chrome/browser/sync/glue/session_data_type_controller.h" 27 #include "chrome/browser/sync/glue/session_data_type_controller.h"
26 #include "chrome/browser/sync/glue/session_model_associator.h" 28 #include "chrome/browser/sync/glue/session_model_associator.h"
27 #include "chrome/browser/sync/glue/sync_backend_host.h" 29 #include "chrome/browser/sync/glue/sync_backend_host.h"
28 #include "chrome/browser/sync/glue/synced_device_tracker.h" 30 #include "chrome/browser/sync/glue/synced_device_tracker.h"
29 #include "chrome/browser/sync/glue/synced_tab_delegate.h" 31 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
30 #include "chrome/browser/sync/glue/tab_node_pool.h" 32 #include "chrome/browser/sync/glue/tab_node_pool.h"
31 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 33 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
32 #include "chrome/browser/sync/profile_sync_service_factory.h" 34 #include "chrome/browser/sync/profile_sync_service_factory.h"
33 #include "chrome/browser/sync/profile_sync_test_util.h" 35 #include "chrome/browser/sync/profile_sync_test_util.h"
34 #include "chrome/browser/sync/test_profile_sync_service.h" 36 #include "chrome/browser/sync/test_profile_sync_service.h"
37 #include "chrome/browser/ui/tabs/tab_strip_model.h"
35 #include "chrome/common/chrome_notification_types.h" 38 #include "chrome/common/chrome_notification_types.h"
36 #include "chrome/test/base/browser_with_test_window_test.h" 39 #include "chrome/test/base/browser_with_test_window_test.h"
37 #include "chrome/test/base/testing_profile.h" 40 #include "chrome/test/base/testing_profile.h"
38 #include "content/public/browser/navigation_entry.h" 41 #include "content/public/browser/navigation_entry.h"
39 #include "content/public/browser/notification_observer.h" 42 #include "content/public/browser/notification_observer.h"
40 #include "content/public/browser/notification_registrar.h" 43 #include "content/public/browser/notification_registrar.h"
41 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
42 #include "content/public/test/test_browser_thread.h" 45 #include "content/public/test/test_browser_thread.h"
46 #include "content/public/test/test_utils.h"
43 #include "google_apis/gaia/gaia_constants.h" 47 #include "google_apis/gaia/gaia_constants.h"
44 #include "googleurl/src/gurl.h" 48 #include "googleurl/src/gurl.h"
45 #include "sync/internal_api/public/base/model_type.h" 49 #include "sync/internal_api/public/base/model_type.h"
46 #include "sync/internal_api/public/change_record.h" 50 #include "sync/internal_api/public/change_record.h"
47 #include "sync/internal_api/public/read_node.h" 51 #include "sync/internal_api/public/read_node.h"
48 #include "sync/internal_api/public/read_transaction.h" 52 #include "sync/internal_api/public/read_transaction.h"
49 #include "sync/internal_api/public/test/test_user_share.h" 53 #include "sync/internal_api/public/test/test_user_share.h"
50 #include "sync/internal_api/public/write_node.h" 54 #include "sync/internal_api/public/write_node.h"
51 #include "sync/internal_api/public/write_transaction.h" 55 #include "sync/internal_api/public/write_transaction.h"
52 #include "sync/protocol/session_specifics.pb.h" 56 #include "sync/protocol/session_specifics.pb.h"
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } 773 }
770 774
771 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed 775 // TODO(jhorwich): Re-enable when crbug.com/121487 addressed
772 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty) { 776 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty) {
773 CreateRootHelper create_root(this); 777 CreateRootHelper create_root(this);
774 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 778 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
775 ASSERT_TRUE(create_root.success()); 779 ASSERT_TRUE(create_root.success());
776 780
777 const size_t num_starting_nodes = 3; 781 const size_t num_starting_nodes = 3;
778 for (size_t i = 0; i < num_starting_nodes; ++i) { 782 for (size_t i = 0; i < num_starting_nodes; ++i) {
779 model_associator_->tab_pool_.AddTabNode(i); 783 model_associator_->tab_pool_.AddTabNode(i, i);
780 } 784 }
781 785
782 std::vector<int64> node_ids; 786 std::vector<int64> node_ids;
783 ASSERT_EQ(num_starting_nodes, model_associator_->tab_pool_.capacity()); 787 ASSERT_EQ(num_starting_nodes, model_associator_->tab_pool_.capacity());
784 ASSERT_FALSE(model_associator_->tab_pool_.empty()); 788 //ASSERT_FALSE(model_associator_->tab_pool_.empty());
785 ASSERT_TRUE(model_associator_->tab_pool_.full()); 789 ASSERT_TRUE(model_associator_->tab_pool_.full());
786 const size_t num_ids = 10; 790 const size_t num_ids = 10;
787 for (size_t i = 0; i < num_ids; ++i) { 791 for (size_t i = 0; i < num_ids; ++i) {
788 int64 id = model_associator_->tab_pool_.GetFreeTabNode(); 792 int64 id = model_associator_->tab_pool_.GetFreeTabNode();
789 ASSERT_GT(id, -1); 793 ASSERT_GT(id, -1);
790 node_ids.push_back(id); 794 node_ids.push_back(id);
791 } 795 }
792 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 796 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
793 ASSERT_TRUE(model_associator_->tab_pool_.empty()); 797 ASSERT_TRUE(model_associator_->tab_pool_.empty());
794 ASSERT_FALSE(model_associator_->tab_pool_.full()); 798 ASSERT_FALSE(model_associator_->tab_pool_.full());
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 } 1177 }
1174 error = model_associator_->AssociateModels(NULL, NULL); 1178 error = model_associator_->AssociateModels(NULL, NULL);
1175 ASSERT_FALSE(error.IsSet()); 1179 ASSERT_FALSE(error.IsSet());
1176 1180
1177 // Add some more tabs to ensure we don't conflict with the pre-existing tab 1181 // Add some more tabs to ensure we don't conflict with the pre-existing tab
1178 // node. 1182 // node.
1179 AddTab(browser(), GURL("http://baz1")); 1183 AddTab(browser(), GURL("http://baz1"));
1180 AddTab(browser(), GURL("http://baz2")); 1184 AddTab(browser(), GURL("http://baz2"));
1181 } 1185 }
1182 1186
1187 void CloseTab(int index) {}
1188
1189 TEST_F(ProfileSyncServiceSessionTest, CheckTabAssociation) {
1190 // Incomplete test currently just verifies that reassociation does not
1191 // cause any errors.
1192 AddTab(browser(), GURL("http://foo1"));
1193 AddTab(browser(), GURL("http://foo2"));
1194 AddTab(browser(), GURL("http://foo3"));
1195
1196 CreateRootHelper create_root(this);
1197 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
1198
1199 std::string local_tag = model_associator_->GetCurrentMachineTag();
1200 change_processor_->StopObserving();
1201 syncer::SyncError error;
1202
1203 error = model_associator_->DisassociateModels();
1204 ASSERT_FALSE(error.IsSet());
1205
1206 content::WindowedNotificationObserver tab_close_observer(
1207 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1208 content::NotificationService::AllSources());
1209 browser()->tab_strip_model()
1210 ->CloseWebContentsAt(0, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB);
1211 tab_close_observer.Wait();
1212
1213 change_processor_->StartObserving();
1214 {
1215 // Delete the first sync tab node.
1216 std::string tab_tag = TabNodePool::TabIdToTag(local_tag, 0);
1217
1218 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1219 syncer::ReadNode root(&trans);
1220 root.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::SESSIONS));
1221 syncer::WriteNode tab_node(&trans);
1222 ASSERT_EQ(syncer::BaseNode::INIT_OK,
1223 tab_node.InitByClientTagLookup(syncer::SESSIONS, tab_tag));
1224 tab_node.Tombstone();
1225 }
1226 error = model_associator_->AssociateModels(NULL, NULL);
1227 ASSERT_FALSE(error.IsSet());
1228
1229 // Add some more tabs to ensure we don't conflict with the pre-existing tab
1230 // node.
1231 AddTab(browser(), GURL("http://baz1"));
1232 AddTab(browser(), GURL("http://baz2"));
1233 }
1234
1183 TEST_F(ProfileSyncServiceSessionTest, Favicons) { 1235 TEST_F(ProfileSyncServiceSessionTest, Favicons) {
1184 CreateRootHelper create_root(this); 1236 CreateRootHelper create_root(this);
1185 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 1237 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
1186 ASSERT_TRUE(create_root.success()); 1238 ASSERT_TRUE(create_root.success());
1187 1239
1188 // Build a foreign session with one window and one tab. 1240 // Build a foreign session with one window and one tab.
1189 std::string tag = "tag1"; 1241 std::string tag = "tag1";
1190 sync_pb::SessionSpecifics meta; 1242 sync_pb::SessionSpecifics meta;
1191 BuildSessionSpecifics(tag, &meta); 1243 BuildSessionSpecifics(tag, &meta);
1192 std::vector<SessionID::id_type> tab_list; 1244 std::vector<SessionID::id_type> tab_list;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 sync_pb::SessionSpecifics specifics; 1296 sync_pb::SessionSpecifics specifics;
1245 header.SetSessionSpecifics(specifics); 1297 header.SetSessionSpecifics(specifics);
1246 } 1298 }
1247 // Ensure we associate properly despite the pre-existing node with our local 1299 // Ensure we associate properly despite the pre-existing node with our local
1248 // tag. 1300 // tag.
1249 error = model_associator_->AssociateModels(NULL, NULL); 1301 error = model_associator_->AssociateModels(NULL, NULL);
1250 ASSERT_FALSE(error.IsSet()); 1302 ASSERT_FALSE(error.IsSet());
1251 } 1303 }
1252 1304
1253 } // namespace browser_sync 1305 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698