OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MockMimeRegistry_h | |
6 #define MockMimeRegistry_h | |
7 | |
8 #include "mojo/public/cpp/bindings/binding.h" | |
9 #include "net/base/mime_util.h" | |
10 #include "public/platform/FilePathConversion.h" | |
11 #include "public/platform/InterfaceProvider.h" | |
12 #include "public/platform/mime_registry.mojom-blink.h" | |
13 | |
14 namespace blink { | |
15 | |
16 // A mock interface provider that just returns mock MimeRegistry interface. | |
17 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
| |
18 public: | |
19 MockMimeRegistryProvider() {} | |
20 ~MockMimeRegistryProvider() {} | |
21 | |
22 void getInterface(const char* name, | |
23 mojo::ScopedMessagePipeHandle handle) override { | |
24 m_mockMimeRegistry = wrapUnique(new MockMimeRegistry( | |
25 mojo::MakeRequest<mojom::blink::MimeRegistry>(std::move(handle)))); | |
26 } | |
27 | |
28 private: | |
29 class MockMimeRegistry : public mojom::blink::MimeRegistry { | |
30 public: | |
31 MockMimeRegistry(mojom::blink::MimeRegistryRequest request) | |
32 : m_binding(this, std::move(request)) {} | |
33 ~MockMimeRegistry() {} | |
34 | |
35 void GetMimeTypeFromExtension( | |
36 const String& ext, | |
37 const GetMimeTypeFromExtensionCallback& callback) override { | |
38 std::string mimeType; | |
39 net::GetMimeTypeFromExtension(WebStringToFilePath(ext).value(), | |
40 &mimeType); | |
41 callback.Run(String::fromUTF8(mimeType.data(), mimeType.length())); | |
42 } | |
43 | |
44 mojo::Binding<mojom::blink::MimeRegistry> m_binding; | |
45 }; | |
46 | |
47 std::unique_ptr<MockMimeRegistry> m_mockMimeRegistry; | |
48 }; | |
49 | |
50 } // namespace blink | |
51 | |
52 #endif // MockMimeRegistry_h | |
OLD | NEW |