Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
component_v2_unittest.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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#include "component_v2.h"
6
7#include <gtest/gtest.h>
8#include <optional>
9
10namespace flutter_runner {
11namespace {
12
13TEST(ComponentV2, ParseProgramMetadataDefaultAssets) {
14 // The assets_path defaults to the "data" value if unspecified.
15 std::vector<fuchsia::data::DictionaryEntry> entries;
16
17 fuchsia::data::DictionaryEntry data_entry;
18 data_entry.key = "data";
19 data_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
20 fuchsia::data::DictionaryValue::WithStr("foobar"));
21 entries.push_back(std::move(data_entry));
22
23 fuchsia::data::Dictionary program_metadata;
24 program_metadata.set_entries(std::move(entries));
25
26 ProgramMetadata result = ComponentV2::ParseProgramMetadata(program_metadata);
27
28 EXPECT_EQ(result.data_path, "pkg/foobar");
29 EXPECT_EQ(result.assets_path, "pkg/foobar");
30 EXPECT_EQ(result.old_gen_heap_size, std::nullopt);
31}
32
33TEST(ComponentV2, ParseProgramMetadataIgnoreInvalidKeys) {
34 // Invalid keys are ignored.
35 std::vector<fuchsia::data::DictionaryEntry> entries;
36
37 fuchsia::data::DictionaryEntry not_data_entry;
38 not_data_entry.key = "not_data";
39 not_data_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
40 fuchsia::data::DictionaryValue::WithStr("foo"));
41 entries.push_back(std::move(not_data_entry));
42
43 fuchsia::data::DictionaryEntry data_entry;
44 data_entry.key = "data";
45 data_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
46 fuchsia::data::DictionaryValue::WithStr("bar"));
47 entries.push_back(std::move(data_entry));
48
49 fuchsia::data::DictionaryEntry assets_entry;
50 assets_entry.key = "assets";
51 assets_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
52 fuchsia::data::DictionaryValue::WithStr("baz"));
53 entries.push_back(std::move(assets_entry));
54
55 fuchsia::data::Dictionary program_metadata;
56 program_metadata.set_entries(std::move(entries));
57
58 ProgramMetadata result = ComponentV2::ParseProgramMetadata(program_metadata);
59
60 EXPECT_EQ(result.data_path, "pkg/bar");
61 EXPECT_EQ(result.assets_path, "pkg/baz");
62 EXPECT_EQ(result.old_gen_heap_size, std::nullopt);
63}
64
65TEST(ComponentV2, ParseProgramMetadataOldGenHeapSize) {
66 // The old_gen_heap_size can be specified.
67 std::vector<fuchsia::data::DictionaryEntry> entries;
68
69 fuchsia::data::DictionaryEntry args_entry;
70 args_entry.key = "args";
71 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
72 fuchsia::data::DictionaryValue::WithStrVec({"--old_gen_heap_size=100"}));
73 entries.push_back(std::move(args_entry));
74
75 fuchsia::data::Dictionary program_metadata;
76 program_metadata.set_entries(std::move(entries));
77
78 ProgramMetadata result = ComponentV2::ParseProgramMetadata(program_metadata);
79
80 EXPECT_EQ(result.data_path, "");
81 EXPECT_EQ(result.assets_path, "");
82 EXPECT_EQ(result.old_gen_heap_size, 100);
83}
84
85TEST(ComponentV2, ParseProgramMetadataOldGenHeapSizeInvalid) {
86 // Invalid old_gen_heap_sizes should be ignored.
87 std::vector<fuchsia::data::DictionaryEntry> entries;
88
89 fuchsia::data::DictionaryEntry args_entry;
90 args_entry.key = "args";
91 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
92 fuchsia::data::DictionaryValue::WithStrVec(
93 {"--old_gen_heap_size=asdf100"}));
94 entries.push_back(std::move(args_entry));
95
96 fuchsia::data::Dictionary program_metadata;
97 program_metadata.set_entries(std::move(entries));
98
99 ProgramMetadata result = ComponentV2::ParseProgramMetadata(program_metadata);
100
101 EXPECT_EQ(result.data_path, "");
102 EXPECT_EQ(result.assets_path, "");
103 EXPECT_EQ(result.old_gen_heap_size, std::nullopt);
104}
105
106TEST(ComponentV2, ParseProgramMetadataNoExposeDirs) {
107 // Should always have a valid expose_dirs entry
108 std::vector<fuchsia::data::DictionaryEntry> entries;
109
110 fuchsia::data::Dictionary program_metadata;
111 program_metadata.set_entries(std::move(entries));
112
113 ProgramMetadata result = ComponentV2::ParseProgramMetadata(program_metadata);
114
115 EXPECT_EQ(result.expose_dirs.empty(), true);
116}
117
118TEST(ComponentV2, ParseProgramMetadataWithSingleExposeDirs) {
119 // Can parse a single exposed dir
120 std::vector<fuchsia::data::DictionaryEntry> entries;
121
122 fuchsia::data::DictionaryEntry args_entry;
123 args_entry.key = "args";
124 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
125 fuchsia::data::DictionaryValue::WithStrVec({"--expose_dirs=foo"}));
126 entries.push_back(std::move(args_entry));
127
128 fuchsia::data::Dictionary program_metadata;
129 program_metadata.set_entries(std::move(entries));
130
131 ProgramMetadata result = ComponentV2::ParseProgramMetadata(program_metadata);
132
133 ASSERT_EQ(result.expose_dirs.size(), 1u);
134 EXPECT_EQ(result.expose_dirs[0], "foo");
135}
136
137TEST(ComponentV2, ParseProgramMetadataWithMultipleExposeDirs) {
138 // Can parse a multiple exposed dirs
139 std::vector<fuchsia::data::DictionaryEntry> entries;
140
141 fuchsia::data::DictionaryEntry args_entry;
142 args_entry.key = "args";
143 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
144 fuchsia::data::DictionaryValue::WithStrVec(
145 {"--expose_dirs=foo,bar,baz"}));
146 entries.push_back(std::move(args_entry));
147
148 fuchsia::data::Dictionary program_metadata;
149 program_metadata.set_entries(std::move(entries));
150
151 ProgramMetadata result = ComponentV2::ParseProgramMetadata(program_metadata);
152
153 ASSERT_EQ(result.expose_dirs.size(), 3u);
154 EXPECT_EQ(result.expose_dirs[0], "foo");
155 EXPECT_EQ(result.expose_dirs[1], "bar");
156 EXPECT_EQ(result.expose_dirs[2], "baz");
157}
158
159TEST(ComponentV2, ParseProgramMetadataWithSingleExposeDirsAndOtherArgs) {
160 // Can parse a single exposed dir when other args are present
161 std::vector<fuchsia::data::DictionaryEntry> entries;
162
163 fuchsia::data::DictionaryEntry args_entry;
164 args_entry.key = "args";
165 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
166 fuchsia::data::DictionaryValue::WithStrVec(
167 {"--expose_dirs=foo", "--foo=bar"}));
168 entries.push_back(std::move(args_entry));
169
170 fuchsia::data::Dictionary program_metadata;
171 program_metadata.set_entries(std::move(entries));
172
173 ProgramMetadata result = ComponentV2::ParseProgramMetadata(program_metadata);
174
175 ASSERT_EQ(result.expose_dirs.size(), 1u);
176 EXPECT_EQ(result.expose_dirs[0], "foo");
177}
178
179} // anonymous namespace
180} // namespace flutter_runner
static ProgramMetadata ParseProgramMetadata(const fuchsia::data::Dictionary &program_metadata)
GAsyncResult * result
TEST(RunnerTZDataTest, LoadsWithoutTZDataPresent)