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 2014/10/18 00:16:00 UTC

[1/2] ios commit: CB-7813 - CDVWebViewDelegate fails to update the webview state properly in iOS

Repository: cordova-ios
Updated Branches:
  refs/heads/master 3058347d4 -> d72a48acd


CB-7813 - CDVWebViewDelegate fails to update the webview state properly in iOS

CDVWebViewDelegate fails to update the webview state properly in iOS when a page loads an iframe using javascript and does a redirect to another page using javascript. Method didFailLoadWithError gets called while in STATE_WAITING_FOR_LOAD_START with a NSURLErrorCancelled (-999) error. Instead of entering STATE_CANCELLED in this situation it always enters STATE_IDLE, which causes didFailLoadWithError event to never fire (which depending on the app, and definitely in our case, can cause a hang condition).

For a simplified Cordova project that reproduces the problem in the most straigtforward
way possible, please refer to: https://github.com/greatvines/cordova-webview-state-bug-www

Signed-off-by: Shazron Abdullah <sh...@apache.org>


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

Branch: refs/heads/master
Commit: 5de0f3f7f1d39e5b45909d00862869b4fc245bb3
Parents: 3058347
Author: pbenschop <pb...@cox.net>
Authored: Mon Sep 29 17:31:30 2014 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Fri Oct 17 15:13:30 2014 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVWebViewDelegate.m | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5de0f3f7/CordovaLib/Classes/CDVWebViewDelegate.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWebViewDelegate.m b/CordovaLib/Classes/CDVWebViewDelegate.m
index cdc3980..5a187f4 100644
--- a/CordovaLib/Classes/CDVWebViewDelegate.m
+++ b/CordovaLib/Classes/CDVWebViewDelegate.m
@@ -378,7 +378,11 @@ static NSString *stripFragment(NSString* url)
             break;
 
         case STATE_WAITING_FOR_LOAD_START:
-            _state = STATE_IDLE;
+            if ([error code] == NSURLErrorCancelled) {
+                _state = STATE_CANCELLED;
+            } else {
+                _state = STATE_IDLE;
+            }
             fireCallback = YES;
             break;
 


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


[2/2] ios commit: CB-7813 - Added unit test

Posted by sh...@apache.org.
CB-7813 - Added unit test


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

Branch: refs/heads/master
Commit: d72a48acd0b9455ece519419f0cbc538a8af808c
Parents: 5de0f3f
Author: Shazron Abdullah <sh...@apache.org>
Authored: Fri Oct 17 15:15:43 2014 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Fri Oct 17 15:15:43 2014 -0700

----------------------------------------------------------------------
 tests/CordovaLibTests/CDVWebViewDelegateTests.m | 35 ++++++++++++++++++++
 1 file changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/d72a48ac/tests/CordovaLibTests/CDVWebViewDelegateTests.m
----------------------------------------------------------------------
diff --git a/tests/CordovaLibTests/CDVWebViewDelegateTests.m b/tests/CordovaLibTests/CDVWebViewDelegateTests.m
index 7edd189..3413638 100644
--- a/tests/CordovaLibTests/CDVWebViewDelegateTests.m
+++ b/tests/CordovaLibTests/CDVWebViewDelegateTests.m
@@ -21,6 +21,27 @@
 
 #import <Cordova/CDVWebViewDelegate.h>
 
+@interface CDVWebViewDelegate2 : CDVWebViewDelegate {}
+
+- (void)setState:(NSInteger)state;
+- (NSInteger)state;
+
+@end
+
+@implementation  CDVWebViewDelegate2
+
+- (void)setState:(NSInteger)state
+{
+    _state = state;
+}
+
+- (NSInteger)state
+{
+    return _state;
+}
+
+@end
+
 @interface CDVWebViewDelegate ()
 
 // expose private interface
@@ -43,6 +64,20 @@
     [super tearDown];
 }
 
+- (void)testFailLoadStateCancelled
+{
+    NSInteger initialState = 1; // STATE_WAITING_FOR_LOAD_START;
+    NSInteger expectedState = 5; // STATE_CANCELLED;
+    NSError* errorCancelled = [NSError errorWithDomain:NSCocoaErrorDomain code:NSURLErrorCancelled userInfo:nil];
+
+    CDVWebViewDelegate2* wvd = [[CDVWebViewDelegate2 alloc] initWithDelegate:nil]; // not really testing delegate handling
+
+    wvd.state = initialState;
+    [wvd webView:nil didFailLoadWithError:errorCancelled];
+
+    XCTAssertTrue(wvd.state == expectedState, @"If the load error was through an iframe redirect (NSURLErrorCancelled), the state should be STATE_CANCELLED");
+}
+
 - (void)testShouldLoadRequest
 {
     CDVWebViewDelegate* wvd = [[CDVWebViewDelegate alloc] initWithDelegate:nil]; // not really testing delegate handling


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