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

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

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup TODOs. merge code. kill more threads. i never get tired of thread carnage. Created 7 years, 5 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/run_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "chrome/browser/invalidation/invalidation_service_factory.h" 19 #include "chrome/browser/invalidation/invalidation_service_factory.h"
20 #include "chrome/browser/signin/signin_manager.h" 20 #include "chrome/browser/signin/signin_manager.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/signin/token_service_factory.h" 22 #include "chrome/browser/signin/token_service_factory.h"
23 #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/device_info.h" 24 #include "chrome/browser/sync/glue/device_info.h"
25 #include "chrome/browser/sync/glue/session_change_processor.h" 25 #include "chrome/browser/sync/glue/session_change_processor.h"
26 #include "chrome/browser/sync/glue/session_data_type_controller.h" 26 #include "chrome/browser/sync/glue/session_data_type_controller.h"
27 #include "chrome/browser/sync/glue/session_model_associator.h" 27 #include "chrome/browser/sync/glue/session_model_associator.h"
28 #include "chrome/browser/sync/glue/sync_backend_host.h" 28 #include "chrome/browser/sync/glue/sync_backend_host.h"
29 #include "chrome/browser/sync/glue/synced_device_tracker.h" 29 #include "chrome/browser/sync/glue/synced_device_tracker.h"
30 #include "chrome/browser/sync/glue/synced_tab_delegate.h" 30 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
31 #include "chrome/browser/sync/glue/tab_node_pool.h" 31 #include "chrome/browser/sync/glue/tab_node_pool.h"
32 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 32 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
33 #include "chrome/browser/sync/profile_sync_service_factory.h" 33 #include "chrome/browser/sync/profile_sync_service_factory.h"
34 #include "chrome/browser/sync/profile_sync_test_util.h" 34 #include "chrome/browser/sync/profile_sync_test_util.h"
35 #include "chrome/browser/sync/test_profile_sync_service.h" 35 #include "chrome/browser/sync/test_profile_sync_service.h"
36 #include "chrome/common/chrome_notification_types.h" 36 #include "chrome/common/chrome_notification_types.h"
37 #include "chrome/test/base/browser_with_test_window_test.h" 37 #include "chrome/test/base/browser_with_test_window_test.h"
38 #include "chrome/test/base/testing_profile.h" 38 #include "chrome/test/base/testing_profile.h"
39 #include "content/public/browser/navigation_entry.h" 39 #include "content/public/browser/navigation_entry.h"
40 #include "content/public/browser/notification_observer.h" 40 #include "content/public/browser/notification_observer.h"
41 #include "content/public/browser/notification_registrar.h" 41 #include "content/public/browser/notification_registrar.h"
42 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
43 #include "content/public/test/test_browser_thread.h" 43 #include "content/public/test/test_browser_thread.h"
44 #include "google_apis/gaia/gaia_constants.h" 44 #include "google_apis/gaia/gaia_constants.h"
45 #include "net/url_request/test_url_fetcher_factory.h"
45 #include "sync/internal_api/public/base/model_type.h" 46 #include "sync/internal_api/public/base/model_type.h"
46 #include "sync/internal_api/public/change_record.h" 47 #include "sync/internal_api/public/change_record.h"
47 #include "sync/internal_api/public/read_node.h" 48 #include "sync/internal_api/public/read_node.h"
48 #include "sync/internal_api/public/read_transaction.h" 49 #include "sync/internal_api/public/read_transaction.h"
49 #include "sync/internal_api/public/test/test_user_share.h" 50 #include "sync/internal_api/public/test/test_user_share.h"
50 #include "sync/internal_api/public/write_node.h" 51 #include "sync/internal_api/public/write_node.h"
51 #include "sync/internal_api/public/write_transaction.h" 52 #include "sync/internal_api/public/write_transaction.h"
52 #include "sync/protocol/session_specifics.pb.h" 53 #include "sync/protocol/session_specifics.pb.h"
53 #include "sync/protocol/sync.pb.h" 54 #include "sync/protocol/sync.pb.h"
54 #include "testing/gmock/include/gmock/gmock.h" 55 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return true; 188 return true;
188 } 189 }
189 190
190 } // namespace 191 } // namespace
191 192
192 class ProfileSyncServiceSessionTest 193 class ProfileSyncServiceSessionTest
193 : public BrowserWithTestWindowTest, 194 : public BrowserWithTestWindowTest,
194 public content::NotificationObserver { 195 public content::NotificationObserver {
195 public: 196 public:
196 ProfileSyncServiceSessionTest() 197 ProfileSyncServiceSessionTest()
197 : io_thread_(BrowserThread::IO), 198 : window_bounds_(0, 1, 2, 3),
198 window_bounds_(0, 1, 2, 3),
199 notified_of_update_(false), 199 notified_of_update_(false),
200 notified_of_refresh_(false) {} 200 notified_of_refresh_(false) {}
201 ProfileSyncService* sync_service() { return sync_service_.get(); } 201 ProfileSyncService* sync_service() { return sync_service_.get(); }
202 202
203 protected: 203 protected:
204 virtual TestingProfile* CreateProfile() OVERRIDE { 204 virtual TestingProfile* CreateProfile() OVERRIDE {
205 TestingProfile* profile = new TestingProfile(); 205 TestingProfile* profile = new TestingProfile();
206 // Don't want the profile to create a real ProfileSyncService. 206 // Don't want the profile to create a real ProfileSyncService.
207 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile, 207 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile,
208 NULL); 208 NULL);
209 invalidation::InvalidationServiceFactory::GetInstance()-> 209 invalidation::InvalidationServiceFactory::GetInstance()->
210 SetBuildOnlyFakeInvalidatorsForTest(true); 210 SetBuildOnlyFakeInvalidatorsForTest(true);
211 return profile; 211 return profile;
212 } 212 }
213 213
214 virtual void SetUp() { 214 virtual void SetUp() {
215 // BrowserWithTestWindowTest implementation. 215 // BrowserWithTestWindowTest implementation.
216 BrowserWithTestWindowTest::SetUp(); 216 BrowserWithTestWindowTest::SetUp();
217 io_thread_.StartIOThread();
218 profile()->CreateRequestContext();
219 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 217 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
220 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, 218 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED,
221 content::NotificationService::AllSources()); 219 content::NotificationService::AllSources());
222 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 220 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
223 content::NotificationService::AllSources()); 221 content::NotificationService::AllSources());
224 } 222 }
225 223
226 virtual void Observe(int type, 224 virtual void Observe(int type,
227 const content::NotificationSource& source, 225 const content::NotificationSource& source,
228 const content::NotificationDetails& details) OVERRIDE { 226 const content::NotificationDetails& details) OVERRIDE {
229 switch (type) { 227 switch (type) {
230 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED: 228 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED:
231 notified_of_update_ = true; 229 notified_of_update_ = true;
232 break; 230 break;
233 case chrome::NOTIFICATION_SYNC_REFRESH_LOCAL: 231 case chrome::NOTIFICATION_SYNC_REFRESH_LOCAL:
234 notified_of_refresh_ = true; 232 notified_of_refresh_ = true;
235 break; 233 break;
236 default: 234 default:
237 NOTREACHED(); 235 NOTREACHED();
238 break; 236 break;
239 } 237 }
240 } 238 }
241 239
242 virtual void TearDown() { 240 virtual void TearDown() {
243 sync_service_->Shutdown(); 241 sync_service_->Shutdown();
244 sync_service_.reset(); 242 sync_service_.reset();
245 profile()->ResetRequestContext();
246 243
247 // We need to destroy the profile before shutting down the threads, because 244 // We need to destroy the profile before shutting down the threads, because
248 // some of the ref counted objects in the profile depend on their 245 // some of the ref counted objects in the profile depend on their
249 // destruction on the io thread. 246 // destruction on the io thread.
250 DestroyBrowserAndProfile(); 247 DestroyBrowserAndProfile();
251 ASSERT_FALSE(profile()); 248 ASSERT_FALSE(profile());
252 249
253 // Pump messages posted by the sync core thread (which may end up 250 // Pump messages posted by the sync core thread (which may end up
254 // posting on the IO thread). 251 // posting on the IO thread).
255 base::MessageLoop::current()->RunUntilIdle(); 252 base::RunLoop().RunUntilIdle();
256 io_thread_.Stop();
257 base::MessageLoop::current()->RunUntilIdle();
258 BrowserWithTestWindowTest::TearDown(); 253 BrowserWithTestWindowTest::TearDown();
259 } 254 }
260 255
261 bool StartSyncService(const base::Closure& callback, 256 bool StartSyncService(const base::Closure& callback,
262 bool will_fail_association) { 257 bool will_fail_association) {
263 if (sync_service_) 258 if (sync_service_)
264 return false; 259 return false;
265 SigninManagerBase* signin = 260 SigninManagerBase* signin =
266 SigninManagerFactory::GetForProfile(profile()); 261 SigninManagerFactory::GetForProfile(profile());
267 signin->SetAuthenticatedUsername("test_user"); 262 signin->SetAuthenticatedUsername("test_user");
(...skipping 29 matching lines...) Expand all
297 292
298 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest( 293 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest(
299 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 294 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
300 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest( 295 TokenServiceFactory::GetForProfile(profile())->IssueAuthTokenForTest(
301 GaiaConstants::kSyncService, "token"); 296 GaiaConstants::kSyncService, "token");
302 sync_service_->Initialize(); 297 sync_service_->Initialize();
303 base::MessageLoop::current()->Run(); 298 base::MessageLoop::current()->Run();
304 return true; 299 return true;
305 } 300 }
306 301
307 content::TestBrowserThread io_thread_;
308 // Path used in testing. 302 // Path used in testing.
309 base::ScopedTempDir temp_dir_; 303 base::ScopedTempDir temp_dir_;
310 SessionModelAssociator* model_associator_; 304 SessionModelAssociator* model_associator_;
311 SessionChangeProcessor* change_processor_; 305 SessionChangeProcessor* change_processor_;
312 SessionID window_id_; 306 SessionID window_id_;
313 scoped_ptr<TestProfileSyncService> sync_service_; 307 scoped_ptr<TestProfileSyncService> sync_service_;
314 const gfx::Rect window_bounds_; 308 const gfx::Rect window_bounds_;
315 bool notified_of_update_; 309 bool notified_of_update_;
316 bool notified_of_refresh_; 310 bool notified_of_refresh_;
317 content::NotificationRegistrar registrar_; 311 content::NotificationRegistrar registrar_;
312 net::TestURLFetcherFactory fetcher_factory_;
318 }; 313 };
319 314
320 class CreateRootHelper { 315 class CreateRootHelper {
321 public: 316 public:
322 explicit CreateRootHelper(ProfileSyncServiceSessionTest* test) 317 explicit CreateRootHelper(ProfileSyncServiceSessionTest* test)
323 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback, 318 : callback_(base::Bind(&CreateRootHelper::CreateRootCallback,
324 base::Unretained(this), test)), 319 base::Unretained(this), test)),
325 success_(false) { 320 success_(false) {
326 } 321 }
327 322
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 tab_list.push_back(5); 1195 tab_list.push_back(5);
1201 AddWindowSpecifics(0, tab_list, &meta); 1196 AddWindowSpecifics(0, tab_list, &meta);
1202 sync_pb::SessionSpecifics tab; 1197 sync_pb::SessionSpecifics tab;
1203 BuildTabSpecifics(tag, 0, tab_list[0], &tab); 1198 BuildTabSpecifics(tag, 0, tab_list[0], &tab);
1204 std::string url = tab.tab().navigation(0).virtual_url(); 1199 std::string url = tab.tab().navigation(0).virtual_url();
1205 scoped_refptr<base::RefCountedMemory> favicon; 1200 scoped_refptr<base::RefCountedMemory> favicon;
1206 1201
1207 // Update associator. 1202 // Update associator.
1208 model_associator_->AssociateForeignSpecifics(meta, base::Time()); 1203 model_associator_->AssociateForeignSpecifics(meta, base::Time());
1209 model_associator_->AssociateForeignSpecifics(tab, base::Time()); 1204 model_associator_->AssociateForeignSpecifics(tab, base::Time());
1210 base::MessageLoop::current()->RunUntilIdle(); 1205 base::RunLoop().RunUntilIdle();
1211 ASSERT_FALSE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); 1206 ASSERT_FALSE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon));
1212 1207
1213 // Now add a favicon. 1208 // Now add a favicon.
1214 tab.mutable_tab()->set_favicon_source("http://favicon_source.com/png.ico"); 1209 tab.mutable_tab()->set_favicon_source("http://favicon_source.com/png.ico");
1215 tab.mutable_tab()->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); 1210 tab.mutable_tab()->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON);
1216 tab.mutable_tab()->set_favicon("data"); 1211 tab.mutable_tab()->set_favicon("data");
1217 model_associator_->AssociateForeignSpecifics(tab, base::Time()); 1212 model_associator_->AssociateForeignSpecifics(tab, base::Time());
1218 base::MessageLoop::current()->RunUntilIdle(); 1213 base::RunLoop().RunUntilIdle();
1219 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); 1214 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon));
1220 ASSERT_TRUE(CompareMemoryToString("data", favicon)); 1215 ASSERT_TRUE(CompareMemoryToString("data", favicon));
1221 1216
1222 // Simulate navigating away. The associator should not delete the favicon. 1217 // Simulate navigating away. The associator should not delete the favicon.
1223 tab.mutable_tab()->clear_navigation(); 1218 tab.mutable_tab()->clear_navigation();
1224 tab.mutable_tab()->add_navigation()->set_virtual_url("http://new_url.com"); 1219 tab.mutable_tab()->add_navigation()->set_virtual_url("http://new_url.com");
1225 tab.mutable_tab()->clear_favicon_source(); 1220 tab.mutable_tab()->clear_favicon_source();
1226 tab.mutable_tab()->clear_favicon_type(); 1221 tab.mutable_tab()->clear_favicon_type();
1227 tab.mutable_tab()->clear_favicon(); 1222 tab.mutable_tab()->clear_favicon();
1228 model_associator_->AssociateForeignSpecifics(tab, base::Time()); 1223 model_associator_->AssociateForeignSpecifics(tab, base::Time());
1229 base::MessageLoop::current()->RunUntilIdle(); 1224 base::RunLoop().RunUntilIdle();
1230 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon)); 1225 ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon));
1231 } 1226 }
1232 1227
1233 TEST_F(ProfileSyncServiceSessionTest, CorruptedLocalHeader) { 1228 TEST_F(ProfileSyncServiceSessionTest, CorruptedLocalHeader) {
1234 AddTab(browser(), GURL("http://foo1")); 1229 AddTab(browser(), GURL("http://foo1"));
1235 NavigateAndCommitActiveTab(GURL("http://foo2")); 1230 NavigateAndCommitActiveTab(GURL("http://foo2"));
1236 AddTab(browser(), GURL("http://bar1")); 1231 AddTab(browser(), GURL("http://bar1"));
1237 NavigateAndCommitActiveTab(GURL("http://bar2")); 1232 NavigateAndCommitActiveTab(GURL("http://bar2"));
1238 CreateRootHelper create_root(this); 1233 CreateRootHelper create_root(this);
1239 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); 1234 ASSERT_TRUE(StartSyncService(create_root.callback(), false));
(...skipping 11 matching lines...) Expand all
1251 sync_pb::SessionSpecifics specifics; 1246 sync_pb::SessionSpecifics specifics;
1252 header.SetSessionSpecifics(specifics); 1247 header.SetSessionSpecifics(specifics);
1253 } 1248 }
1254 // Ensure we associate properly despite the pre-existing node with our local 1249 // Ensure we associate properly despite the pre-existing node with our local
1255 // tag. 1250 // tag.
1256 error = model_associator_->AssociateModels(NULL, NULL); 1251 error = model_associator_->AssociateModels(NULL, NULL);
1257 ASSERT_FALSE(error.IsSet()); 1252 ASSERT_FALSE(error.IsSet());
1258 } 1253 }
1259 1254
1260 } // namespace browser_sync 1255 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698