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/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 public base::NonThreadSafe { | 26 public base::NonThreadSafe { |
27 public: | 27 public: |
28 StubAttachmentService() : call_count_(0), weak_ptr_factory_(this) { | 28 StubAttachmentService() : call_count_(0), weak_ptr_factory_(this) { |
29 // DetachFromThread because we will be constructed in one thread and | 29 // DetachFromThread because we will be constructed in one thread and |
30 // used/destroyed in another. | 30 // used/destroyed in another. |
31 DetachFromThread(); | 31 DetachFromThread(); |
32 } | 32 } |
33 | 33 |
34 ~StubAttachmentService() override {} | 34 ~StubAttachmentService() override {} |
35 | 35 |
| 36 AttachmentStore* GetStore() override { return NULL; } |
| 37 |
36 void GetOrDownloadAttachments( | 38 void GetOrDownloadAttachments( |
37 const AttachmentIdList& attachment_ids, | 39 const AttachmentIdList& attachment_ids, |
38 const GetOrDownloadCallback& callback) override { | 40 const GetOrDownloadCallback& callback) override { |
39 CalledOnValidThread(); | 41 CalledOnValidThread(); |
40 Increment(); | 42 Increment(); |
41 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); | 43 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); |
42 base::MessageLoop::current()->PostTask( | 44 base::MessageLoop::current()->PostTask( |
43 FROM_HERE, | 45 FROM_HERE, |
44 base::Bind(callback, | 46 base::Bind(callback, |
45 AttachmentService::GET_UNSPECIFIED_ERROR, | 47 AttachmentService::GET_UNSPECIFIED_ERROR, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 scoped_ptr<base::Thread> stub_thread; | 125 scoped_ptr<base::Thread> stub_thread; |
124 scoped_ptr<StubAttachmentService> stub; | 126 scoped_ptr<StubAttachmentService> stub; |
125 scoped_ptr<AttachmentServiceProxy> proxy; | 127 scoped_ptr<AttachmentServiceProxy> proxy; |
126 | 128 |
127 AttachmentService::GetOrDownloadCallback callback_get_or_download; | 129 AttachmentService::GetOrDownloadCallback callback_get_or_download; |
128 | 130 |
129 // number of times callback_get_or_download was invoked | 131 // number of times callback_get_or_download was invoked |
130 int count_callback_get_or_download; | 132 int count_callback_get_or_download; |
131 }; | 133 }; |
132 | 134 |
| 135 TEST_F(AttachmentServiceProxyTest, GetStore) { |
| 136 EXPECT_EQ(NULL, proxy->GetStore()); |
| 137 } |
| 138 |
133 // Verify that each of AttachmentServiceProxy's methods are invoked on the stub. | 139 // Verify that each of AttachmentServiceProxy's methods are invoked on the stub. |
134 // Verify that the methods that take callbacks invoke passed callbacks on this | 140 // Verify that the methods that take callbacks invoke passed callbacks on this |
135 // thread. | 141 // thread. |
136 TEST_F(AttachmentServiceProxyTest, MethodsAreProxied) { | 142 TEST_F(AttachmentServiceProxyTest, MethodsAreProxied) { |
137 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); | 143 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); |
138 proxy->UploadAttachments(AttachmentIdSet()); | 144 proxy->UploadAttachments(AttachmentIdSet()); |
139 // Wait for the posted calls to execute in the stub thread. | 145 // Wait for the posted calls to execute in the stub thread. |
140 WaitForStubThread(); | 146 WaitForStubThread(); |
141 EXPECT_EQ(2, stub->GetCallCount()); | 147 EXPECT_EQ(2, stub->GetCallCount()); |
142 // At this point the stub thread has finished executed the calls. However, the | 148 // At this point the stub thread has finished executed the calls. However, the |
(...skipping 26 matching lines...) Expand all Loading... |
169 // Now that the wrapped object has been destroyed, call again and see that we | 175 // Now that the wrapped object has been destroyed, call again and see that we |
170 // don't crash and the count remains the same. | 176 // don't crash and the count remains the same. |
171 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); | 177 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); |
172 WaitForStubThread(); | 178 WaitForStubThread(); |
173 WaitForStubThread(); | 179 WaitForStubThread(); |
174 base::RunLoop().RunUntilIdle(); | 180 base::RunLoop().RunUntilIdle(); |
175 EXPECT_EQ(1, count_callback_get_or_download); | 181 EXPECT_EQ(1, count_callback_get_or_download); |
176 } | 182 } |
177 | 183 |
178 } // namespace syncer | 184 } // namespace syncer |
OLD | NEW |