@@ -13,13 +13,22 @@ @interface FLTWKNavigationDelegateTests : XCTestCase
13
13
14
14
@property (strong , nonatomic ) FlutterMethodChannel *mockMethodChannel;
15
15
@property (strong , nonatomic ) FLTWKNavigationDelegate *navigationDelegate;
16
+ @property (strong , nonatomic ) WKNavigation *navigation;
16
17
17
18
@end
18
19
19
20
@implementation FLTWKNavigationDelegateTests
20
21
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
+
21
29
- (void )setUp {
22
30
self.mockMethodChannel = OCMClassMock (FlutterMethodChannel.class );
31
+ self.navigation = OCMClassMock (WKNavigation .class );
23
32
self.navigationDelegate =
24
33
[[FLTWKNavigationDelegate alloc ] initWithChannel: self .mockMethodChannel];
25
34
}
@@ -38,4 +47,27 @@ - (void)testWebViewWebContentProcessDidTerminateCallsRecourseErrorChannel {
38
47
}
39
48
}
40
49
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
+
41
73
@end
0 commit comments