Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: remove extra space from Objective-C test modules #794

Merged
merged 2 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/CordovaLibTests/CDVStartPageTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:@""]) &&
Expand Down
12 changes: 6 additions & 6 deletions tests/CordovaLibTests/CDVViewControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"]);
Expand All @@ -107,7 +107,7 @@ -(void)testIsUrlEmpty{

-(void)testIfItLoadsAppUrlIfCurrentViewIsBlank{
CDVViewController* viewController = [self viewController];

NSString* appUrl = @"about:blank";
NSString* html = @"<html><body></body></html>";
[viewController.webViewEngine loadHTMLString:html baseURL:[NSURL URLWithString:appUrl]];
Expand Down
48 changes: 24 additions & 24 deletions tests/CordovaLibTests/CDVWebViewEngineTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}

Expand All @@ -68,25 +68,25 @@ - (void) testCanLoadRequest {
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
Expand All @@ -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);
Expand All @@ -120,15 +120,15 @@ - (void) testUpdateInfo {
}
}
}

XCTAssertTrue(wkWebView.scrollView.decelerationRate == UIScrollViewDecelerationRateFast);
}

- (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
Expand All @@ -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);
Expand All @@ -169,25 +169,25 @@ - (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 = @"<html><head><title></title></head></html>";

// about:blank should reload
[wkWebView loadRequest:[NSURLRequest requestWithURL:about_blank]];
XCTAssertTrue([self.plugin shouldReloadWebView]);

// 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:"]];
Expand All @@ -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:@""]);
}
Expand Down
20 changes: 9 additions & 11 deletions tests/CordovaLibTests/CDVWhitelistTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]);
}
Expand Down Expand Up @@ -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"]]);
}

Expand Down Expand Up @@ -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"]]);
Expand Down Expand Up @@ -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