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