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