1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "services/network/trust_tokens/types.h" 6 #include "base/time/time.h" 7 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 10 using ::testing::Optional; 11 12 namespace network { 13 namespace internal { 14 15 // trust_tokens/types.h's TimeToString/StringToTime implementations are 16 // thin wrappers around well-tested //base conversion methods, so these 17 // tests are just sanity checks to make sure that values are actually 18 // getting passed to the pertinent //base libraries. 19 TEST(TrustTokenTypes,TimeToStringRoundtrip)20TEST(TrustTokenTypes, TimeToStringRoundtrip) { 21 auto my_time = base::Time::UnixEpoch() + base::TimeDelta::FromMilliseconds( 22 373849174829374); // arbitrary 23 EXPECT_THAT(StringToTime(TimeToString(my_time)), Optional(my_time)); 24 } 25 TEST(TrustTokenTypes,TimeFromBadStringFails)26TEST(TrustTokenTypes, TimeFromBadStringFails) { 27 EXPECT_EQ(StringToTime("I bet this isn't a valid representation of a time."), 28 base::nullopt); 29 } 30 31 } // namespace internal 32 } // namespace network 33