Commit 7fba5c78 authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Fix StoreDMToken test by retrieving token again.

Change-Id: I8cd9e9bb661938529c2dd97188580e8a0f515a07
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1944271
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720261}
parent 306663d1
......@@ -56,21 +56,12 @@ class BrowserDMTokenStorageTest : public BrowserDMTokenStorageTestBase,
struct StoreAndRetrieveTestParams {
public:
StoreAndRetrieveTestParams(const std::string& dm_token_to_store,
const std::string& expected_retrieved_dm_token,
bool expect_valid,
bool expect_invalid,
bool expect_empty)
const DMToken& expected_retrieved_dm_token)
: dm_token_to_store(dm_token_to_store),
expected_retrieved_dm_token(expected_retrieved_dm_token),
expect_valid(expect_valid),
expect_invalid(expect_invalid),
expect_empty(expect_empty) {}
expected_retrieved_dm_token(expected_retrieved_dm_token) {}
std::string dm_token_to_store;
std::string expected_retrieved_dm_token;
bool expect_valid;
bool expect_invalid;
bool expect_empty;
const DMToken expected_retrieved_dm_token;
};
class BrowserDMTokenStorageStoreAndRetrieveTest
......@@ -82,6 +73,7 @@ class BrowserDMTokenStorageStoreAndRetrieveTest
kEnrollmentToken1,
GetParam().dm_token_to_store,
false) {}
DMToken GetExpectedToken() { return GetParam().expected_retrieved_dm_token; }
};
} // namespace
......@@ -90,10 +82,15 @@ INSTANTIATE_TEST_SUITE_P(
BrowserDMTokenStorageStoreAndRetrieveTest,
BrowserDMTokenStorageStoreAndRetrieveTest,
testing::Values(
StoreAndRetrieveTestParams(kDMToken1, kDMToken1, true, false, false),
StoreAndRetrieveTestParams(kDMToken2, kDMToken2, true, false, false),
StoreAndRetrieveTestParams("INVALID_DM_TOKEN", "", false, true, false),
StoreAndRetrieveTestParams("", "", false, false, true)));
StoreAndRetrieveTestParams(
kDMToken1,
DMToken::CreateValidTokenForTesting(kDMToken1)),
StoreAndRetrieveTestParams(
kDMToken2,
DMToken::CreateValidTokenForTesting(kDMToken2)),
StoreAndRetrieveTestParams("INVALID_DM_TOKEN",
DMToken::CreateInvalidTokenForTesting()),
StoreAndRetrieveTestParams("", DMToken::CreateEmptyTokenForTesting())));
TEST_F(BrowserDMTokenStorageTest, RetrieveClientId) {
EXPECT_EQ(kClientId1, storage_.RetrieveClientId());
......@@ -115,17 +112,21 @@ TEST_F(BrowserDMTokenStorageTest, RetrieveEnrollmentToken) {
TEST_P(BrowserDMTokenStorageStoreAndRetrieveTest, StoreDMToken) {
storage_.SetDMToken(GetParam().dm_token_to_store);
DMToken dm_token = storage_.RetrieveDMToken();
if (GetParam().expect_valid) {
EXPECT_EQ(GetParam().expected_retrieved_dm_token, dm_token.value());
if (GetExpectedToken().is_valid()) {
EXPECT_EQ(GetExpectedToken().value(), dm_token.value());
}
EXPECT_EQ(GetParam().expect_valid, dm_token.is_valid());
EXPECT_EQ(GetParam().expect_invalid, dm_token.is_invalid());
EXPECT_EQ(GetParam().expect_empty, dm_token.is_empty());
EXPECT_EQ(GetExpectedToken().is_valid(), dm_token.is_valid());
EXPECT_EQ(GetExpectedToken().is_invalid(), dm_token.is_invalid());
EXPECT_EQ(GetExpectedToken().is_empty(), dm_token.is_empty());
// The DM token should be cached in memory and not read from the system again.
storage_.SetDMToken("not_saved");
if (GetParam().expect_valid) {
EXPECT_EQ(GetParam().expected_retrieved_dm_token, dm_token.value());
dm_token = storage_.RetrieveDMToken();
EXPECT_EQ(GetExpectedToken().is_valid(), dm_token.is_valid());
EXPECT_EQ(GetExpectedToken().is_invalid(), dm_token.is_invalid());
EXPECT_EQ(GetExpectedToken().is_empty(), dm_token.is_empty());
if (GetExpectedToken().is_valid()) {
EXPECT_EQ(GetExpectedToken().value(), dm_token.value());
}
}
......@@ -153,12 +154,12 @@ TEST_F(BrowserDMTokenStorageTest, ClearDMToken) {
TEST_P(BrowserDMTokenStorageStoreAndRetrieveTest, RetrieveDMToken) {
DMToken dm_token = storage_.RetrieveDMToken();
if (GetParam().expect_valid) {
EXPECT_EQ(GetParam().expected_retrieved_dm_token, dm_token.value());
if (GetExpectedToken().is_valid()) {
EXPECT_EQ(GetExpectedToken().value(), dm_token.value());
}
EXPECT_EQ(GetParam().expect_valid, dm_token.is_valid());
EXPECT_EQ(GetParam().expect_invalid, dm_token.is_invalid());
EXPECT_EQ(GetParam().expect_empty, dm_token.is_empty());
EXPECT_EQ(GetExpectedToken().is_valid(), dm_token.is_valid());
EXPECT_EQ(GetExpectedToken().is_invalid(), dm_token.is_invalid());
EXPECT_EQ(GetExpectedToken().is_empty(), dm_token.is_empty());
}
TEST_F(BrowserDMTokenStorageTest, ShouldDisplayErrorMessageOnFailure) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment