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

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

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 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 <vector> 5 #include <vector>
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 void AddPasswordSyncNode(const PasswordForm& entry) { 119 void AddPasswordSyncNode(const PasswordForm& entry) {
120 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); 120 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare());
121 syncer::ReadNode password_root(&trans); 121 syncer::ReadNode password_root(&trans);
122 ASSERT_EQ(syncer::BaseNode::INIT_OK, 122 ASSERT_EQ(syncer::BaseNode::INIT_OK,
123 password_root.InitByTagLookup(browser_sync::kPasswordTag)); 123 password_root.InitByTagLookup(browser_sync::kPasswordTag));
124 124
125 syncer::WriteNode node(&trans); 125 syncer::WriteNode node(&trans);
126 std::string tag = PasswordModelAssociator::MakeTag(entry); 126 std::string tag = PasswordModelAssociator::MakeTag(entry);
127 syncer::WriteNode::InitUniqueByCreationResult result = 127 syncer::WriteNode::InitUniqueByCreationResult result =
128 node.InitUniqueByCreation(syncable::PASSWORDS, password_root, tag); 128 node.InitUniqueByCreation(syncer::PASSWORDS, password_root, tag);
129 ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result); 129 ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result);
130 PasswordModelAssociator::WriteToSyncNode(entry, &node); 130 PasswordModelAssociator::WriteToSyncNode(entry, &node);
131 } 131 }
132 132
133 protected: 133 protected:
134 ProfileSyncServicePasswordTest() {} 134 ProfileSyncServicePasswordTest() {}
135 135
136 virtual void SetUp() { 136 virtual void SetUp() {
137 AbstractProfileSyncServiceTest::SetUp(); 137 AbstractProfileSyncServiceTest::SetUp();
138 profile_.CreateRequestContext(); 138 profile_.CreateRequestContext();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 SigninManager* signin = SigninManagerFactory::GetForProfile(&profile_); 174 SigninManager* signin = SigninManagerFactory::GetForProfile(&profile_);
175 signin->SetAuthenticatedUsername("test_user"); 175 signin->SetAuthenticatedUsername("test_user");
176 token_service_ = static_cast<TokenService*>( 176 token_service_ = static_cast<TokenService*>(
177 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( 177 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
178 &profile_, BuildTokenService)); 178 &profile_, BuildTokenService));
179 ProfileSyncComponentsFactoryMock* factory = 179 ProfileSyncComponentsFactoryMock* factory =
180 new ProfileSyncComponentsFactoryMock(); 180 new ProfileSyncComponentsFactoryMock();
181 service_.reset(new PasswordTestProfileSyncService( 181 service_.reset(new PasswordTestProfileSyncService(
182 factory, &profile_, signin, false, 182 factory, &profile_, signin, false,
183 root_callback, node_callback)); 183 root_callback, node_callback));
184 syncable::ModelTypeSet preferred_types = 184 syncer::ModelTypeSet preferred_types = service_->GetPreferredDataTypes();
185 service_->GetPreferredDataTypes(); 185 preferred_types.Put(syncer::PASSWORDS);
186 preferred_types.Put(syncable::PASSWORDS);
187 service_->ChangePreferredDataTypes(preferred_types); 186 service_->ChangePreferredDataTypes(preferred_types);
188 PasswordDataTypeController* data_type_controller = 187 PasswordDataTypeController* data_type_controller =
189 new PasswordDataTypeController(factory, 188 new PasswordDataTypeController(factory,
190 &profile_, 189 &profile_,
191 service_.get()); 190 service_.get());
192 191
193 EXPECT_CALL(*factory, CreatePasswordSyncComponents(_, _, _)). 192 EXPECT_CALL(*factory, CreatePasswordSyncComponents(_, _, _)).
194 Times(AtLeast(1)). // Can be more if we hit NEEDS_CRYPTO. 193 Times(AtLeast(1)). // Can be more if we hit NEEDS_CRYPTO.
195 WillRepeatedly(MakePasswordSyncComponents(service_.get(), 194 WillRepeatedly(MakePasswordSyncComponents(service_.get(),
196 password_store_.get(), 195 password_store_.get(),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 StartSyncService(base::Closure(), base::Closure()); 281 StartSyncService(base::Closure(), base::Closure());
283 EXPECT_TRUE(service_->HasUnrecoverableError()); 282 EXPECT_TRUE(service_->HasUnrecoverableError());
284 } 283 }
285 284
286 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { 285 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) {
287 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 286 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
288 .WillOnce(Return(true)); 287 .WillOnce(Return(true));
289 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 288 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
290 .WillOnce(Return(true)); 289 .WillOnce(Return(true));
291 SetIdleChangeProcessorExpectations(); 290 SetIdleChangeProcessorExpectations();
292 CreateRootHelper create_root(this, syncable::PASSWORDS); 291 CreateRootHelper create_root(this, syncer::PASSWORDS);
293 StartSyncService(create_root.callback(), base::Closure()); 292 StartSyncService(create_root.callback(), base::Closure());
294 std::vector<PasswordForm> sync_entries; 293 std::vector<PasswordForm> sync_entries;
295 GetPasswordEntriesFromSyncDB(&sync_entries); 294 GetPasswordEntriesFromSyncDB(&sync_entries);
296 EXPECT_EQ(0U, sync_entries.size()); 295 EXPECT_EQ(0U, sync_entries.size());
297 } 296 }
298 297
299 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { 298 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) {
300 std::vector<PasswordForm*> forms; 299 std::vector<PasswordForm*> forms;
301 std::vector<PasswordForm> expected_forms; 300 std::vector<PasswordForm> expected_forms;
302 PasswordForm* new_form = new PasswordForm; 301 PasswordForm* new_form = new PasswordForm;
303 new_form->scheme = PasswordForm::SCHEME_HTML; 302 new_form->scheme = PasswordForm::SCHEME_HTML;
304 new_form->signon_realm = "pie"; 303 new_form->signon_realm = "pie";
305 new_form->origin = GURL("http://pie.com"); 304 new_form->origin = GURL("http://pie.com");
306 new_form->action = GURL("http://pie.com/submit"); 305 new_form->action = GURL("http://pie.com/submit");
307 new_form->username_element = UTF8ToUTF16("name"); 306 new_form->username_element = UTF8ToUTF16("name");
308 new_form->username_value = UTF8ToUTF16("tom"); 307 new_form->username_value = UTF8ToUTF16("tom");
309 new_form->password_element = UTF8ToUTF16("cork"); 308 new_form->password_element = UTF8ToUTF16("cork");
310 new_form->password_value = UTF8ToUTF16("password1"); 309 new_form->password_value = UTF8ToUTF16("password1");
311 new_form->ssl_valid = true; 310 new_form->ssl_valid = true;
312 new_form->preferred = false; 311 new_form->preferred = false;
313 new_form->date_created = base::Time::FromInternalValue(1234); 312 new_form->date_created = base::Time::FromInternalValue(1234);
314 new_form->blacklisted_by_user = false; 313 new_form->blacklisted_by_user = false;
315 forms.push_back(new_form); 314 forms.push_back(new_form);
316 expected_forms.push_back(*new_form); 315 expected_forms.push_back(*new_form);
317 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 316 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
318 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); 317 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true)));
319 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 318 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
320 .WillOnce(Return(true)); 319 .WillOnce(Return(true));
321 SetIdleChangeProcessorExpectations(); 320 SetIdleChangeProcessorExpectations();
322 CreateRootHelper create_root(this, syncable::PASSWORDS); 321 CreateRootHelper create_root(this, syncer::PASSWORDS);
323 StartSyncService(create_root.callback(), base::Closure()); 322 StartSyncService(create_root.callback(), base::Closure());
324 std::vector<PasswordForm> sync_forms; 323 std::vector<PasswordForm> sync_forms;
325 GetPasswordEntriesFromSyncDB(&sync_forms); 324 GetPasswordEntriesFromSyncDB(&sync_forms);
326 ASSERT_EQ(1U, sync_forms.size()); 325 ASSERT_EQ(1U, sync_forms.size());
327 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); 326 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0]));
328 } 327 }
329 328
330 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { 329 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) {
331 std::vector<PasswordForm*> forms; 330 std::vector<PasswordForm*> forms;
332 std::vector<PasswordForm> expected_forms; 331 std::vector<PasswordForm> expected_forms;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 new_form->blacklisted_by_user = false; 363 new_form->blacklisted_by_user = false;
365 forms.push_back(new_form); 364 forms.push_back(new_form);
366 expected_forms.push_back(*new_form); 365 expected_forms.push_back(*new_form);
367 } 366 }
368 367
369 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 368 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
370 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); 369 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true)));
371 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 370 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
372 .WillOnce(Return(true)); 371 .WillOnce(Return(true));
373 SetIdleChangeProcessorExpectations(); 372 SetIdleChangeProcessorExpectations();
374 CreateRootHelper create_root(this, syncable::PASSWORDS); 373 CreateRootHelper create_root(this, syncer::PASSWORDS);
375 StartSyncService(create_root.callback(), base::Closure()); 374 StartSyncService(create_root.callback(), base::Closure());
376 std::vector<PasswordForm> sync_forms; 375 std::vector<PasswordForm> sync_forms;
377 GetPasswordEntriesFromSyncDB(&sync_forms); 376 GetPasswordEntriesFromSyncDB(&sync_forms);
378 ASSERT_EQ(2U, sync_forms.size()); 377 ASSERT_EQ(2U, sync_forms.size());
379 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); 378 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1]));
380 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); 379 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0]));
381 } 380 }
382 381
383 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { 382 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) {
384 std::vector<PasswordForm*> native_forms; 383 std::vector<PasswordForm*> native_forms;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 new_form.blacklisted_by_user = false; 418 new_form.blacklisted_by_user = false;
420 sync_forms.push_back(new_form); 419 sync_forms.push_back(new_form);
421 expected_forms.push_back(new_form); 420 expected_forms.push_back(new_form);
422 } 421 }
423 422
424 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 423 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
425 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); 424 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true)));
426 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); 425 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true));
427 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); 426 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1);
428 427
429 CreateRootHelper create_root(this, syncable::PASSWORDS); 428 CreateRootHelper create_root(this, syncer::PASSWORDS);
430 StartSyncService(create_root.callback(), 429 StartSyncService(create_root.callback(),
431 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 430 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
432 431
433 std::vector<PasswordForm> new_sync_forms; 432 std::vector<PasswordForm> new_sync_forms;
434 GetPasswordEntriesFromSyncDB(&new_sync_forms); 433 GetPasswordEntriesFromSyncDB(&new_sync_forms);
435 434
436 EXPECT_EQ(2U, new_sync_forms.size()); 435 EXPECT_EQ(2U, new_sync_forms.size());
437 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 436 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
438 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); 437 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1]));
439 } 438 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 483 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
485 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), 484 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms),
486 AcquireSyncTransaction(this), 485 AcquireSyncTransaction(this),
487 Return(true))); 486 Return(true)));
488 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 487 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
489 .WillOnce(DoAll(AcquireSyncTransaction(this), 488 .WillOnce(DoAll(AcquireSyncTransaction(this),
490 Return(true))); 489 Return(true)));
491 EXPECT_CALL(*password_store_, AddLoginImpl(_)) 490 EXPECT_CALL(*password_store_, AddLoginImpl(_))
492 .WillOnce(AcquireSyncTransaction(this)); 491 .WillOnce(AcquireSyncTransaction(this));
493 492
494 CreateRootHelper create_root(this, syncable::PASSWORDS); 493 CreateRootHelper create_root(this, syncer::PASSWORDS);
495 StartSyncService(create_root.callback(), 494 StartSyncService(create_root.callback(),
496 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 495 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
497 496
498 std::vector<PasswordForm> new_sync_forms; 497 std::vector<PasswordForm> new_sync_forms;
499 GetPasswordEntriesFromSyncDB(&new_sync_forms); 498 GetPasswordEntriesFromSyncDB(&new_sync_forms);
500 499
501 EXPECT_EQ(2U, new_sync_forms.size()); 500 EXPECT_EQ(2U, new_sync_forms.size());
502 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 501 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
503 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); 502 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1]));
504 } 503 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 new_form.date_created = base::Time::FromInternalValue(12345); 556 new_form.date_created = base::Time::FromInternalValue(12345);
558 new_form.blacklisted_by_user = false; 557 new_form.blacklisted_by_user = false;
559 expected_forms.push_back(new_form); 558 expected_forms.push_back(new_form);
560 } 559 }
561 560
562 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 561 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
563 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); 562 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true)));
564 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); 563 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true));
565 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); 564 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1);
566 565
567 CreateRootHelper create_root(this, syncable::PASSWORDS); 566 CreateRootHelper create_root(this, syncer::PASSWORDS);
568 StartSyncService(create_root.callback(), 567 StartSyncService(create_root.callback(),
569 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 568 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
570 569
571 std::vector<PasswordForm> new_sync_forms; 570 std::vector<PasswordForm> new_sync_forms;
572 GetPasswordEntriesFromSyncDB(&new_sync_forms); 571 GetPasswordEntriesFromSyncDB(&new_sync_forms);
573 572
574 EXPECT_EQ(1U, new_sync_forms.size()); 573 EXPECT_EQ(1U, new_sync_forms.size());
575 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 574 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
576 } 575 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_mock.h ('k') | chrome/browser/sync/profile_sync_service_preference_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698