BYOAuthTests.m 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #import "FIRAuthE2eTestsBase.h"
  17. /** The url for obtaining a valid custom token string used to test BYOAuth. */
  18. static NSString *const kCustomTokenUrl = @"https://gcip-testapps.wl.r.appspot.com/token";
  19. /** The invalid custom token string for testing BYOAuth. */
  20. static NSString *const kInvalidCustomToken = @"invalid token.";
  21. /** The user name string for BYOAuth testing account. */
  22. static NSString *const kTestingAccountUserID = @"BYU_Test_User_ID";
  23. @interface BYOAuthTests : FIRAuthE2eTestsBase
  24. @end
  25. @implementation BYOAuthTests
  26. /** Test sign in with a valid BYOAuth token retrived from a remote server. */
  27. - (void)testSignInWithValidBYOAuthToken {
  28. NSError *error;
  29. NSString *customToken = [NSString stringWithContentsOfURL:[NSURL URLWithString:kCustomTokenUrl]
  30. encoding:NSUTF8StringEncoding
  31. error:&error];
  32. if (!customToken) {
  33. GREYFail(@"There was an error retrieving the custom token: %@", error);
  34. }
  35. [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"),
  36. grey_sufficientlyVisible(), nil)]
  37. usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)
  38. onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
  39. nil)] performAction:grey_tap()];
  40. [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])]
  41. performAction:grey_replaceText(customToken)] assertWithMatcher:grey_text(customToken)];
  42. [[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()];
  43. [self waitForElementWithText:@"OK" withDelay:kWaitForElementTimeOut];
  44. [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];
  45. [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(kTestingAccountUserID),
  46. grey_sufficientlyVisible(), nil)]
  47. usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, kShortScrollDistance)
  48. onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
  49. nil)] assertWithMatcher:grey_sufficientlyVisible()];
  50. }
  51. - (void)testSignInWithInvalidBYOAuthToken {
  52. [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"),
  53. grey_sufficientlyVisible(), nil)]
  54. usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)
  55. onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
  56. nil)] performAction:grey_tap()];
  57. [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])]
  58. performAction:grey_replaceText(kInvalidCustomToken)]
  59. assertWithMatcher:grey_text(kInvalidCustomToken)];
  60. [[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()];
  61. NSString *invalidTokenErrorMessage = @"Sign-In Error";
  62. [self waitForElementWithText:invalidTokenErrorMessage withDelay:kWaitForElementTimeOut];
  63. [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];
  64. }
  65. @end