|
| 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 | +#define FML_USED_ON_EMBEDDER |
| 6 | + |
| 7 | +#import <OCMock/OCMock.h> |
| 8 | +#import <XCTest/XCTest.h> |
| 9 | + |
| 10 | +#import "flutter/fml/message_loop.h" |
| 11 | +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" |
| 12 | +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h" |
| 13 | +#import "flutter/shell/platform/darwin/ios/platform_view_ios.h" |
| 14 | + |
| 15 | +FLUTTER_ASSERT_NOT_ARC |
| 16 | + |
| 17 | +namespace flutter { |
| 18 | +namespace { |
| 19 | + |
| 20 | +class MockDelegate : public PlatformView::Delegate { |
| 21 | + void OnPlatformViewCreated(std::unique_ptr<Surface> surface) override {} |
| 22 | + void OnPlatformViewDestroyed() override {} |
| 23 | + void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {} |
| 24 | + void OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) override {} |
| 25 | + void OnPlatformViewDispatchPlatformMessage(fml::RefPtr<PlatformMessage> message) override {} |
| 26 | + void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet) override { |
| 27 | + } |
| 28 | + void OnPlatformViewDispatchSemanticsAction(int32_t id, |
| 29 | + SemanticsAction action, |
| 30 | + std::vector<uint8_t> args) override {} |
| 31 | + void OnPlatformViewSetSemanticsEnabled(bool enabled) override {} |
| 32 | + void OnPlatformViewSetAccessibilityFeatures(int32_t flags) override {} |
| 33 | + void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture) override {} |
| 34 | + void OnPlatformViewUnregisterTexture(int64_t texture_id) override {} |
| 35 | + void OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) override {} |
| 36 | + |
| 37 | + std::unique_ptr<std::vector<std::string>> ComputePlatformViewResolvedLocale( |
| 38 | + const std::vector<std::string>& supported_locale_data) override { |
| 39 | + std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>(); |
| 40 | + return out; |
| 41 | + } |
| 42 | +}; |
| 43 | + |
| 44 | +} // namespace |
| 45 | +} // namespace flutter |
| 46 | + |
| 47 | +@interface FlutterEnginePlatformViewTest : XCTestCase |
| 48 | +@end |
| 49 | + |
| 50 | +@implementation FlutterEnginePlatformViewTest |
| 51 | + |
| 52 | +- (void)setUp { |
| 53 | + fml::MessageLoop::EnsureInitializedForCurrentThread(); |
| 54 | +} |
| 55 | + |
| 56 | +- (void)tearDown { |
| 57 | +} |
| 58 | + |
| 59 | +- (void)testCallsNotifyLowMemory { |
| 60 | + flutter::MockDelegate mock_delegate; |
| 61 | + auto thread_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner(); |
| 62 | + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, |
| 63 | + /*platform=*/thread_task_runner, |
| 64 | + /*raster=*/thread_task_runner, |
| 65 | + /*ui=*/thread_task_runner, |
| 66 | + /*io=*/thread_task_runner); |
| 67 | + auto platform_view = std::make_unique<flutter::PlatformViewIOS>( |
| 68 | + /*delegate=*/mock_delegate, |
| 69 | + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, |
| 70 | + /*task_runners=*/runners); |
| 71 | + |
| 72 | + id project = OCMClassMock([FlutterDartProject class]); |
| 73 | + FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"tester" project:project]; |
| 74 | + XCTAssertNotNil(engine); |
| 75 | + id mockEngine = OCMPartialMock(engine); |
| 76 | + OCMStub([mockEngine notifyLowMemory]); |
| 77 | + OCMStub([mockEngine iosPlatformView]).andReturn(platform_view.get()); |
| 78 | + |
| 79 | + [engine setViewController:nil]; |
| 80 | + OCMVerify([mockEngine notifyLowMemory]); |
| 81 | + OCMReject([mockEngine notifyLowMemory]); |
| 82 | + |
| 83 | + [[NSNotificationCenter defaultCenter] |
| 84 | + postNotificationName:UIApplicationDidReceiveMemoryWarningNotification |
| 85 | + object:nil]; |
| 86 | + OCMVerify([mockEngine notifyLowMemory]); |
| 87 | + OCMReject([mockEngine notifyLowMemory]); |
| 88 | + |
| 89 | + [[NSNotificationCenter defaultCenter] |
| 90 | + postNotificationName:UIApplicationDidEnterBackgroundNotification |
| 91 | + object:nil]; |
| 92 | + |
| 93 | + OCMVerify([mockEngine notifyLowMemory]); |
| 94 | +} |
| 95 | + |
| 96 | +@end |
0 commit comments