| 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" |
| 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/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/invalidation/invalidation_service_factory.h" | 21 #include "chrome/browser/invalidation/invalidation_service_factory.h" |
| 22 #include "chrome/browser/sessions/session_tab_helper.h" | 22 #include "chrome/browser/sessions/session_tab_helper.h" |
| 23 #include "chrome/browser/signin/signin_manager.h" | 23 #include "chrome/browser/signin/signin_manager.h" |
| 24 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
| 25 #include "chrome/browser/signin/token_service_factory.h" | 25 #include "chrome/browser/signin/token_service_factory.h" |
| 26 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 26 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 41 #include "chrome/test/base/browser_with_test_window_test.h" | 41 #include "chrome/test/base/browser_with_test_window_test.h" |
| 42 #include "chrome/test/base/testing_profile.h" | 42 #include "chrome/test/base/testing_profile.h" |
| 43 #include "content/public/browser/navigation_controller.h" | 43 #include "content/public/browser/navigation_controller.h" |
| 44 #include "content/public/browser/navigation_entry.h" | 44 #include "content/public/browser/navigation_entry.h" |
| 45 #include "content/public/browser/notification_observer.h" | 45 #include "content/public/browser/notification_observer.h" |
| 46 #include "content/public/browser/notification_registrar.h" | 46 #include "content/public/browser/notification_registrar.h" |
| 47 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
| 49 #include "content/public/test/test_browser_thread.h" | 49 #include "content/public/test/test_browser_thread.h" |
| 50 #include "google_apis/gaia/gaia_constants.h" | 50 #include "google_apis/gaia/gaia_constants.h" |
| 51 #include "net/url_request/test_url_fetcher_factory.h" |
| 51 #include "sync/internal_api/public/base/model_type.h" | 52 #include "sync/internal_api/public/base/model_type.h" |
| 52 #include "sync/internal_api/public/change_record.h" | 53 #include "sync/internal_api/public/change_record.h" |
| 53 #include "sync/internal_api/public/read_node.h" | 54 #include "sync/internal_api/public/read_node.h" |
| 54 #include "sync/internal_api/public/read_transaction.h" | 55 #include "sync/internal_api/public/read_transaction.h" |
| 55 #include "sync/internal_api/public/test/test_user_share.h" | 56 #include "sync/internal_api/public/test/test_user_share.h" |
| 56 #include "sync/internal_api/public/write_node.h" | 57 #include "sync/internal_api/public/write_node.h" |
| 57 #include "sync/internal_api/public/write_transaction.h" | 58 #include "sync/internal_api/public/write_transaction.h" |
| 58 #include "sync/protocol/session_specifics.pb.h" | 59 #include "sync/protocol/session_specifics.pb.h" |
| 59 #include "sync/protocol/sync.pb.h" | 60 #include "sync/protocol/sync.pb.h" |
| 60 #include "testing/gmock/include/gmock/gmock.h" | 61 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return true; | 196 return true; |
| 196 } | 197 } |
| 197 | 198 |
| 198 } // namespace | 199 } // namespace |
| 199 | 200 |
| 200 class ProfileSyncServiceSessionTest | 201 class ProfileSyncServiceSessionTest |
| 201 : public BrowserWithTestWindowTest, | 202 : public BrowserWithTestWindowTest, |
| 202 public content::NotificationObserver { | 203 public content::NotificationObserver { |
| 203 public: | 204 public: |
| 204 ProfileSyncServiceSessionTest() | 205 ProfileSyncServiceSessionTest() |
| 205 : io_thread_(BrowserThread::IO), | 206 : window_bounds_(0, 1, 2, 3), |
| 206 window_bounds_(0, 1, 2, 3), | |
| 207 notified_of_update_(false), | 207 notified_of_update_(false), |
| 208 notified_of_refresh_(false) {} | 208 notified_of_refresh_(false) {} |
| 209 ProfileSyncService* sync_service() { return sync_service_.get(); } | 209 ProfileSyncService* sync_service() { return sync_service_.get(); } |
| 210 | 210 |
| 211 protected: | 211 protected: |
| 212 virtual TestingProfile* CreateProfile() OVERRIDE { | 212 virtual TestingProfile* CreateProfile() OVERRIDE { |
| 213 TestingProfile* profile = new TestingProfile(); | 213 TestingProfile* profile = new TestingProfile(); |
| 214 // Don't want the profile to create a real ProfileSyncService. | 214 // Don't want the profile to create a real ProfileSyncService. |
| 215 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile, | 215 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile, |
| 216 NULL); | 216 NULL); |
| 217 invalidation::InvalidationServiceFactory::GetInstance()-> | 217 invalidation::InvalidationServiceFactory::GetInstance()-> |
| 218 SetBuildOnlyFakeInvalidatorsForTest(true); | 218 SetBuildOnlyFakeInvalidatorsForTest(true); |
| 219 return profile; | 219 return profile; |
| 220 } | 220 } |
| 221 | 221 |
| 222 virtual void SetUp() { | 222 virtual void SetUp() { |
| 223 // BrowserWithTestWindowTest implementation. | 223 // BrowserWithTestWindowTest implementation. |
| 224 BrowserWithTestWindowTest::SetUp(); | 224 BrowserWithTestWindowTest::SetUp(); |
| 225 io_thread_.StartIOThread(); | |
| 226 profile()->CreateRequestContext(); | |
| 227 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 225 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 228 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, | 226 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
| 229 content::NotificationService::AllSources()); | 227 content::NotificationService::AllSources()); |
| 230 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 228 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 231 content::NotificationService::AllSources()); | 229 content::NotificationService::AllSources()); |
| 232 } | 230 } |
| 233 | 231 |
| 234 virtual void Observe(int type, | 232 virtual void Observe(int type, |
| 235 const content::NotificationSource& source, | 233 const content::NotificationSource& source, |
| 236 const content::NotificationDetails& details) OVERRIDE { | 234 const content::NotificationDetails& details) OVERRIDE { |
| 237 switch (type) { | 235 switch (type) { |
| 238 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED: | 236 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED: |
| 239 notified_of_update_ = true; | 237 notified_of_update_ = true; |
| 240 break; | 238 break; |
| 241 case chrome::NOTIFICATION_SYNC_REFRESH_LOCAL: | 239 case chrome::NOTIFICATION_SYNC_REFRESH_LOCAL: |
| 242 notified_of_refresh_ = true; | 240 notified_of_refresh_ = true; |
| 243 break; | 241 break; |
| 244 default: | 242 default: |
| 245 NOTREACHED(); | 243 NOTREACHED(); |
| 246 break; | 244 break; |
| 247 } | 245 } |
| 248 } | 246 } |
| 249 | 247 |
| 250 virtual void TearDown() { | 248 virtual void TearDown() { |
| 251 sync_service_->Shutdown(); | 249 sync_service_->Shutdown(); |
| 252 sync_service_.reset(); | 250 sync_service_.reset(); |
| 253 profile()->ResetRequestContext(); | |
| 254 | 251 |
| 255 // We need to destroy the profile before shutting down the threads, because | 252 // We need to destroy the profile before shutting down the threads, because |
| 256 // some of the ref counted objects in the profile depend on their | 253 // some of the ref counted objects in the profile depend on their |
| 257 // destruction on the io thread. | 254 // destruction on the io thread. |
| 258 DestroyBrowserAndProfile(); | 255 DestroyBrowserAndProfile(); |
| 259 ASSERT_FALSE(profile()); | 256 ASSERT_FALSE(profile()); |
| 260 | 257 |
| 261 // Pump messages posted by the sync core thread (which may end up | 258 // Pump messages posted by the sync core thread (which may end up |
| 262 // posting on the IO thread). | 259 // posting on the IO thread). |
| 263 base::MessageLoop::current()->RunUntilIdle(); | 260 base::RunLoop().RunUntilIdle(); |
| 264 io_thread_.Stop(); | |
| 265 base::MessageLoop::current()->RunUntilIdle(); | |
| 266 BrowserWithTestWindowTest::TearDown(); | 261 BrowserWithTestWindowTest::TearDown(); |
| 267 } | 262 } |
| 268 | 263 |
| 269 bool StartSyncService(const base::Closure& callback, | 264 bool StartSyncService(const base::Closure& callback, |
| 270 bool will_fail_association) { | 265 bool will_fail_association) { |
| 271 if (sync_service_) | 266 if (sync_service_) |
| 272 return false; | 267 return false; |
| 273 SigninManagerBase* signin = | 268 SigninManagerBase* signin = |
| 274 SigninManagerFactory::GetForProfile(profile()); | 269 SigninManagerFactory::GetForProfile(profile()); |
| 275 signin->SetAuthenticatedUsername("test_user"); | 270 signin->SetAuthenticatedUsername("test_user"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 305 | 300 |
| 306 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest( | 301 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest( |
| 307 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 302 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
| 308 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest( | 303 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest( |
| 309 GaiaConstants::kSyncService, "token"); | 304 GaiaConstants::kSyncService, "token"); |
| 310 sync_service_->Initialize(); | 305 sync_service_->Initialize(); |
| 311 base::MessageLoop::current()->Run(); | 306 base::MessageLoop::current()->Run(); |
| 312 return true; | 307 return true; |
| 313 } | 308 } |
| 314 | 309 |
| 315 content::TestBrowserThread io_thread_; | |
| 316 // Path used in testing. | 310 // Path used in testing. |
| 317 base::ScopedTempDir temp_dir_; | 311 base::ScopedTempDir temp_dir_; |
| 318 SessionModelAssociator* model_associator_; | 312 SessionModelAssociator* model_associator_; |
| 319 SessionChangeProcessor* change_processor_; | 313 SessionChangeProcessor* change_processor_; |
| 320 SessionID window_id_; | 314 SessionID window_id_; |
| 321 scoped_ptr<TestProfileSyncService> sync_service_; | 315 scoped_ptr<TestProfileSyncService> sync_service_; |
| 322 const gfx::Rect window_bounds_; | 316 const gfx::Rect window_bounds_; |
| 323 bool notified_of_update_; | 317 bool notified_of_update_; |
| 324 bool notified_of_refresh_; | 318 bool notified_of_refresh_; |
| 325 content::NotificationRegistrar registrar_; | 319 content::NotificationRegistrar registrar_; |
| 320 net::TestURLFetcherFactory fetcher_factory_; |
| 326 }; | 321 }; |
| 327 | 322 |
| 328 class CreateRootHelper { | 323 class CreateRootHelper { |
| 329 public: | 324 public: |
| 330 explicit CreateRootHelper(ProfileSyncServiceSessionTest* test) | 325 explicit CreateRootHelper(ProfileSyncServiceSessionTest* test) |
| 331 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback, | 326 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback, |
| 332 base::Unretained(this), test)), | 327 base::Unretained(this), test)), |
| 333 success_(false) { | 328 success_(false) { |
| 334 } | 329 } |
| 335 | 330 |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 tab_list.push_back(5); | 1210 tab_list.push_back(5); |
| 1216 AddWindowSpecifics(0, tab_list, &meta); | 1211 AddWindowSpecifics(0, tab_list, &meta); |
| 1217 sync_pb::SessionSpecifics tab; | 1212 sync_pb::SessionSpecifics tab; |
| 1218 BuildTabSpecifics(tag, 0, tab_list[0], &tab); | 1213 BuildTabSpecifics(tag, 0, tab_list[0], &tab); |
| 1219 std::string url = tab.tab().navigation(0).virtual_url(); | 1214 std::string url = tab.tab().navigation(0).virtual_url(); |
| 1220 scoped_refptr<base::RefCountedMemory> favicon; | 1215 scoped_refptr<base::RefCountedMemory> favicon; |
| 1221 | 1216 |
| 1222 // Update associator. | 1217 // Update associator. |
| 1223 model_associator_->AssociateForeignSpecifics(meta, base::Time()); | 1218 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 1224 model_associator_->AssociateForeignSpecifics(tab, base::Time()); | 1219 model_associator_->AssociateForeignSpecifics(tab, base::Time()); |
| 1225 base::MessageLoop::current()->RunUntilIdle(); | 1220 base::RunLoop().RunUntilIdle(); |
| 1226 ASSERT_FALSE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); | 1221 ASSERT_FALSE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); |
| 1227 | 1222 |
| 1228 // Now add a favicon. | 1223 // Now add a favicon. |
| 1229 tab.mutable_tab()->set_favicon_source("http://favicon_source.com/png.ico"); | 1224 tab.mutable_tab()->set_favicon_source("http://favicon_source.com/png.ico"); |
| 1230 tab.mutable_tab()->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); | 1225 tab.mutable_tab()->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); |
| 1231 tab.mutable_tab()->set_favicon("data"); | 1226 tab.mutable_tab()->set_favicon("data"); |
| 1232 model_associator_->AssociateForeignSpecifics(tab, base::Time()); | 1227 model_associator_->AssociateForeignSpecifics(tab, base::Time()); |
| 1233 base::MessageLoop::current()->RunUntilIdle(); | 1228 base::RunLoop().RunUntilIdle(); |
| 1234 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); | 1229 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); |
| 1235 ASSERT_TRUE(CompareMemoryToString("data", favicon)); | 1230 ASSERT_TRUE(CompareMemoryToString("data", favicon)); |
| 1236 | 1231 |
| 1237 // Simulate navigating away. The associator should not delete the favicon. | 1232 // Simulate navigating away. The associator should not delete the favicon. |
| 1238 tab.mutable_tab()->clear_navigation(); | 1233 tab.mutable_tab()->clear_navigation(); |
| 1239 tab.mutable_tab()->add_navigation()->set_virtual_url("http://new_url.com"); | 1234 tab.mutable_tab()->add_navigation()->set_virtual_url("http://new_url.com"); |
| 1240 tab.mutable_tab()->clear_favicon_source(); | 1235 tab.mutable_tab()->clear_favicon_source(); |
| 1241 tab.mutable_tab()->clear_favicon_type(); | 1236 tab.mutable_tab()->clear_favicon_type(); |
| 1242 tab.mutable_tab()->clear_favicon(); | 1237 tab.mutable_tab()->clear_favicon(); |
| 1243 model_associator_->AssociateForeignSpecifics(tab, base::Time()); | 1238 model_associator_->AssociateForeignSpecifics(tab, base::Time()); |
| 1244 base::MessageLoop::current()->RunUntilIdle(); | 1239 base::RunLoop().RunUntilIdle(); |
| 1245 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); | 1240 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); |
| 1246 } | 1241 } |
| 1247 | 1242 |
| 1248 TEST_F(ProfileSyncServiceSessionTest, CorruptedLocalHeader) { | 1243 TEST_F(ProfileSyncServiceSessionTest, CorruptedLocalHeader) { |
| 1249 AddTab(browser(), GURL("http://foo1")); | 1244 AddTab(browser(), GURL("http://foo1")); |
| 1250 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1245 NavigateAndCommitActiveTab(GURL("http://foo2")); |
| 1251 AddTab(browser(), GURL("http://bar1")); | 1246 AddTab(browser(), GURL("http://bar1")); |
| 1252 NavigateAndCommitActiveTab(GURL("http://bar2")); | 1247 NavigateAndCommitActiveTab(GURL("http://bar2")); |
| 1253 CreateRootHelper create_root(this); | 1248 CreateRootHelper create_root(this); |
| 1254 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 1249 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 // Freeing the last sync node should drop the free nodes to | 1359 // Freeing the last sync node should drop the free nodes to |
| 1365 // kFreeNodesLowWatermark. | 1360 // kFreeNodesLowWatermark. |
| 1366 model_associator_->tab_pool_.FreeTabNode(last_sync_id); | 1361 model_associator_->tab_pool_.FreeTabNode(last_sync_id); |
| 1367 EXPECT_FALSE(model_associator_->tab_pool_.Empty()); | 1362 EXPECT_FALSE(model_associator_->tab_pool_.Empty()); |
| 1368 EXPECT_TRUE(model_associator_->tab_pool_.Full()); | 1363 EXPECT_TRUE(model_associator_->tab_pool_.Full()); |
| 1369 EXPECT_EQ(TabNodePool::kFreeNodesLowWatermark, | 1364 EXPECT_EQ(TabNodePool::kFreeNodesLowWatermark, |
| 1370 model_associator_->tab_pool_.Capacity()); | 1365 model_associator_->tab_pool_.Capacity()); |
| 1371 } | 1366 } |
| 1372 | 1367 |
| 1373 } // namespace browser_sync | 1368 } // namespace browser_sync |
| OLD | NEW |