Mojo: add native type mapping for base::FilePath
BUG=598821 Review URL: https://codereview.chromium.org/1890643002 Cr-Commit-Position: refs/heads/master@{#388225}
This commit is contained in:
@ -2,15 +2,24 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//mojo/public/tools/bindings/mojom.gni")
|
||||
import("//testing/test.gni")
|
||||
|
||||
group("common") {
|
||||
public_deps = [
|
||||
":common_base",
|
||||
":common_custom_types",
|
||||
":url_type_converters",
|
||||
]
|
||||
}
|
||||
|
||||
# GYP version: mojo/mojo_base.gyp:mojo_common_custom_types
|
||||
mojom("common_custom_types") {
|
||||
sources = [
|
||||
"common_custom_types.mojom",
|
||||
]
|
||||
}
|
||||
|
||||
# GYP version: mojo/mojo_base.gyp:mojo_common_lib
|
||||
component("common_base") {
|
||||
output_name = "mojo_common_lib"
|
||||
@ -58,10 +67,22 @@ source_set("url_type_converters") {
|
||||
]
|
||||
}
|
||||
|
||||
# GYP version: mojo/mojo_base.gyp:mojo_test_common_custom_types
|
||||
mojom("test_common_custom_types") {
|
||||
sources = [
|
||||
"test_common_custom_types.mojom",
|
||||
]
|
||||
public_deps = [
|
||||
":common_custom_types",
|
||||
]
|
||||
}
|
||||
|
||||
# GYP version: mojo/mojo_base.gyp:mojo_common_unittests
|
||||
test("mojo_common_unittests") {
|
||||
deps = [
|
||||
":common",
|
||||
":common_custom_types",
|
||||
":test_common_custom_types",
|
||||
"//base",
|
||||
"//base:message_loop_tests",
|
||||
"//base/test:test_support",
|
||||
@ -79,6 +100,7 @@ test("mojo_common_unittests") {
|
||||
# that we put them here.
|
||||
"../message_pump/handle_watcher_unittest.cc",
|
||||
"../message_pump/message_pump_mojo_unittest.cc",
|
||||
"common_custom_types_unittest.cc",
|
||||
"common_type_converters_unittest.cc",
|
||||
]
|
||||
|
||||
|
8
mojo/common/common_custom_types.mojom
Normal file
8
mojo/common/common_custom_types.mojom
Normal file
@ -0,0 +1,8 @@
|
||||
// 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.
|
||||
|
||||
module mojo.common.mojom;
|
||||
|
||||
[Native]
|
||||
struct FilePath;
|
12
mojo/common/common_custom_types.typemap
Normal file
12
mojo/common/common_custom_types.typemap
Normal file
@ -0,0 +1,12 @@
|
||||
# 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.
|
||||
|
||||
mojom = "//mojo/common/common_custom_types.mojom"
|
||||
public_headers = [ "//base/files/file_path.h" ]
|
||||
traits_headers = [ "//ipc/ipc_message_utils.h" ]
|
||||
deps = [
|
||||
"//ipc",
|
||||
]
|
||||
|
||||
type_mappings = [ "mojo.common.mojom.FilePath=base::FilePath" ]
|
52
mojo/common/common_custom_types_unittest.cc
Normal file
52
mojo/common/common_custom_types_unittest.cc
Normal file
@ -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.
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "mojo/common/common_custom_types.mojom.h"
|
||||
#include "mojo/common/test_common_custom_types.mojom.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace common {
|
||||
namespace test {
|
||||
|
||||
class TestFilePathImpl : public TestFilePath {
|
||||
public:
|
||||
explicit TestFilePathImpl(TestFilePathRequest request)
|
||||
: binding_(this, std::move(request)) {}
|
||||
|
||||
// TestFilePath implementation:
|
||||
void BounceFilePath(const base::FilePath& in,
|
||||
const BounceFilePathCallback& callback) override {
|
||||
callback.Run(in);
|
||||
}
|
||||
|
||||
private:
|
||||
mojo::Binding<TestFilePath> binding_;
|
||||
};
|
||||
|
||||
TEST(CommonCustomTypesTest, FilePath) {
|
||||
base::MessageLoop message_loop;
|
||||
base::RunLoop run_loop;
|
||||
|
||||
TestFilePathPtr ptr;
|
||||
TestFilePathImpl impl(GetProxy(&ptr));
|
||||
|
||||
base::FilePath dir(FILE_PATH_LITERAL("hello"));
|
||||
base::FilePath file = dir.Append(FILE_PATH_LITERAL("world"));
|
||||
|
||||
ptr->BounceFilePath(file, [&run_loop, &file](const base::FilePath& out) {
|
||||
EXPECT_EQ(file, out);
|
||||
run_loop.Quit();
|
||||
});
|
||||
|
||||
run_loop.Run();
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace common
|
||||
} // namespace mojo
|
12
mojo/common/test_common_custom_types.mojom
Normal file
12
mojo/common/test_common_custom_types.mojom
Normal file
@ -0,0 +1,12 @@
|
||||
// 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.
|
||||
|
||||
module mojo.common.test;
|
||||
|
||||
import "mojo/common/common_custom_types.mojom";
|
||||
|
||||
interface TestFilePath {
|
||||
BounceFilePath(mojo.common.mojom.FilePath in)
|
||||
=> (mojo.common.mojom.FilePath out);
|
||||
};
|
5
mojo/common/typemaps.gni
Normal file
5
mojo/common/typemaps.gni
Normal file
@ -0,0 +1,5 @@
|
||||
# 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.
|
||||
|
||||
typemaps = [ "//mojo/common/common_custom_types.typemap" ]
|
@ -58,6 +58,23 @@
|
||||
'common/data_pipe_utils.h',
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/common:common_custom_types
|
||||
'target_name': 'mojo_common_custom_types',
|
||||
'type': 'static_library',
|
||||
'variables': {
|
||||
'mojom_typemaps': [
|
||||
'common/common_custom_types.typemap',
|
||||
],
|
||||
},
|
||||
'sources': [
|
||||
'common/common_custom_types.mojom',
|
||||
],
|
||||
'dependencies': [
|
||||
'../ipc/ipc.gyp:ipc',
|
||||
],
|
||||
'includes': [ 'mojom_bindings_generator.gypi' ],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/common:url_type_converters
|
||||
'target_name': 'mojo_url_type_converters',
|
||||
@ -94,6 +111,23 @@
|
||||
'converters/geometry/mojo_geometry_export.h',
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/common:test_common_custom_types
|
||||
'target_name': 'mojo_test_common_custom_types',
|
||||
'type': 'static_library',
|
||||
'variables': {
|
||||
'mojom_typemaps': [
|
||||
'common/common_custom_types.typemap',
|
||||
],
|
||||
},
|
||||
'sources': [
|
||||
'common/test_common_custom_types.mojom',
|
||||
],
|
||||
'dependencies': [
|
||||
'mojo_common_custom_types',
|
||||
],
|
||||
'includes': [ 'mojom_bindings_generator.gypi' ],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/common:mojo_common_unittests
|
||||
'target_name': 'mojo_common_unittests',
|
||||
@ -104,7 +138,9 @@
|
||||
'../base/base.gyp:base_message_loop_tests',
|
||||
'../testing/gtest.gyp:gtest',
|
||||
'../url/url.gyp:url_lib',
|
||||
'mojo_common_custom_types',
|
||||
'mojo_common_lib',
|
||||
'mojo_test_common_custom_types',
|
||||
'mojo_edk.gyp:mojo_system_impl',
|
||||
'mojo_edk.gyp:mojo_common_test_support',
|
||||
'mojo_edk.gyp:mojo_run_all_unittests',
|
||||
@ -114,6 +150,7 @@
|
||||
'mojo_url_type_converters',
|
||||
],
|
||||
'sources': [
|
||||
'common/common_custom_types_unittest.cc',
|
||||
'common/common_type_converters_unittest.cc',
|
||||
'message_pump/handle_watcher_unittest.cc',
|
||||
'message_pump/message_pump_mojo_unittest.cc',
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
_typemap_imports = [
|
||||
"//gpu/command_buffer/common/typemaps.gni",
|
||||
"//mojo/common/typemaps.gni",
|
||||
"//mojo/public/cpp/bindings/tests/chromium_typemaps.gni",
|
||||
"//url/mojo/typemaps.gni",
|
||||
]
|
||||
|
Reference in New Issue
Block a user