|
| 1 | +/* |
| 2 | + * Copyright 2019 Google |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#import "FIRAuthE2eTestsBase.h" |
| 18 | + |
| 19 | +/** The url for obtaining a valid custom token string used to test BYOAuth. */ |
| 20 | +static NSString *const kCustomTokenUrl = @"https://fb-sa-1211.appspot.com/token"; |
| 21 | + |
| 22 | +/** The invalid custom token string for testing BYOAuth. */ |
| 23 | +static NSString *const kInvalidCustomToken = @"invalid token."; |
| 24 | + |
| 25 | +/** The user name string for BYOAuth testing account. */ |
| 26 | +static NSString *const kTestingAccountUserID = @"BYU_Test_User_ID"; |
| 27 | + |
| 28 | +@interface BYOAuthTests : FIRAuthE2eTestsBase |
| 29 | + |
| 30 | +@end |
| 31 | + |
| 32 | +@implementation BYOAuthTests |
| 33 | + |
| 34 | +/** Test sign in with a valid BYOAuth token retrived from a remote server. */ |
| 35 | +- (void)testSignInWithValidBYOAuthToken { |
| 36 | + NSError *error; |
| 37 | + NSString *customToken = [NSString stringWithContentsOfURL:[NSURL URLWithString:kCustomTokenUrl] |
| 38 | + encoding:NSUTF8StringEncoding |
| 39 | + error:&error]; |
| 40 | + if (!customToken) { |
| 41 | + GREYFail(@"There was an error retrieving the custom token: %@", error); |
| 42 | + } |
| 43 | + |
| 44 | + [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"), |
| 45 | + grey_sufficientlyVisible(), nil)] |
| 46 | + usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance) |
| 47 | + onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]), |
| 48 | + nil)] performAction:grey_tap()]; |
| 49 | + |
| 50 | + [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])] |
| 51 | + performAction:grey_replaceText(customToken)] assertWithMatcher:grey_text(customToken)]; |
| 52 | + |
| 53 | + [[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()]; |
| 54 | + |
| 55 | + [self waitForElementWithText:@"OK" withDelay:kWaitForElementTimeOut]; |
| 56 | + |
| 57 | + [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()]; |
| 58 | + |
| 59 | + [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(kTestingAccountUserID), |
| 60 | + grey_sufficientlyVisible(), nil)] |
| 61 | + usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, kShortScrollDistance) |
| 62 | + onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]), |
| 63 | + nil)] assertWithMatcher:grey_sufficientlyVisible()]; |
| 64 | +} |
| 65 | + |
| 66 | +- (void)testSignInWithInvalidBYOAuthToken { |
| 67 | + [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"), |
| 68 | + grey_sufficientlyVisible(), nil)] |
| 69 | + usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance) |
| 70 | + onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]), |
| 71 | + nil)] performAction:grey_tap()]; |
| 72 | + |
| 73 | + [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])] |
| 74 | + performAction:grey_replaceText(kInvalidCustomToken)] |
| 75 | + assertWithMatcher:grey_text(kInvalidCustomToken)]; |
| 76 | + |
| 77 | + [[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()]; |
| 78 | + |
| 79 | + NSString *invalidTokenErrorMessage = @"Sign-In Error"; |
| 80 | + |
| 81 | + [self waitForElementWithText:invalidTokenErrorMessage withDelay:kWaitForElementTimeOut]; |
| 82 | + |
| 83 | + [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()]; |
| 84 | +} |
| 85 | + |
| 86 | +@end |
0 commit comments