Skip to content

Implement better pasteboard data verification #70

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

Merged
merged 1 commit into from
Apr 4, 2018
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
22 changes: 19 additions & 3 deletions WebDriverAgentLib/Utilities/FBPasteboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,26 @@ + (BOOL)setData:(NSData *)data forType:(NSString *)type error:(NSError **)error
if ([type.lowercaseString isEqualToString:@"plaintext"]) {
pb.string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
} else if ([type.lowercaseString isEqualToString:@"image"]) {
pb.image = [UIImage imageWithData:data];
UIImage *image = [UIImage imageWithData:data];
if (nil == image) {
NSString *description = @"No image can be parsed from the given pasteboard data";
if (error) {
*error = [[FBErrorBuilder.builder withDescription:description] build];
}
return NO;
}
pb.image = image;
} else if ([type.lowercaseString isEqualToString:@"url"]) {
NSString *urlString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
pb.URL = [[NSURL alloc] initWithString:urlString];
NSURL *url = [[NSURL alloc] initWithString:urlString];
if (nil == url) {
NSString *description = @"No URL can be parsed from the given pasteboard data";
if (error) {
*error = [[FBErrorBuilder.builder withDescription:description] build];
}
return NO;
}
pb.URL = url;
} else {
NSString *description = [NSString stringWithFormat:@"Unsupported content type: %@", type];
if (error) {
Expand All @@ -46,7 +62,7 @@ + (NSData *)dataForType:(NSString *)type error:(NSError **)error
}
} else if ([type.lowercaseString isEqualToString:@"url"]) {
if (pb.hasURLs) {
return [NSData dataWithContentsOfURL:(NSURL *)pb.URL];
return [pb.URL.absoluteString dataUsingEncoding:NSUTF8StringEncoding];
}
} else {
NSString *description = [NSString stringWithFormat:@"Unsupported content type: %@", type];
Expand Down
13 changes: 13 additions & 0 deletions WebDriverAgentTests/IntegrationTests/FBPasteboardTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ - (void)testGetPasteboard
XCTAssertEqualObjects(textField.value, [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]);
}

- (void)testUrlCopyPaste
{
NSString *urlString = @"http://appium.io?some=value";
NSError *error;
XCTAssertTrue([FBPasteboard setData:(NSData *)[urlString dataUsingEncoding:NSUTF8StringEncoding]
forType:@"url"
error:&error]);
XCTAssertNil(error);
NSData *result = [FBPasteboard dataForType:@"url" error:&error];
XCTAssertNil(error);
XCTAssertEqualObjects(urlString, [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]);
}

@end