mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
5e66f41697
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42678 Changelog: [internal] This is a re-application of https://github.com/facebook/react-native/pull/42430, which had to be reverted because of crashes in optimized builds on Android: ``` Abort Reason: terminating due to uncaught exception of type facebook::jni::JniException: java.lang.ClassNotFoundException: com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsProvider ``` The root cause of that was that that class was removed because it wasn't statically referenced from Kotlin/Java, but it was dynamically referenced from C++ (in `ReactNativeFeatureFlagsProviderHolder.cpp`). This applies the same changes + adds `DoNotStrip` annotations for the affected class and all its methods. Reviewed By: huntie Differential Revision: D53122992 fbshipit-source-id: efc4d5636a3f2d39b86e9c098bff408b6688b80b
102 lines
2.9 KiB
C++
102 lines
2.9 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
|
#include <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
|
|
#include <stdexcept>
|
|
|
|
namespace facebook::react {
|
|
|
|
uint overrideAccessCount = 0;
|
|
|
|
class ReactNativeFeatureFlagsTestOverrides
|
|
: public ReactNativeFeatureFlagsDefaults {
|
|
public:
|
|
bool commonTestFlag() override {
|
|
overrideAccessCount++;
|
|
return true;
|
|
}
|
|
};
|
|
|
|
class ReactNativeFeatureFlagsTest : public testing::Test {
|
|
protected:
|
|
void SetUp() override {
|
|
overrideAccessCount = 0;
|
|
}
|
|
};
|
|
|
|
TEST_F(ReactNativeFeatureFlagsTest, providesDefaults) {
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), false);
|
|
}
|
|
|
|
TEST_F(ReactNativeFeatureFlagsTest, providesOverriddenValues) {
|
|
ReactNativeFeatureFlags::override(
|
|
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
|
|
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
|
|
}
|
|
|
|
TEST_F(ReactNativeFeatureFlagsTest, preventsOverridingAfterAccess) {
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), false);
|
|
|
|
try {
|
|
ReactNativeFeatureFlags::override(
|
|
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
|
|
FAIL()
|
|
<< "Expected ReactNativeFeatureFlags::override() to throw an exception";
|
|
} catch (const std::runtime_error& e) {
|
|
EXPECT_STREQ(
|
|
"Feature flags were accessed before being overridden: commonTestFlag",
|
|
e.what());
|
|
}
|
|
|
|
// Overrides shouldn't be applied after they've been accessed
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), false);
|
|
}
|
|
|
|
TEST_F(ReactNativeFeatureFlagsTest, cachesValuesFromOverride) {
|
|
ReactNativeFeatureFlags::override(
|
|
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
|
|
|
|
EXPECT_EQ(overrideAccessCount, 0);
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
|
|
EXPECT_EQ(overrideAccessCount, 1);
|
|
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
|
|
EXPECT_EQ(overrideAccessCount, 1);
|
|
}
|
|
|
|
TEST_F(
|
|
ReactNativeFeatureFlagsTest,
|
|
providesDefaulValuesAgainWhenResettingAfterAnOverride) {
|
|
ReactNativeFeatureFlags::override(
|
|
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
|
|
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
|
|
|
|
ReactNativeFeatureFlags::dangerouslyReset();
|
|
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), false);
|
|
}
|
|
|
|
TEST_F(ReactNativeFeatureFlagsTest, allowsOverridingAgainAfterReset) {
|
|
ReactNativeFeatureFlags::override(
|
|
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
|
|
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
|
|
|
|
ReactNativeFeatureFlags::dangerouslyReset();
|
|
|
|
ReactNativeFeatureFlags::override(
|
|
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
|
|
|
|
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
|
|
}
|
|
|
|
} // namespace facebook::react
|