| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/defaults.h" | 8 #include "chrome/browser/defaults.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 (*it)->WaitUntilTimestampIsAtLeast(last_timestamp_, | 303 (*it)->WaitUntilTimestampIsAtLeast(last_timestamp_, |
| 304 "Sync cycle completion on partner client."); | 304 "Sync cycle completion on partner client."); |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 return return_value; | 307 return return_value; |
| 308 } | 308 } |
| 309 | 309 |
| 310 // static | 310 // static |
| 311 bool ProfileSyncServiceTestHarness::AwaitQuiescence( | 311 bool ProfileSyncServiceTestHarness::AwaitQuiescence( |
| 312 std::vector<ProfileSyncServiceTestHarness*>& clients) { | 312 std::vector<ProfileSyncServiceTestHarness*>& clients) { |
| 313 LOG(INFO) << "AwaitQuiescence."; | 313 VLOG(1) << "AwaitQuiescence."; |
| 314 bool return_value = true; | 314 bool return_value = true; |
| 315 for (std::vector<ProfileSyncServiceTestHarness*>::iterator it = | 315 for (std::vector<ProfileSyncServiceTestHarness*>::iterator it = |
| 316 clients.begin(); it != clients.end(); ++it) { | 316 clients.begin(); it != clients.end(); ++it) { |
| 317 if ((*it)->wait_state_ != SYNC_DISABLED) | 317 if ((*it)->wait_state_ != SYNC_DISABLED) |
| 318 return_value = return_value && | 318 return_value = return_value && |
| 319 (*it)->AwaitGroupSyncCycleCompletion(clients); | 319 (*it)->AwaitGroupSyncCycleCompletion(clients); |
| 320 } | 320 } |
| 321 return return_value; | 321 return return_value; |
| 322 } | 322 } |
| 323 | 323 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 EXPECT_FALSE(service() == NULL) | 400 EXPECT_FALSE(service() == NULL) |
| 401 << "EnableSyncForDatatype(): service() is null."; | 401 << "EnableSyncForDatatype(): service() is null."; |
| 402 service()->GetPreferredDataTypes(&synced_datatypes); | 402 service()->GetPreferredDataTypes(&synced_datatypes); |
| 403 syncable::ModelTypeSet::iterator it = synced_datatypes.find( | 403 syncable::ModelTypeSet::iterator it = synced_datatypes.find( |
| 404 syncable::ModelTypeFromInt(datatype)); | 404 syncable::ModelTypeFromInt(datatype)); |
| 405 if (it == synced_datatypes.end()) { | 405 if (it == synced_datatypes.end()) { |
| 406 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); | 406 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); |
| 407 service()->OnUserChoseDatatypes(false, synced_datatypes); | 407 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 408 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; | 408 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; |
| 409 AwaitSyncCycleCompletion("Waiting for datatype configuration."); | 409 AwaitSyncCycleCompletion("Waiting for datatype configuration."); |
| 410 LOG(INFO) << "EnableSyncForDatatype(): Enabled sync for datatype " | 410 VLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " |
| 411 << syncable::ModelTypeToString(datatype) | 411 << syncable::ModelTypeToString(datatype) << " on Client " << id_; |
| 412 << " on Client " << id_ << "."; | |
| 413 } else { | 412 } else { |
| 414 LOG(INFO) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 413 VLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
| 415 << syncable::ModelTypeToString(datatype) | 414 << syncable::ModelTypeToString(datatype) << " on Client " << id_; |
| 416 << " on Client " << id_ << "."; | |
| 417 } | 415 } |
| 418 } | 416 } |
| 419 } | 417 } |
| 420 | 418 |
| 421 void ProfileSyncServiceTestHarness::DisableSyncForDatatype( | 419 void ProfileSyncServiceTestHarness::DisableSyncForDatatype( |
| 422 syncable::ModelType datatype) { | 420 syncable::ModelType datatype) { |
| 423 LogClientInfo("DisableSyncForDatatype"); | 421 LogClientInfo("DisableSyncForDatatype"); |
| 424 syncable::ModelTypeSet synced_datatypes; | 422 syncable::ModelTypeSet synced_datatypes; |
| 425 EXPECT_FALSE(service() == NULL) | 423 EXPECT_FALSE(service() == NULL) |
| 426 << "DisableSyncForDatatype(): service() is null."; | 424 << "DisableSyncForDatatype(): service() is null."; |
| 427 service()->GetPreferredDataTypes(&synced_datatypes); | 425 service()->GetPreferredDataTypes(&synced_datatypes); |
| 428 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 426 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); |
| 429 if (it != synced_datatypes.end()) { | 427 if (it != synced_datatypes.end()) { |
| 430 synced_datatypes.erase(it); | 428 synced_datatypes.erase(it); |
| 431 service()->OnUserChoseDatatypes(false, synced_datatypes); | 429 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 432 AwaitSyncCycleCompletion("Waiting for datatype configuration."); | 430 AwaitSyncCycleCompletion("Waiting for datatype configuration."); |
| 433 LOG(INFO) << "DisableSyncForDatatype(): Disabled sync for datatype " | 431 VLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " |
| 434 << syncable::ModelTypeToString(datatype) | 432 << syncable::ModelTypeToString(datatype) << " on Client " << id_; |
| 435 << " on Client " << id_ << "."; | |
| 436 } else { | 433 } else { |
| 437 LOG(INFO) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 434 VLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
| 438 << syncable::ModelTypeToString(datatype) | 435 << syncable::ModelTypeToString(datatype) << " on Client " << id_; |
| 439 << " on Client " << id_ << "."; | |
| 440 } | 436 } |
| 441 } | 437 } |
| 442 | 438 |
| 443 void ProfileSyncServiceTestHarness::EnableSyncForAllDatatypes() { | 439 void ProfileSyncServiceTestHarness::EnableSyncForAllDatatypes() { |
| 444 LogClientInfo("EnableSyncForAllDatatypes"); | 440 LogClientInfo("EnableSyncForAllDatatypes"); |
| 445 if (wait_state_ == SYNC_DISABLED) { | 441 if (wait_state_ == SYNC_DISABLED) { |
| 446 wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED; | 442 wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED; |
| 447 EXPECT_TRUE(SetupSync()) | 443 EXPECT_TRUE(SetupSync()) |
| 448 << "Reinitialization of Client " << id_ << " failed."; | 444 << "Reinitialization of Client " << id_ << " failed."; |
| 449 } else { | 445 } else { |
| 450 syncable::ModelTypeSet synced_datatypes; | 446 syncable::ModelTypeSet synced_datatypes; |
| 451 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 447 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 452 i < syncable::MODEL_TYPE_COUNT; ++i) { | 448 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 453 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 449 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
| 454 } | 450 } |
| 455 EXPECT_FALSE(service() == NULL) | 451 EXPECT_FALSE(service() == NULL) |
| 456 << "EnableSyncForAllDatatypes(): service() is null."; | 452 << "EnableSyncForAllDatatypes(): service() is null."; |
| 457 service()->OnUserChoseDatatypes(true, synced_datatypes); | 453 service()->OnUserChoseDatatypes(true, synced_datatypes); |
| 458 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; | 454 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; |
| 459 AwaitSyncCycleCompletion("Waiting for datatype configuration."); | 455 AwaitSyncCycleCompletion("Waiting for datatype configuration."); |
| 460 LOG(INFO) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes" | 456 VLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes on " |
| 461 << " on Client " << id_ << "."; | 457 "Client " << id_; |
| 462 } | 458 } |
| 463 } | 459 } |
| 464 | 460 |
| 465 void ProfileSyncServiceTestHarness::DisableSyncForAllDatatypes() { | 461 void ProfileSyncServiceTestHarness::DisableSyncForAllDatatypes() { |
| 466 LogClientInfo("DisableSyncForAllDatatypes"); | 462 LogClientInfo("DisableSyncForAllDatatypes"); |
| 467 EXPECT_FALSE(service() == NULL) | 463 EXPECT_FALSE(service() == NULL) |
| 468 << "EnableSyncForAllDatatypes(): service() is null."; | 464 << "EnableSyncForAllDatatypes(): service() is null."; |
| 469 service()->DisableForUser(); | 465 service()->DisableForUser(); |
| 470 wait_state_ = SYNC_DISABLED; | 466 wait_state_ = SYNC_DISABLED; |
| 471 LOG(INFO) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes" | 467 VLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes on " |
| 472 << " on Client " << id_ << "."; | 468 "Client " << id_; |
| 473 } | 469 } |
| 474 | 470 |
| 475 int64 ProfileSyncServiceTestHarness::GetUpdatedTimestamp() { | 471 int64 ProfileSyncServiceTestHarness::GetUpdatedTimestamp() { |
| 476 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 472 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 477 EXPECT_FALSE(snap == NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; | 473 EXPECT_FALSE(snap == NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; |
| 478 EXPECT_LE(last_timestamp_, snap->max_local_timestamp); | 474 EXPECT_LE(last_timestamp_, snap->max_local_timestamp); |
| 479 last_timestamp_ = snap->max_local_timestamp; | 475 last_timestamp_ = snap->max_local_timestamp; |
| 480 return last_timestamp_; | 476 return last_timestamp_; |
| 481 } | 477 } |
| 482 | 478 |
| 483 void ProfileSyncServiceTestHarness::LogClientInfo(std::string message) { | 479 void ProfileSyncServiceTestHarness::LogClientInfo(std::string message) { |
| 484 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 480 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 485 if (snap) { | 481 if (snap) { |
| 486 LOG(INFO) << "Client " << id_ << ": " << message << ": " | 482 VLOG(1) << "Client " << id_ << ": " << message |
| 487 << "max_local_timestamp: " << snap->max_local_timestamp | 483 << ": max_local_timestamp: " << snap->max_local_timestamp |
| 488 << ", has_more_to_sync: " << snap->has_more_to_sync | 484 << ", has_more_to_sync: " << snap->has_more_to_sync |
| 489 << ", unsynced_count: " << snap->unsynced_count | 485 << ", unsynced_count: " << snap->unsynced_count |
| 490 << ", has_unsynced_items: " << service()->backend()->HasUnsyncedItems() | 486 << ", has_unsynced_items: " |
| 491 << ", notifications_enabled: " << GetStatus().notifications_enabled | 487 << service()->backend()->HasUnsyncedItems() |
| 492 << ", service_is_pushing_changes: " << ServiceIsPushingChanges() | 488 << ", notifications_enabled: " |
| 493 << "."; | 489 << GetStatus().notifications_enabled |
| 490 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); |
| 494 } else { | 491 } else { |
| 495 LOG(INFO) << "Client " << id_ << ": " << message << ": " | 492 VLOG(1) << "Client " << id_ << ": " << message |
| 496 << "Sync session snapshot not available."; | 493 << ": Sync session snapshot not available."; |
| 497 } | 494 } |
| 498 } | 495 } |
| OLD | NEW |