Skip to content

Commit

Permalink
Add FirebaseUI UIAutomation unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yramanchuk committed Oct 10, 2016
1 parent 454f4be commit 8e1eb27
Show file tree
Hide file tree
Showing 15 changed files with 982 additions and 4 deletions.
2 changes: 0 additions & 2 deletions FirebaseAuthUI/FIRAuthProviderUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ typedef void (^FIRAuthProviderSignInCompletionBlock)(FIRAuthCredential *_Nullabl
which is one of the @c FIRAuthErrorCode codes. It is very important that all possible code
paths eventually call this method to inform the auth system of the result of the sign-in
flow.
@param auth The @c FIRAuth instance which is starting the sign-in flow.
@param email The email address of the user if it's known.
@param presentingViewController The view controller used to present the UI.
@param completion See remarks. A block to invoke when the sign-in process completes.
Expand All @@ -86,7 +85,6 @@ typedef void (^FIRAuthProviderSignInCompletionBlock)(FIRAuthCredential *_Nullabl

/** @fn signOut
@brief Called when the user wants to sign out.
@param auth The @c FIRAuth instance which is starting the sign out flow.
*/
- (void)signOut;

Expand Down
448 changes: 448 additions & 0 deletions FirebaseUI.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions FirebaseUI.xcodeproj/xcshareddata/xcschemes/FirebaseUI.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@
ReferencedContainer = "container:FirebaseUI.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C329B15A1DA8694A00059A13"
BuildableName = "FirebaseUISampleUITests.xctest"
BlueprintName = "FirebaseUISampleUITests"
ReferencedContainer = "container:FirebaseUI.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand Down
93 changes: 93 additions & 0 deletions FirebaseUISample/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
27 changes: 27 additions & 0 deletions FirebaseUISample/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
40 changes: 40 additions & 0 deletions FirebaseUISample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="FIRViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="h7D-Mv-g50">
<frame key="frameInset" minX="164" minY="318" width="47" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Sign In"/>
<connections>
<action selector="onAuthorization:" destination="BYZ-38-t0r" eventType="touchUpInside" id="JUz-gN-DGh"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<connections>
<outlet property="btnAuthorization" destination="h7D-Mv-g50" id="ztP-Kg-kgA"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
25 changes: 25 additions & 0 deletions FirebaseUISample/FIRAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <UIKit/UIKit.h>

@interface FIRAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

39 changes: 39 additions & 0 deletions FirebaseUISample/FIRAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "FIRAppDelegate.h"
#import <FirebaseCore/FIRApp.h>

@implementation FIRAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"0:000000000000:ios:0000000000000000"
bundleID:@"testBundleIdValue"
GCMSenderID:@"testGCMSenderIDValue"
APIKey:@"testAPIKeyValue"
clientID:@"testclientID"
trackingID:@"testTrackingIDValue"
androidClientID:@"testAndroidClientIDValue"
databaseURL:@"testDatabaseURLValue"
storageBucket:@"testStorageBucketValue"
deepLinkURLScheme:@"testDeepLinkURLSchemeValue"];
[FIRApp configureWithOptions:options];

return YES;
}


@end
23 changes: 23 additions & 0 deletions FirebaseUISample/FIRViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <UIKit/UIKit.h>

@interface FIRViewController : UIViewController


@end

106 changes: 106 additions & 0 deletions FirebaseUISample/FIRViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "FIRViewController.h"
#import <FirebaseAuth/FIRAuth.h>
#import <FirebaseAuthUI/FirebaseAuthUI.h>
#import <FirebaseCore/FIRApp.h>
#import <FirebaseGoogleAuthUI/FirebaseGoogleAuthUI.h>
#import <OCMock/OCMock.h>

@interface FIRViewController () <FIRAuthUIDelegate>
@property (weak, nonatomic) IBOutlet UIButton *btnAuthorization;

@property (nonatomic) id authMock;
@property (nonatomic) id authUIMock;

@end

@implementation FIRViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.authMock = OCMPartialMock([FIRAuth auth]);

OCMStub(ClassMethod([self.authMock auth])).andReturn(self.authMock);

FIRAuthUI *authUI = [FIRAuthUI defaultAuthUI];
authUI.delegate = self;
self.authUIMock = OCMPartialMock(authUI);

OCMStub([self.authMock fetchProvidersForEmail:OCMOCK_ANY completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) {
FIRProviderQueryCallback mockedResponse;
[invocation getArgument:&mockedResponse atIndex:3];
mockedResponse(@[@"password"], nil);
});
}

- (IBAction)onAuthorization:(id)sender {
if (![self.authMock currentUser]) {
UIViewController *controller = [self.authUIMock authViewController];
[self presentViewController:controller animated:YES completion:nil];
} else {
[self signOut];
}
}

- (void)signOut {
// sign out from Firebase
NSError *error;
[self.authMock signOut:&error];
if (error) {
[self showAlert:error.localizedDescription];
}

// sign out from all providers (wipes provider tokens too)
for (id<FIRAuthProviderUI> provider in [self.authUIMock providers]) {
[provider signOut];
}

}

#pragma mark - FIRAuthUIDelegate methods

// this method is called only when FIRAuthViewController is delgate of AuthUI
- (void)authUI:(FIRAuthUI *)authUI didSignInWithUser:(nullable FIRUser *)user error:(nullable NSError *)error {
if (error) {
if (error.code == FIRAuthUIErrorCodeUserCancelledSignIn) {
[self showAlert:@"User cancelled sign-in"];
} else {
NSError *detailedError = error.userInfo[NSUnderlyingErrorKey];
if (!detailedError) {
detailedError = error;
}
[self showAlert:detailedError.localizedDescription];
}
}
}

- (void)showAlert:(NSString *)message {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* closeButton = [UIAlertAction
actionWithTitle:@"Close"
style:UIAlertActionStyleDefault
handler:nil];
[alert addAction:closeButton];
[self presentViewController:alert animated:YES completion:nil];

}

@end
Loading

0 comments on commit 8e1eb27

Please sign in to comment.