| Flutter iOS Embedder |

FlutterViewTest.mm
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 #import <XCTest/XCTest.h>
6
7 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
8 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
9 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
10
11 FLUTTER_ASSERT_ARC
12
13 @interface FakeDelegate : NSObject <FlutterViewEngineDelegate>
14 @property(nonatomic) BOOL callbackCalled;
15 @property(nonatomic, assign) BOOL isUsingImpeller;
16 @end
17
18 @implementation FakeDelegate {
19 std::shared_ptr<flutter::FlutterPlatformViewsController> _platformViewsController;
20 }
21
22 - (instancetype)init {
23 _callbackCalled = NO;
24 _platformViewsController = std::shared_ptr<flutter::FlutterPlatformViewsController>(nullptr);
25 return self;
26 }
27
28 - (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type
29 asBase64Encoded:(BOOL)base64Encode {
30 return {};
31 }
32
33 - (std::shared_ptr<flutter::FlutterPlatformViewsController>&)platformViewsController {
34 return _platformViewsController;
35 }
36
37 - (void)flutterViewAccessibilityDidCall {
38 _callbackCalled = YES;
39 }
40
41 @end
42
43 @interface FlutterViewTest : XCTestCase
44 @end
45
46 @implementation FlutterViewTest
47
48 - (void)testFlutterViewEnableSemanticsWhenIsAccessibilityElementIsCalled {
49 FakeDelegate* delegate = [[FakeDelegate alloc] init];
50 FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:NO];
51 delegate.callbackCalled = NO;
52 XCTAssertFalse(view.isAccessibilityElement);
53 XCTAssertTrue(delegate.callbackCalled);
54 }
55
56 - (void)testFlutterViewBackgroundColorIsNotNil {
57 FakeDelegate* delegate = [[FakeDelegate alloc] init];
58 FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:NO];
59 XCTAssertNotNil(view.backgroundColor);
60 }
61
62 - (void)testIgnoreWideColorWithoutImpeller {
63 FakeDelegate* delegate = [[FakeDelegate alloc] init];
64 delegate.isUsingImpeller = NO;
65 FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:YES];
66 [view layoutSubviews];
67 XCTAssertTrue([view.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]);
68 CAMetalLayer* layer = (CAMetalLayer*)view.layer;
69 XCTAssertEqual(layer.pixelFormat, MTLPixelFormatBGRA8Unorm);
70 }
71
72 - (void)testLayerScalesMatchScreenAfterLayoutSubviews {
73 FakeDelegate* delegate = [[FakeDelegate alloc] init];
74 FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:NO];
75 view.layer.contentsScale = CGFloat(-99.0);
76 view.layer.rasterizationScale = CGFloat(-99.0);
77 UIScreen* screen = [view screen];
78 XCTAssertNotEqual(view.layer.contentsScale, screen.scale);
79 XCTAssertNotEqual(view.layer.rasterizationScale, screen.scale);
80 [view layoutSubviews];
81 XCTAssertEqual(view.layer.contentsScale, screen.scale);
82 XCTAssertEqual(view.layer.rasterizationScale, screen.scale);
83 }
84
85 @end
FlutterViewTest
Definition: FlutterViewTest.mm:43
FakeDelegate
Definition: FlutterViewTest.mm:13
FlutterEngine_Internal.h
FlutterViewEngineDelegate-p
Definition: FlutterView.h:19
FlutterMacros.h
_platformViewsController
std::shared_ptr< flutter::FlutterPlatformViewsController > _platformViewsController
Definition: FlutterEngine.mm:125
FakeDelegate::callbackCalled
BOOL callbackCalled
Definition: FlutterViewTest.mm:14
flutter
Definition: accessibility_bridge.h:28
FlutterView
Definition: FlutterView.h:39
FakeDelegate::isUsingImpeller
BOOL isUsingImpeller
Definition: FlutterViewTest.mm:15
-[FlutterView screen]
UIScreen * screen()
Definition: FlutterView.mm:40
FLUTTER_ASSERT_ARC
Definition: VsyncWaiterIosTest.mm:15
FlutterView.h