Flutter Engine
 
Loading...
Searching...
No Matches
switches_unittests.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 <initializer_list>
6
10
11#include "gtest/gtest.h"
12
13// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
14// NOLINTBEGIN(bugprone-unchecked-optional-access)
15
16namespace flutter {
17namespace testing {
18
19TEST(SwitchesTest, SkiaTraceAllowlistFlag) {
20 fml::CommandLine command_line =
22 Settings settings = SettingsFromCommandLine(command_line);
23#if !FLUTTER_RELEASE
24 EXPECT_TRUE(settings.trace_skia);
25 EXPECT_TRUE(settings.trace_skia_allowlist.has_value());
26 EXPECT_EQ(settings.trace_skia_allowlist->size(), 1ul);
27#else
28 EXPECT_FALSE(settings.trace_skia);
29#endif
30
31 command_line =
32 fml::CommandLineFromInitializerList({"command", "--trace-skia"});
33 settings = SettingsFromCommandLine(command_line);
34#if !FLUTTER_RELEASE
35 EXPECT_TRUE(settings.trace_skia);
36 EXPECT_FALSE(settings.trace_skia_allowlist.has_value());
37#else
38 EXPECT_FALSE(settings.trace_skia);
39#endif
40
42 {"command", "--trace-skia-allowlist=aaa,bbb,ccc"});
43 settings = SettingsFromCommandLine(command_line);
44#if !FLUTTER_RELEASE
45 EXPECT_TRUE(settings.trace_skia);
46 EXPECT_TRUE(settings.trace_skia_allowlist.has_value());
47 EXPECT_EQ(settings.trace_skia_allowlist->size(), 3ul);
48 EXPECT_EQ(settings.trace_skia_allowlist->back(), "ccc");
49#else
50 EXPECT_FALSE(settings.trace_skia);
51#endif
52}
53
54TEST(SwitchesTest, TraceToFile) {
56 {"command", "--trace-to-file=trace.binpb"});
57 EXPECT_TRUE(command_line.HasOption("trace-to-file"));
58 Settings settings = SettingsFromCommandLine(command_line);
59 EXPECT_EQ(settings.trace_to_file, "trace.binpb");
60}
61
62TEST(SwitchesTest, ProfileMicrotasks) {
63 {
65 {"command", "--profile-microtasks"});
66 EXPECT_TRUE(command_line.HasOption("profile-microtasks"));
67 Settings settings = SettingsFromCommandLine(command_line);
68 EXPECT_EQ(settings.profile_microtasks, true);
69 }
70 {
71 // default
72 fml::CommandLine command_line =
74 Settings settings = SettingsFromCommandLine(command_line);
75 EXPECT_EQ(settings.profile_microtasks, false);
76 }
77}
78
79TEST(SwitchesTest, RouteParsedFlag) {
80 fml::CommandLine command_line =
81 fml::CommandLineFromInitializerList({"command", "--route=/animation"});
82 Settings settings = SettingsFromCommandLine(command_line);
83 EXPECT_EQ(settings.route, "/animation");
84 command_line = fml::CommandLineFromInitializerList({"command", "--route"});
85 settings = SettingsFromCommandLine(command_line);
86 EXPECT_TRUE(settings.route.empty());
87}
88
89TEST(SwitchesTest, EnableEmbedderAPI) {
90 {
91 // enable
93 {"command", "--enable-embedder-api"});
94 Settings settings = SettingsFromCommandLine(command_line);
95 EXPECT_EQ(settings.enable_embedder_api, true);
96 }
97 {
98 // default
99 fml::CommandLine command_line =
101 Settings settings = SettingsFromCommandLine(command_line);
102 EXPECT_EQ(settings.enable_embedder_api, false);
103 }
104}
105
106TEST(SwitchesTest, NoEnableImpeller) {
107 {
108 // enable
109 fml::CommandLine command_line =
110 fml::CommandLineFromInitializerList({"command", "--enable-impeller"});
111 EXPECT_TRUE(command_line.HasOption("enable-impeller"));
112 Settings settings = SettingsFromCommandLine(command_line);
113 EXPECT_EQ(settings.enable_impeller, true);
114 }
115 {
116 // disable
118 {"command", "--enable-impeller=false"});
119 EXPECT_TRUE(command_line.HasOption("enable-impeller"));
120 Settings settings = SettingsFromCommandLine(command_line);
121 EXPECT_EQ(settings.enable_impeller, false);
122 }
123}
124
125TEST(SwitchesTest, ProfileStartup) {
126 {
127 fml::CommandLine command_line =
128 fml::CommandLineFromInitializerList({"command", "--profile-startup"});
129 EXPECT_TRUE(command_line.HasOption("profile-startup"));
130 Settings settings = SettingsFromCommandLine(command_line);
131 EXPECT_EQ(settings.profile_startup, true);
132 }
133 {
134 // default
135 fml::CommandLine command_line =
137 Settings settings = SettingsFromCommandLine(command_line);
138 EXPECT_EQ(settings.profile_startup, false);
139 }
140}
141
142#if !FLUTTER_RELEASE
143TEST(SwitchesTest, EnableAsserts) {
145 {"command", "--dart-flags=--enable-asserts"});
146 Settings settings = SettingsFromCommandLine(command_line);
147 ASSERT_EQ(settings.dart_flags.size(), 1ul);
148 EXPECT_EQ(settings.dart_flags[0], "--enable-asserts");
149}
150#endif
151
152#ifndef OS_FUCHSIA
153TEST(SwitchesTest, RequireMergedPlatformUIThread) {
155 {"command", "--merged-platform-ui-thread=disabled"});
156 Settings settings = SettingsFromCommandLine(command_line);
157 EXPECT_EQ(settings.merged_platform_ui_thread,
159
160 EXPECT_DEATH_IF_SUPPORTED(SettingsFromCommandLine(command_line, true),
161 "This platform does not support the "
162 "merged-platform-ui-thread=disabled flag");
163}
164#endif // !OS_FUCHSIA
165
166} // namespace testing
167} // namespace flutter
168
169// NOLINTEND(bugprone-unchecked-optional-access)
bool HasOption(std::string_view name, size_t *index=nullptr) const
TEST(NativeAssetsManagerTest, NoAvailableAssets)
Settings SettingsFromCommandLine(const fml::CommandLine &command_line, bool require_merged_platform_ui_thread)
Definition switches.cc:230
CommandLine CommandLineFromInitializerList(std::initializer_list< StringType > argv)
bool profile_microtasks
Definition settings.h:164
std::string trace_to_file
Definition settings.h:154