diff options
-rw-r--r-- | sync/api/attachments/attachment_service_proxy_for_test.cc | 14 | ||||
-rw-r--r-- | sync/api/attachments/attachment_service_proxy_for_test.h | 5 |
2 files changed, 15 insertions, 4 deletions
diff --git a/sync/api/attachments/attachment_service_proxy_for_test.cc b/sync/api/attachments/attachment_service_proxy_for_test.cc index 7f9f873..7d03ed8 100644 --- a/sync/api/attachments/attachment_service_proxy_for_test.cc +++ b/sync/api/attachments/attachment_service_proxy_for_test.cc @@ -4,6 +4,7 @@ #include "sync/api/attachments/attachment_service_proxy_for_test.h" +#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop_proxy.h" #include "sync/api/attachments/fake_attachment_service.h" @@ -36,8 +37,17 @@ AttachmentServiceProxy AttachmentServiceProxyForTest::Create() { scoped_refptr<Core> core_for_test( new OwningCore(wrapped.Pass(), weak_ptr_factory.Pass())); - return AttachmentServiceProxyForTest(base::MessageLoopProxy::current(), - core_for_test); + + scoped_refptr<base::SequencedTaskRunner> runner( + base::MessageLoopProxy::current()); + if (!runner) { + // Dummy runner for tests that don't care about AttachmentServiceProxy. + DVLOG(1) << "Creating dummy MessageLoop for AttachmentServiceProxy."; + base::MessageLoop loop; + // This works because |runner| takes a ref to the proxy. + runner = loop.message_loop_proxy(); + } + return AttachmentServiceProxyForTest(runner, core_for_test); } AttachmentServiceProxyForTest::~AttachmentServiceProxyForTest() { diff --git a/sync/api/attachments/attachment_service_proxy_for_test.h b/sync/api/attachments/attachment_service_proxy_for_test.h index 916e788..2fb5c86 100644 --- a/sync/api/attachments/attachment_service_proxy_for_test.h +++ b/sync/api/attachments/attachment_service_proxy_for_test.h @@ -14,8 +14,9 @@ namespace syncer { // An self-contained AttachmentServiceProxy to reduce boilerplate code in tests. // -// Constructs and owns an AttachmentService suitable for use in tests. Assumes -// the current thread has a MessageLoop. +// Constructs and owns an AttachmentService suitable for use in tests. +// NOTE: This class does not require the current thread to have a MessageLoop, +// however all methods will effectively become no-op stubs in that case. class SYNC_EXPORT AttachmentServiceProxyForTest : public AttachmentServiceProxy { public: |