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