Skip to content

Commit fda39c8

Browse files
committed
Merge branch 'implement_zoomEnabled_for_ios_and_android' into add_zoom_to_android_webview
* implement_zoomEnabled_for_ios_and_android: Adding test coverage for iOS
2 parents a5af43d + 74addca commit fda39c8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FLTWKNavigationDelegateTests.m

+32
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ @interface FLTWKNavigationDelegateTests : XCTestCase
1313

1414
@property(strong, nonatomic) FlutterMethodChannel *mockMethodChannel;
1515
@property(strong, nonatomic) FLTWKNavigationDelegate *navigationDelegate;
16+
@property(strong, nonatomic) WKNavigation *navigation;
1617

1718
@end
1819

1920
@implementation FLTWKNavigationDelegateTests
2021

22+
NSString *const expectedJavascript =
23+
@"var meta = document.createElement('meta');"
24+
@"meta.name = 'viewport';"
25+
@"meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0,"
26+
@"user-scalable=no';"
27+
@"var head = document.getElementsByTagName('head')[0];head.appendChild(meta);";
28+
2129
- (void)setUp {
2230
self.mockMethodChannel = OCMClassMock(FlutterMethodChannel.class);
31+
self.navigation = OCMClassMock(WKNavigation.class);
2332
self.navigationDelegate =
2433
[[FLTWKNavigationDelegate alloc] initWithChannel:self.mockMethodChannel];
2534
}
@@ -38,4 +47,27 @@ - (void)testWebViewWebContentProcessDidTerminateCallsRecourseErrorChannel {
3847
}
3948
}
4049

50+
- (void)testWebViewWebEvaluateJavaScriptSourceIsCorrectWhenShouldEnableZoomIsFalse {
51+
WKWebView *webview = OCMClassMock(WKWebView.class);
52+
NSURL *testUrl = [[NSURL alloc] initWithString:@"www.example.com"];
53+
OCMStub([webview URL]).andReturn(testUrl);
54+
55+
self.navigationDelegate.shouldEnableZoom = false;
56+
[self.navigationDelegate webView:webview didFinishNavigation:self.navigation];
57+
58+
OCMVerify([webview evaluateJavaScript:expectedJavascript completionHandler:nil]);
59+
}
60+
61+
- (void)testWebViewWebEvaluateJavaScriptShouldNotBeCalledWhenShouldEnableZoomIsTrue {
62+
WKWebView *webview = OCMClassMock(WKWebView.class);
63+
NSURL *testUrl = [[NSURL alloc] initWithString:@"www.example.com"];
64+
OCMStub([webview URL]).andReturn(testUrl);
65+
66+
self.navigationDelegate.shouldEnableZoom = true;
67+
68+
OCMReject([webview evaluateJavaScript:expectedJavascript completionHandler:nil]);
69+
70+
[self.navigationDelegate webView:webview didFinishNavigation:self.navigation];
71+
}
72+
4173
@end

0 commit comments

Comments
 (0)