OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | |
11 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
12 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
13 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
14 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
15 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
16 #include "sync/api/attachments/attachment.h" | 15 #include "sync/api/attachments/attachment.h" |
17 #include "sync/internal_api/public/attachments/attachment_service.h" | 16 #include "sync/internal_api/public/attachments/attachment_service.h" |
18 #include "sync/internal_api/public/base/model_type.h" | 17 #include "sync/internal_api/public/base/model_type.h" |
19 #include "sync/protocol/sync.pb.h" | 18 #include "sync/protocol/sync.pb.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 proxy->DropAttachments(AttachmentIdList(), callback_drop); | 164 proxy->DropAttachments(AttachmentIdList(), callback_drop); |
166 proxy->UploadAttachments(AttachmentIdSet()); | 165 proxy->UploadAttachments(AttachmentIdSet()); |
167 // Wait for the posted calls to execute in the stub thread. | 166 // Wait for the posted calls to execute in the stub thread. |
168 WaitForStubThread(); | 167 WaitForStubThread(); |
169 EXPECT_EQ(3, stub->GetCallCount()); | 168 EXPECT_EQ(3, stub->GetCallCount()); |
170 // At this point the stub thread has finished executed the calls. However, the | 169 // At this point the stub thread has finished executed the calls. However, the |
171 // result callbacks it has posted may not have executed yet. Wait a second | 170 // result callbacks it has posted may not have executed yet. Wait a second |
172 // time to ensure the stub thread has executed the posted result callbacks. | 171 // time to ensure the stub thread has executed the posted result callbacks. |
173 WaitForStubThread(); | 172 WaitForStubThread(); |
174 | 173 |
175 loop.RunUntilIdle(); | 174 base::RunLoop().RunUntilIdle(); |
176 EXPECT_EQ(1, count_callback_get_or_download); | 175 EXPECT_EQ(1, count_callback_get_or_download); |
177 EXPECT_EQ(1, count_callback_drop); | 176 EXPECT_EQ(1, count_callback_drop); |
178 } | 177 } |
179 | 178 |
180 // Verify that it's safe to use an AttachmentServiceProxy even after its wrapped | 179 // Verify that it's safe to use an AttachmentServiceProxy even after its wrapped |
181 // AttachmentService has been destroyed. | 180 // AttachmentService has been destroyed. |
182 TEST_F(AttachmentServiceProxyTest, WrappedIsDestroyed) { | 181 TEST_F(AttachmentServiceProxyTest, WrappedIsDestroyed) { |
183 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); | 182 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); |
184 // Wait for the posted calls to execute in the stub thread. | 183 // Wait for the posted calls to execute in the stub thread. |
185 WaitForStubThread(); | 184 WaitForStubThread(); |
186 EXPECT_EQ(1, stub->GetCallCount()); | 185 EXPECT_EQ(1, stub->GetCallCount()); |
187 // Wait a second time ensure the stub thread has executed the posted result | 186 // Wait a second time ensure the stub thread has executed the posted result |
188 // callbacks. | 187 // callbacks. |
189 WaitForStubThread(); | 188 WaitForStubThread(); |
190 | 189 |
191 loop.RunUntilIdle(); | 190 base::RunLoop().RunUntilIdle(); |
192 EXPECT_EQ(1, count_callback_get_or_download); | 191 EXPECT_EQ(1, count_callback_get_or_download); |
193 | 192 |
194 // Destroy the stub and call GetOrDownloadAttachments again. | 193 // Destroy the stub and call GetOrDownloadAttachments again. |
195 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); | 194 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); |
196 WaitForStubThread(); | 195 WaitForStubThread(); |
197 | 196 |
198 // Now that the wrapped object has been destroyed, call again and see that we | 197 // Now that the wrapped object has been destroyed, call again and see that we |
199 // don't crash and the count remains the same. | 198 // don't crash and the count remains the same. |
200 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); | 199 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); |
201 WaitForStubThread(); | 200 WaitForStubThread(); |
202 WaitForStubThread(); | 201 WaitForStubThread(); |
203 loop.RunUntilIdle(); | 202 base::RunLoop().RunUntilIdle(); |
204 EXPECT_EQ(1, count_callback_get_or_download); | 203 EXPECT_EQ(1, count_callback_get_or_download); |
205 } | 204 } |
206 | 205 |
207 } // namespace syncer | 206 } // namespace syncer |
OLD | NEW |