diff --git a/tests/CordovaLibTests/CDVStartPageTests.m b/tests/CordovaLibTests/CDVStartPageTests.m
index 5f72d88b6..99d73b24d 100644
--- a/tests/CordovaLibTests/CDVStartPageTests.m
+++ b/tests/CordovaLibTests/CDVStartPageTests.m
@@ -91,7 +91,7 @@ - (void)testParametersInStartPage
[self waitForConditionName:@"getting href" block:^{
NSURL* vc1URL = vc1WebViewEngine.URL;
NSURL* vc2URL = vc2WebViewEngine.URL;
-
+
return
(BOOL)(
(vc1URL != nil && ![[vc1URL absoluteString] isEqualToString:@"about:blank"] && ![[vc1URL absoluteString] isEqualToString:@""]) &&
diff --git a/tests/CordovaLibTests/CDVViewControllerTest.m b/tests/CordovaLibTests/CDVViewControllerTest.m
index 9e13a883f..b9276fe13 100644
--- a/tests/CordovaLibTests/CDVViewControllerTest.m
+++ b/tests/CordovaLibTests/CDVViewControllerTest.m
@@ -50,10 +50,10 @@ -(void)doTestInitWithConfigFile:(NSString*)configFile expectedSettingValue:(NSSt
}else{
// Do not specify config file ==> fallback to default config.xml
}
-
+
// Trigger -viewDidLoad
[viewController view];
-
+
// Assert that the proper file was actually loaded, checking the value of a test setting it must contain
NSString* settingValue = [viewController.settings objectForKey:CDVViewControllerTestSettingKey];
XCTAssertEqualObjects(settingValue, value);
@@ -75,18 +75,18 @@ -(void)testInitWithCustomConfigFileRelativePath{
-(void)testColorFromColorString{
CDVViewController* viewController = [self viewController];
-
+
// Comparison values: #FFAABB and #99FFAABB
UIColor* referenceColor = [UIColor colorWithRed:255.0/255.0 green:170.0/255.0 blue:187.0/255.0 alpha:1.0];
UIColor* referenceColorAlpha = [UIColor colorWithRed:255.0/255.0 green:170.0/255.0 blue:187.0/255.0 alpha:0.6];
-
+
// Valid values
XCTAssertTrue([[viewController colorFromColorString:@"#FAB"] isEqual:referenceColor]);
XCTAssertTrue([[viewController colorFromColorString:@"#FFAABB"] isEqual:referenceColor]);
XCTAssertTrue([[viewController colorFromColorString:@"0xFFAABB"] isEqual:referenceColor]);
XCTAssertTrue([[viewController colorFromColorString:@"#99FFAABB"] isEqual:referenceColorAlpha]);
XCTAssertTrue([[viewController colorFromColorString:@"0x99FFAABB"] isEqual:referenceColorAlpha]);
-
+
// Invalid values
XCTAssertNil([viewController colorFromColorString:nil]);
XCTAssertNil([viewController colorFromColorString:@"black"]);
@@ -107,7 +107,7 @@ -(void)testIsUrlEmpty{
-(void)testIfItLoadsAppUrlIfCurrentViewIsBlank{
CDVViewController* viewController = [self viewController];
-
+
NSString* appUrl = @"about:blank";
NSString* html = @"
";
[viewController.webViewEngine loadHTMLString:html baseURL:[NSURL URLWithString:appUrl]];
diff --git a/tests/CordovaLibTests/CDVWebViewEngineTest.m b/tests/CordovaLibTests/CDVWebViewEngineTest.m
index e21efc42f..c3334b867 100644
--- a/tests/CordovaLibTests/CDVWebViewEngineTest.m
+++ b/tests/CordovaLibTests/CDVWebViewEngineTest.m
@@ -6,9 +6,9 @@ Licensed to the Apache Software Foundation (ASF) under one
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -51,10 +51,10 @@ @implementation CDVWebViewEngineTest
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
-
+
// NOTE: no app settings are set, so it will rely on default WKWebViewConfiguration settings
self.plugin = [[CDVWebViewEngine alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
-
+
XCTAssert([self.plugin conformsToProtocol:@protocol(CDVWebViewEngineProtocol)], @"Plugin does not conform to CDVWebViewEngineProtocol");
}
@@ -68,14 +68,14 @@ - (void) testCanLoadRequest {
NSURLRequest* httpUrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://apache.org"]];
NSURLRequest* miscUrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"foo://bar"]];
id 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]);
}
@@ -83,10 +83,10 @@ - (void) testCanLoadRequest {
- (void) testUpdateInfo {
// Add -ObjC to Other Linker Flags to test project, to load Categories
// Update objc test template generator as well
-
+
id 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
@@ -100,16 +100,16 @@ - (void) testUpdateInfo {
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
XCTAssertTrue(wkWebView.configuration.mediaTypesRequiringUserActionForPlayback);
XCTAssertFalse(wkWebView.configuration.allowsInlineMediaPlayback);
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);
@@ -120,7 +120,7 @@ - (void) testUpdateInfo {
}
}
}
-
+
XCTAssertTrue(wkWebView.scrollView.decelerationRate == UIScrollViewDecelerationRateFast);
}
@@ -128,7 +128,7 @@ - (void) testConfigurationFromSettings {
// we need to re-set the plugin from the "setup" to take in the app settings we need
self.plugin = [[CDVWebViewEngine alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
self.viewController = [[CDVViewController alloc] init];
-
+
// generate the app settings
NSDictionary* settings = @{
[@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0
@@ -141,24 +141,24 @@ - (void) testConfigurationFromSettings {
};
// this can be set because of the Category at the top of the file
self.viewController.settings = [settings mutableCopy];
-
+
// app settings are read after you register the plugin
[self.viewController registerPlugin:self.plugin withClassName:NSStringFromClass([self.plugin class])];
XCTAssert([self.plugin conformsToProtocol:@protocol(CDVWebViewEngineProtocol)], @"Plugin does not conform to CDVWebViewEngineProtocol");
-
+
// after registering (thus plugin initialization), we can grab the webview configuration
WKWebView* wkWebView = (WKWebView*)self.plugin.engineWebView;
-
+
// 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
XCTAssertTrue(wkWebView.configuration.mediaTypesRequiringUserActionForPlayback);
XCTAssertTrue(wkWebView.configuration.allowsInlineMediaPlayback);
XCTAssertTrue(wkWebView.configuration.suppressesIncrementalRendering);
// The test case below is in a separate test "testConfigurationWithMediaPlaybackAllowsAirPlay" (Apple bug)
// XCTAssertFalse(wkWebView.configuration.mediaPlaybackAllowsAirPlay);
-
+
// in the test above, DisallowOverscroll is YES, so no bounce
if ([wkWebView respondsToSelector:@selector(scrollView)]) {
XCTAssertFalse(((UIScrollView*)[wkWebView scrollView]).bounces);
@@ -169,17 +169,17 @@ - (void) testConfigurationFromSettings {
}
}
}
-
+
XCTAssertTrue(wkWebView.scrollView.decelerationRate == UIScrollViewDecelerationRateFast);
}
- (void) testShouldReloadWebView {
WKWebView* wkWebView = (WKWebView*)self.plugin.engineWebView;
-
+
NSURL* about_blank = [NSURL URLWithString:@"about:blank"];
NSURL* real_site = [NSURL URLWithString:@"https://cordova.apache.org"];
NSString* empty_title_document = @"";
-
+
// about:blank should reload
[wkWebView loadRequest:[NSURLRequest requestWithURL:about_blank]];
XCTAssertTrue([self.plugin shouldReloadWebView]);
@@ -187,7 +187,7 @@ - (void) testShouldReloadWebView {
// a network location should *not* reload
[wkWebView loadRequest:[NSURLRequest requestWithURL:real_site]];
XCTAssertFalse([self.plugin shouldReloadWebView]);
-
+
// document with empty title should *not* reload
// baseURL:nil results in about:blank, so we use a dummy here
[wkWebView loadHTMLString:empty_title_document baseURL:[NSURL URLWithString:@"about:"]];
@@ -197,10 +197,10 @@ - (void) testShouldReloadWebView {
// the title is nil, should always reload
XCTAssertTrue([self.plugin shouldReloadWebView:about_blank title:nil]);
XCTAssertTrue([self.plugin shouldReloadWebView:real_site title:nil]);
-
+
// about:blank should always reload
XCTAssertTrue([self.plugin shouldReloadWebView:about_blank title:@"some title"]);
-
+
// non about:blank with a non-nil title should **not** reload
XCTAssertFalse([self.plugin shouldReloadWebView:real_site title:@""]);
}
diff --git a/tests/CordovaLibTests/CDVWhitelistTests.m b/tests/CordovaLibTests/CDVWhitelistTests.m
index bd25418fc..15f5dbf75 100644
--- a/tests/CordovaLibTests/CDVWhitelistTests.m
+++ b/tests/CordovaLibTests/CDVWhitelistTests.m
@@ -91,9 +91,9 @@ - (void)testURISchemesNotFollowedByDoubleSlashes
@"tel:*",
@"sms:*",
nil];
-
+
CDVWhitelist* whitelist = [[CDVWhitelist alloc] initWithArray:allowedHosts];
-
+
XCTAssertTrue([whitelist URLIsAllowed:[NSURL URLWithString:@"tel:1234567890"]]);
XCTAssertTrue([whitelist URLIsAllowed:[NSURL URLWithString:@"sms:1234567890"]]);
}
@@ -162,17 +162,17 @@ - (void)testIpWildcardMatch
@"192.168.1.*",
@"192.168.2.*",
nil];
-
+
CDVWhitelist* whitelist = [[CDVWhitelist alloc] initWithArray:allowedHosts];
XCTAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"http://apache.org"]]);
-
+
// Ever since Cordova 3.1, whitelist wildcards are simplified, only "*" and "*.apache.org" (subdomain example) are allowed. Therefore the next four tests should fail
XCTAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"http://192.168.1.1"]]);
XCTAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"http://192.168.1.2"]]);
XCTAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"http://192.168.2.1"]]);
XCTAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"http://192.168.2.2"]]);
-
+
XCTAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"http://192.168.3.1"]]);
}
@@ -252,7 +252,7 @@ - (void)testWildcardScheme
XCTAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"http://apache.org"]]);
XCTAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"gopher://testtt.com"]]);
-
+
XCTAssertTrue([whitelist URLIsAllowed:[NSURL URLWithString:@"gopher://test.com"]]);
XCTAssertTrue([whitelist URLIsAllowed:[NSURL URLWithString:@"http://test.com"]]);
XCTAssertTrue([whitelist URLIsAllowed:[NSURL URLWithString:@"http://my.test.com"]]);
@@ -285,22 +285,20 @@ - (void)testAllowIntentsAndNavigations
{
NSArray* allowIntents = @[ @"https://*" ];
NSArray* allowNavigations = @[ @"https://*.apache.org" ];
-
+
CDVWhitelist* intentsWhitelist = [[CDVWhitelist alloc] initWithArray:allowIntents];
CDVWhitelist* navigationsWhitelist = [[CDVWhitelist alloc] initWithArray:allowNavigations];
-
+
// Test allow-navigation superceding allow-intent
XCTAssertEqual([CDVIntentAndNavigationFilter filterUrl:[NSURL URLWithString:@"https://apache.org/foo.html"] intentsWhitelist:intentsWhitelist navigationsWhitelist:navigationsWhitelist], CDVIntentAndNavigationFilterValueNavigationAllowed);
// Test wildcard https as allow-intent
XCTAssertEqual([CDVIntentAndNavigationFilter filterUrl:[NSURL URLWithString:@"https://google.com"] intentsWhitelist:intentsWhitelist navigationsWhitelist:navigationsWhitelist], CDVIntentAndNavigationFilterValueIntentAllowed);
// Test http (not allowed in either)
XCTAssertEqual([CDVIntentAndNavigationFilter filterUrl:[NSURL URLWithString:@"http://google.com"] intentsWhitelist:intentsWhitelist navigationsWhitelist:navigationsWhitelist], CDVIntentAndNavigationFilterValueNoneAllowed);
-
-
+
NSURL* telUrl = [NSURL URLWithString:@"tel:5555555"];
NSMutableURLRequest* telRequest = [NSMutableURLRequest requestWithURL:telUrl];
telRequest.mainDocumentURL = telUrl;
}
-
@end