summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2018-05-14 16:45:35 -0400
committerGitHub <noreply@github.com>2018-05-14 16:45:35 -0400
commit3c8b96baa241060b3ff4315412ecd7b3a6e1b7a7 (patch)
treeb4bf2b32b35fab414f732af712e8043423df4d94
parent9fceb95a2f9c192ba7ea2648b5bc207c1e32b263 (diff)
parent00ce9de351e2e8c41cf2ddc80f64c258e5fb0d13 (diff)
downloadsdl_ios-3c8b96baa241060b3ff4315412ecd7b3a6e1b7a7.tar.gz
Merge pull request #958 from smartdevicelink/bugfix/issue_955_image_buttons_sent_early
Fixed image soft buttons getting sent early
-rw-r--r--SmartDeviceLink/SDLSoftButtonManager.m7
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m73
2 files changed, 74 insertions, 6 deletions
diff --git a/SmartDeviceLink/SDLSoftButtonManager.m b/SmartDeviceLink/SDLSoftButtonManager.m
index 023dcdc85..8785c2c53 100644
--- a/SmartDeviceLink/SDLSoftButtonManager.m
+++ b/SmartDeviceLink/SDLSoftButtonManager.m
@@ -202,12 +202,15 @@ NS_ASSUME_NONNULL_BEGIN
self.inProgressHandler = [handler copy];
self.inProgressUpdate = [[SDLShow alloc] init];
self.inProgressUpdate.mainField1 = self.currentMainField1 ?: @"";
+
+ BOOL headUnitSupportsImages = self.softButtonCapabilities ? self.softButtonCapabilities.imageSupported.boolValue : NO;
+
if (self.softButtonObjects == nil) {
SDLLogV(@"Soft button objects are nil, sending an empty array");
self.inProgressUpdate.softButtons = @[];
} else if (([self sdl_currentStateHasImages] && ![self sdl_allCurrentStateImagesAreUploaded])
- && (self.softButtonCapabilities ? !self.softButtonCapabilities.imageSupported : YES)) {
- // The images don't yet exist on the head unit, or we cannot use images, send a text update if possible, otherwise, don't send anything yet
+ || !headUnitSupportsImages) {
+ // The images don't yet exist on the head unit, or we cannot use images, send a text update, if possible. Otherwise, don't send anything yet.
NSArray<SDLSoftButton *> *textOnlyButtons = [self sdl_textButtonsForCurrentState];
if (textOnlyButtons != nil) {
SDLLogV(@"Soft button images unavailable, sending text buttons");
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m
index 0115d318e..edd06554e 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m
@@ -60,10 +60,13 @@ describe(@"a soft button manager", ^{
__block SDLSoftButtonObject *testObject2 = nil;
__block NSString *object2Name = @"O2 Name";
__block NSString *object2State1Name = @"O2S1 Name";
+ __block NSString *object2State2Name = @"O2S2 Name";
__block NSString *object2State1Text = @"O2S1 Text";
+ __block NSString *object2State2Text = @"O2S2 Text";
__block NSString *object2State1ArtworkName = @"O2S1 Artwork";
__block SDLArtwork *object2State1Art = [[SDLArtwork alloc] initWithData:[@"TestData" dataUsingEncoding:NSUTF8StringEncoding] name:object2State1ArtworkName fileExtension:@"png" persistent:YES];
__block SDLSoftButtonState *object2State1 = [[SDLSoftButtonState alloc] initWithStateName:object2State1Name text:object2State1Text artwork:object2State1Art];
+ __block SDLSoftButtonState *object2State2 = [[SDLSoftButtonState alloc] initWithStateName:object2State2Name text:object2State2Text image:nil];
beforeEach(^{
testFileManager = OCMClassMock([SDLFileManager class]);
@@ -156,8 +159,14 @@ describe(@"a soft button manager", ^{
});
});
- describe(@"uploading the images", ^{
- context(@"when files are already on the file system", ^{
+ describe(@"uploading soft buttons to a head unit that supports images", ^{
+ beforeEach(^{
+ SDLSoftButtonCapabilities *softButtonImagesSupported = [[SDLSoftButtonCapabilities alloc] init];
+ softButtonImagesSupported.imageSupported = @YES;
+ testManager.softButtonCapabilities = softButtonImagesSupported;
+ });
+
+ context(@"when button artworks are already on the file system", ^{
beforeEach(^{
OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(YES);
@@ -184,7 +193,7 @@ describe(@"a soft button manager", ^{
});
});
- context(@"when files are not already on the file system, before upload finishes", ^{
+ context(@"when button artworks are not already on the file system, before upload finishes", ^{
beforeEach(^{
OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(NO);
@@ -211,7 +220,7 @@ describe(@"a soft button manager", ^{
});
});
- context(@"when files are not already on the file system, after upload finishes", ^{
+ context(@"when button artworks are not already on the file system, after upload finishes", ^{
beforeEach(^{
OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(NO);
OCMStub([testFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg invokeBlock]]);
@@ -240,6 +249,62 @@ describe(@"a soft button manager", ^{
});
});
+ describe(@"uploading soft buttons to a head unit that does not support images", ^{
+ beforeEach(^{
+ SDLSoftButtonCapabilities *softButtonImagesSupported = [[SDLSoftButtonCapabilities alloc] init];
+ softButtonImagesSupported.imageSupported = @NO;
+ testManager.softButtonCapabilities = softButtonImagesSupported;
+ });
+
+ context(@"when the button contains images", ^{
+ beforeEach(^{
+ testObject1 = [[SDLSoftButtonObject alloc] initWithName:object1Name states:@[object1State1, object1State2] initialStateName:object1State1Name handler:nil];
+ testObject2 = [[SDLSoftButtonObject alloc] initWithName:object2Name state:object2State2 handler:nil];
+ testManager.softButtonObjects = @[testObject1, testObject2];
+ });
+
+ it(@"should not have attempted to upload any artworks", ^{
+ OCMReject([testFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg any]]);
+ });
+
+ it(@"should set the in progress update to be text buttons", ^{
+ NSArray<SDLSoftButton *> *inProgressSoftButtons = testManager.inProgressUpdate.softButtons;
+
+ expect(testManager.hasQueuedUpdate).to(beFalse());
+ expect(testManager.inProgressUpdate.mainField1).to(equal(@""));
+ expect(inProgressSoftButtons).to(haveCount(2));
+ expect(inProgressSoftButtons[0].text).to(equal(object1State1Text));
+ expect(inProgressSoftButtons[1].text).to(equal(object2State2Text));
+ expect(inProgressSoftButtons[0].image).to(beNil());
+ expect(inProgressSoftButtons[1].image.value).to(beNil());
+ });
+ });
+
+ context(@"when the button does not contain images", ^{
+ beforeEach(^{
+ testObject1 = [[SDLSoftButtonObject alloc] initWithName:object1Name states:@[object1State1, object1State2] initialStateName:object1State1Name handler:nil];
+ testObject2 = [[SDLSoftButtonObject alloc] initWithName:object2Name state:object2State2 handler:nil];
+ testManager.softButtonObjects = @[testObject1, testObject2];
+ });
+
+ it(@"should not have attempted to upload any artworks", ^{
+ OCMReject([testFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg any]]);
+ });
+
+ it(@"should set the in progress update to be text buttons", ^{
+ NSArray<SDLSoftButton *> *inProgressSoftButtons = testManager.inProgressUpdate.softButtons;
+
+ expect(testManager.hasQueuedUpdate).to(beFalse());
+ expect(testManager.inProgressUpdate.mainField1).to(equal(@""));
+ expect(inProgressSoftButtons).to(haveCount(2));
+ expect(inProgressSoftButtons[0].text).to(equal(object1State1Text));
+ expect(inProgressSoftButtons[1].text).to(equal(object2State2Text));
+ expect(inProgressSoftButtons[0].image).to(beNil());
+ expect(inProgressSoftButtons[1].image.value).to(beNil());
+ });
+ });
+ });
+
describe(@"transitioning soft button states", ^{
beforeEach(^{
OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(YES);