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" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 base::AutoLock lock(mutex_); | 84 base::AutoLock lock(mutex_); |
85 ++call_count_; | 85 ++call_count_; |
86 } | 86 } |
87 }; | 87 }; |
88 | 88 |
89 class AttachmentServiceProxyTest : public testing::Test, | 89 class AttachmentServiceProxyTest : public testing::Test, |
90 public base::NonThreadSafe { | 90 public base::NonThreadSafe { |
91 protected: | 91 protected: |
92 AttachmentServiceProxyTest() {} | 92 AttachmentServiceProxyTest() {} |
93 | 93 |
94 virtual void SetUp() { | 94 void SetUp() override { |
95 CalledOnValidThread(); | 95 CalledOnValidThread(); |
96 stub_thread.reset(new base::Thread("attachment service stub thread")); | 96 stub_thread.reset(new base::Thread("attachment service stub thread")); |
97 stub_thread->Start(); | 97 stub_thread->Start(); |
98 stub.reset(new StubAttachmentService); | 98 stub.reset(new StubAttachmentService); |
99 proxy.reset(new AttachmentServiceProxy(stub_thread->message_loop_proxy(), | 99 proxy.reset(new AttachmentServiceProxy(stub_thread->message_loop_proxy(), |
100 stub->AsWeakPtr())); | 100 stub->AsWeakPtr())); |
101 | 101 |
102 callback_get_or_download = | 102 callback_get_or_download = |
103 base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload, | 103 base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload, |
104 base::Unretained(this)); | 104 base::Unretained(this)); |
105 callback_drop = base::Bind(&AttachmentServiceProxyTest::IncrementDrop, | 105 callback_drop = base::Bind(&AttachmentServiceProxyTest::IncrementDrop, |
106 base::Unretained(this)); | 106 base::Unretained(this)); |
107 count_callback_get_or_download = 0; | 107 count_callback_get_or_download = 0; |
108 count_callback_drop = 0; | 108 count_callback_drop = 0; |
109 } | 109 } |
110 | 110 |
111 virtual void TearDown() | 111 void TearDown() override { |
112 override { | |
113 // We must take care to call the stub's destructor on the stub_thread | 112 // We must take care to call the stub's destructor on the stub_thread |
114 // because that's the thread to which its WeakPtrs are bound. | 113 // because that's the thread to which its WeakPtrs are bound. |
115 if (stub) { | 114 if (stub) { |
116 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); | 115 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); |
117 WaitForStubThread(); | 116 WaitForStubThread(); |
118 } | 117 } |
119 stub_thread->Stop(); | 118 stub_thread->Stop(); |
120 } | 119 } |
121 | 120 |
122 // a GetOrDownloadCallback | 121 // a GetOrDownloadCallback |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // Now that the wrapped object has been destroyed, call again and see that we | 198 // Now that the wrapped object has been destroyed, call again and see that we |
200 // don't crash and the count remains the same. | 199 // don't crash and the count remains the same. |
201 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); | 200 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); |
202 WaitForStubThread(); | 201 WaitForStubThread(); |
203 WaitForStubThread(); | 202 WaitForStubThread(); |
204 loop.RunUntilIdle(); | 203 loop.RunUntilIdle(); |
205 EXPECT_EQ(1, count_callback_get_or_download); | 204 EXPECT_EQ(1, count_callback_get_or_download); |
206 } | 205 } |
207 | 206 |
208 } // namespace syncer | 207 } // namespace syncer |
OLD | NEW |