Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
engine_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 "flutter/shell/platform/common/engine_switches.h"
6
7#include "gtest/gtest.h"
8
9namespace flutter {
10
11namespace {
12// Sets |key=value| in the environment of this process.
13void SetEnvironmentVariable(const char* key, const char* value) {
14#ifdef _WIN32
15 _putenv_s(key, value);
16#else
17 setenv(key, value, 1);
18#endif
19}
20
21// Removes |key| from the environment of this process, if present.
22void ClearEnvironmentVariable(const char* key) {
23#ifdef _WIN32
24 _putenv_s(key, "");
25#else
26 unsetenv(key);
27#endif
28}
29} // namespace
30
31TEST(FlutterProjectBundle, SwitchesEmpty) {
32 // Clear the main environment variable, since test order is not guaranteed.
33 ClearEnvironmentVariable("FLUTTER_ENGINE_SWITCHES");
34
35 EXPECT_EQ(GetSwitchesFromEnvironment().size(), 0U);
36}
37
38#ifdef FLUTTER_RELEASE
39TEST(FlutterProjectBundle, SwitchesIgnoredInRelease) {
40 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCHES", "2");
41 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_1", "abc");
42 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
43
44 std::vector<std::string> switches = GetSwitchesFromEnvironment();
45 EXPECT_EQ(switches.size(), 0U);
46}
47#endif // FLUTTER_RELEASE
48
49#ifndef FLUTTER_RELEASE
51 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCHES", "2");
52 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_1", "abc");
53 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
54
55 std::vector<std::string> switches = GetSwitchesFromEnvironment();
56 EXPECT_EQ(switches.size(), 2U);
57 EXPECT_EQ(switches[0], "--abc");
58 EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
59}
60
61TEST(FlutterProjectBundle, SwitchesExtraValues) {
62 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCHES", "1");
63 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_1", "abc");
64 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
65
66 std::vector<std::string> switches = GetSwitchesFromEnvironment();
67 EXPECT_EQ(switches.size(), 1U);
68 EXPECT_EQ(switches[0], "--abc");
69}
70
71TEST(FlutterProjectBundle, SwitchesMissingValues) {
72 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCHES", "4");
73 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_1", "abc");
74 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
75 ClearEnvironmentVariable("FLUTTER_ENGINE_SWITCH_3");
76 SetEnvironmentVariable("FLUTTER_ENGINE_SWITCH_4", "oops");
77
78 std::vector<std::string> switches = GetSwitchesFromEnvironment();
79 EXPECT_EQ(switches.size(), 3U);
80 EXPECT_EQ(switches[0], "--abc");
81 EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
82 // The missing switch should be skipped, leaving SWITCH_4 as the third
83 // switch in the array.
84 EXPECT_EQ(switches[2], "--oops");
85}
86#endif // !FLUTTER_RELEASE
87
88} // namespace flutter
#define TEST(S, s, D, expected)
std::vector< std::string > GetSwitchesFromEnvironment()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259