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