flutter_flutter/shell/platform/fuchsia/flutter/component_unittest.cc
James Robinson e3fdb23304
[fuchsia] Add ability to configure separate data and asset dirs (#18858)
This allows Fuchsia components executed by the Flutter runner to
specify a directory containing assets if they wish to store assets
separate from program data. This is specified in the program metadata
field within the component's specification with the new "assets"
attribute. If this attribute is absent, assets are loaded relative to
the path specified in the "data" attribute as before.

This is useful in the short term to use a location in the package where
we can store small files more efficiently. It is also potentially
useful longer term to enforce a stronger separatation between
executable program data and non-executable assets.

This commit adds some basic unit testing for the data parsing to the
flutter_runner_tests suite.
2020-06-12 14:41:27 -07:00

52 lines
1.5 KiB
C++

// Copyright 2013 The Flutter 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 "flutter/shell/platform/fuchsia/flutter/component.h"
#include <gtest/gtest.h>
namespace flutter_runner {
namespace {
TEST(Component, ParseProgramMetadata) {
std::string data_path;
std::string assets_path;
// The ProgramMetadata field may be null. We should parse this as if no
// fields were specified.
Application::ParseProgramMetadata(nullptr, &data_path, &assets_path);
EXPECT_EQ(data_path, "");
EXPECT_EQ(assets_path, "");
// The ProgramMetadata field may be empty. Treat this the same as null.
fidl::VectorPtr<fuchsia::sys::ProgramMetadata> program_metadata(size_t{0});
Application::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
EXPECT_EQ(data_path, "");
EXPECT_EQ(assets_path, "");
// The assets_path defaults to the "data" value if unspecified
program_metadata = {{"data", "foobar"}};
Application::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
EXPECT_EQ(data_path, "pkg/foobar");
EXPECT_EQ(assets_path, "pkg/foobar");
data_path = "";
assets_path = "";
program_metadata = {{"not_data", "foo"}, {"data", "bar"}, {"assets", "baz"}};
Application::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
EXPECT_EQ(data_path, "pkg/bar");
EXPECT_EQ(assets_path, "pkg/baz");
}
} // anonymous namespace
} // namespace flutter_runner