Remove the standalone a11y test runners and merge its tests into embedder_unittests. (flutter/engine#8338)
Also cleans up the a11y unittests to use the new builder API and avoids polluting the global namespace with state for assertions.
This commit is contained in:
@@ -7,7 +7,7 @@ import("$flutter_root/common/config.gni")
|
||||
# Whether to build the dartdevc sdk, libraries, and source files
|
||||
# required for the flutter web sdk.
|
||||
declare_args() {
|
||||
full_dart_sdk = false
|
||||
full_dart_sdk = false
|
||||
}
|
||||
|
||||
group("flutter") {
|
||||
@@ -32,9 +32,7 @@ group("flutter") {
|
||||
]
|
||||
|
||||
if (full_dart_sdk) {
|
||||
public_deps += [
|
||||
"$flutter_root/web_sdk",
|
||||
]
|
||||
public_deps += [ "$flutter_root/web_sdk" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +50,6 @@ group("flutter") {
|
||||
"$flutter_root/runtime:runtime_unittests",
|
||||
"$flutter_root/shell/common:shell_unittests",
|
||||
"$flutter_root/shell/platform/embedder:embedder_unittests",
|
||||
"$flutter_root/shell/platform/embedder:embedder_a11y_unittests", # TODO(cbracken) build these into a different kernel blob in the embedder tests and load that in a test in embedder_unittests
|
||||
"$flutter_root/synchronization:synchronization_unittests",
|
||||
"$flutter_root/third_party/txt:txt_unittests",
|
||||
]
|
||||
|
||||
@@ -686,8 +686,7 @@ FILE: ../../../flutter/shell/platform/embedder/embedder_task_runner.cc
|
||||
FILE: ../../../flutter/shell/platform/embedder/embedder_task_runner.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/embedder_thread_host.cc
|
||||
FILE: ../../../flutter/shell/platform/embedder/embedder_thread_host.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/a11y_main.dart
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/simple_main.dart
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/main.dart
|
||||
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.cc
|
||||
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.cc
|
||||
|
||||
@@ -64,7 +64,7 @@ source_set("embedder") {
|
||||
}
|
||||
|
||||
test_fixtures("fixtures") {
|
||||
fixtures = [ "fixtures/simple_main.dart" ]
|
||||
fixtures = [ "fixtures/main.dart" ]
|
||||
}
|
||||
|
||||
executable("embedder_unittests") {
|
||||
@@ -73,6 +73,7 @@ executable("embedder_unittests") {
|
||||
include_dirs = [ "." ]
|
||||
|
||||
sources = [
|
||||
"tests/embedder_a11y_unittests.cc",
|
||||
"tests/embedder_config_builder.cc",
|
||||
"tests/embedder_config_builder.h",
|
||||
"tests/embedder_context.cc",
|
||||
@@ -87,6 +88,7 @@ executable("embedder_unittests") {
|
||||
deps = [
|
||||
":embedder",
|
||||
":fixtures",
|
||||
"$flutter_root/lib/ui",
|
||||
"$flutter_root/runtime",
|
||||
"$flutter_root/testing",
|
||||
"//third_party/skia",
|
||||
@@ -98,34 +100,6 @@ executable("embedder_unittests") {
|
||||
}
|
||||
}
|
||||
|
||||
test_fixtures("fixtures_a11y") {
|
||||
fixtures = [ "fixtures/a11y_main.dart" ]
|
||||
}
|
||||
|
||||
executable("embedder_a11y_unittests") {
|
||||
testonly = true
|
||||
|
||||
include_dirs = [ "." ]
|
||||
|
||||
sources = [
|
||||
"tests/embedder_a11y_unittests.cc",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":embedder",
|
||||
":fixtures_a11y",
|
||||
"$flutter_root/lib/ui:ui",
|
||||
"$flutter_root/shell/common",
|
||||
"$flutter_root/testing",
|
||||
"//third_party/skia",
|
||||
"//third_party/tonic",
|
||||
]
|
||||
|
||||
if (is_linux) {
|
||||
ldflags = [ "-rdynamic" ]
|
||||
}
|
||||
}
|
||||
|
||||
shared_library("flutter_engine_library") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
|
||||
@@ -2,6 +2,34 @@ import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
void main() {}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void customEntrypoint() {
|
||||
sayHiFromCustomEntrypoint();
|
||||
}
|
||||
|
||||
void sayHiFromCustomEntrypoint() native "SayHiFromCustomEntrypoint";
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void customEntrypoint1() {
|
||||
sayHiFromCustomEntrypoint1();
|
||||
sayHiFromCustomEntrypoint2();
|
||||
sayHiFromCustomEntrypoint3();
|
||||
}
|
||||
|
||||
void sayHiFromCustomEntrypoint1() native "SayHiFromCustomEntrypoint1";
|
||||
void sayHiFromCustomEntrypoint2() native "SayHiFromCustomEntrypoint2";
|
||||
void sayHiFromCustomEntrypoint3() native "SayHiFromCustomEntrypoint3";
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void invokePlatformTaskRunner() {
|
||||
window.sendPlatformMessage('OhHi', null, null);
|
||||
}
|
||||
|
||||
|
||||
Float64List kTestTransform = () {
|
||||
final Float64List values = Float64List(16);
|
||||
values[0] = 1.0; // scaleX
|
||||
@@ -17,9 +45,9 @@ Float64List kTestTransform = () {
|
||||
}();
|
||||
|
||||
void signalNativeTest() native 'SignalNativeTest';
|
||||
void notifySemanticsEnabled(bool enabled) native 'NotifyTestData1';
|
||||
void notifyAccessibilityFeatures(bool reduceMotion) native 'NotifyTestData1';
|
||||
void notifySemanticsAction(int nodeId, int action, List<int> data) native 'NotifyTestData3';
|
||||
void notifySemanticsEnabled(bool enabled) native 'NotifyTestData';
|
||||
void notifyAccessibilityFeatures(bool reduceMotion) native 'NotifyTestData';
|
||||
void notifySemanticsAction(int nodeId, int action, List<int> data) native 'NotifyTestData';
|
||||
|
||||
/// Returns a future that completes when `window.onSemanticsEnabledChanged`
|
||||
/// fires.
|
||||
@@ -52,7 +80,8 @@ Future<SemanticsActionData> get semanticsAction {
|
||||
return actionReceived.future;
|
||||
}
|
||||
|
||||
main() async {
|
||||
@pragma('vm:entry-point')
|
||||
void a11y_main() async {
|
||||
// Return initial state (semantics disabled).
|
||||
notifySemanticsEnabled(window.semanticsEnabled);
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import 'dart:ui';
|
||||
|
||||
void main() {}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void customEntrypoint() {
|
||||
sayHiFromCustomEntrypoint();
|
||||
}
|
||||
|
||||
void sayHiFromCustomEntrypoint() native "SayHiFromCustomEntrypoint";
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void customEntrypoint1() {
|
||||
sayHiFromCustomEntrypoint1();
|
||||
sayHiFromCustomEntrypoint2();
|
||||
sayHiFromCustomEntrypoint3();
|
||||
}
|
||||
|
||||
void sayHiFromCustomEntrypoint1() native "SayHiFromCustomEntrypoint1";
|
||||
void sayHiFromCustomEntrypoint2() native "SayHiFromCustomEntrypoint2";
|
||||
void sayHiFromCustomEntrypoint3() native "SayHiFromCustomEntrypoint3";
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void invokePlatformTaskRunner() {
|
||||
window.sendPlatformMessage('OhHi', null, null);
|
||||
}
|
||||
@@ -7,152 +7,92 @@
|
||||
#define FML_USED_ON_EMBEDDER
|
||||
|
||||
#include <functional>
|
||||
#include "embedder.h"
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/message_loop.h"
|
||||
#include "flutter/fml/synchronization/waitable_event.h"
|
||||
#include "flutter/lib/ui/semantics/semantics_node.h"
|
||||
#include "flutter/shell/platform/embedder/embedder_engine.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
#include "flutter/shell/platform/embedder/tests/embedder_config_builder.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "third_party/dart/runtime/include/dart_api.h"
|
||||
#include "third_party/tonic/converter/dart_converter.h"
|
||||
#include "third_party/tonic/dart_library_natives.h"
|
||||
|
||||
#define REGISTER_FUNCTION(name, count) {"" #name, name, count, true},
|
||||
#define DECLARE_FUNCTION(name, count) \
|
||||
extern void name(Dart_NativeArguments args);
|
||||
#define BUILTIN_NATIVE_LIST(V) \
|
||||
V(SignalNativeTest, 0) \
|
||||
V(NotifyTestData1, 1) \
|
||||
V(NotifyTestData3, 3)
|
||||
namespace shell {
|
||||
namespace testing {
|
||||
|
||||
BUILTIN_NATIVE_LIST(DECLARE_FUNCTION);
|
||||
using Embedder11yTest = testing::EmbedderTest;
|
||||
|
||||
static tonic::DartLibraryNatives* g_natives;
|
||||
TEST_F(Embedder11yTest, A11yTreeIsConsistent) {
|
||||
auto& context = GetEmbedderContext();
|
||||
|
||||
Dart_NativeFunction GetNativeFunction(Dart_Handle name,
|
||||
int argument_count,
|
||||
bool* auto_setup_scope) {
|
||||
return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope);
|
||||
}
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
|
||||
const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
|
||||
return g_natives->GetSymbol(native_function);
|
||||
}
|
||||
// Called by the Dart text fixture on the UI thread to signal that the C++
|
||||
// unittest should resume.
|
||||
context.AddNativeCallback(
|
||||
"SignalNativeTest", CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments) {
|
||||
latch.Signal();
|
||||
})));
|
||||
|
||||
using OnTestDataCallback = std::function<void(Dart_NativeArguments)>;
|
||||
// Called by test fixture on UI thread to pass data back to this test.
|
||||
NativeEntry callback;
|
||||
context.AddNativeCallback(
|
||||
"NotifyTestData",
|
||||
CREATE_NATIVE_ENTRY(([&callback](Dart_NativeArguments args) {
|
||||
ASSERT_NE(callback, nullptr);
|
||||
callback(args);
|
||||
})));
|
||||
|
||||
fml::AutoResetWaitableEvent g_latch;
|
||||
OnTestDataCallback g_test_data_callback = [](Dart_NativeArguments) {};
|
||||
EmbedderConfigBuilder builder(context);
|
||||
builder.SetDartEntrypoint("a11y_main");
|
||||
|
||||
// Called by the Dart text fixture on the UI thread to signal that the C++
|
||||
// unittest should resume.
|
||||
void SignalNativeTest(Dart_NativeArguments args) {
|
||||
g_latch.Signal();
|
||||
}
|
||||
|
||||
// Called by test fixture on UI thread to pass data back to this test.
|
||||
// 1 parameter version.
|
||||
void NotifyTestData1(Dart_NativeArguments args) {
|
||||
g_test_data_callback(args);
|
||||
}
|
||||
|
||||
// Called by test fixture on UI thread to pass data back to this test.
|
||||
// 3 parameter version.
|
||||
void NotifyTestData3(Dart_NativeArguments args) {
|
||||
g_test_data_callback(args);
|
||||
}
|
||||
|
||||
TEST(EmbedderTest, CanLaunchAndShutdownWithValidProjectArgs) {
|
||||
FlutterSoftwareRendererConfig renderer;
|
||||
renderer.struct_size = sizeof(FlutterSoftwareRendererConfig);
|
||||
renderer.surface_present_callback = [](void*, const void*, size_t, size_t) {
|
||||
return false;
|
||||
};
|
||||
|
||||
FlutterRendererConfig config = {};
|
||||
config.type = FlutterRendererType::kSoftware;
|
||||
config.software = renderer;
|
||||
|
||||
FlutterProjectArgs args = {};
|
||||
args.struct_size = sizeof(FlutterProjectArgs);
|
||||
args.assets_path = testing::GetFixturesPath();
|
||||
|
||||
// Register native functions to be called from test fixture.
|
||||
g_natives = new tonic::DartLibraryNatives();
|
||||
g_natives->Register({BUILTIN_NATIVE_LIST(REGISTER_FUNCTION)});
|
||||
args.root_isolate_create_callback = [](void*) {
|
||||
Dart_SetNativeResolver(Dart_RootLibrary(), GetNativeFunction, GetSymbol);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
std::function<void(const FlutterSemanticsNode*)> on_semantics_update;
|
||||
std::function<void(const FlutterSemanticsCustomAction*)>
|
||||
on_custom_action_update;
|
||||
} TestData;
|
||||
auto test_data = TestData{};
|
||||
args.update_semantics_node_callback = [](const FlutterSemanticsNode* node,
|
||||
void* data) {
|
||||
auto test_data = reinterpret_cast<TestData*>(data);
|
||||
test_data->on_semantics_update(node);
|
||||
};
|
||||
args.update_semantics_custom_action_callback =
|
||||
[](const FlutterSemanticsCustomAction* action, void* data) {
|
||||
auto test_data = reinterpret_cast<TestData*>(data);
|
||||
test_data->on_custom_action_update(action);
|
||||
};
|
||||
|
||||
// Start the engine, run text fixture.
|
||||
FlutterEngine engine = nullptr;
|
||||
FlutterEngineResult result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config,
|
||||
&args, &test_data, &engine);
|
||||
ASSERT_EQ(result, FlutterEngineResult::kSuccess);
|
||||
auto engine = builder.LaunchEngine();
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
// Wait for initial NotifySemanticsEnabled(false).
|
||||
g_test_data_callback = [](Dart_NativeArguments args) {
|
||||
bool enabled;
|
||||
callback = [&](Dart_NativeArguments args) {
|
||||
bool enabled = true;
|
||||
Dart_GetNativeBooleanArgument(args, 0, &enabled);
|
||||
ASSERT_FALSE(enabled);
|
||||
g_latch.Signal();
|
||||
latch.Signal();
|
||||
};
|
||||
g_latch.Wait();
|
||||
latch.Wait();
|
||||
|
||||
// Enable semantics. Wait for NotifySemanticsEnabled(true).
|
||||
g_test_data_callback = [](Dart_NativeArguments args) {
|
||||
bool enabled;
|
||||
callback = [&](Dart_NativeArguments args) {
|
||||
bool enabled = false;
|
||||
Dart_GetNativeBooleanArgument(args, 0, &enabled);
|
||||
ASSERT_TRUE(enabled);
|
||||
g_latch.Signal();
|
||||
latch.Signal();
|
||||
};
|
||||
result = FlutterEngineUpdateSemanticsEnabled(engine, true);
|
||||
auto result = FlutterEngineUpdateSemanticsEnabled(engine.get(), true);
|
||||
ASSERT_EQ(result, FlutterEngineResult::kSuccess);
|
||||
g_latch.Wait();
|
||||
latch.Wait();
|
||||
|
||||
// Wait for initial accessibility features (reduce_motion == false)
|
||||
g_test_data_callback = [](Dart_NativeArguments args) {
|
||||
bool enabled;
|
||||
callback = [&](Dart_NativeArguments args) {
|
||||
bool enabled = true;
|
||||
Dart_GetNativeBooleanArgument(args, 0, &enabled);
|
||||
ASSERT_FALSE(enabled);
|
||||
g_latch.Signal();
|
||||
latch.Signal();
|
||||
};
|
||||
g_latch.Wait();
|
||||
latch.Wait();
|
||||
|
||||
// Set accessibility features: (reduce_motion == true)
|
||||
g_test_data_callback = [](Dart_NativeArguments args) {
|
||||
bool enabled;
|
||||
callback = [&](Dart_NativeArguments args) {
|
||||
bool enabled = false;
|
||||
Dart_GetNativeBooleanArgument(args, 0, &enabled);
|
||||
ASSERT_TRUE(enabled);
|
||||
g_latch.Signal();
|
||||
latch.Signal();
|
||||
};
|
||||
result = FlutterEngineUpdateAccessibilityFeatures(
|
||||
engine, kFlutterAccessibilityFeatureReduceMotion);
|
||||
engine.get(), kFlutterAccessibilityFeatureReduceMotion);
|
||||
ASSERT_EQ(result, FlutterEngineResult::kSuccess);
|
||||
g_latch.Wait();
|
||||
latch.Wait();
|
||||
|
||||
// Wait for UpdateSemantics callback on platform (current) thread.
|
||||
int node_count = 0;
|
||||
int node_batch_end_count = 0;
|
||||
test_data.on_semantics_update =
|
||||
context.SetSemanticsNodeCallback(
|
||||
[&node_count, &node_batch_end_count](const FlutterSemanticsNode* node) {
|
||||
if (node->id == kFlutterSemanticsNodeIdBatchEnd) {
|
||||
++node_batch_end_count;
|
||||
@@ -168,10 +108,11 @@ TEST(EmbedderTest, CanLaunchAndShutdownWithValidProjectArgs) {
|
||||
ASSERT_EQ(8.0, node->transform.pers1);
|
||||
ASSERT_EQ(9.0, node->transform.pers2);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
int action_count = 0;
|
||||
int action_batch_end_count = 0;
|
||||
test_data.on_custom_action_update =
|
||||
context.SetSemanticsCustomActionCallback(
|
||||
[&action_count,
|
||||
&action_batch_end_count](const FlutterSemanticsCustomAction* action) {
|
||||
if (action->id == kFlutterSemanticsCustomActionIdBatchEnd) {
|
||||
@@ -179,8 +120,9 @@ TEST(EmbedderTest, CanLaunchAndShutdownWithValidProjectArgs) {
|
||||
} else {
|
||||
++action_count;
|
||||
}
|
||||
};
|
||||
g_latch.Wait();
|
||||
});
|
||||
|
||||
latch.Wait();
|
||||
fml::MessageLoop::GetCurrent().RunExpiredTasksNow();
|
||||
ASSERT_EQ(4, node_count);
|
||||
ASSERT_EQ(1, node_batch_end_count);
|
||||
@@ -188,8 +130,8 @@ TEST(EmbedderTest, CanLaunchAndShutdownWithValidProjectArgs) {
|
||||
ASSERT_EQ(1, action_batch_end_count);
|
||||
|
||||
// Dispatch a tap to semantics node 42. Wait for NotifySemanticsAction.
|
||||
g_test_data_callback = [](Dart_NativeArguments args) {
|
||||
int64_t node_id;
|
||||
callback = [&](Dart_NativeArguments args) {
|
||||
int64_t node_id = 0;
|
||||
Dart_GetNativeIntegerArgument(args, 0, &node_id);
|
||||
ASSERT_EQ(42, node_id);
|
||||
|
||||
@@ -206,24 +148,24 @@ TEST(EmbedderTest, CanLaunchAndShutdownWithValidProjectArgs) {
|
||||
dart_int = Dart_ListGetAt(semantic_args, 1);
|
||||
Dart_IntegerToInt64(dart_int, &data);
|
||||
ASSERT_EQ(1, data);
|
||||
g_latch.Signal();
|
||||
latch.Signal();
|
||||
};
|
||||
std::vector<uint8_t> bytes({2, 1});
|
||||
result = FlutterEngineDispatchSemanticsAction(
|
||||
engine, 42, kFlutterSemanticsActionTap, &bytes[0], bytes.size());
|
||||
g_latch.Wait();
|
||||
engine.get(), 42, kFlutterSemanticsActionTap, &bytes[0], bytes.size());
|
||||
latch.Wait();
|
||||
|
||||
// Disable semantics. Wait for NotifySemanticsEnabled(false).
|
||||
g_test_data_callback = [](Dart_NativeArguments args) {
|
||||
bool enabled;
|
||||
callback = [&](Dart_NativeArguments args) {
|
||||
bool enabled = true;
|
||||
Dart_GetNativeBooleanArgument(args, 0, &enabled);
|
||||
ASSERT_FALSE(enabled);
|
||||
g_latch.Signal();
|
||||
latch.Signal();
|
||||
};
|
||||
result = FlutterEngineUpdateSemanticsEnabled(engine, false);
|
||||
ASSERT_EQ(result, FlutterEngineResult::kSuccess);
|
||||
g_latch.Wait();
|
||||
|
||||
result = FlutterEngineShutdown(engine);
|
||||
result = FlutterEngineUpdateSemanticsEnabled(engine.get(), false);
|
||||
ASSERT_EQ(result, FlutterEngineResult::kSuccess);
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace shell
|
||||
|
||||
@@ -22,6 +22,7 @@ EmbedderConfigBuilder::EmbedderConfigBuilder(
|
||||
SetAssetsPath();
|
||||
SetSnapshots();
|
||||
SetIsolateCreateCallbackHook();
|
||||
SetSemanticsCallbackHooks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +64,13 @@ void EmbedderConfigBuilder::SetIsolateCreateCallbackHook() {
|
||||
EmbedderContext::GetIsolateCreateCallbackHook();
|
||||
}
|
||||
|
||||
void EmbedderConfigBuilder::SetSemanticsCallbackHooks() {
|
||||
project_args_.update_semantics_node_callback =
|
||||
EmbedderContext::GetUpdateSemanticsNodeCallbackHook();
|
||||
project_args_.update_semantics_custom_action_callback =
|
||||
EmbedderContext::GetUpdateSemanticsCustomActionCallbackHook();
|
||||
}
|
||||
|
||||
void EmbedderConfigBuilder::SetDartEntrypoint(std::string entrypoint) {
|
||||
if (entrypoint.size() == 0) {
|
||||
return;
|
||||
|
||||
@@ -48,6 +48,8 @@ class EmbedderConfigBuilder {
|
||||
|
||||
void SetIsolateCreateCallbackHook();
|
||||
|
||||
void SetSemanticsCallbackHooks();
|
||||
|
||||
void SetDartEntrypoint(std::string entrypoint);
|
||||
|
||||
void AddCommandLineArgument(std::string arg);
|
||||
|
||||
@@ -105,5 +105,36 @@ void EmbedderContext::AddNativeCallback(const char* name,
|
||||
native_resolver_->AddNativeCallback({name}, function);
|
||||
}
|
||||
|
||||
void EmbedderContext::SetSemanticsNodeCallback(
|
||||
SemanticsNodeCallback update_semantics_node_callback) {
|
||||
update_semantics_node_callback_ = update_semantics_node_callback;
|
||||
}
|
||||
|
||||
void EmbedderContext::SetSemanticsCustomActionCallback(
|
||||
SemanticsActionCallback update_semantics_custom_action_callback) {
|
||||
update_semantics_custom_action_callback_ =
|
||||
update_semantics_custom_action_callback;
|
||||
}
|
||||
|
||||
FlutterUpdateSemanticsNodeCallback
|
||||
EmbedderContext::GetUpdateSemanticsNodeCallbackHook() {
|
||||
return [](const FlutterSemanticsNode* semantics_node, void* user_data) {
|
||||
auto context = reinterpret_cast<EmbedderContext*>(user_data);
|
||||
if (auto callback = context->update_semantics_node_callback_) {
|
||||
callback(semantics_node);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
FlutterUpdateSemanticsCustomActionCallback
|
||||
EmbedderContext::GetUpdateSemanticsCustomActionCallbackHook() {
|
||||
return [](const FlutterSemanticsCustomAction* action, void* user_data) {
|
||||
auto context = reinterpret_cast<EmbedderContext*>(user_data);
|
||||
if (auto callback = context->update_semantics_custom_action_callback_) {
|
||||
callback(action);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace shell
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#define CREATE_NATIVE_ENTRY(native_entry) \
|
||||
([&]() { \
|
||||
static ::shell::testing::EmbedderContext::NativeEntry closure; \
|
||||
static ::shell::testing::NativeEntry closure; \
|
||||
static Dart_NativeFunction entrypoint = [](Dart_NativeArguments args) { \
|
||||
closure(args); \
|
||||
}; \
|
||||
@@ -29,10 +29,13 @@
|
||||
namespace shell {
|
||||
namespace testing {
|
||||
|
||||
using NativeEntry = std::function<void(Dart_NativeArguments)>;
|
||||
using SemanticsNodeCallback = std::function<void(const FlutterSemanticsNode*)>;
|
||||
using SemanticsActionCallback =
|
||||
std::function<void(const FlutterSemanticsCustomAction*)>;
|
||||
|
||||
class EmbedderContext {
|
||||
public:
|
||||
using NativeEntry = std::function<void(Dart_NativeArguments)>;
|
||||
|
||||
EmbedderContext(std::string assets_path = "");
|
||||
|
||||
~EmbedderContext();
|
||||
@@ -51,6 +54,11 @@ class EmbedderContext {
|
||||
|
||||
void AddNativeCallback(const char* name, Dart_NativeFunction function);
|
||||
|
||||
void SetSemanticsNodeCallback(SemanticsNodeCallback update_semantics_node);
|
||||
|
||||
void SetSemanticsCustomActionCallback(
|
||||
SemanticsActionCallback semantics_custom_action);
|
||||
|
||||
private:
|
||||
// This allows the builder to access the hooks.
|
||||
friend class EmbedderConfigBuilder;
|
||||
@@ -62,9 +70,17 @@ class EmbedderContext {
|
||||
std::unique_ptr<fml::Mapping> isolate_snapshot_instructions_;
|
||||
std::vector<fml::closure> isolate_create_callbacks_;
|
||||
std::shared_ptr<EmbedderTestResolver> native_resolver_;
|
||||
SemanticsNodeCallback update_semantics_node_callback_;
|
||||
SemanticsActionCallback update_semantics_custom_action_callback_;
|
||||
|
||||
static VoidCallback GetIsolateCreateCallbackHook();
|
||||
|
||||
static FlutterUpdateSemanticsNodeCallback
|
||||
GetUpdateSemanticsNodeCallbackHook();
|
||||
|
||||
static FlutterUpdateSemanticsCustomActionCallback
|
||||
GetUpdateSemanticsCustomActionCallbackHook();
|
||||
|
||||
void FireIsolateCreateCallbacks();
|
||||
|
||||
void SetNativeResolver();
|
||||
|
||||
Reference in New Issue
Block a user