| 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 "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
| 7 #include "chrome/browser/pref_service.h" | 7 #include "chrome/browser/pref_service.h" |
| 8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
| 9 #include "chrome/browser/sync/glue/sync_backend_host.h" | 9 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 10 #include "chrome/browser/sync/sessions/session_state.h" | 10 #include "chrome/browser/sync/sessions/session_state.h" |
| 11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/live_sync/profile_sync_service_test_harness.h" | 13 #include "chrome/test/live_sync/profile_sync_service_test_harness.h" |
| 14 #include "chrome/test/ui_test_utils.h" | 14 #include "chrome/test/ui_test_utils.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using browser_sync::sessions::SyncSessionSnapshot; | 17 using browser_sync::sessions::SyncSessionSnapshot; |
| 18 | 18 |
| 19 // The default value for min_updates_needed_ when we're not in a call to | 19 // The default value for min_timestamp_needed_ when we're not in the |
| 20 // WaitForUpdatesRecievedAtLeast. | 20 // WAITING_FOR_UPDATES state. |
| 21 static const int kMinUpdatesNeededNone = -1; | 21 static const int kMinTimestampNeededNone = -1; |
| 22 | 22 |
| 23 static const ProfileSyncService::Status kInvalidStatus = {}; | 23 static const ProfileSyncService::Status kInvalidStatus = {}; |
| 24 | 24 |
| 25 // Simple class to implement a timeout using PostDelayedTask. If it is not | 25 // Simple class to implement a timeout using PostDelayedTask. If it is not |
| 26 // aborted before picked up by a message queue, then it asserts with the message | 26 // aborted before picked up by a message queue, then it asserts with the message |
| 27 // provided. This class is not thread safe. | 27 // provided. This class is not thread safe. |
| 28 class StateChangeTimeoutEvent | 28 class StateChangeTimeoutEvent |
| 29 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { | 29 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { |
| 30 public: | 30 public: |
| 31 explicit StateChangeTimeoutEvent(ProfileSyncServiceTestHarness* caller, | 31 explicit StateChangeTimeoutEvent(ProfileSyncServiceTestHarness* caller, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 aborted_ = true; | 80 aborted_ = true; |
| 81 caller_ = NULL; | 81 caller_ = NULL; |
| 82 return !did_timeout_; | 82 return !did_timeout_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 ProfileSyncServiceTestHarness::ProfileSyncServiceTestHarness( | 85 ProfileSyncServiceTestHarness::ProfileSyncServiceTestHarness( |
| 86 Profile* p, const std::string& username, const std::string& password) | 86 Profile* p, const std::string& username, const std::string& password) |
| 87 : wait_state_(WAITING_FOR_INITIAL_CALLBACK), profile_(p), service_(NULL), | 87 : wait_state_(WAITING_FOR_INITIAL_CALLBACK), profile_(p), service_(NULL), |
| 88 last_status_(kInvalidStatus), | 88 last_status_(kInvalidStatus), |
| 89 last_timestamp_(0), | 89 last_timestamp_(0), |
| 90 min_timestamp_needed_(kMinUpdatesNeededNone), | 90 min_timestamp_needed_(kMinTimestampNeededNone), |
| 91 username_(username), password_(password) { | 91 username_(username), password_(password) { |
| 92 // Ensure the profile has enough prefs registered for use by sync. | 92 // Ensure the profile has enough prefs registered for use by sync. |
| 93 if (!p->GetPrefs()->FindPreference(prefs::kAcceptLanguages)) | 93 if (!p->GetPrefs()->FindPreference(prefs::kAcceptLanguages)) |
| 94 TabContents::RegisterUserPrefs(p->GetPrefs()); | 94 TabContents::RegisterUserPrefs(p->GetPrefs()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool ProfileSyncServiceTestHarness::SetupSync() { | 97 bool ProfileSyncServiceTestHarness::SetupSync() { |
| 98 service_ = profile_->GetProfileSyncService(); | 98 service_ = profile_->GetProfileSyncService(); |
| 99 service_->SetSyncSetupCompleted(); | 99 service_->SetSyncSetupCompleted(); |
| 100 service_->EnableForUser(); | 100 service_->EnableForUser(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Wait for the OnBackendInitialized callback. | 213 // Wait for the OnBackendInitialized callback. |
| 214 service_->backend()->Authenticate(username_, password_, std::string()); | 214 service_->backend()->Authenticate(username_, password_, std::string()); |
| 215 EXPECT_EQ(wait_state_, WAITING_FOR_READY_TO_PROCESS_CHANGES); | 215 EXPECT_EQ(wait_state_, WAITING_FOR_READY_TO_PROCESS_CHANGES); |
| 216 if (!AwaitStatusChangeWithTimeout(30, "Waiting on backend initialization.")) { | 216 if (!AwaitStatusChangeWithTimeout(30, "Waiting on backend initialization.")) { |
| 217 return false; | 217 return false; |
| 218 } | 218 } |
| 219 return service_->sync_initialized(); | 219 return service_->sync_initialized(); |
| 220 } | 220 } |
| OLD | NEW |