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

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

Powered by Google App Engine
This is Rietveld 408576698