|
32 | 32 | #include "flutter/shell/common/vsync_waiter_fallback.h" |
33 | 33 | #include "flutter/shell/version/version.h" |
34 | 34 | #include "flutter/testing/testing.h" |
| 35 | +#include "gmock/gmock.h" |
35 | 36 | #include "third_party/rapidjson/include/rapidjson/writer.h" |
36 | 37 | #include "third_party/skia/include/core/SkPictureRecorder.h" |
37 | 38 | #include "third_party/tonic/converter/dart_converter.h" |
|
42 | 43 |
|
43 | 44 | namespace flutter { |
44 | 45 | namespace testing { |
| 46 | +namespace { |
| 47 | +class MockPlatformViewDelegate : public PlatformView::Delegate { |
| 48 | + MOCK_METHOD1(OnPlatformViewCreated, void(std::unique_ptr<Surface> surface)); |
| 49 | + |
| 50 | + MOCK_METHOD0(OnPlatformViewDestroyed, void()); |
| 51 | + |
| 52 | + MOCK_METHOD1(OnPlatformViewSetNextFrameCallback, |
| 53 | + void(const fml::closure& closure)); |
| 54 | + |
| 55 | + MOCK_METHOD1(OnPlatformViewSetViewportMetrics, |
| 56 | + void(const ViewportMetrics& metrics)); |
| 57 | + |
| 58 | + MOCK_METHOD1(OnPlatformViewDispatchPlatformMessage, |
| 59 | + void(fml::RefPtr<PlatformMessage> message)); |
| 60 | + |
| 61 | + MOCK_METHOD1(OnPlatformViewDispatchPointerDataPacket, |
| 62 | + void(std::unique_ptr<PointerDataPacket> packet)); |
| 63 | + |
| 64 | + MOCK_METHOD3(OnPlatformViewDispatchSemanticsAction, |
| 65 | + void(int32_t id, |
| 66 | + SemanticsAction action, |
| 67 | + std::vector<uint8_t> args)); |
| 68 | + |
| 69 | + MOCK_METHOD1(OnPlatformViewSetSemanticsEnabled, void(bool enabled)); |
| 70 | + |
| 71 | + MOCK_METHOD1(OnPlatformViewSetAccessibilityFeatures, void(int32_t flags)); |
| 72 | + |
| 73 | + MOCK_METHOD1(OnPlatformViewRegisterTexture, |
| 74 | + void(std::shared_ptr<Texture> texture)); |
| 75 | + |
| 76 | + MOCK_METHOD1(OnPlatformViewUnregisterTexture, void(int64_t texture_id)); |
| 77 | + |
| 78 | + MOCK_METHOD1(OnPlatformViewMarkTextureFrameAvailable, |
| 79 | + void(int64_t texture_id)); |
| 80 | + |
| 81 | + MOCK_METHOD3(LoadDartDeferredLibrary, |
| 82 | + void(intptr_t loading_unit_id, |
| 83 | + std::unique_ptr<const fml::Mapping> snapshot_data, |
| 84 | + std::unique_ptr<const fml::Mapping> snapshot_instructions)); |
| 85 | + |
| 86 | + MOCK_METHOD3(LoadDartDeferredLibraryError, |
| 87 | + void(intptr_t loading_unit_id, |
| 88 | + const std::string error_message, |
| 89 | + bool transient)); |
| 90 | + |
| 91 | + MOCK_METHOD1(UpdateAssetManager, |
| 92 | + void(std::shared_ptr<AssetManager> asset_manager)); |
| 93 | +}; |
| 94 | + |
| 95 | +class MockSurface : public Surface { |
| 96 | + MOCK_METHOD0(IsValid, bool()); |
| 97 | + |
| 98 | + MOCK_METHOD1(AcquireFrame, |
| 99 | + std::unique_ptr<SurfaceFrame>(const SkISize& size)); |
| 100 | + |
| 101 | + MOCK_CONST_METHOD0(GetRootTransformation, SkMatrix()); |
| 102 | + |
| 103 | + MOCK_METHOD0(GetContext, GrDirectContext*()); |
| 104 | + |
| 105 | + MOCK_METHOD0(MakeRenderContextCurrent, std::unique_ptr<GLContextResult>()); |
| 106 | + |
| 107 | + MOCK_METHOD0(ClearRenderContext, bool()); |
| 108 | +}; |
| 109 | + |
| 110 | +class MockPlatformView : public PlatformView { |
| 111 | + public: |
| 112 | + MockPlatformView(MockPlatformViewDelegate& delegate, TaskRunners task_runners) |
| 113 | + : PlatformView(delegate, task_runners) {} |
| 114 | + MOCK_METHOD0(CreateRenderingSurface, std::unique_ptr<Surface>()); |
| 115 | +}; |
| 116 | +} // namespace |
45 | 117 |
|
46 | 118 | static bool ValidateShell(Shell* shell) { |
47 | 119 | if (!shell) { |
@@ -2318,5 +2390,52 @@ TEST_F(ShellTest, AssetManagerMulti) { |
2318 | 2390 | } |
2319 | 2391 | } |
2320 | 2392 |
|
| 2393 | +TEST_F(ShellTest, Spawn) { |
| 2394 | + auto settings = CreateSettingsForFixture(); |
| 2395 | + auto shell = CreateShell(settings); |
| 2396 | + ASSERT_TRUE(ValidateShell(shell.get())); |
| 2397 | + |
| 2398 | + auto configuration = RunConfiguration::InferFromSettings(settings); |
| 2399 | + ASSERT_TRUE(configuration.IsValid()); |
| 2400 | + configuration.SetEntrypoint("fixturesAreFunctionalMain"); |
| 2401 | + |
| 2402 | + fml::AutoResetWaitableEvent main_latch; |
| 2403 | + AddNativeCallback( |
| 2404 | + "SayHiFromFixturesAreFunctionalMain", |
| 2405 | + CREATE_NATIVE_ENTRY([&main_latch](auto args) { main_latch.Signal(); })); |
| 2406 | + |
| 2407 | + RunEngine(shell.get(), std::move(configuration)); |
| 2408 | + main_latch.Wait(); |
| 2409 | + ASSERT_TRUE(DartVMRef::IsInstanceRunning()); |
| 2410 | + |
| 2411 | + { |
| 2412 | + fml::AutoResetWaitableEvent latch; |
| 2413 | + fml::TaskRunner::RunNowOrPostTask( |
| 2414 | + shell->GetTaskRunners().GetPlatformTaskRunner(), |
| 2415 | + [this, &spawner = shell, &latch, settings]() { |
| 2416 | + MockPlatformViewDelegate platform_view_delegate; |
| 2417 | + auto spawn = spawner->Spawn( |
| 2418 | + settings, |
| 2419 | + [&platform_view_delegate](Shell& shell) { |
| 2420 | + auto result = std::make_unique<MockPlatformView>( |
| 2421 | + platform_view_delegate, shell.GetTaskRunners()); |
| 2422 | + ON_CALL(*result, CreateRenderingSurface()) |
| 2423 | + .WillByDefault(::testing::Invoke( |
| 2424 | + [] { return std::make_unique<MockSurface>(); })); |
| 2425 | + return result; |
| 2426 | + }, |
| 2427 | + [](Shell& shell) { return std::make_unique<Rasterizer>(shell); }); |
| 2428 | + ASSERT_NE(nullptr, spawn.get()); |
| 2429 | + ASSERT_TRUE(ValidateShell(spawn.get())); |
| 2430 | + DestroyShell(std::move(spawn)); |
| 2431 | + latch.Signal(); |
| 2432 | + }); |
| 2433 | + latch.Wait(); |
| 2434 | + } |
| 2435 | + |
| 2436 | + DestroyShell(std::move(shell)); |
| 2437 | + ASSERT_FALSE(DartVMRef::IsInstanceRunning()); |
| 2438 | +} |
| 2439 | + |
2321 | 2440 | } // namespace testing |
2322 | 2441 | } // namespace flutter |
0 commit comments