bmc: add utilty method to only add a blob id if not present

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I96f3335a1341bc29eeff398f200214f240861047
diff --git a/test/firmware_state_notyetstarted_unittest.cpp b/test/firmware_state_notyetstarted_unittest.cpp
index 0cc724d..a97a348 100644
--- a/test/firmware_state_notyetstarted_unittest.cpp
+++ b/test/firmware_state_notyetstarted_unittest.cpp
@@ -99,6 +99,8 @@
     EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
     EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
               realHandler->getCurrentState());
+
+    EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId));
 }
 
 TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange)
@@ -110,6 +112,8 @@
     EXPECT_TRUE(handler->open(session, flags, hashBlobId));
     EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
               realHandler->getCurrentState());
+
+    EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId));
 }
 
 } // namespace
diff --git a/test/firmware_state_verificationpending_unittest.cpp b/test/firmware_state_verificationpending_unittest.cpp
index e8a3bf2..af777c7 100644
--- a/test/firmware_state_verificationpending_unittest.cpp
+++ b/test/firmware_state_verificationpending_unittest.cpp
@@ -21,6 +21,7 @@
 
 using ::testing::IsEmpty;
 using ::testing::Return;
+using ::testing::UnorderedElementsAreArray;
 
 /*
  * There are the following calls (parameters may vary):
@@ -150,12 +151,26 @@
        OpenImageBlobTransitionsToUploadInProgress)
 {
     getToVerificationPending(staticLayoutBlobId);
+
+    /* Verify the active blob for the image is in the list once to start.
+     * Note: This is truly tested under the notYetStarted::open() test.
+     */
+    std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId,
+                                              verifyBlobId, activeImageBlobId};
+
+    EXPECT_THAT(handler->getBlobIds(),
+                UnorderedElementsAreArray(expectedBlobs));
+
     EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
     EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
 
     auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
     EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
               realHandler->getCurrentState());
+
+    /* Verify the active blob ID was not added to the list twice. */
+    EXPECT_THAT(handler->getBlobIds(),
+                UnorderedElementsAreArray(expectedBlobs));
 }
 
 /*