Skip to content

Commit

Permalink
[webview_flutter_wkwebview] Update variable names for changes coming in
Browse files Browse the repository at this point in the history
  • Loading branch information
bparrishMines authored and yutaaraki-toydium committed Jun 4, 2022
1 parent e76d2d5 commit 6efcffc
Show file tree
Hide file tree
Showing 42 changed files with 1,076 additions and 1,102 deletions.
Expand Up @@ -14,15 +14,15 @@ @interface FWFHTTPCookieStoreHostApiTests : XCTestCase
@implementation FWFHTTPCookieStoreHostApiTests
- (void)testCreateFromWebsiteDataStoreWithIdentifier API_AVAILABLE(ios(11.0)) {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFHTTPCookieStoreHostApiImpl *hostApi =
FWFHTTPCookieStoreHostApiImpl *hostAPI =
[[FWFHTTPCookieStoreHostApiImpl alloc] initWithInstanceManager:instanceManager];

WKWebsiteDataStore *mockDataStore = OCMClassMock([WKWebsiteDataStore class]);
OCMStub([mockDataStore httpCookieStore]).andReturn(OCMClassMock([WKHTTPCookieStore class]));
[instanceManager addInstance:mockDataStore withIdentifier:0];
[instanceManager addDartCreatedInstance:mockDataStore withIdentifier:0];

FlutterError *error;
[hostApi createFromWebsiteDataStoreWithIdentifier:@1 dataStoreIdentifier:@0 error:&error];
[hostAPI createFromWebsiteDataStoreWithIdentifier:@1 dataStoreIdentifier:@0 error:&error];
WKHTTPCookieStore *cookieStore = (WKHTTPCookieStore *)[instanceManager instanceForIdentifier:1];
XCTAssertTrue([cookieStore isKindOfClass:[WKHTTPCookieStore class]]);
XCTAssertNil(error);
Expand All @@ -32,17 +32,17 @@ - (void)testSetCookie API_AVAILABLE(ios(11.0)) {
WKHTTPCookieStore *mockHttpCookieStore = OCMClassMock([WKHTTPCookieStore class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockHttpCookieStore withIdentifier:0];
[instanceManager addDartCreatedInstance:mockHttpCookieStore withIdentifier:0];

FWFHTTPCookieStoreHostApiImpl *hostApi =
FWFHTTPCookieStoreHostApiImpl *hostAPI =
[[FWFHTTPCookieStoreHostApiImpl alloc] initWithInstanceManager:instanceManager];

FWFNSHttpCookieData *cookieData = [FWFNSHttpCookieData
makeWithPropertyKeys:@[ [FWFNSHttpCookiePropertyKeyEnumData
makeWithValue:FWFNSHttpCookiePropertyKeyEnumName] ]
propertyValues:@[ @"hello" ]];
FlutterError *__block blockError;
[hostApi setCookieForStoreWithIdentifier:@0
[hostAPI setCookieForStoreWithIdentifier:@0
cookie:cookieData
completion:^(FlutterError *error) {
blockError = error;
Expand Down
Expand Up @@ -9,19 +9,19 @@ @interface FWFInstanceManagerTests : XCTestCase
@end

@implementation FWFInstanceManagerTests
- (void)testAddInstance {
- (void)testAddInstanceCreatedFromDart {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
NSObject *object = [[NSObject alloc] init];

[instanceManager addInstance:object withIdentifier:5];
[instanceManager addDartCreatedInstance:object withIdentifier:5];
XCTAssertEqualObjects([instanceManager instanceForIdentifier:5], object);
XCTAssertEqual([instanceManager identifierForInstance:object], 5);
}

- (void)testRemoveInstance {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
NSObject *object = [[NSObject alloc] init];
[instanceManager addInstance:object withIdentifier:5];
[instanceManager addDartCreatedInstance:object withIdentifier:5];

[instanceManager removeInstance:object];
XCTAssertNil([instanceManager instanceForIdentifier:5]);
Expand All @@ -31,7 +31,7 @@ - (void)testRemoveInstance {
- (void)testRemoveInstanceWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
NSObject *object = [[NSObject alloc] init];
[instanceManager addInstance:object withIdentifier:5];
[instanceManager addDartCreatedInstance:object withIdentifier:5];

[instanceManager removeInstanceWithIdentifier:5];
XCTAssertNil([instanceManager instanceForIdentifier:5]);
Expand Down
Expand Up @@ -14,11 +14,11 @@ @interface FWFNavigationDelegateHostApiTests : XCTestCase
@implementation FWFNavigationDelegateHostApiTests
- (void)testCreateWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFNavigationDelegateHostApiImpl *hostApi =
FWFNavigationDelegateHostApiImpl *hostAPI =
[[FWFNavigationDelegateHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi createWithIdentifier:@0 error:&error];
[hostAPI createWithIdentifier:@0 error:&error];
FWFNavigationDelegate *navigationDelegate =
(FWFNavigationDelegate *)[instanceManager instanceForIdentifier:0];

Expand Down
Expand Up @@ -16,16 +16,16 @@ - (void)testAddObserver {
NSObject *mockObject = OCMClassMock([NSObject class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockObject withIdentifier:0];
[instanceManager addDartCreatedInstance:mockObject withIdentifier:0];

FWFObjectHostApiImpl *hostApi =
FWFObjectHostApiImpl *hostAPI =
[[FWFObjectHostApiImpl alloc] initWithInstanceManager:instanceManager];

NSObject *observerObject = [[NSObject alloc] init];
[instanceManager addInstance:observerObject withIdentifier:1];
[instanceManager addDartCreatedInstance:observerObject withIdentifier:1];

FlutterError *error;
[hostApi
[hostAPI
addObserverForObjectWithIdentifier:@0
observerIdentifier:@1
keyPath:@"myKey"
Expand All @@ -48,16 +48,16 @@ - (void)testRemoveObserver {
NSObject *mockObject = OCMClassMock([NSObject class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockObject withIdentifier:0];
[instanceManager addDartCreatedInstance:mockObject withIdentifier:0];

FWFObjectHostApiImpl *hostApi =
FWFObjectHostApiImpl *hostAPI =
[[FWFObjectHostApiImpl alloc] initWithInstanceManager:instanceManager];

NSObject *observerObject = [[NSObject alloc] init];
[instanceManager addInstance:observerObject withIdentifier:1];
[instanceManager addDartCreatedInstance:observerObject withIdentifier:1];

FlutterError *error;
[hostApi removeObserverForObjectWithIdentifier:@0
[hostAPI removeObserverForObjectWithIdentifier:@0
observerIdentifier:@1
keyPath:@"myKey"
error:&error];
Expand All @@ -69,13 +69,13 @@ - (void)testDispose {
NSObject *object = [[NSObject alloc] init];

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:object withIdentifier:0];
[instanceManager addDartCreatedInstance:object withIdentifier:0];

FWFObjectHostApiImpl *hostApi =
FWFObjectHostApiImpl *hostAPI =
[[FWFObjectHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi disposeObjectWithIdentifier:@0 error:&error];
[hostAPI disposeObjectWithIdentifier:@0 error:&error];
XCTAssertEqual([instanceManager identifierForInstance:object], NSNotFound);
XCTAssertNil(error);
}
Expand Down
Expand Up @@ -14,13 +14,13 @@ @interface FWFPreferencesHostApiTests : XCTestCase
@implementation FWFPreferencesHostApiTests
- (void)testCreateFromWebViewConfigurationWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFPreferencesHostApiImpl *hostApi =
FWFPreferencesHostApiImpl *hostAPI =
[[FWFPreferencesHostApiImpl alloc] initWithInstanceManager:instanceManager];

[instanceManager addInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0];
[instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0];

FlutterError *error;
[hostApi createFromWebViewConfigurationWithIdentifier:@1 configurationIdentifier:@0 error:&error];
[hostAPI createFromWebViewConfigurationWithIdentifier:@1 configurationIdentifier:@0 error:&error];
WKPreferences *preferences = (WKPreferences *)[instanceManager instanceForIdentifier:1];
XCTAssertTrue([preferences isKindOfClass:[WKPreferences class]]);
XCTAssertNil(error);
Expand All @@ -30,13 +30,13 @@ - (void)testSetJavaScriptEnabled {
WKPreferences *mockPreferences = OCMClassMock([WKPreferences class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockPreferences withIdentifier:0];
[instanceManager addDartCreatedInstance:mockPreferences withIdentifier:0];

FWFPreferencesHostApiImpl *hostApi =
FWFPreferencesHostApiImpl *hostAPI =
[[FWFPreferencesHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi setJavaScriptEnabledForPreferencesWithIdentifier:@0 isEnabled:@YES error:&error];
[hostAPI setJavaScriptEnabledForPreferencesWithIdentifier:@0 isEnabled:@YES error:&error];
OCMVerify([mockPreferences setJavaScriptEnabled:YES]);
XCTAssertNil(error);
}
Expand Down
Expand Up @@ -14,11 +14,11 @@ @interface FWFScriptMessageHandlerHostApiTests : XCTestCase
@implementation FWFScriptMessageHandlerHostApiTests
- (void)testCreateWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFScriptMessageHandlerHostApiImpl *hostApi =
FWFScriptMessageHandlerHostApiImpl *hostAPI =
[[FWFScriptMessageHandlerHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi createWithIdentifier:@0 error:&error];
[hostAPI createWithIdentifier:@0 error:&error];

FWFScriptMessageHandler *scriptMessageHandler =
(FWFScriptMessageHandler *)[instanceManager instanceForIdentifier:0];
Expand Down
Expand Up @@ -17,14 +17,14 @@ - (void)testGetContentOffset {
OCMStub([mockScrollView contentOffset]).andReturn(CGPointMake(1.0, 2.0));

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockScrollView withIdentifier:0];
[instanceManager addDartCreatedInstance:mockScrollView withIdentifier:0];

FWFScrollViewHostApiImpl *hostApi =
FWFScrollViewHostApiImpl *hostAPI =
[[FWFScrollViewHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
NSArray<NSNumber *> *expectedValue = @[ @1.0, @2.0 ];
XCTAssertEqualObjects([hostApi contentOffsetForScrollViewWithIdentifier:@0 error:&error],
XCTAssertEqualObjects([hostAPI contentOffsetForScrollViewWithIdentifier:@0 error:&error],
expectedValue);
XCTAssertNil(error);
}
Expand All @@ -34,13 +34,13 @@ - (void)testScrollBy {
scrollView.contentOffset = CGPointMake(1, 2);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:scrollView withIdentifier:0];
[instanceManager addDartCreatedInstance:scrollView withIdentifier:0];

FWFScrollViewHostApiImpl *hostApi =
FWFScrollViewHostApiImpl *hostAPI =
[[FWFScrollViewHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi scrollByForScrollViewWithIdentifier:@0 x:@1 y:@2 error:&error];
[hostAPI scrollByForScrollViewWithIdentifier:@0 x:@1 y:@2 error:&error];
XCTAssertEqual(scrollView.contentOffset.x, 2);
XCTAssertEqual(scrollView.contentOffset.y, 4);
XCTAssertNil(error);
Expand All @@ -50,13 +50,13 @@ - (void)testSetContentOffset {
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:scrollView withIdentifier:0];
[instanceManager addDartCreatedInstance:scrollView withIdentifier:0];

FWFScrollViewHostApiImpl *hostApi =
FWFScrollViewHostApiImpl *hostAPI =
[[FWFScrollViewHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi setContentOffsetForScrollViewWithIdentifier:@0 toX:@1 y:@2 error:&error];
[hostAPI setContentOffsetForScrollViewWithIdentifier:@0 toX:@1 y:@2 error:&error];
XCTAssertEqual(scrollView.contentOffset.x, 1);
XCTAssertEqual(scrollView.contentOffset.y, 2);
XCTAssertNil(error);
Expand Down
Expand Up @@ -14,11 +14,11 @@ @interface FWFUIDelegateHostApiTests : XCTestCase
@implementation FWFUIDelegateHostApiTests
- (void)testCreateWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFUIDelegateHostApiImpl *hostApi =
FWFUIDelegateHostApiImpl *hostAPI =
[[FWFUIDelegateHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi createWithIdentifier:@0 error:&error];
[hostAPI createWithIdentifier:@0 error:&error];
FWFUIDelegate *delegate = (FWFUIDelegate *)[instanceManager instanceForIdentifier:0];

XCTAssertTrue([delegate conformsToProtocol:@protocol(WKUIDelegate)]);
Expand Down
Expand Up @@ -16,13 +16,13 @@ - (void)testSetBackgroundColor {
UIView *mockUIView = OCMClassMock([UIView class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockUIView withIdentifier:0];
[instanceManager addDartCreatedInstance:mockUIView withIdentifier:0];

FWFUIViewHostApiImpl *hostApi =
FWFUIViewHostApiImpl *hostAPI =
[[FWFUIViewHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi setBackgroundColorForViewWithIdentifier:@0 toValue:@123 error:&error];
[hostAPI setBackgroundColorForViewWithIdentifier:@0 toValue:@123 error:&error];

OCMVerify([mockUIView setBackgroundColor:[UIColor colorWithRed:(123 >> 16 & 0xff) / 255.0
green:(123 >> 8 & 0xff) / 255.0
Expand All @@ -35,13 +35,13 @@ - (void)testSetOpaque {
UIView *mockUIView = OCMClassMock([UIView class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockUIView withIdentifier:0];
[instanceManager addDartCreatedInstance:mockUIView withIdentifier:0];

FWFUIViewHostApiImpl *hostApi =
FWFUIViewHostApiImpl *hostAPI =
[[FWFUIViewHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi setOpaqueForViewWithIdentifier:@0 isOpaque:@YES error:&error];
[hostAPI setOpaqueForViewWithIdentifier:@0 isOpaque:@YES error:&error];
OCMVerify([mockUIView setOpaque:YES]);
XCTAssertNil(error);
}
Expand Down
Expand Up @@ -14,13 +14,13 @@ @interface FWFUserContentControllerHostApiTests : XCTestCase
@implementation FWFUserContentControllerHostApiTests
- (void)testCreateFromWebViewConfigurationWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFUserContentControllerHostApiImpl *hostApi =
FWFUserContentControllerHostApiImpl *hostAPI =
[[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager];

[instanceManager addInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0];
[instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0];

FlutterError *error;
[hostApi createFromWebViewConfigurationWithIdentifier:@1 configurationIdentifier:@0 error:&error];
[hostAPI createFromWebViewConfigurationWithIdentifier:@1 configurationIdentifier:@0 error:&error];
WKUserContentController *userContentController =
(WKUserContentController *)[instanceManager instanceForIdentifier:1];
XCTAssertTrue([userContentController isKindOfClass:[WKUserContentController class]]);
Expand All @@ -32,17 +32,17 @@ - (void)testAddScriptMessageHandler {
OCMClassMock([WKUserContentController class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockUserContentController withIdentifier:0];
[instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0];

FWFUserContentControllerHostApiImpl *hostApi =
FWFUserContentControllerHostApiImpl *hostAPI =
[[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager];

id<WKScriptMessageHandler> mockMessageHandler =
OCMProtocolMock(@protocol(WKScriptMessageHandler));
[instanceManager addInstance:mockMessageHandler withIdentifier:1];
[instanceManager addDartCreatedInstance:mockMessageHandler withIdentifier:1];

FlutterError *error;
[hostApi addScriptMessageHandlerForControllerWithIdentifier:@0
[hostAPI addScriptMessageHandlerForControllerWithIdentifier:@0
handlerIdentifier:@1
ofName:@"apple"
error:&error];
Expand All @@ -55,13 +55,13 @@ - (void)testRemoveScriptMessageHandler {
OCMClassMock([WKUserContentController class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockUserContentController withIdentifier:0];
[instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0];

FWFUserContentControllerHostApiImpl *hostApi =
FWFUserContentControllerHostApiImpl *hostAPI =
[[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi removeScriptMessageHandlerForControllerWithIdentifier:@0 name:@"apple" error:&error];
[hostAPI removeScriptMessageHandlerForControllerWithIdentifier:@0 name:@"apple" error:&error];
OCMVerify([mockUserContentController removeScriptMessageHandlerForName:@"apple"]);
XCTAssertNil(error);
}
Expand All @@ -71,13 +71,13 @@ - (void)testRemoveAllScriptMessageHandlers API_AVAILABLE(ios(14.0)) {
OCMClassMock([WKUserContentController class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockUserContentController withIdentifier:0];
[instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0];

FWFUserContentControllerHostApiImpl *hostApi =
FWFUserContentControllerHostApiImpl *hostAPI =
[[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi removeAllScriptMessageHandlersForControllerWithIdentifier:@0 error:&error];
[hostAPI removeAllScriptMessageHandlersForControllerWithIdentifier:@0 error:&error];
OCMVerify([mockUserContentController removeAllScriptMessageHandlers]);
XCTAssertNil(error);
}
Expand All @@ -87,13 +87,13 @@ - (void)testAddUserScript {
OCMClassMock([WKUserContentController class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockUserContentController withIdentifier:0];
[instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0];

FWFUserContentControllerHostApiImpl *hostApi =
FWFUserContentControllerHostApiImpl *hostAPI =
[[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi
[hostAPI
addUserScriptForControllerWithIdentifier:@0
userScript:
[FWFWKUserScriptData
Expand All @@ -114,13 +114,13 @@ - (void)testRemoveAllUserScripts {
OCMClassMock([WKUserContentController class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addInstance:mockUserContentController withIdentifier:0];
[instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0];

FWFUserContentControllerHostApiImpl *hostApi =
FWFUserContentControllerHostApiImpl *hostAPI =
[[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager];

FlutterError *error;
[hostApi removeAllUserScriptsForControllerWithIdentifier:@0 error:&error];
[hostAPI removeAllUserScriptsForControllerWithIdentifier:@0 error:&error];
OCMVerify([mockUserContentController removeAllUserScripts]);
XCTAssertNil(error);
}
Expand Down

0 comments on commit 6efcffc

Please sign in to comment.