forked from mirrors/linphone-iphone
319 lines
10 KiB
Objective-C
319 lines
10 KiB
Objective-C
//
|
|
// ChatTester.m
|
|
// linphone
|
|
//
|
|
// Created by Guillaume on 17/01/2015.
|
|
//
|
|
//
|
|
|
|
#import "ChatTester.h"
|
|
#include "LinphoneManager.h"
|
|
|
|
@implementation ChatTester
|
|
|
|
#pragma mark - setup
|
|
|
|
- (void)beforeAll {
|
|
[super beforeAll];
|
|
[self switchToValidAccountIfNeeded];
|
|
}
|
|
|
|
- (void)beforeEach {
|
|
[super beforeEach];
|
|
[self goBackFromChat];
|
|
[tester tapViewWithAccessibilityLabel:@"Chat"];
|
|
[self removeAllRooms];
|
|
}
|
|
|
|
- (void)afterAll {
|
|
[super afterAll];
|
|
// at the end of tests, go back to chat rooms to display main bar
|
|
[self goBackFromChat];
|
|
ASSERT_EQ([LinphoneManager instance].fileTransferDelegates.count, 0)
|
|
}
|
|
|
|
#pragma mark - tools
|
|
|
|
- (void)removeAllRooms {
|
|
if (![tester tryFindingTappableViewWithAccessibilityLabel:@"Edit" error:nil])
|
|
return;
|
|
|
|
[tester tapViewWithAccessibilityLabel:@"Edit" traits:UIAccessibilityTraitButton];
|
|
[tester tapViewWithAccessibilityLabel:@"Select all" traits:UIAccessibilityTraitButton];
|
|
[tester tapViewWithAccessibilityLabel:@"Delete all" traits:UIAccessibilityTraitButton];
|
|
[tester tapViewWithAccessibilityLabel:@"DELETE" traits:UIAccessibilityTraitButton];
|
|
}
|
|
|
|
- (void)dismissKeyboard {
|
|
[tester tapScreenAtPoint:CGPointMake(0, 0)]; // dismiss keyboard, if any
|
|
}
|
|
- (void)goBackFromChat {
|
|
[self dismissKeyboard];
|
|
if ([tester tryFindingTappableViewWithAccessibilityLabel:@"Back" error:nil]) {
|
|
[tester tapViewWithAccessibilityLabel:@"Back"];
|
|
}
|
|
}
|
|
|
|
- (void)startChatWith:(NSString *)user {
|
|
[tester tapViewWithAccessibilityLabel:@"New discussion"];
|
|
[tester clearTextFromFirstResponder];
|
|
[tester enterTextIntoCurrentFirstResponder:user];
|
|
[tester tapRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
|
inTableViewWithAccessibilityIdentifier:@"Suggested addresses"];
|
|
}
|
|
|
|
- (void)sendMessage:(NSString *)message {
|
|
[tester enterText:message intoViewWithAccessibilityLabel:@"Message field"];
|
|
[tester tapViewWithAccessibilityLabel:@"Send"];
|
|
}
|
|
|
|
- (void)uploadImageWithQuality:(NSString *)quality {
|
|
UITableView *tv = [self findTableView:@"ChatRoom list"];
|
|
|
|
long messagesCount = [tv numberOfRowsInSection:0];
|
|
[tester tapViewWithAccessibilityLabel:@"Send picture"];
|
|
[tester tapViewWithAccessibilityLabel:@"Photo library"];
|
|
// if popup "Linphone would access your photo" pops up, click OK.
|
|
#if TARGET_IPHONE_SIMULATOR
|
|
if ([tester acknowledgeSystemAlert]) {
|
|
[tester waitForTimeInterval:1];
|
|
}
|
|
#endif
|
|
|
|
// select random photo to avoid having the same multiple times
|
|
[tester choosePhotoInAlbum:@"Camera Roll" atRow:2 column:2 + (messagesCount % 2)];
|
|
|
|
// wait for the quality popup to show up
|
|
UIAccessibilityElement *element = nil;
|
|
float timeout = 10;
|
|
while (!element && timeout > 0.f) {
|
|
[tester waitForTimeInterval:.5];
|
|
timeout -= .5f;
|
|
element =
|
|
[[UIApplication sharedApplication] accessibilityElementMatchingBlock:^BOOL(UIAccessibilityElement *e) {
|
|
return [e.accessibilityLabel containsString:quality];
|
|
}];
|
|
}
|
|
XCTAssertNotNil(element);
|
|
[tester tapViewWithAccessibilityLabel:element.accessibilityLabel];
|
|
}
|
|
|
|
- (void)downloadImage {
|
|
[self startChatWith:[self me]];
|
|
[self uploadImageWithQuality:@"Minimum"];
|
|
// wait for the upload to terminate...
|
|
for (int i = 0; i < 45; i++) {
|
|
[tester waitForTimeInterval:1.f];
|
|
if ([[[LinphoneManager instance] fileTransferDelegates] count] == 0)
|
|
break;
|
|
}
|
|
[tester waitForViewWithAccessibilityLabel:@"Download"];
|
|
[tester tapViewWithAccessibilityLabel:@"Download"];
|
|
[tester waitForTimeInterval:.5f]; // just wait a few secs to start download
|
|
ASSERT_EQ(LinphoneManager.instance.fileTransferDelegates.count, 1);
|
|
}
|
|
|
|
#pragma mark - tests
|
|
|
|
- (void)testChatFromContactPhoneNumber {
|
|
[tester tapViewWithAccessibilityLabel:@"Contacts"];
|
|
[tester tapViewWithAccessibilityLabel:@"Anna Haro"];
|
|
[tester tapViewWithAccessibilityLabel:@"Chat with 555-522-8243"];
|
|
[self goBackFromChat];
|
|
UITableView *tv = [self findTableView:@"Chat list"];
|
|
ASSERT_EQ([tv numberOfRowsInSection:0], 1);
|
|
[tester waitForViewWithAccessibilityLabel:@"Contact name, Message"
|
|
value:@"Anna Haro (0)"
|
|
traits:UIAccessibilityTraitStaticText];
|
|
}
|
|
|
|
- (void)testInvalidSIPAddress {
|
|
[self startChatWith:@"sip://toto"];
|
|
|
|
[tester waitForViewWithAccessibilityLabel:@"Invalid address" traits:UIAccessibilityTraitStaticText];
|
|
[tester tapViewWithAccessibilityLabel:@"OK"];
|
|
}
|
|
|
|
- (void)testMessageRemoval {
|
|
NSString *user = [self getUUID];
|
|
|
|
[self startChatWith:user];
|
|
[self sendMessage:user];
|
|
[tester waitForViewWithAccessibilityLabel:@"Delivery failed" traits:UIAccessibilityTraitImage];
|
|
[self dismissKeyboard];
|
|
|
|
[tester tapViewWithAccessibilityLabel:@"Edit" traits:UIAccessibilityTraitButton];
|
|
[tester waitForViewWithAccessibilityLabel:@"Checkbox" value:@"Deselected" traits:UIAccessibilityTraitButton];
|
|
[tester tapRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
|
inTableViewWithAccessibilityIdentifier:@"ChatRoom list"];
|
|
[tester waitForViewWithAccessibilityLabel:@"Checkbox" value:@"Selected" traits:UIAccessibilityTraitButton];
|
|
[tester tapViewWithAccessibilityLabel:@"Delete all"];
|
|
[tester tapViewWithAccessibilityLabel:@"DELETE" traits:UIAccessibilityTraitButton];
|
|
|
|
// check that the tableview is empty
|
|
UITableView *tv = [self findTableView:@"ChatRoom list"];
|
|
ASSERT_EQ([tv numberOfRowsInSection:0], 0); // no more messages
|
|
|
|
[self goBackFromChat];
|
|
}
|
|
|
|
- (void)testPerformanceHugeChatList {
|
|
[tester tapViewWithAccessibilityLabel:@"Dialer"];
|
|
|
|
// create lots of chat rooms...
|
|
LinphoneCore *lc = [LinphoneManager getLc];
|
|
for (int i = 0; i < 100; i++) {
|
|
linphone_core_get_chat_room_from_uri(lc, [[NSString stringWithFormat:@"%@ - %d", [self me], i] UTF8String]);
|
|
}
|
|
|
|
NSTimeInterval before = [[NSDate date] timeIntervalSince1970];
|
|
[tester tapViewWithAccessibilityLabel:@"Chat"];
|
|
NSTimeInterval after = [[NSDate date] timeIntervalSince1970];
|
|
|
|
XCTAssertEqual([[self findTableView:@"Chat list"] numberOfRowsInSection:0], 100);
|
|
// conversation loading MUST be less than 1 sec
|
|
XCTAssertLessThan(after - before, 1.);
|
|
}
|
|
|
|
- (void)testPerformanceHugeConversation {
|
|
int count = 0;
|
|
LinphoneCore *lc = [LinphoneManager getLc];
|
|
LinphoneChatRoom *room = linphone_core_get_chat_room_from_uri(lc, [[self me] UTF8String]);
|
|
|
|
NSTimeInterval beforeEmpty = [[NSDate date] timeIntervalSince1970];
|
|
[self startChatWith:[self me]];
|
|
NSTimeInterval afterEmpty = [[NSDate date] timeIntervalSince1970];
|
|
[self goBackFromChat];
|
|
|
|
// generate lots of messages...
|
|
for (; count < 50; count++) {
|
|
LinphoneChatMessage *msg =
|
|
linphone_chat_room_create_message(room, [[NSString stringWithFormat:@"Message %d", count + 1] UTF8String]);
|
|
linphone_chat_room_send_chat_message(room, msg);
|
|
}
|
|
|
|
for (int i = 0; i < 25; i++) {
|
|
[tester waitForTimeInterval:1.f];
|
|
if (linphone_chat_room_get_history_size(room) == count * 2) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
[tester waitForViewWithAccessibilityLabel:@"Contact name, Message"
|
|
value:[NSString stringWithFormat:@"%@, Message %d (%d)", self.me, count, count]
|
|
traits:UIAccessibilityTraitStaticText];
|
|
|
|
NSTimeInterval before = [[NSDate date] timeIntervalSince1970];
|
|
[self startChatWith:[self me]];
|
|
NSTimeInterval after = [[NSDate date] timeIntervalSince1970];
|
|
|
|
// conversation loading MUST be less than 1 sec - loading messages only
|
|
XCTAssertLessThan(after - before, afterEmpty - beforeEmpty + 1.);
|
|
}
|
|
|
|
- (void)testRemoveAllChats {
|
|
NSArray *uuids = [self getUUIDArrayOfSize:3];
|
|
|
|
for (NSString *uuid in uuids) {
|
|
[self startChatWith:uuid];
|
|
[self sendMessage:@"Test"];
|
|
[self goBackFromChat];
|
|
}
|
|
|
|
UITableView *tv = [self findTableView:@"Chat list"];
|
|
|
|
ASSERT_EQ([tv numberOfRowsInSection:0], uuids.count);
|
|
|
|
[self removeAllRooms];
|
|
|
|
// check that the tableview is empty
|
|
ASSERT_EQ([tv numberOfRowsInSection:0], 0);
|
|
|
|
// test that there's no more chatrooms in the core
|
|
ASSERT_EQ(linphone_core_get_chat_rooms([LinphoneManager getLc]), NULL);
|
|
}
|
|
|
|
- (void)testSendMessageToMyself {
|
|
[self startChatWith:[self me]];
|
|
|
|
[self sendMessage:@"Hello"];
|
|
[tester waitForViewWithAccessibilityLabel:@"Outgoing message" value:@"Hello" traits:UIAccessibilityTraitStaticText];
|
|
[tester waitForViewWithAccessibilityLabel:@"Incoming message" value:@"Hello" traits:UIAccessibilityTraitStaticText];
|
|
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Message status"];
|
|
|
|
[self goBackFromChat];
|
|
}
|
|
|
|
- (void)testSendToSIPAddress {
|
|
NSString *sipAddr = [NSString stringWithFormat:@"sip:%@@%@", [self me], [self accountDomain]];
|
|
|
|
[self startChatWith:sipAddr];
|
|
|
|
[tester waitForViewWithAccessibilityLabel:@"Contact name" value:[self me] traits:0];
|
|
|
|
[self goBackFromChat];
|
|
}
|
|
|
|
- (void)testTransferCancelDownloadImage {
|
|
[self downloadImage];
|
|
[tester tapViewWithAccessibilityLabel:@"Cancel"];
|
|
ASSERT_EQ([[[LinphoneManager instance] fileTransferDelegates] count], 0);
|
|
}
|
|
|
|
- (void)testTransferCancelUploadImage {
|
|
[self startChatWith:[self me]];
|
|
[self uploadImageWithQuality:@"Minimum"];
|
|
[tester tapViewWithAccessibilityLabel:@"Cancel"];
|
|
ASSERT_EQ([[[LinphoneManager instance] fileTransferDelegates] count], 0);
|
|
}
|
|
|
|
- (void)testTransferDestroyRoomWhileUploading {
|
|
[self startChatWith:[self me]];
|
|
[self uploadImageWithQuality:@"Maximum"];
|
|
[self goBackFromChat];
|
|
[self removeAllRooms];
|
|
}
|
|
|
|
- (void)testTransferDownloadImage {
|
|
[self downloadImage];
|
|
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Cancel"];
|
|
ASSERT_EQ([[[LinphoneManager instance] fileTransferDelegates] count], 0);
|
|
}
|
|
|
|
- (void)testTransferSimultanouslyDownload {
|
|
[self startChatWith:[self me]];
|
|
[self uploadImageWithQuality:@"Minimum"];
|
|
[self uploadImageWithQuality:@"Minimum"];
|
|
UITableView *tv = [self findTableView:@"ChatRoom list"];
|
|
int timeout = 3;
|
|
// wait for ALL uploads to terminate...
|
|
for (int i = 0; i < 90; i++) {
|
|
[tester waitForTimeInterval:1.f];
|
|
if ([tv numberOfRowsInSection:0] == 4)
|
|
break;
|
|
}
|
|
[tester waitForTimeInterval:.5f];
|
|
ASSERT_EQ([[LinphoneManager instance] fileTransferDelegates].count, 0);
|
|
[tester scrollViewWithAccessibilityIdentifier:@"ChatRoom list" byFractionOfSizeHorizontal:0.f vertical:1.f];
|
|
for (int i = 0; i < 2; i++) {
|
|
// messages order is not known: if upload bitrate is huge, first image can be uploaded before last started
|
|
timeout = 3;
|
|
while (![tester tryFindingTappableViewWithAccessibilityLabel:@"Download" error:nil] && timeout) {
|
|
[tester scrollViewWithAccessibilityIdentifier:@"ChatRoom list"
|
|
byFractionOfSizeHorizontal:0.f
|
|
vertical:-.1f];
|
|
timeout--;
|
|
}
|
|
[tester waitForViewWithAccessibilityLabel:@"Download"];
|
|
[tester tapViewWithAccessibilityLabel:@"Download"];
|
|
[tester waitForTimeInterval:.2f]; // just wait a few secs to start download
|
|
}
|
|
timeout = 30;
|
|
while ([LinphoneManager instance].fileTransferDelegates.count > 0 && timeout) {
|
|
[tester waitForTimeInterval:.5];
|
|
timeout--;
|
|
}
|
|
[self goBackFromChat];
|
|
}
|
|
|
|
@end
|