sharesheet_mojom_traits_unittest.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2022 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. #include "chromeos/crosapi/mojom/sharesheet_mojom_traits.h"
  5. #include "chromeos/crosapi/mojom/sharesheet.mojom.h"
  6. #include "mojo/public/cpp/bindings/enum_traits.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace crosapi {
  9. namespace mojom {
  10. namespace {
  11. template <typename MojomType, typename T>
  12. void RoundTrip(T value, MojomType mojomValue) {
  13. using Traits = mojo::EnumTraits<MojomType, T>;
  14. EXPECT_EQ(Traits::ToMojom(value), mojomValue);
  15. T output = T();
  16. EXPECT_TRUE(Traits::FromMojom(mojomValue, &output));
  17. EXPECT_EQ(output, value);
  18. }
  19. } // namespace
  20. // Test that every value in sharesheet::LaunchSource is
  21. // correctly converted.
  22. TEST(SharesheetTraitsTest, SharesheetLaunchSource) {
  23. RoundTrip(sharesheet::LaunchSource::kUnknown,
  24. SharesheetLaunchSource::kUnknown);
  25. RoundTrip(sharesheet::LaunchSource::kWebShare,
  26. SharesheetLaunchSource::kWebShare);
  27. RoundTrip(sharesheet::LaunchSource::kOmniboxShare,
  28. SharesheetLaunchSource::kOmniboxShare);
  29. }
  30. // Test that every value in sharesheet::SharesheetResult is correctly converted.
  31. TEST(SharesheetTraitsTest, SharesheetResult) {
  32. RoundTrip(sharesheet::SharesheetResult::kSuccess, SharesheetResult::kSuccess);
  33. RoundTrip(sharesheet::SharesheetResult::kCancel, SharesheetResult::kCancel);
  34. RoundTrip(sharesheet::SharesheetResult::kErrorAlreadyOpen,
  35. SharesheetResult::kErrorAlreadyOpen);
  36. RoundTrip(sharesheet::SharesheetResult::kErrorWindowClosed,
  37. SharesheetResult::kErrorWindowClosed);
  38. }
  39. } // namespace mojom
  40. } // namespace crosapi