Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
semantics_update_builder_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/lib/ui/semantics/semantics_update_builder.h"
6#include "flutter/shell/common/shell_test.h"
7
8#include "gtest/gtest.h"
9
10namespace flutter {
11namespace testing {
12
14
15TEST_F(SemanticsUpdateBuilderTest, CanHandleAttributedStrings) {
16 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
17
18 auto nativeSemanticsUpdate = [message_latch](Dart_NativeArguments args) {
19 auto handle = Dart_GetNativeArgument(args, 0);
20 intptr_t peer = 0;
23 ASSERT_FALSE(Dart_IsError(result));
24 SemanticsUpdate* update = reinterpret_cast<SemanticsUpdate*>(peer);
25 SemanticsNodeUpdates nodes = update->takeNodes();
26 ASSERT_EQ(nodes.size(), (size_t)1);
27 auto node = nodes.find(0)->second;
28 // Should match the updateNode in ui_test.dart.
29 ASSERT_EQ(node.label, "label");
30 ASSERT_EQ(node.labelAttributes.size(), (size_t)1);
31 ASSERT_EQ(node.labelAttributes[0]->start, 1);
32 ASSERT_EQ(node.labelAttributes[0]->end, 2);
33 ASSERT_EQ(node.labelAttributes[0]->type, StringAttributeType::kSpellOut);
34
35 ASSERT_EQ(node.value, "value");
36 ASSERT_EQ(node.valueAttributes.size(), (size_t)1);
37 ASSERT_EQ(node.valueAttributes[0]->start, 2);
38 ASSERT_EQ(node.valueAttributes[0]->end, 3);
39 ASSERT_EQ(node.valueAttributes[0]->type, StringAttributeType::kSpellOut);
40
41 ASSERT_EQ(node.hint, "hint");
42 ASSERT_EQ(node.hintAttributes.size(), (size_t)1);
43 ASSERT_EQ(node.hintAttributes[0]->start, 0);
44 ASSERT_EQ(node.hintAttributes[0]->end, 1);
45 ASSERT_EQ(node.hintAttributes[0]->type, StringAttributeType::kLocale);
46 auto local_attribute =
47 std::static_pointer_cast<LocaleStringAttribute>(node.hintAttributes[0]);
48 ASSERT_EQ(local_attribute->locale, "en-MX");
49
50 ASSERT_EQ(node.increasedValue, "increasedValue");
51 ASSERT_EQ(node.increasedValueAttributes.size(), (size_t)1);
52 ASSERT_EQ(node.increasedValueAttributes[0]->start, 4);
53 ASSERT_EQ(node.increasedValueAttributes[0]->end, 5);
54 ASSERT_EQ(node.increasedValueAttributes[0]->type,
56
57 ASSERT_EQ(node.decreasedValue, "decreasedValue");
58 ASSERT_EQ(node.decreasedValueAttributes.size(), (size_t)1);
59 ASSERT_EQ(node.decreasedValueAttributes[0]->start, 5);
60 ASSERT_EQ(node.decreasedValueAttributes[0]->end, 6);
61 ASSERT_EQ(node.decreasedValueAttributes[0]->type,
63 message_latch->Signal();
64 };
65
66 Settings settings = CreateSettingsForFixture();
67 TaskRunners task_runners("test", // label
68 GetCurrentTaskRunner(), // platform
69 CreateNewThread(), // raster
70 CreateNewThread(), // ui
71 CreateNewThread() // io
72 );
73
74 AddNativeCallback("SemanticsUpdate",
75 CREATE_NATIVE_ENTRY(nativeSemanticsUpdate));
76
77 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
78
79 ASSERT_TRUE(shell->IsSetup());
80 auto configuration = RunConfiguration::InferFromSettings(settings);
81 configuration.SetEntrypoint("sendSemanticsUpdate");
82
83 shell->RunEngine(std::move(configuration), [](auto result) {
85 });
86
87 message_latch->Wait();
88 DestroyShell(std::move(shell), task_runners);
89}
90
91} // namespace testing
92} // namespace flutter
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, int index, intptr_t *value)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
TEST_F(DisplayListTest, Defaults)
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
#define CREATE_NATIVE_ENTRY(native_entry)