ambient_animation_static_resources_impl_unittest.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2021 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 "ash/ambient/resources/ambient_animation_static_resources.h"
  5. #include "ash/ambient/resources/ambient_animation_resource_constants.h"
  6. #include "ash/constants/ambient_animation_theme.h"
  7. #include "base/json/json_reader.h"
  8. #include "cc/paint/skottie_wrapper.h"
  9. #include "testing/gmock/include/gmock/gmock.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. #include "ui/gfx/image/image_skia.h"
  12. namespace ash {
  13. using ::testing::IsEmpty;
  14. using ::testing::IsNull;
  15. using ::testing::Not;
  16. using ::testing::NotNull;
  17. // AmbientAnimationStaticResources actually has very little application logic
  18. // and is more a class to house static data. Thus, an animation theme is picked
  19. // as an example and the basics are tested with it. A test case does not need to
  20. // exist for every possible animation theme.
  21. TEST(AmbientAnimationStaticResourcesTest, LoadsLottieData) {
  22. auto resources = AmbientAnimationStaticResources::Create(
  23. AmbientAnimationTheme::kFeelTheBreeze, /*serializable=*/false);
  24. ASSERT_THAT(resources->GetSkottieWrapper(), NotNull());
  25. EXPECT_TRUE(resources->GetSkottieWrapper()->is_valid());
  26. }
  27. TEST(AmbientAnimationStaticResourcesTest, LoadsStaticAssets) {
  28. auto resources = AmbientAnimationStaticResources::Create(
  29. AmbientAnimationTheme::kFeelTheBreeze, /*serializable=*/false);
  30. ASSERT_THAT(resources, NotNull());
  31. for (base::StringPiece asset_id :
  32. ambient::resources::kAllFeelTheBreezeStaticAssets) {
  33. gfx::ImageSkia image_original = resources->GetStaticImageAsset(asset_id);
  34. ASSERT_FALSE(image_original.isNull());
  35. gfx::ImageSkia image_reloaded = resources->GetStaticImageAsset(asset_id);
  36. ASSERT_FALSE(image_reloaded.isNull());
  37. EXPECT_TRUE(image_reloaded.BackedBySameObjectAs(image_original));
  38. }
  39. }
  40. TEST(AmbientAnimationStaticResourcesTest, FailsForSlideshowTheme) {
  41. EXPECT_THAT(AmbientAnimationStaticResources::Create(
  42. AmbientAnimationTheme::kSlideshow, /*serializable=*/false),
  43. IsNull());
  44. }
  45. TEST(AmbientAnimationStaticResourcesTest, FailsForUnknownAssetId) {
  46. auto resources = AmbientAnimationStaticResources::Create(
  47. AmbientAnimationTheme::kFeelTheBreeze, /*serializable=*/false);
  48. ASSERT_THAT(resources, NotNull());
  49. gfx::ImageSkia image = resources->GetStaticImageAsset("unknown_asset_id");
  50. EXPECT_TRUE(image.isNull());
  51. }
  52. } // namespace ash