You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2016/08/04 22:44:46 UTC

cordova-plugin-wkwebview-engine git commit: CB-11496 - Add obj-c unit tests for WKWebViewConfiguration, WKPreference

Repository: cordova-plugin-wkwebview-engine
Updated Branches:
  refs/heads/master 1b31d4d9f -> c0a10b72c


CB-11496 - Add obj-c unit tests for WKWebViewConfiguration, WKPreference


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/commit/c0a10b72
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/tree/c0a10b72
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/diff/c0a10b72

Branch: refs/heads/master
Commit: c0a10b72c00d44eae4e5a5af90c7abfdfa153881
Parents: 1b31d4d
Author: Shazron Abdullah <sh...@apache.org>
Authored: Thu Aug 4 15:47:59 2016 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Aug 4 15:47:59 2016 -0700

----------------------------------------------------------------------
 .../CDVWKWebViewEngineTest.m                    | 70 ++++++++++++++++++--
 .../project.pbxproj                             |  2 +
 2 files changed, 67 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/blob/c0a10b72/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m
----------------------------------------------------------------------
diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m
index 73b5b0a..af736b8 100644
--- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m
+++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m
@@ -20,10 +20,12 @@
 #import <UIKit/UIKit.h>
 #import <XCTest/XCTest.h>
 #import "CDVWKWebViewEngine.h"
+#import <Cordova/NSDictionary+CordovaPreferences.h>
 
 @interface CDVWKWebViewEngineTest : XCTestCase
 
 @property (nonatomic, strong) CDVWKWebViewEngine* plugin;
+@property (nonatomic, strong) CDVViewController* viewController;
 
 @end
 
@@ -39,7 +41,11 @@
     [super setUp];
     // Put setup code here. This method is called before the invocation of each test method in the class.
     
-    self.plugin = [[CDVWKWebViewEngine alloc] init];
+    self.plugin = [[CDVWKWebViewEngine alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
+    self.viewController = [[CDVViewController alloc] init];
+    [self.viewController registerPlugin:self.plugin withClassName:NSStringFromClass([self.plugin class])];
+    
+    XCTAssert([self.plugin conformsToProtocol:@protocol(CDVWebViewEngineProtocol)], @"Plugin does not conform to CDVWebViewEngineProtocol");
 }
 
 - (void)tearDown {
@@ -47,11 +53,65 @@
     [super tearDown];
 }
 
-- (void) testCDVWKWebViewEngine {
+- (void) testCanLoadRequest {
+    NSURLRequest* fileUrlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:@"path/to/file.html"]];
+    NSURLRequest* httpUrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://apache.org"]];
+    NSURLRequest* miscUrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"foo://bar"]];
+    id<CDVWebViewEngineProtocol> webViewEngineProtocol = self.plugin;
+    
+    SEL wk_sel = NSSelectorFromString(@"loadFileURL:allowingReadAccessToURL:");
+    if ([self.plugin.engineWebView respondsToSelector:wk_sel]) {
+        XCTAssertTrue([webViewEngineProtocol canLoadRequest:fileUrlRequest]);
+    } else {
+        XCTAssertFalse([webViewEngineProtocol canLoadRequest:fileUrlRequest]);
+    }
+    
+    XCTAssertTrue([webViewEngineProtocol canLoadRequest:httpUrlRequest]);
+    XCTAssertTrue([webViewEngineProtocol canLoadRequest:miscUrlRequest]);
+}
+
+- (void) testUpdateInfo {
+    // Add -ObjC to Other Linker Flags to test project, to load Categories
+    // Update objc test template generator as well
+    
+    id<CDVWebViewEngineProtocol> webViewEngineProtocol = self.plugin;
+    WKWebView* wkWebView = (WKWebView*)self.plugin.engineWebView;
+    
+    NSDictionary* preferences = @{
+                               [@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0
+                               [@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO
+                               [@"MediaPlaybackRequiresUserAction" lowercaseString] : @NO, // default is YES
+                               [@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO
+                               [@"MediaPlaybackAllowsAirPlay" lowercaseString] : @NO, // default is YES
+                               [@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO
+                               [@"WKWebViewDecelerationSpeed" lowercaseString] : @"fast" // default is 'normal'
+                               };
+    NSDictionary* info = @{
+                           kCDVWebViewEngineWebViewPreferences : preferences
+                           };
+    [webViewEngineProtocol updateWithInfo:info];
+    
+    // the only preference we can set, we **can** change this during runtime
+    XCTAssertEqualWithAccuracy(wkWebView.configuration.preferences.minimumFontSize, 1.1, 0.0001);
+    
+    // the WKWebViewConfiguration properties, we **cannot** change outside of initialization
+    XCTAssertFalse(wkWebView.configuration.allowsInlineMediaPlayback);
+    XCTAssertTrue(wkWebView.configuration.mediaPlaybackRequiresUserAction);
+    XCTAssertFalse(wkWebView.configuration.suppressesIncrementalRendering);
+    XCTAssertTrue(wkWebView.configuration.mediaPlaybackAllowsAirPlay);
+    
+    // in the test above, DisallowOverscroll is YES, so no bounce
+    if ([wkWebView respondsToSelector:@selector(scrollView)]) {
+        XCTAssertFalse(((UIScrollView*)[wkWebView scrollView]).bounces);
+    } else {
+        for (id subview in wkWebView.subviews) {
+            if ([[subview class] isSubclassOfClass:[UIScrollView class]]) {
+                XCTAssertFalse(((UIScrollView*)subview).bounces = NO);
+            }
+        }
+    }
     
-    // Failing tests
-    XCTAssertTrue(NO);
-    XCTAssertFalse(YES);
+    XCTAssertTrue(wkWebView.scrollView.decelerationRate == UIScrollViewDecelerationRateFast);
 }
 
 @end

http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/blob/c0a10b72/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj
index caa1c1e..74436bd 100644
--- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj
+++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj
@@ -285,12 +285,14 @@
 		7E9F517619DA09CE00DA31AC /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				OTHER_LDFLAGS = "-ObjC";
 			};
 			name = Debug;
 		};
 		7E9F517719DA09CE00DA31AC /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				OTHER_LDFLAGS = "-ObjC";
 			};
 			name = Release;
 		};


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org