cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject ios commit: Fixed the failing unit-tests, plus style fix-ups.
Date Fri, 07 Nov 2014 20:08:08 GMT
Repository: cordova-ios
Updated Branches:
  refs/heads/wkwebview 96fd4cb74 -> c343e2ec3


Fixed the failing unit-tests, plus style fix-ups.

Note that some of these tests, like the User-Agent tests, are specific to UIWebView and are
treated as such. The StartPage test should also work for WKWebView, and should be changed
to support that as well, although it is not trivial.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/c343e2ec
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/c343e2ec
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/c343e2ec

Branch: refs/heads/wkwebview
Commit: c343e2ec3ab1d1956f28b7c6b052bf7136fb5cc0
Parents: 96fd4cb
Author: Shazron Abdullah <shazron@apache.org>
Authored: Fri Nov 7 12:08:08 2014 -0800
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Fri Nov 7 12:08:08 2014 -0800

----------------------------------------------------------------------
 tests/CordovaLibTests/CDVStartPageTests.m       | 14 ++++--
 tests/CordovaLibTests/CDVUserAgentTest.m        | 52 +++++++++++++++-----
 tests/CordovaLibTests/CDVWebViewDelegateTests.m | 10 ++--
 tests/CordovaLibTests/CDVWebViewTest.m          |  6 +--
 4 files changed, 58 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c343e2ec/tests/CordovaLibTests/CDVStartPageTests.m
----------------------------------------------------------------------
diff --git a/tests/CordovaLibTests/CDVStartPageTests.m b/tests/CordovaLibTests/CDVStartPageTests.m
index 5df0057..85cd3da 100644
--- a/tests/CordovaLibTests/CDVStartPageTests.m
+++ b/tests/CordovaLibTests/CDVStartPageTests.m
@@ -80,15 +80,23 @@
 
     self.appDelegate.window.rootViewController = rootVc;
 
+    UIWebView* vc1WebView = (UIWebView*)rootVc.vc1.webView;
+    UIWebView* vc2WebView = (UIWebView*)rootVc.vc2.webView;
+
+    // sanity check
+    if (![vc1WebView isKindOfClass:[UIWebView class]] && ![vc2WebView isKindOfClass:[UIWebView
class]]) {
+        return;
+    }
+
     NSString* geHREF = @"window.location.href";
     [self waitForConditionName:@"getting href" block:^{
-        return (BOOL)(rootVc.vc1.webView.request != nil && rootVc.vc1.webView.request
!= nil);
+        return (BOOL)(vc1WebView.request != nil && vc1WebView.request != nil);
     }];
 
-    NSString* href = [rootVc.vc1.webView stringByEvaluatingJavaScriptFromString:geHREF];
+    NSString* href = [vc1WebView stringByEvaluatingJavaScriptFromString:geHREF];
     XCTAssertTrue([href hasSuffix:@"index.html"], @"href should point to index.html");
 
