This repository was archived by the owner on Sep 14, 2023. It is now read-only.
forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFWFUIDelegateHostApiTests.m
More file actions
100 lines (83 loc) · 4.17 KB
/
FWFUIDelegateHostApiTests.m
File metadata and controls
100 lines (83 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@import Flutter;
@import XCTest;
@import webview_flutter_wkwebview;
#import <OCMock/OCMock.h>
@interface FWFUIDelegateHostApiTests : XCTestCase
@end
@implementation FWFUIDelegateHostApiTests
/**
* Creates a partially mocked FWFUIDelegate and adds it to instanceManager.
*
* @param instanceManager Instance manager to add the delegate to.
* @param identifier Identifier for the delegate added to the instanceManager.
*
* @return A mock FWFUIDelegate.
*/
- (id)mockDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier {
FWFUIDelegate *delegate = [[FWFUIDelegate alloc]
initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger))
instanceManager:instanceManager];
[instanceManager addDartCreatedInstance:delegate withIdentifier:0];
return OCMPartialMock(delegate);
}
/**
* Creates a mock FWFUIDelegateFlutterApiImpl with instanceManager.
*
* @param instanceManager Instance manager passed to the Flutter API.
*
* @return A mock FWFUIDelegateFlutterApiImpl.
*/
- (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager {
FWFUIDelegateFlutterApiImpl *flutterAPI = [[FWFUIDelegateFlutterApiImpl alloc]
initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger))
instanceManager:instanceManager];
return OCMPartialMock(flutterAPI);
}
- (void)testCreateWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFUIDelegateHostApiImpl *hostAPI = [[FWFUIDelegateHostApiImpl alloc]
initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger))
instanceManager:instanceManager];
FlutterError *error;
[hostAPI createWithIdentifier:@0 error:&error];
FWFUIDelegate *delegate = (FWFUIDelegate *)[instanceManager instanceForIdentifier:0];
XCTAssertTrue([delegate conformsToProtocol:@protocol(WKUIDelegate)]);
XCTAssertNil(error);
}
- (void)testOnCreateWebViewForDelegateWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFUIDelegate *mockDelegate = [self mockDelegateWithManager:instanceManager identifier:0];
FWFUIDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager];
OCMStub([mockDelegate UIDelegateAPI]).andReturn(mockFlutterAPI);
WKWebView *mockWebView = OCMClassMock([WKWebView class]);
[instanceManager addDartCreatedInstance:mockWebView withIdentifier:1];
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
id mockConfigurationFlutterApi = OCMPartialMock(mockFlutterAPI.webViewConfigurationFlutterApi);
NSNumber *__block configurationIdentifier;
OCMStub([mockConfigurationFlutterApi createWithIdentifier:[OCMArg checkWithBlock:^BOOL(id value) {
configurationIdentifier = value;
return YES;
}]
completion:OCMOCK_ANY]);
WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]);
OCMStub([mockNavigationAction request])
.andReturn([NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev"]]);
WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]);
OCMStub([mockFrameInfo isMainFrame]).andReturn(YES);
OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo);
[mockDelegate webView:mockWebView
createWebViewWithConfiguration:configuration
forNavigationAction:mockNavigationAction
windowFeatures:OCMClassMock([WKWindowFeatures class])];
OCMVerify([mockFlutterAPI
onCreateWebViewForDelegateWithIdentifier:@0
webViewIdentifier:@1
configurationIdentifier:configurationIdentifier
navigationAction:[OCMArg
isKindOfClass:[FWFWKNavigationActionData class]]
completion:OCMOCK_ANY]);
}
@end