Skip to content

Commit

Permalink
Add close window action tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Mar 25, 2014
1 parent 47c9c6c commit fe271f2
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Airship/Common/UACloseWindowAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ - (void)performWithArguments:(UAActionArguments *)arguments
if ([webView.delegate respondsToSelector:@selector(closeWindow:)]) {
[(id<UARichContentWindow>)webView.delegate closeWindow:YES];
}
completionHandler([UAActionResult emptyResult]);
}

completionHandler([UAActionResult emptyResult]);
}

@end
4 changes: 4 additions & 0 deletions AirshipLib/AirshipLib.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@
CCA3A5051803184D009C7371 /* UAActionRegistryEntry+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = CCA3A5031803184D009C7371 /* UAActionRegistryEntry+Internal.h */; };
CCB7DF5B17BBF1B800CEDC56 /* UAInboxDBManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CCB7DF5A17BBF1B800CEDC56 /* UAInboxDBManagerTests.m */; };
CCB7DF5E17BBF71000CEDC56 /* UAInboxDBManager+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = CCB7DF5C17BBF71000CEDC56 /* UAInboxDBManager+Internal.h */; };
CCB9990B18E23E68007F911D /* UACloseWindowActionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CCB9990A18E23E68007F911D /* UACloseWindowActionTest.m */; };
CCBFA2DA17B5436500F97E1D /* NSJSONSerialization+UAAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = CCBFA2D817B5436500F97E1D /* NSJSONSerialization+UAAdditions.h */; };
CCBFA2DB17B5436500F97E1D /* NSJSONSerialization+UAAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CCBFA2D917B5436500F97E1D /* NSJSONSerialization+UAAdditions.m */; };
CCBFA2DC17B5436500F97E1D /* NSJSONSerialization+UAAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CCBFA2D917B5436500F97E1D /* NSJSONSerialization+UAAdditions.m */; };
Expand Down Expand Up @@ -702,6 +703,7 @@
CCA3A5031803184D009C7371 /* UAActionRegistryEntry+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UAActionRegistryEntry+Internal.h"; sourceTree = "<group>"; };
CCB7DF5A17BBF1B800CEDC56 /* UAInboxDBManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UAInboxDBManagerTests.m; sourceTree = "<group>"; };
CCB7DF5C17BBF71000CEDC56 /* UAInboxDBManager+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UAInboxDBManager+Internal.h"; sourceTree = "<group>"; };
CCB9990A18E23E68007F911D /* UACloseWindowActionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UACloseWindowActionTest.m; sourceTree = "<group>"; };
CCBFA2D817B5436500F97E1D /* NSJSONSerialization+UAAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSJSONSerialization+UAAdditions.h"; sourceTree = "<group>"; };
CCBFA2D917B5436500F97E1D /* NSJSONSerialization+UAAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSJSONSerialization+UAAdditions.m"; sourceTree = "<group>"; };
CCBFA2DF17B547B600F97E1D /* NSJSONSerialization+UAAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSJSONSerialization+UAAdditionsTests.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1264,6 +1266,7 @@
4995C6B2180DC5D3004F8724 /* UATagActionsTest.m */,
49E9C9C5183C28E900B7BCFF /* UAActionJSDelegateTest.m */,
49416D5E18C025E900A18B72 /* UALandingPageActionTest.m */,
CCB9990A18E23E68007F911D /* UACloseWindowActionTest.m */,
);
name = Actions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1852,6 +1855,7 @@
CCD3158417CFBD5A002E93A1 /* UAPushTest.m in Sources */,
7649615518C644D4003AF5EE /* UAInboxPushHandlerTest.m in Sources */,
BBB87D5F150574DE00971CEC /* CLLocationManager+Test.m in Sources */,
CCB9990B18E23E68007F911D /* UACloseWindowActionTest.m in Sources */,
CCDD37A51807157500B8866E /* UAIncomingRichPushActionTest.m in Sources */,
495526B117D95552009BC301 /* UAInboxMessageListTest.m in Sources */,
BBB87D63150574DE00971CEC /* UALocationProviderTests.m in Sources */,
Expand Down
105 changes: 105 additions & 0 deletions AirshipLib/AirshipLogicTests/UACloseWindowActionTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Copyright 2009-2013 Urban Airship Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binaryform must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided withthe distribution.
THIS SOFTWARE IS PROVIDED BY THE URBAN AIRSHIP INC``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL URBAN AIRSHIP INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#import <XCTest/XCTest.h>
#import "UAWebInvocationActionArguments.h"
#import "UACloseWindowAction.h"
#import <OCMock/OCMock.h>
#import "UARichContentWindow.h"


@interface UACloseWindowActionTest : XCTestCase
@property(nonatomic, strong)id mockWebView;
@property(nonatomic, strong)id mockUARichContentWindow;
@property(nonatomic, strong)UACloseWindowAction *action;
@end

@implementation UACloseWindowActionTest

- (void)setUp {
[super setUp];

self.action = [[UACloseWindowAction alloc] init];

self.mockUARichContentWindow = [OCMockObject niceMockForProtocol:@protocol(UARichContentWindow)];

self.mockWebView = [OCMockObject niceMockForClass:[UIWebView class]];
[[[self.mockWebView stub] andReturn:self.mockUARichContentWindow] delegate];
}

- (void)tearDown{
[self.mockWebView stopMocking];
[self.mockUARichContentWindow stopMocking];
[super tearDown];
}

/**
* Test the action accepts UASituationWebViewInvocation and UAWebInvocationActionArguments
*/
- (void)testAcceptsArguments {
UAActionArguments *args = [UAWebInvocationActionArguments argumentsWithValue:nil withSituation:UASituationWebViewInvocation withWebView:self.mockWebView];
XCTAssertTrue([self.action acceptsArguments:args], @"Close window action should accept any UAWebInvocationActionArguments with situation UASituationWebViewInvocation.");

args.situation = UASituationManualInvocation;
XCTAssertFalse([self.action acceptsArguments:args], @"Close window action should not accept UASituationManualInvocation.");

args = [UAActionArguments argumentsWithValue:@"blah" withSituation:UASituationWebViewInvocation];
XCTAssertFalse([self.action acceptsArguments:args], @"Close window action should not accept standard UAActionArguments.");
}

/**
* Test actions perform
*/
- (void)testPerform {
UAActionArguments *args = [UAWebInvocationActionArguments argumentsWithValue:nil withSituation:UASituationWebViewInvocation withWebView:self.mockWebView];

[[self.mockUARichContentWindow expect] closeWindow:YES];

__block id actionResult;

[self.action performWithArguments:args withCompletionHandler:^(UAActionResult *result){
actionResult = result;
}];

XCTAssertNotNil(actionResult, @"Completion handler should be called with an empty result");
XCTAssertNoThrow([self.mockUARichContentWindow verify], @"The delegate's close method should be called");
}

/**
* Test actions perform
*/
- (void)testPerformNilWebView {
UAActionArguments *args = [UAWebInvocationActionArguments argumentsWithValue:nil withSituation:UASituationWebViewInvocation withWebView:nil];

__block id actionResult;

[self.action performWithArguments:args withCompletionHandler:^(UAActionResult *result){
actionResult = result;
}];

XCTAssertNotNil(actionResult, @"Completion handler should be called with an empty result");
}

@end

0 comments on commit fe271f2

Please sign in to comment.