| 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/api/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" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "sync/api/attachments/attachment.h" | 16 #include "sync/api/attachments/attachment.h" |
| 17 #include "sync/api/attachments/attachment_service.h" | 17 #include "sync/internal_api/public/attachments/attachment_service.h" |
| 18 #include "sync/api/sync_data.h" | |
| 19 #include "sync/internal_api/public/base/model_type.h" | 18 #include "sync/internal_api/public/base/model_type.h" |
| 20 #include "sync/protocol/sync.pb.h" | 19 #include "sync/protocol/sync.pb.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace syncer { | 22 namespace syncer { |
| 24 | 23 |
| 25 // A stub implementation of AttachmentService that counts the number of times | 24 // A stub implementation of AttachmentService that counts the number of times |
| 26 // its methods are invoked. | 25 // its methods are invoked. |
| 27 class StubAttachmentService : public AttachmentService, | 26 class StubAttachmentService : public AttachmentService, |
| 28 public base::NonThreadSafe { | 27 public base::NonThreadSafe { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 AttachmentServiceProxyTest() {} | 93 AttachmentServiceProxyTest() {} |
| 95 | 94 |
| 96 virtual void SetUp() { | 95 virtual void SetUp() { |
| 97 CalledOnValidThread(); | 96 CalledOnValidThread(); |
| 98 stub_thread.reset(new base::Thread("attachment service stub thread")); | 97 stub_thread.reset(new base::Thread("attachment service stub thread")); |
| 99 stub_thread->Start(); | 98 stub_thread->Start(); |
| 100 stub.reset(new StubAttachmentService); | 99 stub.reset(new StubAttachmentService); |
| 101 proxy.reset(new AttachmentServiceProxy(stub_thread->message_loop_proxy(), | 100 proxy.reset(new AttachmentServiceProxy(stub_thread->message_loop_proxy(), |
| 102 stub->AsWeakPtr())); | 101 stub->AsWeakPtr())); |
| 103 | 102 |
| 104 sync_data = | |
| 105 SyncData::CreateLocalData("tag", "title", sync_pb::EntitySpecifics()); | |
| 106 sync_data_delete = | |
| 107 SyncData::CreateLocalDelete("tag", syncer::PREFERENCES); | |
| 108 | |
| 109 callback_get_or_download = | 103 callback_get_or_download = |
| 110 base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload, | 104 base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload, |
| 111 base::Unretained(this)); | 105 base::Unretained(this)); |
| 112 callback_drop = base::Bind(&AttachmentServiceProxyTest::IncrementDrop, | 106 callback_drop = base::Bind(&AttachmentServiceProxyTest::IncrementDrop, |
| 113 base::Unretained(this)); | 107 base::Unretained(this)); |
| 114 callback_store = base::Bind(&AttachmentServiceProxyTest::IncrementStore, | 108 callback_store = base::Bind(&AttachmentServiceProxyTest::IncrementStore, |
| 115 base::Unretained(this)); | 109 base::Unretained(this)); |
| 116 count_callback_get_or_download = 0; | 110 count_callback_get_or_download = 0; |
| 117 count_callback_drop = 0; | 111 count_callback_drop = 0; |
| 118 count_callback_store = 0; | 112 count_callback_store = 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 FROM_HERE, | 148 FROM_HERE, |
| 155 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 149 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 156 done.Wait(); | 150 done.Wait(); |
| 157 } | 151 } |
| 158 | 152 |
| 159 base::MessageLoop loop; | 153 base::MessageLoop loop; |
| 160 scoped_ptr<base::Thread> stub_thread; | 154 scoped_ptr<base::Thread> stub_thread; |
| 161 scoped_ptr<StubAttachmentService> stub; | 155 scoped_ptr<StubAttachmentService> stub; |
| 162 scoped_ptr<AttachmentServiceProxy> proxy; | 156 scoped_ptr<AttachmentServiceProxy> proxy; |
| 163 | 157 |
| 164 SyncData sync_data; | |
| 165 SyncData sync_data_delete; | |
| 166 | |
| 167 AttachmentService::GetOrDownloadCallback callback_get_or_download; | 158 AttachmentService::GetOrDownloadCallback callback_get_or_download; |
| 168 AttachmentService::DropCallback callback_drop; | 159 AttachmentService::DropCallback callback_drop; |
| 169 AttachmentService::StoreCallback callback_store; | 160 AttachmentService::StoreCallback callback_store; |
| 170 | 161 |
| 171 // number of times callback_get_or_download was invoked | 162 // number of times callback_get_or_download was invoked |
| 172 int count_callback_get_or_download; | 163 int count_callback_get_or_download; |
| 173 // number of times callback_drop was invoked | 164 // number of times callback_drop was invoked |
| 174 int count_callback_drop; | 165 int count_callback_drop; |
| 175 // number of times callback_store was invoked | 166 // number of times callback_store was invoked |
| 176 int count_callback_store; | 167 int count_callback_store; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // Now that the wrapped object has been destroyed, call again and see that we | 209 // Now that the wrapped object has been destroyed, call again and see that we |
| 219 // don't crash and the count remains the same. | 210 // don't crash and the count remains the same. |
| 220 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); | 211 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); |
| 221 WaitForStubThread(); | 212 WaitForStubThread(); |
| 222 WaitForStubThread(); | 213 WaitForStubThread(); |
| 223 loop.RunUntilIdle(); | 214 loop.RunUntilIdle(); |
| 224 EXPECT_EQ(1, count_callback_get_or_download); | 215 EXPECT_EQ(1, count_callback_get_or_download); |
| 225 } | 216 } |
| 226 | 217 |
| 227 } // namespace syncer | 218 } // namespace syncer |
| OLD | NEW |