-
Notifications
You must be signed in to change notification settings - Fork 808
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
NSURLSession should throw for creating tasks with nil request or resume data #1860
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//****************************************************************************** | ||
// | ||
// Copyright (c) 2015 Microsoft Corporation. All rights reserved. | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// | ||
// This code is licensed under the MIT License (MIT). | ||
// | ||
|
@@ -33,6 +33,21 @@ | |
|
||
#import <StubReturn.h> | ||
|
||
#define THROW_IF_NULL_REQUEST(request) \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have the urge to say "since this macro is internal to this function it should have some signature indication that." |
||
do { \ | ||
if (request == nil) { \ | ||
@throw [NSException \ | ||
exceptionWithName:NSInvalidArgumentException \ | ||
reason:[NSString \ | ||
stringWithFormat:@"*** %@ Cannot create data " \ | ||
@"task without request or " \ | ||
@"resume data", \ | ||
NSStringFromSelector(_cmd)] \ | ||
userInfo:nil]; \ | ||
} \ | ||
} \ | ||
while (false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
nit: 0 to be in par #WontFix |
||
|
||
NSString* const NSURLErrorBackgroundTaskCancelledReasonKey = @"NSURLErrorBackgroundTaskCancelledReasonKey"; | ||
|
||
template <typename... Args> | ||
|
@@ -305,6 +320,7 @@ - (NSURLSessionDataTask*)dataTaskWithRequest:(NSURLRequest*)request { | |
@Status Interoperable | ||
*/ | ||
- (NSURLSessionDataTask*)dataTaskWithRequest:(NSURLRequest*)request completionHandler:(NSURLSessionTaskCompletionHandler)completionHandler { | ||
THROW_IF_NULL_REQUEST(request); | ||
if (_invalidating) { | ||
return nil; | ||
} | ||
|
@@ -344,6 +360,7 @@ - (NSURLSessionDownloadTask*)downloadTaskWithRequest:(NSURLRequest*)request { | |
*/ | ||
- (NSURLSessionDownloadTask*)downloadTaskWithRequest:(NSURLRequest*)request | ||
completionHandler:(NSURLSessionDownloadTaskCompletionHandler)completionHandler { | ||
THROW_IF_NULL_REQUEST(request); | ||
if (_invalidating) { | ||
return nil; | ||
} | ||
|
@@ -368,6 +385,7 @@ - (NSURLSessionDownloadTask*)downloadTaskWithResumeData:(NSData*)resumeData { | |
*/ | ||
- (NSURLSessionDownloadTask*)downloadTaskWithResumeData:(NSData*)resumeData | ||
completionHandler:(NSURLSessionDownloadTaskCompletionHandler)completionHandler { | ||
THROW_IF_NULL_REQUEST(resumeData); | ||
if (_invalidating) { | ||
return nil; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//****************************************************************************** | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// | ||
// This code is licensed under the MIT License (MIT). | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
//****************************************************************************** | ||
|
||
#import <Foundation/Foundation.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the whole Foundation? |
||
#import <TestFramework.h> | ||
#import <Starboard/SmartTypes.h> | ||
|
||
TEST(NSURLSession, ShouldThrowForNilRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test these on OSX 10.12 please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10.11 |
||
NSURLSession* session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; | ||
EXPECT_ANY_THROW([session downloadTaskWithRequest:nil]); | ||
EXPECT_ANY_THROW([session dataTaskWithRequest:nil]); | ||
} | ||
|
||
TEST(NSURLSession, ShouldThrowForNilResumeData) { | ||
NSURLSession* session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; | ||
EXPECT_ANY_THROW([session downloadTaskWithResumeData:nil]); | ||
} | ||
|
||
TEST(NSURLSession, ShouldNOTThrowForNilURL) { | ||
NSURLSession* session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; | ||
EXPECT_NO_THROW([session downloadTaskWithURL:nil]); | ||
EXPECT_NO_THROW([session dataTaskWithURL:nil]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shocking, AJ using macros.