Skip to content

Commit

Permalink
CB-13093: (iOS) Infinite looping when stressing navigation (#328)
Browse files Browse the repository at this point in the history
* CB-13093: (iOS) Infinite looping when stressing navigation

* CB-13093: added a unit test to reproduce the issue
  • Loading branch information
luissilvaos authored and shazron committed Aug 8, 2017
1 parent 8edd13a commit d44cec6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,10 @@ - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)re
NSLog(@"%@", description);
_loadCount = 0;
_state = STATE_WAITING_FOR_LOAD_START;
if ([_delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) {
NSDictionary* errorDictionary = @{NSLocalizedDescriptionKey : description};
NSError* error = [[NSError alloc] initWithDomain:@"CDVUIWebViewDelegate" code:1 userInfo:errorDictionary];
[_delegate webView:webView didFailLoadWithError:error];
}

NSDictionary* errorDictionary = @{NSLocalizedDescriptionKey : description};
NSError* error = [[NSError alloc] initWithDomain:@"CDVUIWebViewDelegate" code:1 userInfo:errorDictionary];
[self webView:webView didFailLoadWithError:error];
}
}
} else {
Expand Down
17 changes: 17 additions & 0 deletions tests/CordovaLibTests/CDVWebViewDelegateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ @interface CDVUIWebViewDelegate ()
// expose private interface
- (BOOL)shouldLoadRequest:(NSURLRequest*)request;

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType;

@end

@interface CDVWebViewDelegateTests : XCTestCase
Expand All @@ -64,6 +66,21 @@ - (void)tearDown
[super tearDown];
}

- (void)testShouldLoadRequestWithStateWaitForStart
{
NSInteger initialState = 1; // STATE_WAITING_FOR_LOAD_START;
NSInteger expectedState = 0; // STATE_IDLE;

CDVWebViewDelegate2* wvd = [[CDVWebViewDelegate2 alloc] initWithDelegate:nil]; // not really testing delegate handling
wvd.state = initialState;

// Testing a top-level navigation
[wvd webView:[UIWebView new] shouldStartLoadWithRequest:nil navigationType:UIWebViewNavigationTypeLinkClicked];

XCTAssertTrue(wvd.state == expectedState, @"If the navigation started with state STATE_WAITING_FOR_LOAD_START then it must fail and the state should be STATE_IDLE");
}


- (void)testFailLoadStateCancelled
{
NSInteger initialState = 1; // STATE_WAITING_FOR_LOAD_START;
Expand Down

0 comments on commit d44cec6

Please sign in to comment.