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_impl.h" | 5 #include "sync/internal_api/public/attachments/attachment_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/timer/mock_timer.h" | 11 #include "base/timer/mock_timer.h" |
12 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" | 12 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" |
13 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | 13 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" |
14 #include "testing/gmock/include/gmock/gmock-matchers.h" | 14 #include "testing/gmock/include/gmock/gmock-matchers.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace syncer { | 17 namespace syncer { |
18 | 18 |
| 19 namespace { |
| 20 |
19 class MockAttachmentStore : public AttachmentStore, | 21 class MockAttachmentStore : public AttachmentStore, |
20 public base::SupportsWeakPtr<MockAttachmentStore> { | 22 public base::SupportsWeakPtr<MockAttachmentStore> { |
21 public: | 23 public: |
22 MockAttachmentStore() {} | 24 MockAttachmentStore() {} |
23 | 25 |
24 virtual void Read(const AttachmentIdList& ids, | 26 virtual void Read(const AttachmentIdList& ids, |
25 const ReadCallback& callback) OVERRIDE { | 27 const ReadCallback& callback) OVERRIDE { |
26 read_ids.push_back(ids); | 28 read_ids.push_back(ids); |
27 read_callbacks.push_back(callback); | 29 read_callbacks.push_back(callback); |
28 } | 30 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 base::MessageLoop::current()->PostTask( | 145 base::MessageLoop::current()->PostTask( |
144 FROM_HERE, base::Bind(upload_requests[id], result, id)); | 146 FROM_HERE, base::Bind(upload_requests[id], result, id)); |
145 upload_requests.erase(id); | 147 upload_requests.erase(id); |
146 } | 148 } |
147 | 149 |
148 std::map<AttachmentId, UploadCallback> upload_requests; | 150 std::map<AttachmentId, UploadCallback> upload_requests; |
149 | 151 |
150 DISALLOW_COPY_AND_ASSIGN(MockAttachmentUploader); | 152 DISALLOW_COPY_AND_ASSIGN(MockAttachmentUploader); |
151 }; | 153 }; |
152 | 154 |
| 155 } // namespace |
| 156 |
153 class AttachmentServiceImplTest : public testing::Test, | 157 class AttachmentServiceImplTest : public testing::Test, |
154 public AttachmentService::Delegate { | 158 public AttachmentService::Delegate { |
155 protected: | 159 protected: |
156 AttachmentServiceImplTest() {} | 160 AttachmentServiceImplTest() {} |
157 | 161 |
158 virtual void SetUp() OVERRIDE { | 162 virtual void SetUp() OVERRIDE { |
159 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 163 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
160 InitializeAttachmentService(make_scoped_ptr(new MockAttachmentUploader()), | 164 InitializeAttachmentService(make_scoped_ptr(new MockAttachmentUploader()), |
161 make_scoped_ptr(new MockAttachmentDownloader()), | 165 make_scoped_ptr(new MockAttachmentDownloader()), |
162 this); | 166 this); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( | 549 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
546 net::NetworkChangeNotifier::CONNECTION_WIFI); | 550 net::NetworkChangeNotifier::CONNECTION_WIFI); |
547 RunLoop(); | 551 RunLoop(); |
548 | 552 |
549 // No longer in backoff. | 553 // No longer in backoff. |
550 ASSERT_TRUE(mock_timer()->IsRunning()); | 554 ASSERT_TRUE(mock_timer()->IsRunning()); |
551 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); | 555 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); |
552 } | 556 } |
553 | 557 |
554 } // namespace syncer | 558 } // namespace syncer |
OLD | NEW |