Commit f43c7aa8 authored by wutao's avatar wutao Committed by Commit Bot

ambient: Add autotest API to wait for photo animation

This cl adds an autotest private API which can be used by a follow up cl
to add tast test to measure the photo transition animation perf.
This API will wait to run several photo transition animations.

Bug: b/156854495
Test: new unittests
Change-Id: Icc9d9ab6e83657e160c6228d1702237ac9eba56e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2163146Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770725}
parent 1db37a78
...@@ -43,6 +43,7 @@ component("ash") { ...@@ -43,6 +43,7 @@ component("ash") {
"multi_user/multi_user_window_manager_impl.h", "multi_user/multi_user_window_manager_impl.h",
"public/cpp/arc_custom_tab.h", "public/cpp/arc_custom_tab.h",
"public/cpp/ash_prefs.h", "public/cpp/ash_prefs.h",
"public/cpp/autotest_ambient_api.h",
"public/cpp/autotest_desks_api.h", "public/cpp/autotest_desks_api.h",
"public/cpp/autotest_private_api_utils.h", "public/cpp/autotest_private_api_utils.h",
"public/cpp/debug_utils.h", "public/cpp/debug_utils.h",
...@@ -171,6 +172,7 @@ component("ash") { ...@@ -171,6 +172,7 @@ component("ash") {
"ambient/ambient_photo_controller.h", "ambient/ambient_photo_controller.h",
"ambient/ambient_view_delegate_impl.cc", "ambient/ambient_view_delegate_impl.cc",
"ambient/ambient_view_delegate_impl.h", "ambient/ambient_view_delegate_impl.h",
"ambient/autotest_ambient_api.cc",
"ambient/fake_ambient_backend_controller_impl.cc", "ambient/fake_ambient_backend_controller_impl.cc",
"ambient/fake_ambient_backend_controller_impl.h", "ambient/fake_ambient_backend_controller_impl.h",
"ambient/model/ambient_backend_model.cc", "ambient/model/ambient_backend_model.cc",
...@@ -1819,6 +1821,7 @@ test("ash_unittests") { ...@@ -1819,6 +1821,7 @@ test("ash_unittests") {
"accessibility/touch_exploration_manager_unittest.cc", "accessibility/touch_exploration_manager_unittest.cc",
"ambient/ambient_controller_unittest.cc", "ambient/ambient_controller_unittest.cc",
"ambient/ambient_photo_controller_unittest.cc", "ambient/ambient_photo_controller_unittest.cc",
"ambient/autotest_ambient_api_unittest.cc",
"ambient/model/ambient_backend_model_unittest.cc", "ambient/model/ambient_backend_model_unittest.cc",
"ambient/ui/ambient_container_view_unittest.cc", "ambient/ui/ambient_container_view_unittest.cc",
"app_list/app_list_controller_impl_unittest.cc", "app_list/app_list_controller_impl_unittest.cc",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/ambient/fake_ambient_backend_controller_impl.h" #include "ash/ambient/fake_ambient_backend_controller_impl.h"
#include "ash/ambient/model/ambient_backend_model_observer.h" #include "ash/ambient/model/ambient_backend_model_observer.h"
#include "ash/ambient/ui/ambient_container_view.h" #include "ash/ambient/ui/ambient_container_view.h"
#include "ash/ambient/ui/ambient_view_delegate.h"
#include "ash/ambient/util/ambient_util.h" #include "ash/ambient/util/ambient_util.h"
#include "ash/login/ui/lock_screen.h" #include "ash/login/ui/lock_screen.h"
#include "ash/public/cpp/ambient/ambient_backend_controller.h" #include "ash/public/cpp/ambient/ambient_backend_controller.h"
...@@ -194,6 +195,16 @@ void AmbientController::RequestAccessToken( ...@@ -194,6 +195,16 @@ void AmbientController::RequestAccessToken(
access_token_controller_.RequestAccessToken(std::move(callback)); access_token_controller_.RequestAccessToken(std::move(callback));
} }
void AmbientController::AddAmbientViewDelegateObserver(
AmbientViewDelegateObserver* observer) {
delegate_.AddObserver(observer);
}
void AmbientController::RemoveAmbientViewDelegateObserver(
AmbientViewDelegateObserver* observer) {
delegate_.RemoveObserver(observer);
}
void AmbientController::CreateContainerView() { void AmbientController::CreateContainerView() {
DCHECK(!container_view_); DCHECK(!container_view_);
container_view_ = new AmbientContainerView(&delegate_); container_view_ = new AmbientContainerView(&delegate_);
......
...@@ -25,6 +25,7 @@ namespace ash { ...@@ -25,6 +25,7 @@ namespace ash {
class AmbientBackendController; class AmbientBackendController;
class AmbientContainerView; class AmbientContainerView;
class AmbientPhotoController; class AmbientPhotoController;
class AmbientViewDelegateObserver;
// Class to handle all ambient mode functionalities. // Class to handle all ambient mode functionalities.
class ASH_EXPORT AmbientController : public views::WidgetObserver, class ASH_EXPORT AmbientController : public views::WidgetObserver,
...@@ -56,6 +57,9 @@ class ASH_EXPORT AmbientController : public views::WidgetObserver, ...@@ -56,6 +57,9 @@ class ASH_EXPORT AmbientController : public views::WidgetObserver,
void RequestAccessToken( void RequestAccessToken(
AmbientAccessTokenController::AccessTokenCallback callback); AmbientAccessTokenController::AccessTokenCallback callback);
void AddAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer);
void RemoveAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer);
AmbientBackendModel* ambient_backend_model(); AmbientBackendModel* ambient_backend_model();
bool is_showing() const { return !!container_view_; } bool is_showing() const { return !!container_view_; }
......
...@@ -17,6 +17,16 @@ AmbientViewDelegateImpl::AmbientViewDelegateImpl( ...@@ -17,6 +17,16 @@ AmbientViewDelegateImpl::AmbientViewDelegateImpl(
AmbientViewDelegateImpl::~AmbientViewDelegateImpl() = default; AmbientViewDelegateImpl::~AmbientViewDelegateImpl() = default;
void AmbientViewDelegateImpl::AddObserver(
AmbientViewDelegateObserver* observer) {
view_delegate_observers_.AddObserver(observer);
}
void AmbientViewDelegateImpl::RemoveObserver(
AmbientViewDelegateObserver* observer) {
view_delegate_observers_.RemoveObserver(observer);
}
AmbientBackendModel* AmbientViewDelegateImpl::GetAmbientBackendModel() { AmbientBackendModel* AmbientViewDelegateImpl::GetAmbientBackendModel() {
return ambient_controller_->ambient_backend_model(); return ambient_controller_->ambient_backend_model();
} }
...@@ -25,4 +35,9 @@ void AmbientViewDelegateImpl::OnBackgroundPhotoEvents() { ...@@ -25,4 +35,9 @@ void AmbientViewDelegateImpl::OnBackgroundPhotoEvents() {
ambient_controller_->OnBackgroundPhotoEvents(); ambient_controller_->OnBackgroundPhotoEvents();
} }
void AmbientViewDelegateImpl::OnPhotoTransitionAnimationCompleted() {
for (auto& observer : view_delegate_observers_)
observer.OnPhotoTransitionAnimationCompleted();
}
} // namespace ash } // namespace ash
...@@ -24,10 +24,16 @@ class AmbientViewDelegateImpl : public AmbientViewDelegate { ...@@ -24,10 +24,16 @@ class AmbientViewDelegateImpl : public AmbientViewDelegate {
// AmbientViewDelegate: // AmbientViewDelegate:
AmbientBackendModel* GetAmbientBackendModel() override; AmbientBackendModel* GetAmbientBackendModel() override;
void OnBackgroundPhotoEvents() override; void OnBackgroundPhotoEvents() override;
void OnPhotoTransitionAnimationCompleted() override;
void AddObserver(AmbientViewDelegateObserver* observer);
void RemoveObserver(AmbientViewDelegateObserver* observer);
private: private:
AmbientController* const ambient_controller_; // Owned by Shell. AmbientController* const ambient_controller_; // Owned by Shell.
base::ObserverList<AmbientViewDelegateObserver> view_delegate_observers_;
base::WeakPtrFactory<AmbientViewDelegateImpl> weak_factory_{this}; base::WeakPtrFactory<AmbientViewDelegateImpl> weak_factory_{this};
}; };
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/public/cpp/autotest_ambient_api.h"
#include "ash/ambient/ambient_controller.h"
#include "ash/ambient/ui/ambient_view_delegate.h"
#include "ash/public/cpp/ambient/ambient_backend_controller.h"
#include "ash/shell.h"
#include "base/callback.h"
namespace ash {
namespace {
class PhotoTransitionAnimationObserver : public AmbientViewDelegateObserver {
public:
PhotoTransitionAnimationObserver(int num_completions,
base::OnceClosure on_complete)
: num_completions_(num_completions),
on_complete_(std::move(on_complete)) {
DCHECK_GT(num_completions, 0);
Shell::Get()->ambient_controller()->AddAmbientViewDelegateObserver(this);
}
PhotoTransitionAnimationObserver(const PhotoTransitionAnimationObserver&) =
delete;
PhotoTransitionAnimationObserver& operator=(
const PhotoTransitionAnimationObserver&) = delete;
~PhotoTransitionAnimationObserver() override {
Shell::Get()->ambient_controller()->RemoveAmbientViewDelegateObserver(this);
}
// AmbientViewDelegateObserver:
void OnPhotoTransitionAnimationCompleted() override {
--num_completions_;
if (num_completions_ == 0) {
std::move(on_complete_).Run();
delete this;
}
}
private:
int num_completions_;
base::OnceClosure on_complete_;
};
} // namespace
AutotestAmbientApi::AutotestAmbientApi() = default;
AutotestAmbientApi::~AutotestAmbientApi() = default;
void AutotestAmbientApi::WaitForPhotoTransitionAnimationCompleted(
int refresh_interval_s,
int num_completions,
base::OnceClosure on_complete) {
ash::AmbientBackendController::Get()->SetPhotoRefreshInterval(
base::TimeDelta::FromSeconds(refresh_interval_s));
new PhotoTransitionAnimationObserver(num_completions, std::move(on_complete));
}
} // namespace ash
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/public/cpp/autotest_ambient_api.h"
#include "ash/ambient/ambient_controller.h"
#include "ash/ambient/test/ambient_ash_test_base.h"
#include "base/run_loop.h"
namespace ash {
using AutotestAmbientApiTest = AmbientAshTestBase;
TEST_F(AutotestAmbientApiTest,
ShouldSuccessfullyWaitForPhotoTransitionAnimation) {
AutotestAmbientApi test_api;
// Start ambient mode.
ambient_controller()->Toggle();
// Wait for 10 photo transition animation to complete.
base::RunLoop run_loop;
test_api.WaitForPhotoTransitionAnimationCompleted(
/*refresh_interval_s=*/2,
/*num_completions=*/10, run_loop.QuitClosure());
run_loop.Run();
}
} // namespace ash
...@@ -6,11 +6,18 @@ ...@@ -6,11 +6,18 @@
#define ASH_AMBIENT_UI_AMBIENT_VIEW_DELEGATE_H_ #define ASH_AMBIENT_UI_AMBIENT_VIEW_DELEGATE_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/observer_list_types.h"
namespace ash { namespace ash {
class AmbientBackendModel; class AmbientBackendModel;
class ASH_EXPORT AmbientViewDelegateObserver : public base::CheckedObserver {
public:
// Invoked when the photo transition animation completed.
virtual void OnPhotoTransitionAnimationCompleted() = 0;
};
class ASH_EXPORT AmbientViewDelegate { class ASH_EXPORT AmbientViewDelegate {
public: public:
virtual ~AmbientViewDelegate() = default; virtual ~AmbientViewDelegate() = default;
...@@ -23,6 +30,9 @@ class ASH_EXPORT AmbientViewDelegate { ...@@ -23,6 +30,9 @@ class ASH_EXPORT AmbientViewDelegate {
// Invoked when user interacting with the background photo using mouse, // Invoked when user interacting with the background photo using mouse,
// touchpad, or touchscreen. // touchpad, or touchscreen.
virtual void OnBackgroundPhotoEvents() = 0; virtual void OnBackgroundPhotoEvents() = 0;
// Invoked when the photo transition animation completed.
virtual void OnPhotoTransitionAnimationCompleted() = 0;
}; };
} // namespace ash } // namespace ash
......
...@@ -169,6 +169,7 @@ void PhotoView::OnImplicitAnimationsCompleted() { ...@@ -169,6 +169,7 @@ void PhotoView::OnImplicitAnimationsCompleted() {
// same time. // same time.
this->layer()->SetTransform(gfx::Transform()); this->layer()->SetTransform(gfx::Transform());
UpdateImages(); UpdateImages();
delegate_->OnPhotoTransitionAnimationCompleted();
} }
bool PhotoView::NeedToAnimateTransition() const { bool PhotoView::NeedToAnimateTransition() const {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_PUBLIC_CPP_AUTOTEST_AMBIENT_API_H_
#define ASH_PUBLIC_CPP_AUTOTEST_AMBIENT_API_H_
#include "ash/ash_export.h"
#include "base/callback_forward.h"
namespace ash {
// Exposes limited API for the autotest private APIs to interact with Ambient
// mode.
class ASH_EXPORT AutotestAmbientApi {
public:
AutotestAmbientApi();
AutotestAmbientApi(const AutotestAmbientApi&) = delete;
AutotestAmbientApi& operator=(const AutotestAmbientApi&) = delete;
~AutotestAmbientApi();
// Wait for the photo transition animation completes |num_completions| times.
// |refresh_interval_s| is the photo refresh interval.
void WaitForPhotoTransitionAnimationCompleted(int refresh_interval_s,
int num_completions,
base::OnceClosure on_complete);
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_AUTOTEST_AMBIENT_API_H_
...@@ -12,10 +12,12 @@ ...@@ -12,10 +12,12 @@
#include <utility> #include <utility>
#include "ash/public/cpp/accelerators.h" #include "ash/public/cpp/accelerators.h"
#include "ash/public/cpp/ambient/ambient_mode_state.h"
#include "ash/public/cpp/app_list/app_list_types.h" #include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/cpp/app_types.h" #include "ash/public/cpp/app_types.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/assistant/assistant_client.h" #include "ash/public/cpp/assistant/assistant_client.h"
#include "ash/public/cpp/autotest_ambient_api.h"
#include "ash/public/cpp/autotest_desks_api.h" #include "ash/public/cpp/autotest_desks_api.h"
#include "ash/public/cpp/autotest_private_api_utils.h" #include "ash/public/cpp/autotest_private_api_utils.h"
#include "ash/public/cpp/default_frame_header.h" #include "ash/public/cpp/default_frame_header.h"
...@@ -4448,6 +4450,55 @@ AutotestPrivateStopSmoothnessTrackingFunction::Run() { ...@@ -4448,6 +4450,55 @@ AutotestPrivateStopSmoothnessTrackingFunction::Run() {
return RespondNow(OneArgument(std::make_unique<base::Value>(smoothness))); return RespondNow(OneArgument(std::make_unique<base::Value>(smoothness)));
} }
///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateWaitForAmbientPhotoAnimationFunction
//////////////////////////////////////////////////////////////////////////////
AutotestPrivateWaitForAmbientPhotoAnimationFunction::
AutotestPrivateWaitForAmbientPhotoAnimationFunction() = default;
AutotestPrivateWaitForAmbientPhotoAnimationFunction::
~AutotestPrivateWaitForAmbientPhotoAnimationFunction() = default;
ExtensionFunction::ResponseAction
AutotestPrivateWaitForAmbientPhotoAnimationFunction::Run() {
std::unique_ptr<api::autotest_private::WaitForAmbientPhotoAnimation::Params>
params(
api::autotest_private::WaitForAmbientPhotoAnimation::Params::Create(
*args_));
EXTENSION_FUNCTION_VALIDATE(params);
// Wait for photo transition animation completed in ambient mode.
ash::AutotestAmbientApi().WaitForPhotoTransitionAnimationCompleted(
params->photo_refresh_interval, params->num_completions,
base::BindOnce(&AutotestPrivateWaitForAmbientPhotoAnimationFunction::
OnPhotoTransitionAnimationCompleted,
this));
// Set up a timer to finish waiting after |timeout_s|.
timeout_timer_.Start(
FROM_HERE, base::TimeDelta::FromSeconds(params->timeout),
base::BindOnce(
&AutotestPrivateWaitForAmbientPhotoAnimationFunction::Timeout, this));
return did_respond() ? AlreadyResponded() : RespondLater();
}
void AutotestPrivateWaitForAmbientPhotoAnimationFunction::
OnPhotoTransitionAnimationCompleted() {
if (did_respond())
return;
Respond(NoArguments());
}
void AutotestPrivateWaitForAmbientPhotoAnimationFunction::Timeout() {
if (did_respond())
return;
Respond(Error("No enough animations completed before time out."));
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateAPI // AutotestPrivateAPI
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
......
...@@ -1244,6 +1244,27 @@ class AutotestPrivateStopSmoothnessTrackingFunction : public ExtensionFunction { ...@@ -1244,6 +1244,27 @@ class AutotestPrivateStopSmoothnessTrackingFunction : public ExtensionFunction {
ResponseAction Run() override; ResponseAction Run() override;
}; };
class AutotestPrivateWaitForAmbientPhotoAnimationFunction
: public ExtensionFunction {
public:
AutotestPrivateWaitForAmbientPhotoAnimationFunction();
DECLARE_EXTENSION_FUNCTION("autotestPrivate.waitForAmbientPhotoAnimation",
AUTOTESTPRIVATE_WAITFORAMBIENTPHOTOANIMATION)
private:
~AutotestPrivateWaitForAmbientPhotoAnimationFunction() override;
ResponseAction Run() override;
// Called when photo transition animations completed.
void OnPhotoTransitionAnimationCompleted();
// Called when photo transition animations fail to finish in a certain amount
// of time. We will respond with an error.
void Timeout();
base::OneShotTimer timeout_timer_;
};
template <> template <>
KeyedService* KeyedService*
BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor( BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor(
......
...@@ -1024,6 +1024,17 @@ namespace autotestPrivate { ...@@ -1024,6 +1024,17 @@ namespace autotestPrivate {
// the display specified by the display id is used. // the display specified by the display id is used.
static void stopSmoothnessTracking(optional DOMString displayId, static void stopSmoothnessTracking(optional DOMString displayId,
StopSmoothnessTrackingCallback callback); StopSmoothnessTrackingCallback callback);
// Waits for the completion of photo transition animation in ambient mode.
// |photoRefreshInterval|: photo refresh interval in seconds.
// |numCompletions|: number of completions of the animation.
// |timeout|: the timeout in seconds.
// |callback|: Called when the operation has completed.
static void waitForAmbientPhotoAnimation(
long photoRefreshInterval,
long numCompletions,
long timeout,
VoidCallback callback);
}; };
interface Events { interface Events {
......
...@@ -1538,6 +1538,7 @@ enum HistogramValue { ...@@ -1538,6 +1538,7 @@ enum HistogramValue {
AUTOTESTPRIVATE_SHOWPLUGINVMINSTALLER = 1475, AUTOTESTPRIVATE_SHOWPLUGINVMINSTALLER = 1475,
PASSWORDSPRIVATE_REMOVESAVEDPASSWORDS = 1476, PASSWORDSPRIVATE_REMOVESAVEDPASSWORDS = 1476,
PASSWORDSPRIVATE_REMOVEPASSWORDEXCEPTIONS = 1477, PASSWORDSPRIVATE_REMOVEPASSWORDEXCEPTIONS = 1477,
AUTOTESTPRIVATE_WAITFORAMBIENTPHOTOANIMATION = 1478,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -23014,6 +23014,7 @@ Called by update_extension_histograms.py.--> ...@@ -23014,6 +23014,7 @@ Called by update_extension_histograms.py.-->
<int value="1475" label="AUTOTESTPRIVATE_SHOWPLUGINVMINSTALLER"/> <int value="1475" label="AUTOTESTPRIVATE_SHOWPLUGINVMINSTALLER"/>
<int value="1476" label="PASSWORDSPRIVATE_REMOVESAVEDPASSWORDS"/> <int value="1476" label="PASSWORDSPRIVATE_REMOVESAVEDPASSWORDS"/>
<int value="1477" label="PASSWORDSPRIVATE_REMOVEPASSWORDEXCEPTIONS"/> <int value="1477" label="PASSWORDSPRIVATE_REMOVEPASSWORDEXCEPTIONS"/>
<int value="1478" label="AUTOTESTPRIVATE_WAITFORAMBIENTPHOTOANIMATION"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
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