-    href = [rootVc.vc2.webView stringByEvaluatingJavaScriptFromString:geHREF];
+    href = [vc2WebView stringByEvaluatingJavaScriptFromString:geHREF];
     XCTAssertTrue([href hasSuffix:@"index.html?delta=true"], @"href should point to index.html?delta=true");
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c343e2ec/tests/CordovaLibTests/CDVUserAgentTest.m
----------------------------------------------------------------------
diff --git a/tests/CordovaLibTests/CDVUserAgentTest.m b/tests/CordovaLibTests/CDVUserAgentTest.m
index 42d238c..f52178a 100644
--- a/tests/CordovaLibTests/CDVUserAgentTest.m
+++ b/tests/CordovaLibTests/CDVUserAgentTest.m
@@ -85,17 +85,26 @@
 - (void)testDefaultUserAgent
 {
     CDVUserAgentTestViewController* rootVc = [[CDVUserAgentTestViewController alloc] init];
-    
+
     self.appDelegate.window.rootViewController = rootVc;
-    
-    
+
+    // These tests only work on a UIWebView, which is the default web engine
+
+    UIWebView* vc1WebView = (UIWebView*)rootVc.vc1.webView;
+    UIWebView* vc2WebView = (UIWebView*)rootVc.vc2.webView;
+
+    // sanity check
+    if (![vc1WebView isKindOfClass:[UIWebView class]] && ![vc2WebView isKindOfClass:[UIWebView
class]]) {
+        return;
+    }
+
     NSString* getWebUserAgent = @"navigator.userAgent";
     [self waitForConditionName:@"getting user-agents" block:^BOOL {
-        return (rootVc.vc1.webView.request != nil && rootVc.vc2.webView.request !=
nil);
+        return vc1WebView.request != nil && vc2WebView.request != nil;
     }];
-    NSString* webUserAgent = [rootVc.vc1.webView stringByEvaluatingJavaScriptFromString:getWebUserAgent];
+    NSString* webUserAgent = [vc1WebView stringByEvaluatingJavaScriptFromString:getWebUserAgent];
     NSString* cordovaUserAgent = rootVc.vc1.userAgent;
-    
+
     XCTAssertTrue([cordovaUserAgent hasPrefix:webUserAgent], @"Default Cordova user agent
should be based on navigator.userAgent.");
 }
 
@@ -105,12 +114,20 @@
 
     self.appDelegate.window.rootViewController = rootVc;
 
+    UIWebView* vc1WebView = (UIWebView*)rootVc.vc1.webView;
+    UIWebView* vc2WebView = (UIWebView*)rootVc.vc2.webView;
+
+    // sanity check
+    if (![vc1WebView isKindOfClass:[UIWebView class]] && ![vc2WebView isKindOfClass:[UIWebView
class]]) {
+        return;
+    }
+
     NSString* getUserAgentCode = @"navigator.userAgent";
     [self waitForConditionName:@"getting user-agents" block:^BOOL {
-        return (rootVc.vc1.webView.request != nil && rootVc.vc2.webView.request !=
nil);
+        return vc1WebView.request != nil && vc2WebView.request != nil;
     }];
-    NSString* ua1 = [rootVc.vc1.webView stringByEvaluatingJavaScriptFromString:getUserAgentCode];
-    NSString* ua2 = [rootVc.vc2.webView stringByEvaluatingJavaScriptFromString:getUserAgentCode];
+    NSString* ua1 = [vc1WebView stringByEvaluatingJavaScriptFromString:getUserAgentCode];
+    NSString* ua2 = [vc2WebView stringByEvaluatingJavaScriptFromString:getUserAgentCode];
 
     XCTAssertFalse([ua1 isEqual:ua2], @"User-Agents should be different.");
 }
@@ -118,17 +135,26 @@
 - (void)testBaseUserAgent
 {
     CDVUserAgentTestViewController* rootVc = [[CDVUserAgentTestViewController alloc] init];
+
     rootVc.vc1.baseUserAgent = @"A different baseline user agent 1";
     rootVc.vc2.baseUserAgent = @"A different baseline user agent 2";
-    
+
     self.appDelegate.window.rootViewController = rootVc;
-    
+
+    UIWebView* vc1WebView = (UIWebView*)rootVc.vc1.webView;
+    UIWebView* vc2WebView = (UIWebView*)rootVc.vc2.webView;
+
+    // sanity check
+    if (![vc1WebView isKindOfClass:[UIWebView class]] && ![vc2WebView isKindOfClass:[UIWebView
class]]) {
+        return;
+    }
+
     [self waitForConditionName:@"getting user-agents" block:^BOOL {
-        return (rootVc.vc1.webView.request != nil && rootVc.vc2.webView.request !=
nil);
+        return vc1WebView.request != nil && vc2WebView.request != nil;
     }];
     NSString* cordovaUserAgent1 = rootVc.vc1.userAgent;
     NSString* cordovaUserAgent2 = rootVc.vc2.userAgent;
-    
+
     XCTAssertTrue([cordovaUserAgent1 hasPrefix:rootVc.vc1.baseUserAgent], @"Cordova user
agent should be based on base user agent.");
     XCTAssertTrue([cordovaUserAgent2 hasPrefix:rootVc.vc2.baseUserAgent], @"Cordova user
agent should be based on base user agent.");
 }

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c343e2ec/tests/CordovaLibTests/CDVWebViewDelegateTests.m
----------------------------------------------------------------------
diff --git a/tests/CordovaLibTests/CDVWebViewDelegateTests.m b/tests/CordovaLibTests/CDVWebViewDelegateTests.m
index 3413638..5606db6 100644
--- a/tests/CordovaLibTests/CDVWebViewDelegateTests.m
+++ b/tests/CordovaLibTests/CDVWebViewDelegateTests.m
@@ -19,9 +19,9 @@
 
 #import <XCTest/XCTest.h>
 
-#import <Cordova/CDVWebViewDelegate.h>
+#import <Cordova/CDVUIWebViewDelegate.h>
 
-@interface CDVWebViewDelegate2 : CDVWebViewDelegate {}
+@interface CDVWebViewDelegate2 : CDVUIWebViewDelegate {}
 
 - (void)setState:(NSInteger)state;
 - (NSInteger)state;
@@ -42,7 +42,7 @@
 
 @end
 
-@interface CDVWebViewDelegate ()
+@interface CDVUIWebViewDelegate ()
 
 // expose private interface
 - (BOOL)shouldLoadRequest:(NSURLRequest*)request;
@@ -80,7 +80,7 @@
 
 - (void)testShouldLoadRequest
 {
-    CDVWebViewDelegate* wvd = [[CDVWebViewDelegate alloc] initWithDelegate:nil]; // not really
testing delegate handling
+    CDVUIWebViewDelegate* wvd = [[CDVUIWebViewDelegate alloc] initWithDelegate:nil]; // not
really testing delegate handling
 
     NSURLRequest* mailtoUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:@"mailto:dev@cordova.apache.org"]];
     NSURLRequest* telUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:12345"]];
@@ -109,7 +109,7 @@
 
 - (void)doTestFragmentIdentifiersWithBaseUrl:(NSString*)baseUrl fragment:(NSString*)fragment
 {
-    CDVWebViewDelegate* wvd = [[CDVWebViewDelegate alloc] initWithDelegate:nil]; // not really
testing delegate handling
+    CDVUIWebViewDelegate* wvd = [[CDVUIWebViewDelegate alloc] initWithDelegate:nil]; // not
really testing delegate handling
 
     NSString* originalUrlString = baseUrl;
     NSURL* originalUrl = [NSURL URLWithString:originalUrlString];

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c343e2ec/tests/CordovaLibTests/CDVWebViewTest.m
----------------------------------------------------------------------
diff --git a/tests/CordovaLibTests/CDVWebViewTest.m b/tests/CordovaLibTests/CDVWebViewTest.m
index c395f48..02513c1 100644
--- a/tests/CordovaLibTests/CDVWebViewTest.m
+++ b/tests/CordovaLibTests/CDVWebViewTest.m
@@ -38,7 +38,7 @@
     // first exception makes it much easier to identify the source of the error.
     // On iOS < 5 there is a bug in SenTestingKit where the exception is
     // uncaught and the app crashes upon a failed STAssert (oh well).
-    //[self raiseAfterFailure];
+    // [self raiseAfterFailure];
 }
 
 - (void)tearDown
@@ -71,7 +71,7 @@
 
 - (UIWebView*)webView
 {
-    return self.viewController.webView;
+    return (UIWebView*)self.viewController.webView;
 }
 
 - (id)pluginInstance:(NSString*)pluginName
@@ -110,7 +110,7 @@
 - (void)waitForPageLoad
 {
     [self waitForConditionName:@"PageLoad" block:^{
-        return [@"true" isEqualToString :[self evalJs:@"window.pageIsLoaded"]];
+        return [@"true" isEqualToString:[self evalJs:@"window.pageIsLoaded"]];
     }];
 }
 


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


Mime
View raw message