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