Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
AppExtensionTests.m
Go to the documentation of this file.
1// Copyright 2020 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>
7
8@interface AppExtensionTests : XCTestCase
9@property(nonatomic, strong) XCUIApplication* hostApplication;
10@end
11
12@implementation AppExtensionTests
13
14- (void)setUp {
15 [super setUp];
16 self.continueAfterFailure = NO;
17 self.hostApplication =
18 [[XCUIApplication alloc] initWithBundleIdentifier:@"dev.flutter.FlutterAppExtensionTestHost"];
19}
20
22 // Launch the Scenarios app first to ensure it's installed then close it.
23 XCUIApplication* app = [[XCUIApplication alloc] init];
24 [app launch];
25 [app terminate];
26
27 [self.hostApplication launch];
28 XCUIElement* button = self.hostApplication.buttons[@"Open Share"];
29 if (![button waitForExistenceWithTimeout:10]) {
30 NSLog(@"%@", self.hostApplication.debugDescription);
31 XCTFail(@"Failed due to not able to find any button with %@ seconds", @(10));
32 }
33 [button tap];
34 BOOL launchedExtensionInFlutter = NO;
35
36 // Wait for first cell of share sheet to appear.
37 XCUIElement* firstCell = self.hostApplication.collectionViews.cells.firstMatch;
38 if (![firstCell waitForExistenceWithTimeout:10]) {
39 NSLog(@"%@", self.hostApplication.debugDescription);
40 XCTFail(@"Failed due to not able to find any cells with %@ seconds", @(10));
41 }
42
43 // Custom share extension button (like the one in this test) does not have a
44 // unique identity on older versions of iOS. They are all identified as
45 // `XCElementSnapshotPrivilegedValuePlaceholder`. On iOS 17, they are
46 // identified by name. Loop through all the buttons labeled
47 // `XCElementSnapshotPrivilegedValuePlaceholder` or `Scenarios` to find the
48 // Flutter one.
49 NSPredicate* cellPredicate = [NSPredicate
50 predicateWithFormat:
51 @"label == 'XCElementSnapshotPrivilegedValuePlaceholder' OR label = 'Scenarios'"];
52 NSArray<XCUIElement*>* shareSheetCells =
53 [self.hostApplication.collectionViews.cells matchingPredicate:cellPredicate]
54 .allElementsBoundByIndex;
55 for (XCUIElement* shareSheetCell in shareSheetCells) {
56 [shareSheetCell tap];
57
58 XCUIElement* flutterView = self.hostApplication.otherElements[@"flutter_view"];
59 if ([flutterView waitForExistenceWithTimeout:10]) {
60 launchedExtensionInFlutter = YES;
61 break;
62 }
63
64 // All the built-in share extensions have a Cancel button.
65 // Tap the Cancel button to close the built-in extension.
66 XCUIElement* cancel = self.hostApplication.buttons[@"Cancel"];
67 if ([cancel waitForExistenceWithTimeout:10]) {
68 [cancel tap];
69 }
70 }
71 // App extension successfully launched flutter view.
72 XCTAssertTrue(launchedExtensionInFlutter);
73}
74
75@end
XCUIApplication * hostApplication
int BOOL