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 <memory> |
6 | #include "flutter/common/task_runners.h" |
7 | #include "flutter/fml/synchronization/waitable_event.h" |
8 | #include "flutter/lib/ui/painting/vertices.h" |
9 | #include "flutter/runtime/dart_vm.h" |
10 | #include "flutter/shell/common/shell_test.h" |
11 | #include "flutter/shell/common/thread_host.h" |
12 | #include "flutter/testing/testing.h" |
13 | |
14 | namespace flutter { |
15 | namespace testing { |
16 | |
17 | TEST_F(ShellTest, VerticesAccuratelyReportsSize) { |
18 | auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>(); |
19 | |
20 | auto nativeValidateVertices = [message_latch](Dart_NativeArguments args) { |
21 | auto handle = Dart_GetNativeArgument(args, 0); |
22 | intptr_t peer = 0; |
23 | Dart_Handle result = Dart_GetNativeInstanceField( |
24 | handle, tonic::DartWrappable::kPeerIndex, &peer); |
25 | ASSERT_FALSE(Dart_IsError(result)); |
26 | Vertices* vertices = reinterpret_cast<Vertices*>(peer); |
27 | // GT because we don't want to be too dependent on platform specific |
28 | // differences, or minor changes to Skia. The actual value of this on |
29 | // macOS as of the test writing is 1441890ul. Just need to assert it's |
30 | // big enough to get the Dart GC's attention. |
31 | ASSERT_GT(vertices->GetAllocationSize(), 1300000ul); |
32 | message_latch->Signal(); |
33 | }; |
34 | |
35 | Settings settings = CreateSettingsForFixture(); |
36 | TaskRunners task_runners("test" , // label |
37 | GetCurrentTaskRunner(), // platform |
38 | CreateNewThread(), // raster |
39 | CreateNewThread(), // ui |
40 | CreateNewThread() // io |
41 | ); |
42 | |
43 | AddNativeCallback("ValidateVertices" , |
44 | CREATE_NATIVE_ENTRY(nativeValidateVertices)); |
45 | |
46 | std::unique_ptr<Shell> shell = |
47 | CreateShell(std::move(settings), std::move(task_runners)); |
48 | |
49 | ASSERT_TRUE(shell->IsSetup()); |
50 | auto configuration = RunConfiguration::InferFromSettings(settings); |
51 | configuration.SetEntrypoint("createVertices" ); |
52 | |
53 | shell->RunEngine(std::move(configuration), [](auto result) { |
54 | ASSERT_EQ(result, Engine::RunStatus::Success); |
55 | }); |
56 | |
57 | message_latch->Wait(); |
58 | DestroyShell(std::move(shell), std::move(task_runners)); |
59 | } |
60 | |
61 | } // namespace testing |
62 | } // namespace flutter |
63 | |