| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 profile()->ResetRequestContext(); | 244 profile()->ResetRequestContext(); |
| 245 | 245 |
| 246 // We need to destroy the profile before shutting down the threads, because | 246 // We need to destroy the profile before shutting down the threads, because |
| 247 // some of the ref counted objects in the profile depend on their | 247 // some of the ref counted objects in the profile depend on their |
| 248 // destruction on the io thread. | 248 // destruction on the io thread. |
| 249 DestroyBrowserAndProfile(); | 249 DestroyBrowserAndProfile(); |
| 250 set_profile(NULL); | 250 set_profile(NULL); |
| 251 | 251 |
| 252 // Pump messages posted by the sync core thread (which may end up | 252 // Pump messages posted by the sync core thread (which may end up |
| 253 // posting on the IO thread). | 253 // posting on the IO thread). |
| 254 MessageLoop::current()->RunUntilIdle(); | 254 base::MessageLoop::current()->RunUntilIdle(); |
| 255 io_thread_.Stop(); | 255 io_thread_.Stop(); |
| 256 MessageLoop::current()->RunUntilIdle(); | 256 base::MessageLoop::current()->RunUntilIdle(); |
| 257 BrowserWithTestWindowTest::TearDown(); | 257 BrowserWithTestWindowTest::TearDown(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool StartSyncService(const base::Closure& callback, | 260 bool StartSyncService(const base::Closure& callback, |
| 261 bool will_fail_association) { | 261 bool will_fail_association) { |
| 262 if (sync_service_.get()) | 262 if (sync_service_.get()) |
| 263 return false; | 263 return false; |
| 264 SigninManagerBase* signin = | 264 SigninManagerBase* signin = |
| 265 SigninManagerFactory::GetForProfile(profile()); | 265 SigninManagerFactory::GetForProfile(profile()); |
| 266 signin->SetAuthenticatedUsername("test_user"); | 266 signin->SetAuthenticatedUsername("test_user"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 288 true /* setup_for_test */); | 288 true /* setup_for_test */); |
| 289 EXPECT_CALL(*factory, CreateSessionSyncComponents(_, _)). | 289 EXPECT_CALL(*factory, CreateSessionSyncComponents(_, _)). |
| 290 WillOnce(Return(ProfileSyncComponentsFactory::SyncComponents( | 290 WillOnce(Return(ProfileSyncComponentsFactory::SyncComponents( |
| 291 model_associator_, change_processor_))); | 291 model_associator_, change_processor_))); |
| 292 EXPECT_CALL(*factory, CreateDataTypeManager(_, _, _, _, _)). | 292 EXPECT_CALL(*factory, CreateDataTypeManager(_, _, _, _, _)). |
| 293 WillOnce(ReturnNewDataTypeManager()); | 293 WillOnce(ReturnNewDataTypeManager()); |
| 294 | 294 |
| 295 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest( | 295 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest( |
| 296 GaiaConstants::kSyncService, "token"); | 296 GaiaConstants::kSyncService, "token"); |
| 297 sync_service_->Initialize(); | 297 sync_service_->Initialize(); |
| 298 MessageLoop::current()->Run(); | 298 base::MessageLoop::current()->Run(); |
| 299 return true; | 299 return true; |
| 300 } | 300 } |
| 301 | 301 |
| 302 content::TestBrowserThread io_thread_; | 302 content::TestBrowserThread io_thread_; |
| 303 // Path used in testing. | 303 // Path used in testing. |
| 304 base::ScopedTempDir temp_dir_; | 304 base::ScopedTempDir temp_dir_; |
| 305 SessionModelAssociator* model_associator_; | 305 SessionModelAssociator* model_associator_; |
| 306 SessionChangeProcessor* change_processor_; | 306 SessionChangeProcessor* change_processor_; |
| 307 SessionID window_id_; | 307 SessionID window_id_; |
| 308 scoped_ptr<TestProfileSyncService> sync_service_; | 308 scoped_ptr<TestProfileSyncService> sync_service_; |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 tab_list.push_back(5); | 1196 tab_list.push_back(5); |
| 1197 AddWindowSpecifics(0, tab_list, &meta); | 1197 AddWindowSpecifics(0, tab_list, &meta); |
| 1198 sync_pb::SessionSpecifics tab; | 1198 sync_pb::SessionSpecifics tab; |
| 1199 BuildTabSpecifics(tag, 0, tab_list[0], &tab); | 1199 BuildTabSpecifics(tag, 0, tab_list[0], &tab); |
| 1200 std::string url = tab.tab().navigation(0).virtual_url(); | 1200 std::string url = tab.tab().navigation(0).virtual_url(); |
| 1201 scoped_refptr<base::RefCountedMemory> favicon; | 1201 scoped_refptr<base::RefCountedMemory> favicon; |
| 1202 | 1202 |
| 1203 // Update associator. | 1203 // Update associator. |
| 1204 model_associator_->AssociateForeignSpecifics(meta, base::Time()); | 1204 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 1205 model_associator_->AssociateForeignSpecifics(tab, base::Time()); | 1205 model_associator_->AssociateForeignSpecifics(tab, base::Time()); |
| 1206 MessageLoop::current()->RunUntilIdle(); | 1206 base::MessageLoop::current()->RunUntilIdle(); |
| 1207 ASSERT_FALSE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); | 1207 ASSERT_FALSE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); |
| 1208 | 1208 |
| 1209 // Now add a favicon. | 1209 // Now add a favicon. |
| 1210 tab.mutable_tab()->set_favicon_source("http://favicon_source.com/png.ico"); | 1210 tab.mutable_tab()->set_favicon_source("http://favicon_source.com/png.ico"); |
| 1211 tab.mutable_tab()->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); | 1211 tab.mutable_tab()->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); |
| 1212 tab.mutable_tab()->set_favicon("data"); | 1212 tab.mutable_tab()->set_favicon("data"); |
| 1213 model_associator_->AssociateForeignSpecifics(tab, base::Time()); | 1213 model_associator_->AssociateForeignSpecifics(tab, base::Time()); |
| 1214 MessageLoop::current()->RunUntilIdle(); | 1214 base::MessageLoop::current()->RunUntilIdle(); |
| 1215 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); | 1215 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); |
| 1216 ASSERT_TRUE(CompareMemoryToString("data", favicon)); | 1216 ASSERT_TRUE(CompareMemoryToString("data", favicon)); |
| 1217 | 1217 |
| 1218 // Simulate navigating away. The associator should not delete the favicon. | 1218 // Simulate navigating away. The associator should not delete the favicon. |
| 1219 tab.mutable_tab()->clear_navigation(); | 1219 tab.mutable_tab()->clear_navigation(); |
| 1220 tab.mutable_tab()->add_navigation()->set_virtual_url("http://new_url.com"); | 1220 tab.mutable_tab()->add_navigation()->set_virtual_url("http://new_url.com"); |
| 1221 tab.mutable_tab()->clear_favicon_source(); | 1221 tab.mutable_tab()->clear_favicon_source(); |
| 1222 tab.mutable_tab()->clear_favicon_type(); | 1222 tab.mutable_tab()->clear_favicon_type(); |
| 1223 tab.mutable_tab()->clear_favicon(); | 1223 tab.mutable_tab()->clear_favicon(); |
| 1224 model_associator_->AssociateForeignSpecifics(tab, base::Time()); | 1224 model_associator_->AssociateForeignSpecifics(tab, base::Time()); |
| 1225 MessageLoop::current()->RunUntilIdle(); | 1225 base::MessageLoop::current()->RunUntilIdle(); |
| 1226 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); | 1226 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 TEST_F(ProfileSyncServiceSessionTest, CorruptedLocalHeader) { | 1229 TEST_F(ProfileSyncServiceSessionTest, CorruptedLocalHeader) { |
| 1230 AddTab(browser(), GURL("http://foo1")); | 1230 AddTab(browser(), GURL("http://foo1")); |
| 1231 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1231 NavigateAndCommitActiveTab(GURL("http://foo2")); |
| 1232 AddTab(browser(), GURL("http://bar1")); | 1232 AddTab(browser(), GURL("http://bar1")); |
| 1233 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1233 NavigateAndCommitActiveTab(GURL("http://bar2")); |
| 1234 CreateRootHelper create_root(this); | 1234 CreateRootHelper create_root(this); |
| 1235 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1235 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1247 sync_pb::SessionSpecifics specifics; | 1247 sync_pb::SessionSpecifics specifics; |
| 1248 header.SetSessionSpecifics(specifics); | 1248 header.SetSessionSpecifics(specifics); |
| 1249 } | 1249 } |
| 1250 // Ensure we associate properly despite the pre-existing node with our local | 1250 // Ensure we associate properly despite the pre-existing node with our local |
| 1251 // tag. | 1251 // tag. |
| 1252 error = model_associator_->AssociateModels(NULL, NULL); | 1252 error = model_associator_->AssociateModels(NULL, NULL); |
| 1253 ASSERT_FALSE(error.IsSet()); | 1253 ASSERT_FALSE(error.IsSet()); |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 } // namespace browser_sync | 1256 } // namespace browser_sync |
| OLD | NEW |