mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Replaces the (temporary) compile-time option to pass engine switches with the ability to pass them temporarily at runtime via environment variables. This moves the recently-added code for doing this on Windows to a shared location for use by all desktop embeddings. This is enabled only for debug/profile to avoid potential issues with tampering with released applications, but if there is a need for that in the future it could be added (potentially with a whitelist, as is currently used for Dart VM flags). Temporarily adds a way to enable mirrors as a compile time option, as is already provided in the Linux embedding, to provide a migration path for the one remaining known need for compile-time options that has been raised in flutter/flutter#38569.
71 lines
2.3 KiB
C++
71 lines
2.3 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/windows/flutter_project_bundle.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace flutter {
|
|
namespace testing {
|
|
|
|
TEST(FlutterProjectBundle, BasicPropertiesAbsolutePaths) {
|
|
FlutterDesktopEngineProperties properties = {};
|
|
properties.assets_path = L"C:\\foo\\flutter_assets";
|
|
properties.icu_data_path = L"C:\\foo\\icudtl.dat";
|
|
|
|
FlutterProjectBundle project(properties);
|
|
|
|
EXPECT_TRUE(project.HasValidPaths());
|
|
EXPECT_EQ(project.assets_path().string(), "C:\\foo\\flutter_assets");
|
|
EXPECT_EQ(project.icu_path().string(), "C:\\foo\\icudtl.dat");
|
|
}
|
|
|
|
TEST(FlutterProjectBundle, BasicPropertiesRelativePaths) {
|
|
FlutterDesktopEngineProperties properties = {};
|
|
properties.assets_path = L"foo\\flutter_assets";
|
|
properties.icu_data_path = L"foo\\icudtl.dat";
|
|
|
|
FlutterProjectBundle project(properties);
|
|
|
|
EXPECT_TRUE(project.HasValidPaths());
|
|
EXPECT_TRUE(project.assets_path().is_absolute());
|
|
EXPECT_EQ(project.assets_path().filename().string(), "flutter_assets");
|
|
EXPECT_TRUE(project.icu_path().is_absolute());
|
|
EXPECT_EQ(project.icu_path().filename().string(), "icudtl.dat");
|
|
}
|
|
|
|
TEST(FlutterProjectBundle, SwitchesEmpty) {
|
|
FlutterDesktopEngineProperties properties = {};
|
|
properties.assets_path = L"foo\\flutter_assets";
|
|
properties.icu_data_path = L"foo\\icudtl.dat";
|
|
|
|
// Clear the main environment variable, since test order is not guaranteed.
|
|
_putenv_s("FLUTTER_ENGINE_SWITCHES", "");
|
|
|
|
FlutterProjectBundle project(properties);
|
|
|
|
EXPECT_EQ(project.GetSwitches().size(), 0);
|
|
}
|
|
|
|
#ifndef FLUTTER_RELEASE
|
|
TEST(FlutterProjectBundle, Switches) {
|
|
FlutterDesktopEngineProperties properties = {};
|
|
properties.assets_path = L"foo\\flutter_assets";
|
|
properties.icu_data_path = L"foo\\icudtl.dat";
|
|
|
|
_putenv_s("FLUTTER_ENGINE_SWITCHES", "2");
|
|
_putenv_s("FLUTTER_ENGINE_SWITCH_1", "abc");
|
|
_putenv_s("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
|
|
|
|
FlutterProjectBundle project(properties);
|
|
|
|
std::vector<std::string> switches = project.GetSwitches();
|
|
EXPECT_EQ(switches.size(), 2);
|
|
EXPECT_EQ(switches[0], "--abc");
|
|
EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
|
|
}
|
|
#endif // !FLUTTER_RELEASE
|
|
|
|
} // namespace testing
|
|
} // namespace flutter
|