Flutter Engine
platform_view_android_delegate_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/android/platform_view_android_delegate/platform_view_android_delegate.h"
6 
7 #include "flutter/shell/platform/android/jni/jni_mock.h"
8 #include "gmock/gmock.h"
9 #include "gtest/gtest.h"
10 
11 namespace flutter {
12 namespace testing {
13 
14 TEST(PlatformViewShell, UpdateSemanticsDoesFlutterViewUpdateSemantics) {
15  auto jni_mock = std::make_shared<JNIMock>();
16  auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
17 
20  node0.id = 0;
21  node0.label = "label";
22  update.insert(std::make_pair(0, std::move(node0)));
23 
24  std::vector<uint8_t> expected_buffer(164);
25  size_t position = 0;
26  int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
27  float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
28  std::vector<std::string> expected_strings;
29  buffer_int32[position++] = node0.id;
30  buffer_int32[position++] = node0.flags;
31  buffer_int32[position++] = node0.actions;
32  buffer_int32[position++] = node0.maxValueLength;
33  buffer_int32[position++] = node0.currentValueLength;
34  buffer_int32[position++] = node0.textSelectionBase;
35  buffer_int32[position++] = node0.textSelectionExtent;
36  buffer_int32[position++] = node0.platformViewId;
37  buffer_int32[position++] = node0.scrollChildren;
38  buffer_int32[position++] = node0.scrollIndex;
39  buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
40  buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
41  buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
42  buffer_int32[position++] = expected_strings.size(); // node0.label
43  expected_strings.push_back(node0.label);
44  buffer_int32[position++] = -1; // node0.value
45  buffer_int32[position++] = -1; // node0.increasedValue
46  buffer_int32[position++] = -1; // node0.decreasedValue
47  buffer_int32[position++] = -1; // node0.hint
48  buffer_int32[position++] = node0.textDirection;
49  buffer_float32[position++] = node0.rect.left();
50  buffer_float32[position++] = node0.rect.top();
51  buffer_float32[position++] = node0.rect.right();
52  buffer_float32[position++] = node0.rect.bottom();
53  node0.transform.getColMajor(&buffer_float32[position]);
54  position += 16;
55  buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
56  buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
57 
58  EXPECT_CALL(*jni_mock,
59  FlutterViewUpdateSemantics(expected_buffer, expected_strings));
60  // Creates empty custom actions.
62  delegate->UpdateSemantics(update, actions);
63 }
64 
65 TEST(PlatformViewShell,
66  UpdateSemanticsDoesFlutterViewUpdateCustomAccessibilityActions) {
67  auto jni_mock = std::make_shared<JNIMock>();
68  auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
69 
72  action0.id = 0;
73  action0.overrideId = 1;
74  action0.label = "label";
75  action0.hint = "hint";
76  actions.insert(std::make_pair(0, std::move(action0)));
77 
78  std::vector<uint8_t> expected_actions_buffer(16);
79  int32_t* actions_buffer_int32 =
80  reinterpret_cast<int32_t*>(&expected_actions_buffer[0]);
81  std::vector<std::string> expected_action_strings;
82  actions_buffer_int32[0] = action0.id;
83  actions_buffer_int32[1] = action0.overrideId;
84  actions_buffer_int32[2] = expected_action_strings.size();
85  expected_action_strings.push_back(action0.label);
86  actions_buffer_int32[3] = expected_action_strings.size();
87  expected_action_strings.push_back(action0.hint);
88 
89  EXPECT_CALL(*jni_mock, FlutterViewUpdateCustomAccessibilityActions(
90  expected_actions_buffer, expected_action_strings));
91  // Creates empty update.
93  delegate->UpdateSemantics(update, actions);
94 }
95 
96 } // namespace testing
97 } // namespace flutter
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithNoMutations)