Skip to content
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

[various] Update invalid NSURL tests #4959

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ final class URLLauncherTests: XCTestCase {
var error: FlutterError?
let result = createPlugin().canLaunchURL("urls can't have spaces", error: &error)

XCTAssertNil(result)
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, "argument_error")
XCTAssertEqual(error?.message, "Unable to parse URL")
XCTAssertEqual(error?.details as? String, "Provided URL: urls can't have spaces")
if (error == nil) {
// When linking against the iOS 17 SDK or later, NSURL uses a lenient parser, and won't
// fail to parse URLs, so the test must allow for either outcome.
XCTAssertNotNil(result)
XCTAssertFalse(result?.boolValue ?? true)
XCTAssertNil(error)
} else {
XCTAssertNil(result)
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, "argument_error")
XCTAssertEqual(error?.message, "Unable to parse URL")
XCTAssertEqual(error?.details as? String, "Provided URL: urls can't have spaces")
}
}

func testLaunchSuccess() {
Expand Down Expand Up @@ -75,11 +83,19 @@ final class URLLauncherTests: XCTestCase {
let expectation = XCTestExpectation(description: "completion called")

createPlugin().launchURL("urls can't have spaces", universalLinksOnly: false) { result, error in
XCTAssertNil(result)
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, "argument_error")
XCTAssertEqual(error?.message, "Unable to parse URL")
XCTAssertEqual(error?.details as? String, "Provided URL: urls can't have spaces")
if (error == nil) {
// When linking against the iOS 17 SDK or later, NSURL uses a lenient parser, and won't
// fail to parse URLs, so the test must allow for either outcome.
XCTAssertNotNil(result)
XCTAssertFalse(result?.boolValue ?? true)
XCTAssertNil(error)
} else {
XCTAssertNil(result)
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, "argument_error")
XCTAssertEqual(error?.message, "Unable to parse URL")
XCTAssertEqual(error?.details as? String, "Provided URL: urls can't have spaces")
}

expectation.fulfill()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ - (void)testLoadRequest {

- (void)testLoadRequestWithInvalidUrl {
FWFWebView *mockWebView = OCMClassMock([FWFWebView class]);
OCMReject([mockWebView loadRequest:OCMOCK_ANY]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
[instanceManager addDartCreatedInstance:mockWebView withIdentifier:0];
Expand All @@ -65,16 +64,24 @@ - (void)testLoadRequestWithInvalidUrl {
initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger))
instanceManager:instanceManager];

NSString *badURLString = @"%invalidUrl%";
FlutterError *error;
FWFNSUrlRequestData *requestData = [FWFNSUrlRequestData makeWithUrl:@"%invalidUrl%"
FWFNSUrlRequestData *requestData = [FWFNSUrlRequestData makeWithUrl:badURLString
httpMethod:nil
httpBody:nil
allHttpHeaderFields:@{}];
[hostAPI loadRequestForWebViewWithIdentifier:@0 request:requestData error:&error];
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.code, @"FWFURLRequestParsingError");
XCTAssertEqualObjects(error.message, @"Failed instantiating an NSURLRequest.");
XCTAssertEqualObjects(error.details, @"URL was: '%invalidUrl%'");
// When linking against the iOS 17 SDK or later, NSURL uses a lenient parser, and won't
// fail to parse URLs, so the test must allow for either outcome.
if (error) {
XCTAssertEqualObjects(error.code, @"FWFURLRequestParsingError");
XCTAssertEqualObjects(error.message, @"Failed instantiating an NSURLRequest.");
XCTAssertEqualObjects(error.details, @"URL was: '%invalidUrl%'");
} else {
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:badURLString]];
OCMVerify([mockWebView loadRequest:request]);
}
}

- (void)testSetCustomUserAgent {
Expand Down