autotest_ambient_api_unittest.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2020 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/public/cpp/autotest_ambient_api.h"
  5. #include "ash/ambient/ambient_controller.h"
  6. #include "ash/ambient/test/ambient_ash_test_base.h"
  7. #include "ash/public/cpp/ambient/ambient_prefs.h"
  8. #include "ash/session/session_controller_impl.h"
  9. #include "ash/shell.h"
  10. #include "base/bind.h"
  11. #include "base/notreached.h"
  12. #include "base/run_loop.h"
  13. #include "components/prefs/pref_service.h"
  14. namespace ash {
  15. using AutotestAmbientApiTest = AmbientAshTestBase;
  16. TEST_F(AutotestAmbientApiTest,
  17. ShouldSuccessfullyWaitForPhotoTransitionAnimation) {
  18. PrefService* prefs =
  19. Shell::Get()->session_controller()->GetPrimaryUserPrefService();
  20. prefs->SetInteger(ambient::prefs::kAmbientModePhotoRefreshIntervalSeconds, 2);
  21. ShowAmbientScreen();
  22. // Wait for 10 photo transition animation to complete.
  23. base::RunLoop run_loop;
  24. AutotestAmbientApi test_api;
  25. test_api.WaitForPhotoTransitionAnimationCompleted(
  26. /*num_completions=*/10, /*timeout=*/base::Seconds(30),
  27. /*on_complete=*/run_loop.QuitClosure(),
  28. /*on_timeout=*/base::BindOnce([]() { NOTREACHED(); }));
  29. run_loop.Run();
  30. }
  31. TEST_F(AutotestAmbientApiTest,
  32. ShouldCallTimeoutCallbackIfNotEnoughPhotoTransitions) {
  33. PrefService* prefs =
  34. Shell::Get()->session_controller()->GetPrimaryUserPrefService();
  35. prefs->SetInteger(ambient::prefs::kAmbientModePhotoRefreshIntervalSeconds, 2);
  36. ShowAmbientScreen();
  37. base::RunLoop run_loop;
  38. AutotestAmbientApi test_api;
  39. test_api.WaitForPhotoTransitionAnimationCompleted(
  40. /*num_completions=*/10, /*timeout=*/base::Seconds(5),
  41. /*on_complete=*/base::BindOnce([]() { NOTREACHED(); }),
  42. /*on_timeout=*/run_loop.QuitClosure());
  43. run_loop.Run();
  44. }
  45. } // namespace ash