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

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: Fix indent, and remove some redundant using declarations 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 =
rlarocque 2012/07/03 17:51:25 nit: put this one one line. This probably isn't t
akalin 2012/07/03 21:47:08 I went through the CL and cleaned up as much as I
185 service_->GetPreferredDataTypes(); 185 service_->GetPreferredDataTypes();
186 preferred_types.Put(syncable::PASSWORDS); 186 preferred_types.Put(syncer::PASSWORDS);
187 service_->ChangePreferredDataTypes(preferred_types); 187 service_->ChangePreferredDataTypes(preferred_types);
188 PasswordDataTypeController* data_type_controller = 188 PasswordDataTypeController* data_type_controller =
189 new PasswordDataTypeController(factory, 189 new PasswordDataTypeController(factory,
190 &profile_, 190 &profile_,
191 service_.get()); 191 service_.get());
192 192
193 EXPECT_CALL(*factory, CreatePasswordSyncComponents(_, _, _)). 193 EXPECT_CALL(*factory, CreatePasswordSyncComponents(_, _, _)).
194 Times(AtLeast(1)). // Can be more if we hit NEEDS_CRYPTO. 194 Times(AtLeast(1)). // Can be more if we hit NEEDS_CRYPTO.
195 WillRepeatedly(MakePasswordSyncComponents(service_.get(), 195 WillRepeatedly(MakePasswordSyncComponents(service_.get(),
196 password_store_.get(), 196 password_store_.get(),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 StartSyncService(base::Closure(), base::Closure()); 282 StartSyncService(base::Closure(), base::Closure());
283 EXPECT_TRUE(service_->HasUnrecoverableError()); 283 EXPECT_TRUE(service_->HasUnrecoverableError());
284 } 284 }
285 285
286 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { 286 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) {
287 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 287 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
288 .WillOnce(Return(true)); 288 .WillOnce(Return(true));
289 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 289 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
290 .WillOnce(Return(true)); 290 .WillOnce(Return(true));
291 SetIdleChangeProcessorExpectations(); 291 SetIdleChangeProcessorExpectations();
292 CreateRootHelper create_root(this, syncable::PASSWORDS); 292 CreateRootHelper create_root(this, syncer::PASSWORDS);
293 StartSyncService(create_root.callback(), base::Closure()); 293 StartSyncService(create_root.callback(), base::Closure());
294 std::vector<PasswordForm> sync_entries; 294 std::vector<PasswordForm> sync_entries;
295 GetPasswordEntriesFromSyncDB(&sync_entries); 295 GetPasswordEntriesFromSyncDB(&sync_entries);
296 EXPECT_EQ(0U, sync_entries.size()); 296 EXPECT_EQ(0U, sync_entries.size());
297 } 297 }
298 298
299 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { 299 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) {
300 std::vector<PasswordForm*> forms; 300 std::vector<PasswordForm*> forms;
301 std::vector<PasswordForm> expected_forms; 301 std::vector<PasswordForm> expected_forms;
302 PasswordForm* new_form = new PasswordForm; 302 PasswordForm* new_form = new PasswordForm;
303 new_form->scheme = PasswordForm::SCHEME_HTML; 303 new_form->scheme = PasswordForm::SCHEME_HTML;
304 new_form->signon_realm = "pie"; 304 new_form->signon_realm = "pie";
305 new_form->origin = GURL("http://pie.com"); 305 new_form->origin = GURL("http://pie.com");
306 new_form->action = GURL("http://pie.com/submit"); 306 new_form->action = GURL("http://pie.com/submit");
307 new_form->username_element = UTF8ToUTF16("name"); 307 new_form->username_element = UTF8ToUTF16("name");
308 new_form->username_value = UTF8ToUTF16("tom"); 308 new_form->username_value = UTF8ToUTF16("tom");
309 new_form->password_element = UTF8ToUTF16("cork"); 309 new_form->password_element = UTF8ToUTF16("cork");
310 new_form->password_value = UTF8ToUTF16("password1"); 310 new_form->password_value = UTF8ToUTF16("password1");
311 new_form->ssl_valid = true; 311 new_form->ssl_valid = true;
312 new_form->preferred = false; 312 new_form->preferred = false;
313 new_form->date_created = base::Time::FromInternalValue(1234); 313 new_form->date_created = base::Time::FromInternalValue(1234);
314 new_form->blacklisted_by_user = false; 314 new_form->blacklisted_by_user = false;
315 forms.push_back(new_form); 315 forms.push_back(new_form);
316 expected_forms.push_back(*new_form); 316 expected_forms.push_back(*new_form);
317 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 317 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
318 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); 318 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true)));
319 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 319 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
320 .WillOnce(Return(true)); 320 .WillOnce(Return(true));
321 SetIdleChangeProcessorExpectations(); 321 SetIdleChangeProcessorExpectations();
322 CreateRootHelper create_root(this, syncable::PASSWORDS); 322 CreateRootHelper create_root(this, syncer::PASSWORDS);
323 StartSyncService(create_root.callback(), base::Closure()); 323 StartSyncService(create_root.callback(), base::Closure());
324 std::vector<PasswordForm> sync_forms; 324 std::vector<PasswordForm> sync_forms;
325 GetPasswordEntriesFromSyncDB(&sync_forms); 325 GetPasswordEntriesFromSyncDB(&sync_forms);
326 ASSERT_EQ(1U, sync_forms.size()); 326 ASSERT_EQ(1U, sync_forms.size());
327 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); 327 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0]));
328 } 328 }
329 329
330 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { 330 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) {
331 std::vector<PasswordForm*> forms; 331 std::vector<PasswordForm*> forms;
332 std::vector<PasswordForm> expected_forms; 332 std::vector<PasswordForm> expected_forms;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 new_form->blacklisted_by_user = false; 364 new_form->blacklisted_by_user = false;
365 forms.push_back(new_form); 365 forms.push_back(new_form);
366 expected_forms.push_back(*new_form); 366 expected_forms.push_back(*new_form);
367 } 367 }
368 368
369 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 369 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
370 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); 370 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true)));
371 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 371 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
372 .WillOnce(Return(true)); 372 .WillOnce(Return(true));
373 SetIdleChangeProcessorExpectations(); 373 SetIdleChangeProcessorExpectations();
374 CreateRootHelper create_root(this, syncable::PASSWORDS); 374 CreateRootHelper create_root(this, syncer::PASSWORDS);
375 StartSyncService(create_root.callback(), base::Closure()); 375 StartSyncService(create_root.callback(), base::Closure());
376 std::vector<PasswordForm> sync_forms; 376 std::vector<PasswordForm> sync_forms;
377 GetPasswordEntriesFromSyncDB(&sync_forms); 377 GetPasswordEntriesFromSyncDB(&sync_forms);
378 ASSERT_EQ(2U, sync_forms.size()); 378 ASSERT_EQ(2U, sync_forms.size());
379 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); 379 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1]));
380 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); 380 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0]));
381 } 381 }
382 382
383 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { 383 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) {
384 std::vector<PasswordForm*> native_forms; 384 std::vector<PasswordForm*> native_forms;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 new_form.blacklisted_by_user = false; 419 new_form.blacklisted_by_user = false;
420 sync_forms.push_back(new_form); 420 sync_forms.push_back(new_form);
421 expected_forms.push_back(new_form); 421 expected_forms.push_back(new_form);
422 } 422 }
423 423
424 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 424 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
425 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); 425 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true)));
426 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); 426 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true));
427 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); 427 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1);
428 428
429 CreateRootHelper create_root(this, syncable::PASSWORDS); 429 CreateRootHelper create_root(this, syncer::PASSWORDS);
430 StartSyncService(create_root.callback(), 430 StartSyncService(create_root.callback(),
431 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 431 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
432 432
433 std::vector<PasswordForm> new_sync_forms; 433 std::vector<PasswordForm> new_sync_forms;
434 GetPasswordEntriesFromSyncDB(&new_sync_forms); 434 GetPasswordEntriesFromSyncDB(&new_sync_forms);
435 435
436 EXPECT_EQ(2U, new_sync_forms.size()); 436 EXPECT_EQ(2U, new_sync_forms.size());
437 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 437 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
438 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); 438 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1]));
439 } 439 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 484 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
485 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), 485 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms),
486 AcquireSyncTransaction(this), 486 AcquireSyncTransaction(this),
487 Return(true))); 487 Return(true)));
488 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) 488 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
489 .WillOnce(DoAll(AcquireSyncTransaction(this), 489 .WillOnce(DoAll(AcquireSyncTransaction(this),
490 Return(true))); 490 Return(true)));
491 EXPECT_CALL(*password_store_, AddLoginImpl(_)) 491 EXPECT_CALL(*password_store_, AddLoginImpl(_))
492 .WillOnce(AcquireSyncTransaction(this)); 492 .WillOnce(AcquireSyncTransaction(this));
493 493
494 CreateRootHelper create_root(this, syncable::PASSWORDS); 494 CreateRootHelper create_root(this, syncer::PASSWORDS);
495 StartSyncService(create_root.callback(), 495 StartSyncService(create_root.callback(),
496 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 496 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
497 497
498 std::vector<PasswordForm> new_sync_forms; 498 std::vector<PasswordForm> new_sync_forms;
499 GetPasswordEntriesFromSyncDB(&new_sync_forms); 499 GetPasswordEntriesFromSyncDB(&new_sync_forms);
500 500
501 EXPECT_EQ(2U, new_sync_forms.size()); 501 EXPECT_EQ(2U, new_sync_forms.size());
502 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 502 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
503 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); 503 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1]));
504 } 504 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 new_form.date_created = base::Time::FromInternalValue(12345); 557 new_form.date_created = base::Time::FromInternalValue(12345);
558 new_form.blacklisted_by_user = false; 558 new_form.blacklisted_by_user = false;
559 expected_forms.push_back(new_form); 559 expected_forms.push_back(new_form);
560 } 560 }
561 561
562 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) 562 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
563 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); 563 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true)));
564 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); 564 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true));
565 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); 565 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1);
566 566
567 CreateRootHelper create_root(this, syncable::PASSWORDS); 567 CreateRootHelper create_root(this, syncer::PASSWORDS);
568 StartSyncService(create_root.callback(), 568 StartSyncService(create_root.callback(),
569 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); 569 base::Bind(&AddPasswordEntriesCallback, this, sync_forms));
570 570
571 std::vector<PasswordForm> new_sync_forms; 571 std::vector<PasswordForm> new_sync_forms;
572 GetPasswordEntriesFromSyncDB(&new_sync_forms); 572 GetPasswordEntriesFromSyncDB(&new_sync_forms);
573 573
574 EXPECT_EQ(1U, new_sync_forms.size()); 574 EXPECT_EQ(1U, new_sync_forms.size());
575 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 575 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
576 } 576 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698