Index: third_party/WebKit/Source/platform/network/mime/MockMimeRegistry.h |
diff --git a/third_party/WebKit/Source/platform/network/mime/MockMimeRegistry.h b/third_party/WebKit/Source/platform/network/mime/MockMimeRegistry.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f044a04e865b2152e694fe24c8fd87c1bc312085 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/network/mime/MockMimeRegistry.h |
@@ -0,0 +1,52 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MockMimeRegistry_h |
+#define MockMimeRegistry_h |
+ |
+#include "mojo/public/cpp/bindings/binding.h" |
+#include "net/base/mime_util.h" |
+#include "public/platform/FilePathConversion.h" |
+#include "public/platform/InterfaceProvider.h" |
+#include "public/platform/mime_registry.mojom-blink.h" |
+ |
+namespace blink { |
+ |
+// A mock interface provider that just returns mock MimeRegistry interface. |
+class MockMimeRegistryProvider : public blink::InterfaceProvider { |
Reilly Grant (use Gerrit)
2016/10/27 22:31:23
This seems like an unnecessary level of abstractio
kinuko
2016/10/28 00:40:07
I wanted to have something like InterfaceProvider:
Reilly Grant (use Gerrit)
2016/10/28 01:04:26
In that case we still want to be registering servi
kinuko
2016/10/28 01:09:15
Yeah using interface provider as an indirection is
|
+ public: |
+ MockMimeRegistryProvider() {} |
+ ~MockMimeRegistryProvider() {} |
+ |
+ void getInterface(const char* name, |
+ mojo::ScopedMessagePipeHandle handle) override { |
+ m_mockMimeRegistry = wrapUnique(new MockMimeRegistry( |
+ mojo::MakeRequest<mojom::blink::MimeRegistry>(std::move(handle)))); |
+ } |
+ |
+ private: |
+ class MockMimeRegistry : public mojom::blink::MimeRegistry { |
+ public: |
+ MockMimeRegistry(mojom::blink::MimeRegistryRequest request) |
+ : m_binding(this, std::move(request)) {} |
+ ~MockMimeRegistry() {} |
+ |
+ void GetMimeTypeFromExtension( |
+ const String& ext, |
+ const GetMimeTypeFromExtensionCallback& callback) override { |
+ std::string mimeType; |
+ net::GetMimeTypeFromExtension(WebStringToFilePath(ext).value(), |
+ &mimeType); |
+ callback.Run(String::fromUTF8(mimeType.data(), mimeType.length())); |
+ } |
+ |
+ mojo::Binding<mojom::blink::MimeRegistry> m_binding; |
+ }; |
+ |
+ std::unique_ptr<MockMimeRegistry> m_mockMimeRegistry; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // MockMimeRegistry_h |