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

Side by Side Diff: sync/internal_api/attachments/attachment_service_proxy_unittest.cc

Issue 2086363002: Remove calls to deprecated MessageLoop methods in sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « sync/engine/sync_scheduler_unittest.cc ('k') | sync/internal_api/http_bridge_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sync/internal_api/public/attachments/attachment_service_proxy.h" 5 #include "sync/internal_api/public/attachments/attachment_service_proxy.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 callback_get_or_download = 94 callback_get_or_download =
95 base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload, 95 base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload,
96 base::Unretained(this)); 96 base::Unretained(this));
97 count_callback_get_or_download = 0; 97 count_callback_get_or_download = 0;
98 } 98 }
99 99
100 void TearDown() override { 100 void TearDown() override {
101 // We must take care to call the stub's destructor on the stub_thread 101 // We must take care to call the stub's destructor on the stub_thread
102 // because that's the thread to which its WeakPtrs are bound. 102 // because that's the thread to which its WeakPtrs are bound.
103 if (stub) { 103 if (stub) {
104 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); 104 stub_thread->task_runner()->DeleteSoon(FROM_HERE, stub.release());
105 WaitForStubThread(); 105 WaitForStubThread();
106 } 106 }
107 stub_thread->Stop(); 107 stub_thread->Stop();
108 } 108 }
109 109
110 // a GetOrDownloadCallback 110 // a GetOrDownloadCallback
111 void IncrementGetOrDownload(const AttachmentService::GetOrDownloadResult&, 111 void IncrementGetOrDownload(const AttachmentService::GetOrDownloadResult&,
112 std::unique_ptr<AttachmentMap>) { 112 std::unique_ptr<AttachmentMap>) {
113 CalledOnValidThread(); 113 CalledOnValidThread();
114 ++count_callback_get_or_download; 114 ++count_callback_get_or_download;
115 } 115 }
116 116
117 void WaitForStubThread() { 117 void WaitForStubThread() {
118 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, 118 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC,
119 base::WaitableEvent::InitialState::NOT_SIGNALED); 119 base::WaitableEvent::InitialState::NOT_SIGNALED);
120 stub_thread->message_loop()->PostTask( 120 stub_thread->task_runner()->PostTask(
121 FROM_HERE, 121 FROM_HERE,
122 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 122 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
123 done.Wait(); 123 done.Wait();
124 } 124 }
125 125
126 base::MessageLoop loop; 126 base::MessageLoop loop;
127 std::unique_ptr<base::Thread> stub_thread; 127 std::unique_ptr<base::Thread> stub_thread;
128 std::unique_ptr<StubAttachmentService> stub; 128 std::unique_ptr<StubAttachmentService> stub;
129 std::unique_ptr<AttachmentServiceProxy> proxy; 129 std::unique_ptr<AttachmentServiceProxy> proxy;
130 130
(...skipping 29 matching lines...) Expand all
160 WaitForStubThread(); 160 WaitForStubThread();
161 EXPECT_EQ(1, stub->GetCallCount()); 161 EXPECT_EQ(1, stub->GetCallCount());
162 // Wait a second time ensure the stub thread has executed the posted result 162 // Wait a second time ensure the stub thread has executed the posted result
163 // callbacks. 163 // callbacks.
164 WaitForStubThread(); 164 WaitForStubThread();
165 165
166 base::RunLoop().RunUntilIdle(); 166 base::RunLoop().RunUntilIdle();
167 EXPECT_EQ(1, count_callback_get_or_download); 167 EXPECT_EQ(1, count_callback_get_or_download);
168 168
169 // Destroy the stub and call GetOrDownloadAttachments again. 169 // Destroy the stub and call GetOrDownloadAttachments again.
170 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); 170 stub_thread->task_runner()->DeleteSoon(FROM_HERE, stub.release());
171 WaitForStubThread(); 171 WaitForStubThread();
172 172
173 // Now that the wrapped object has been destroyed, call again and see that we 173 // Now that the wrapped object has been destroyed, call again and see that we
174 // don't crash and the count remains the same. 174 // don't crash and the count remains the same.
175 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); 175 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download);
176 WaitForStubThread(); 176 WaitForStubThread();
177 WaitForStubThread(); 177 WaitForStubThread();
178 base::RunLoop().RunUntilIdle(); 178 base::RunLoop().RunUntilIdle();
179 EXPECT_EQ(1, count_callback_get_or_download); 179 EXPECT_EQ(1, count_callback_get_or_download);
180 } 180 }
181 181
182 } // namespace syncer 182 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler_unittest.cc ('k') | sync/internal_api/http_bridge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698