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

Side by Side Diff: chrome/browser/sync/engine/syncer_thread_unittest.cc

Issue 6142009: Upating the app, ceee, chrome, ipc, media, and net directories to use the correct lock.h file. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Unified patch updating all references to the new base/synchronization/lock.h Created 9 years, 11 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <list> 5 #include <list>
6 #include <map> 6 #include <map>
7 7
8 #include "base/lock.h"
9 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/synchronization/lock.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "chrome/browser/sync/engine/model_safe_worker.h" 12 #include "chrome/browser/sync/engine/model_safe_worker.h"
13 #include "chrome/browser/sync/engine/syncer_thread.h" 13 #include "chrome/browser/sync/engine/syncer_thread.h"
14 #include "chrome/browser/sync/engine/syncer_types.h" 14 #include "chrome/browser/sync/engine/syncer_types.h"
15 #include "chrome/browser/sync/sessions/sync_session_context.h" 15 #include "chrome/browser/sync/sessions/sync_session_context.h"
16 #include "chrome/browser/sync/util/channel.h" 16 #include "chrome/browser/sync/util/channel.h"
17 #include "chrome/test/sync/engine/mock_connection_manager.h" 17 #include "chrome/test/sync/engine/mock_connection_manager.h"
18 #include "chrome/test/sync/engine/test_directory_setter_upper.h" 18 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
19 #include "chrome/test/sync/sessions/test_scoped_session_event_listener.h" 19 #include "chrome/test/sync/sessions/test_scoped_session_event_listener.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 sync_cycle_ended_event_.TimedWait(max_wait_time_); 106 sync_cycle_ended_event_.TimedWait(max_wait_time_);
107 max_cycles--; 107 max_cycles--;
108 } 108 }
109 109
110 return syncer_thread()->IsSyncingCurrentlySilenced(); 110 return syncer_thread()->IsSyncingCurrentlySilenced();
111 } 111 }
112 112
113 void WaitForDisconnect() { 113 void WaitForDisconnect() {
114 // Wait for the SyncerThread to detect loss of connection, up to a max of 114 // Wait for the SyncerThread to detect loss of connection, up to a max of
115 // 10 seconds to timeout the test. 115 // 10 seconds to timeout the test.
116 AutoLock lock(syncer_thread()->lock_); 116 base::AutoLock lock(syncer_thread()->lock_);
117 TimeTicks start = TimeTicks::Now(); 117 TimeTicks start = TimeTicks::Now();
118 TimeDelta ten_seconds = TimeDelta::FromSeconds(10); 118 TimeDelta ten_seconds = TimeDelta::FromSeconds(10);
119 while (syncer_thread()->vault_.connected_) { 119 while (syncer_thread()->vault_.connected_) {
120 syncer_thread()->vault_field_changed_.TimedWait(ten_seconds); 120 syncer_thread()->vault_field_changed_.TimedWait(ten_seconds);
121 if (TimeTicks::Now() - start > ten_seconds) 121 if (TimeTicks::Now() - start > ten_seconds)
122 break; 122 break;
123 } 123 }
124 EXPECT_FALSE(syncer_thread()->vault_.connected_); 124 EXPECT_FALSE(syncer_thread()->vault_.connected_);
125 } 125 }
126 126
127 bool Pause(ListenerMock* listener) { 127 bool Pause(ListenerMock* listener) {
128 WaitableEvent event(false, false); 128 WaitableEvent event(false, false);
129 { 129 {
130 AutoLock lock(syncer_thread()->lock_); 130 base::AutoLock lock(syncer_thread()->lock_);
131 EXPECT_CALL(*listener, OnSyncEngineEvent( 131 EXPECT_CALL(*listener, OnSyncEngineEvent(
132 Field(&SyncEngineEvent::what_happened, 132 Field(&SyncEngineEvent::what_happened,
133 SyncEngineEvent::SYNCER_THREAD_PAUSED))). 133 SyncEngineEvent::SYNCER_THREAD_PAUSED))).
134 WillOnce(SignalEvent(&event)); 134 WillOnce(SignalEvent(&event));
135 } 135 }
136 if (!syncer_thread()->RequestPause()) 136 if (!syncer_thread()->RequestPause())
137 return false; 137 return false;
138 return event.TimedWait(max_wait_time_); 138 return event.TimedWait(max_wait_time_);
139 } 139 }
140 140
141 bool Resume(ListenerMock* listener) { 141 bool Resume(ListenerMock* listener) {
142 WaitableEvent event(false, false); 142 WaitableEvent event(false, false);
143 { 143 {
144 AutoLock lock(syncer_thread()->lock_); 144 base::AutoLock lock(syncer_thread()->lock_);
145 EXPECT_CALL(*listener, OnSyncEngineEvent( 145 EXPECT_CALL(*listener, OnSyncEngineEvent(
146 Field(&SyncEngineEvent::what_happened, 146 Field(&SyncEngineEvent::what_happened,
147 SyncEngineEvent::SYNCER_THREAD_RESUMED))). 147 SyncEngineEvent::SYNCER_THREAD_RESUMED))).
148 WillOnce(SignalEvent(&event)); 148 WillOnce(SignalEvent(&event));
149 } 149 }
150 if (!syncer_thread()->RequestResume()) 150 if (!syncer_thread()->RequestResume())
151 return false; 151 return false;
152 return event.TimedWait(max_wait_time_); 152 return event.TimedWait(max_wait_time_);
153 } 153 }
154 154
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 311 }
312 312
313 TEST_F(SyncerThreadTest, CalculatePollingWaitTime) { 313 TEST_F(SyncerThreadTest, CalculatePollingWaitTime) {
314 // Set up the environment. 314 // Set up the environment.
315 int user_idle_milliseconds_param = 0; 315 int user_idle_milliseconds_param = 0;
316 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL, 316 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL,
317 std::vector<SyncEngineEventListener*>()); 317 std::vector<SyncEngineEventListener*>());
318 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context)); 318 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context));
319 syncer_thread->DisableIdleDetection(); 319 syncer_thread->DisableIdleDetection();
320 // Hold the lock to appease asserts in code. 320 // Hold the lock to appease asserts in code.
321 AutoLock lock(syncer_thread->lock_); 321 base::AutoLock lock(syncer_thread->lock_);
322 322
323 // Notifications disabled should result in a polling interval of 323 // Notifications disabled should result in a polling interval of
324 // kDefaultShortPollInterval. 324 // kDefaultShortPollInterval.
325 { 325 {
326 context->set_notifications_enabled(false); 326 context->set_notifications_enabled(false);
327 bool continue_sync_cycle_param = false; 327 bool continue_sync_cycle_param = false;
328 328
329 // No work and no backoff. 329 // No work and no backoff.
330 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( 330 WaitInterval interval = syncer_thread->CalculatePollingWaitTime(
331 0, 331 0,
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 EXPECT_CALL(listener, OnSyncEngineEvent( 1114 EXPECT_CALL(listener, OnSyncEngineEvent(
1115 Field(&SyncEngineEvent::what_happened, 1115 Field(&SyncEngineEvent::what_happened,
1116 SyncEngineEvent::SYNCER_THREAD_EXITING))); 1116 SyncEngineEvent::SYNCER_THREAD_EXITING)));
1117 1117
1118 ASSERT_TRUE(Resume(&listener)); 1118 ASSERT_TRUE(Resume(&listener));
1119 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); 1119 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_));
1120 EXPECT_TRUE(syncer_thread()->Stop(2000)); 1120 EXPECT_TRUE(syncer_thread()->Stop(2000));
1121 } 1121 }
1122 1122
1123 } // namespace browser_sync 1123 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer_thread.cc ('k') | chrome/browser/sync/glue/autofill_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698