Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set webView.delegate to nil upon dealloc. Add some comments. Make uni…

…t tests pass.
  • Loading branch information...
commit 1450e0c42ba3b137d5b20d2cda8361f9842e9d6c 1 parent ac55f61
@mcglincy mcglincy authored
View
43 UnitTests/EvernoteSessionTests.m
@@ -17,6 +17,7 @@ @interface EvernoteSessionTests() {
}
@property (nonatomic, retain) id mockSession;
+@property (nonatomic, retain) id mockViewController;
@property (nonatomic, retain) NSURLConnection *dummyURLConnection;
@end
@@ -24,11 +25,13 @@ @interface EvernoteSessionTests() {
@implementation EvernoteSessionTests
@synthesize mockSession = _mockSession;
+@synthesize mockViewController = _mockViewController;
@synthesize dummyURLConnection = _dummyURLConnection;
- (void)dealloc
{
[_mockSession release];
+ [_mockViewController release];
[_dummyURLConnection release];
[super dealloc];
}
@@ -50,6 +53,8 @@ - (void)setUp
// mock out our verification methods, since we don't care
[[self.mockSession stub] verifyConsumerKeyAndSecret];
+ self.mockViewController = [OCMockObject mockForClass:[UIViewController class]];
+
// mock out our connection-making method to return a dummy
self.dummyURLConnection = [[[NSURLConnection alloc]
initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"file:foo"]]
@@ -82,11 +87,9 @@ - (void)testAuthenticationVerifyMethods
[session authenticateWithViewController:nil completionHandler:^(NSError *error) {}];
}
-// Make sure a nil NSURLConnection causes a proper error calback.
-- (void)testNilConnection
+// Make sure a nil UIViewController causes a proper error callback.
+- (void)testNilViewController
{
- [[[self.mockSession stub] andReturn:nil] connectionWithRequest:[OCMArg any]];
-
[self.mockSession authenticateWithViewController:nil completionHandler:^(NSError *error) {
authenticationCompleted = YES;
authenticationError = error;
@@ -95,6 +98,22 @@ - (void)testNilConnection
STAssertTrue(authenticationCompleted, nil);
STAssertNotNil(authenticationError, nil);
STAssertEqualObjects(authenticationError.domain, EvernoteSDKErrorDomain, nil);
+ STAssertEquals(authenticationError.code, EvernoteSDKErrorCode_NO_VIEWCONTROLLER, nil);
+}
+
+// Make sure a nil NSURLConnection causes a proper error callback.
+- (void)testNilConnection
+{
+ [[[self.mockSession stub] andReturn:nil] connectionWithRequest:[OCMArg any]];
+
+ [self.mockSession authenticateWithViewController:self.mockViewController completionHandler:^(NSError *error) {
+ authenticationCompleted = YES;
+ authenticationError = error;
+ }];
+
+ STAssertTrue(authenticationCompleted, nil);
+ STAssertNotNil(authenticationError, nil);
+ STAssertEqualObjects(authenticationError.domain, EvernoteSDKErrorDomain, nil);
STAssertEquals(authenticationError.code, EvernoteSDKErrorCode_TRANSPORT_ERROR, nil);
}
@@ -103,7 +122,7 @@ - (void)testURLConnectionDidFailWithError
{
[[[self.mockSession stub] andReturn:self.dummyURLConnection] connectionWithRequest:[OCMArg any]];
- [self.mockSession authenticateWithViewController:nil completionHandler:^(NSError *error) {
+ [self.mockSession authenticateWithViewController:self.mockViewController completionHandler:^(NSError *error) {
authenticationCompleted = YES;
authenticationError = error;
}];
@@ -119,7 +138,7 @@ - (void)testURLConnectionNon200
{
[[[self.mockSession stub] andReturn:self.dummyURLConnection] connectionWithRequest:[OCMArg any]];
- [self.mockSession authenticateWithViewController:nil completionHandler:^(NSError *error) {
+ [self.mockSession authenticateWithViewController:self.mockViewController completionHandler:^(NSError *error) {
authenticationCompleted = YES;
authenticationError = error;
}];
@@ -149,7 +168,7 @@ - (void)testBadTempTokenResponse
{
[[[self.mockSession stub] andReturn:self.dummyURLConnection] connectionWithRequest:[OCMArg any]];
- [self.mockSession authenticateWithViewController:nil completionHandler:^(NSError *error) {
+ [self.mockSession authenticateWithViewController:self.mockViewController completionHandler:^(NSError *error) {
authenticationCompleted = YES;
authenticationError = error;
}];
@@ -179,7 +198,7 @@ - (void)testSuccessfulAuthentication
{
[[[self.mockSession stub] andReturn:self.dummyURLConnection] connectionWithRequest:[OCMArg any]];
- [self.mockSession authenticateWithViewController:nil completionHandler:^(NSError *error) {
+ [self.mockSession authenticateWithViewController:self.mockViewController completionHandler:^(NSError *error) {
authenticationCompleted = YES;
authenticationError = error;
}];
@@ -206,12 +225,17 @@ - (void)testSuccessfulAuthentication
STAssertFalse(authenticationCompleted, nil);
STAssertNil(authenticationError, nil);
[self.mockSession verify];
+
+ // successful authentication will dismiss the modal popup
+ [[self.mockViewController expect] dismissModalViewControllerAnimated:YES];
NSString *urlString = @"en-dummyaccount-1234://response?action=oauthCallback&oauth_token=en_oauth_test.12BF88D95B9.687474703A2F2F6C6F63616C686F73742F7E736574682F4544414D576562546573742F696E6465782E7068703F616374696F6E3D63616C6C6261636B.AEDE24F1FAFD67D267E78D27D14F01D3&oauth_verifier=0D6A636CD623302F8D69DBB8DF76D86E";
[self.mockSession oauthViewController:nil receivedOAuthCallbackURL:[NSURL URLWithString:urlString]];
- // now we can poke the NSURLConnectionDelegate methods again, for the 4th step of OAuth.
+ [self.mockViewController verify];
+ // now we can poke the NSURLConnectionDelegate methods again, for the 4th step of OAuth.
+
// connection:didReceiveResponse:
[self.mockSession connection:self.dummyURLConnection didReceiveResponse:responseMock];
STAssertFalse(authenticationCompleted, nil);
@@ -232,6 +256,7 @@ - (void)testSuccessfulAuthentication
authenticationToken:@"sometokenvalue"];
[self.mockSession connectionDidFinishLoading:self.dummyURLConnection];
[self.mockSession verify];
+
// and make sure our callback happened, without error.
STAssertTrue(authenticationCompleted, nil);
STAssertNil(authenticationError, nil);
View
7 evernote-sdk-ios/internal/ENOAuthViewController.m
@@ -26,10 +26,11 @@ @implementation ENOAuthViewController
- (void)dealloc
{
self.delegate = nil;
+ self.webView.delegate = nil;
[self.webView stopLoading];
+ [_webView release];
[_authorizationURL release];
[_oauthCallbackPrefix release];
- [_webView release];
[super dealloc];
}
@@ -55,7 +56,7 @@ - (void)viewDidLoad
target:self action:@selector(cancel:)];
self.navigationItem.rightBarButtonItem = cancelItem;
- // Using self.view.frame leaves a 20px black space above the webview... from status bar spacing?
+ // TODO: Using self.view.frame leaves a 20px black space above the webview... from status bar spacing?
//self.webView = [[UIWebView alloc] initWithFrame:self.view.frame];
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -89,7 +90,7 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
}
if (error.code == NSURLErrorCancelled) {
- // ignore rapid repeated clicking
+ // ignore rapid repeated clicking (error code -999)
return;
}
Please sign in to comment.
Something went wrong with that request. Please try again.