Updated Branches: refs/heads/master cbee723dd -> 6aa58d21c
Fix executing legacy plugins when callbackId is null. This fixes the InAppPurchaseManager plugin. https://issues.apache.org/jira/browse/CB-1385 Also adds unit tests for CDVInvokedUrlCommand. Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/6aa58d21 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/6aa58d21 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/6aa58d21 Branch: refs/heads/master Commit: 6aa58d21c25cc8bd4fca94222dfdae88e91903ad Parents: cbee723 Author: Andrew Grieve <agri...@chromium.org> Authored: Mon Sep 10 14:46:26 2012 -0400 Committer: Andrew Grieve <agri...@chromium.org> Committed: Mon Sep 10 14:49:54 2012 -0400 ---------------------------------------------------------------------- CordovaLib/Classes/CDVInvokedUrlCommand.m | 8 +- .../CordovaLibTests/CDVInvokedUrlCommandTests.m | 93 +++++++++++++++ CordovaLib/CordovaTests.xcodeproj/project.pbxproj | 6 +- 3 files changed, 104 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/6aa58d21/CordovaLib/Classes/CDVInvokedUrlCommand.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVInvokedUrlCommand.m b/CordovaLib/Classes/CDVInvokedUrlCommand.m index a75afdc..eaeb5c8 100644 --- a/CordovaLib/Classes/CDVInvokedUrlCommand.m +++ b/CordovaLib/Classes/CDVInvokedUrlCommand.m @@ -34,7 +34,8 @@ - (id) initFromJson:(NSArray*)jsonEntry { - NSString* callbackId = [jsonEntry objectAtIndex:0]; + id tmp = [jsonEntry objectAtIndex:0]; + NSString* callbackId = tmp == [NSNull null] ? nil : tmp; NSString* className = [jsonEntry objectAtIndex:1]; NSString* methodName = [jsonEntry objectAtIndex:2]; NSMutableArray* arguments = [jsonEntry objectAtIndex:3]; @@ -71,7 +72,10 @@ break; } } - [newArguments insertObject:_callbackId atIndex:0]; + // Legacy (two versions back) has no callbackId. + if (_callbackId != nil) { + [newArguments insertObject:_callbackId atIndex:0]; + } if (legacyArguments != NULL) { *legacyArguments = newArguments; } http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/6aa58d21/CordovaLib/CordovaLibTests/CDVInvokedUrlCommandTests.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLibTests/CDVInvokedUrlCommandTests.m b/CordovaLib/CordovaLibTests/CDVInvokedUrlCommandTests.m new file mode 100644 index 0000000..0b50f78 --- /dev/null +++ b/CordovaLib/CordovaLibTests/CDVInvokedUrlCommandTests.m @@ -0,0 +1,93 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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 <SenTestingKit/SenTestingKit.h> + +#import "CDVInvokedUrlCommand.h" + +@interface CDVInvokedUrlCommandTests : SenTestCase +@end + +@implementation CDVInvokedUrlCommandTests + +- (void) testInitWithNoArgs +{ + NSArray* jsonArr = [NSArray arrayWithObjects:@"callbackId", @"className", @"methodName", [NSArray array], nil]; + CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonArr]; + STAssertEquals(@"callbackId", command.callbackId, nil); + STAssertEquals(@"className", command.className, nil); + STAssertEquals(@"methodName", command.methodName, nil); + STAssertEquals([NSArray array], command.arguments, nil); +} + +- (void) testLegacyArgsNoDict +{ + NSArray* args = [NSArray arrayWithObjects:@"a", @"b", nil]; + NSArray* jsonArr = [NSArray arrayWithObjects:@"callbackId", @"className", @"methodName", args, nil]; + CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonArr]; + NSMutableArray* legacyArgs = nil; + NSMutableDictionary* dict = nil; + [command legacyArguments:&legacyArgs andDict:&dict]; + // Ensure properties don't change. + STAssertEquals(@"callbackId", command.callbackId, nil); + STAssertEquals(@"className", command.className, nil); + STAssertEquals(@"methodName", command.methodName, nil); + STAssertEquals(args, command.arguments, nil); + + NSArray* expected = [NSArray arrayWithObjects:@"callbackId", @"a", @"b", nil]; + STAssertEqualObjects(expected, legacyArgs, nil); + STAssertNil(dict, nil); +} + +- (void) testLegacyArgsWithDicts +{ + NSDictionary* dummyDict1 = [NSDictionary dictionaryWithObjectsAndKeys:@"val", @"key", nil]; + NSDictionary* dummyDict2 = [NSDictionary dictionaryWithObjectsAndKeys:@"val", @"key", nil]; + NSArray* args = [NSArray arrayWithObjects:@"a", dummyDict1, dummyDict2, @"b", nil]; + NSArray* jsonArr = [NSArray arrayWithObjects:@"callbackId", @"className", @"methodName", args, nil]; + CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonArr]; + NSMutableArray* legacyArgs = nil; + NSMutableDictionary* dict = nil; + [command legacyArguments:&legacyArgs andDict:&dict]; + // Ensure properties don't change. + STAssertEquals(@"callbackId", command.callbackId, nil); + STAssertEquals(@"className", command.className, nil); + STAssertEquals(@"methodName", command.methodName, nil); + STAssertEquals(args, command.arguments, nil); + + NSArray* expected = [NSArray arrayWithObjects:@"callbackId", @"a", dummyDict2, @"b", nil]; + STAssertEqualObjects(expected, legacyArgs, nil); + STAssertEqualObjects(dict, dummyDict1, nil); +} + +- (void) testLegacyArgsNoCallbackId +{ + NSArray* args = [NSArray arrayWithObjects:@"a", @"b", nil]; + NSArray* jsonArr = [NSArray arrayWithObjects:[NSNull null], @"className", @"methodName", args, nil]; + CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonArr]; + NSMutableArray* legacyArgs = nil; + NSMutableDictionary* dict = nil; + [command legacyArguments:&legacyArgs andDict:&dict]; + + NSArray* expected = [NSArray arrayWithObjects:@"a", @"b", nil]; + STAssertEqualObjects(expected, legacyArgs, nil); +} + + +@end http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/6aa58d21/CordovaLib/CordovaTests.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaTests.xcodeproj/project.pbxproj b/CordovaLib/CordovaTests.xcodeproj/project.pbxproj index 3d1fda3..513fbf5 100644 --- a/CordovaLib/CordovaTests.xcodeproj/project.pbxproj +++ b/CordovaLib/CordovaTests.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ 68A32D7E141030EB006B237C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 686357AA141002F100DF4CF2 /* UIKit.framework */; }; 68A32D7F141030F3006B237C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 686357AC141002F100DF4CF2 /* Foundation.framework */; }; EB37019415D18B9A00BEBC43 /* libCordova.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EB37018C15D18B2E00BEBC43 /* libCordova.a */; }; + EB89634A15FE66EA00E12277 /* CDVInvokedUrlCommandTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EB89634915FE66EA00E12277 /* CDVInvokedUrlCommandTests.m */; }; EBA3554615A731F100F4DE24 /* CDVFakeFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */; }; EBA3556F15ABD0C900F4DE24 /* CDVFileTransferTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */; }; /* End PBXBuildFile section */ @@ -105,6 +106,7 @@ 686357DC14100B1600DF4CF2 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; 68A32D7414103017006B237C /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; }; EB37018115D18B2D00BEBC43 /* CordovaLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = CordovaLib.xcodeproj; sourceTree = "<group>"; }; + EB89634915FE66EA00E12277 /* CDVInvokedUrlCommandTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVInvokedUrlCommandTests.m; sourceTree = "<group>"; }; EBA3550F15A5F18900F4DE24 /* CDVWebViewTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDVWebViewTest.h; sourceTree = "<group>"; }; EBA3554415A731F100F4DE24 /* CDVFakeFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVFakeFileManager.h; sourceTree = "<group>"; }; EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVFakeFileManager.m; sourceTree = "<group>"; }; @@ -225,6 +227,7 @@ 30B342F415224B360070E6A5 /* CDVWebViewTest.m */, 30D1B08B15A2B36D0060C291 /* CDVBase64Tests.m */, EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */, + EB89634915FE66EA00E12277 /* CDVInvokedUrlCommandTests.m */, 3062D1AD151D4D9D000D9128 /* CDVLocalStorageTests.m */, 686357B9141002F200DF4CF2 /* CDVPluginResultJSONSerializationTests.m */, 30356213141049E1006C2D43 /* CDVWhitelistTests.m */, @@ -374,7 +377,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "cp ${PROJECT_DIR}/javascript/cordova.ios.js ${PROJECT_DIR}/CordovaLibApp/www"; + shellScript = "cp \"${PROJECT_DIR}/javascript/cordova.ios.js\" \"${PROJECT_DIR}/CordovaLibApp/www\""; showEnvVarsInLog = 0; }; 686357A7141002F100DF4CF2 /* ShellScript */ = { @@ -415,6 +418,7 @@ 30D1B08C15A2B36D0060C291 /* CDVBase64Tests.m in Sources */, EBA3554615A731F100F4DE24 /* CDVFakeFileManager.m in Sources */, EBA3556F15ABD0C900F4DE24 /* CDVFileTransferTests.m in Sources */, + EB89634A15FE66EA00E12277 /* CDVInvokedUrlCommandTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };