Commit e841acfe authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

Revert "ambient: support multiple displays"

This reverts commit 6d681c88.

Reason for revert: Causing test failures on MSAN builds:

https://ci.chromium.org/p/chromium/builders/ci/Linux%20ChromiumOS%20MSan%20Tests/21346

Original change's description:
> ambient: support multiple displays
>
> Run ambient mode UI on each connected display.
> RootWindowController construction handles adding ambient widgets
> to new displays while ambient mode is running, and destructing them
> on display removed.
>
> BUG=b:139953389
>
> Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
> Change-Id: Ic57c33491098b66c7c0e90ef1f3d12c71f1fc303
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2516968
> Commit-Queue: Jeffrey Young <cowmoo@chromium.org>
> Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
> Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
> Reviewed-by: Tao Wu <wutao@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#828329}

TBR=oshima@chromium.org,xiaohuic@chromium.org,wutao@chromium.org,cowmoo@chromium.org

Change-Id: I255333ed722549fdc9d0e945c65cf3f742b1cabc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b:139953389
Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2545752Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828486}
parent b32e1d46
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector>
#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"
...@@ -23,7 +22,6 @@ ...@@ -23,7 +22,6 @@
#include "ash/public/cpp/ambient/fake_ambient_backend_controller_impl.h" #include "ash/public/cpp/ambient/fake_ambient_backend_controller_impl.h"
#include "ash/public/cpp/assistant/controller/assistant_ui_controller.h" #include "ash/public/cpp/assistant/controller/assistant_ui_controller.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/power/power_status.h" #include "ash/system/power/power_status.h"
...@@ -46,6 +44,7 @@ ...@@ -46,6 +44,7 @@
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/base/user_activity/user_activity_detector.h" #include "ui/base/user_activity/user_activity_detector.h"
#include "ui/events/types/event_type.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
#include "ui/wm/core/cursor_manager.h" #include "ui/wm/core/cursor_manager.h"
...@@ -77,6 +76,11 @@ std::unique_ptr<AmbientBackendController> CreateAmbientBackendController() { ...@@ -77,6 +76,11 @@ std::unique_ptr<AmbientBackendController> CreateAmbientBackendController() {
#endif // BUILDFLAG(ENABLE_CROS_AMBIENT_MODE_BACKEND) #endif // BUILDFLAG(ENABLE_CROS_AMBIENT_MODE_BACKEND)
} }
aura::Window* GetWidgetContainer() {
return Shell::GetContainer(Shell::GetPrimaryRootWindow(),
kShellWindowId_AmbientModeContainer);
}
// Returns the name of the ambient widget. // Returns the name of the ambient widget.
std::string GetWidgetName() { std::string GetWidgetName() {
if (ambient::util::IsShowing(LockScreen::ScreenType::kLock)) if (ambient::util::IsShowing(LockScreen::ScreenType::kLock))
...@@ -186,7 +190,10 @@ AmbientController::AmbientController( ...@@ -186,7 +190,10 @@ AmbientController::AmbientController(
fingerprint_observer_receiver_.BindNewPipeAndPassRemote()); fingerprint_observer_receiver_.BindNewPipeAndPassRemote());
} }
AmbientController::~AmbientController() = default; AmbientController::~AmbientController() {
if (container_view_)
container_view_->GetWidget()->CloseNow();
}
void AmbientController::OnAmbientUiVisibilityChanged( void AmbientController::OnAmbientUiVisibilityChanged(
AmbientUiVisibility visibility) { AmbientUiVisibility visibility) {
...@@ -221,7 +228,7 @@ void AmbientController::OnAmbientUiVisibilityChanged( ...@@ -221,7 +228,7 @@ void AmbientController::OnAmbientUiVisibilityChanged(
break; break;
case AmbientUiVisibility::kHidden: case AmbientUiVisibility::kHidden:
case AmbientUiVisibility::kClosed: case AmbientUiVisibility::kClosed:
CloseAllWidgets(/*immediately=*/false); CloseWidget(/*immediately=*/false);
// TODO(wutao): This will clear the image cache currently. It will not // TODO(wutao): This will clear the image cache currently. It will not
// work with `kHidden` if the token has expired and ambient mode is shown // work with `kHidden` if the token has expired and ambient mode is shown
...@@ -279,6 +286,7 @@ void AmbientController::OnAmbientUiVisibilityChanged( ...@@ -279,6 +286,7 @@ void AmbientController::OnAmbientUiVisibilityChanged(
void AmbientController::OnAutoShowTimeOut() { void AmbientController::OnAutoShowTimeOut() {
DCHECK(IsUiHidden(ambient_ui_model_.ui_visibility())); DCHECK(IsUiHidden(ambient_ui_model_.ui_visibility()));
DCHECK(!container_view_);
// Show ambient screen after time out. // Show ambient screen after time out.
ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kShown); ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kShown);
...@@ -380,6 +388,48 @@ void AmbientController::OnPowerStatusChanged() { ...@@ -380,6 +388,48 @@ void AmbientController::OnPowerStatusChanged() {
} }
} }
void AmbientController::ScreenBrightnessChanged(
const power_manager::BacklightBrightnessChange& change) {
DVLOG(1) << "ScreenBrightnessChanged: "
<< (change.has_percent() ? change.percent() : -1);
if (!change.has_percent())
return;
constexpr double kMinBrightness = 0.01;
if (change.percent() < kMinBrightness) {
if (is_screen_off_)
return;
DVLOG(1) << "Screen is off, close ambient mode.";
is_screen_off_ = true;
// If screen is off, turn everything off. This covers:
// 1. Manually turn screen off.
// 2. Clicking tablet power button.
// 3. Close lid.
// Need to specially close the widget immediately here to be able to close
// the UI before device goes to suspend. Otherwise when opening lid after
// lid closed, there may be a flash of the old window before previous
// closing finished.
CloseWidget(/*immediately=*/true);
CloseUi();
return;
}
// change.percent() > kMinBrightness
if (!is_screen_off_)
return;
is_screen_off_ = false;
// Reset image failures to allow retrying ambient mode because screen has
// turned back on.
GetAmbientBackendModel()->ResetImageFailures();
// If screen is back on, turn on ambient mode for lock screen.
if (LockScreen::HasInstance())
ShowHiddenUi();
}
void AmbientController::ScreenIdleStateChanged( void AmbientController::ScreenIdleStateChanged(
const power_manager::ScreenIdleState& idle_state) { const power_manager::ScreenIdleState& idle_state) {
DVLOG(1) << "ScreenIdleStateChanged: dimmed(" << idle_state.dimmed() DVLOG(1) << "ScreenIdleStateChanged: dimmed(" << idle_state.dimmed()
...@@ -388,48 +438,25 @@ void AmbientController::ScreenIdleStateChanged( ...@@ -388,48 +438,25 @@ void AmbientController::ScreenIdleStateChanged(
if (!IsAmbientModeEnabled()) if (!IsAmbientModeEnabled())
return; return;
if (idle_state.off()) { // "off" state should already be handled by the screen brightness handler.
DVLOG(1) << "Screen is off, close ambient mode."; if (idle_state.off())
CloseAllWidgets(/*immediately=*/true);
CloseUi();
return; return;
}
if (idle_state.dimmed()) { if (!idle_state.dimmed())
// Do not show the UI if lockscreen is active. The inactivity monitor should return;
// have activated ambient mode.
if (LockScreen::HasInstance())
return;
// Do not show UI if loading images was unsuccessful.
if (GetAmbientBackendModel()->ImageLoadingFailed()) {
VLOG(1) << "Skipping ambient mode activation due to prior failure";
return;
}
ShowUi(); // Do not show the UI if lockscreen is active. The inactivity monitor should
// have activated ambient mode.
if (LockScreen::HasInstance())
return; return;
}
if (LockScreen::HasInstance() && // Do not show UI if loading images was unsuccessful.
ambient_ui_model_.ui_visibility() == AmbientUiVisibility::kClosed) { if (GetAmbientBackendModel()->ImageLoadingFailed()) {
// Restart hidden ui if the screen is back on and lockscreen is shown. VLOG(1) << "Skipping ambient mode activation due to prior failure";
ShowHiddenUi(); return;
} }
}
void AmbientController::SuspendImminent( ShowUi();
power_manager::SuspendImminent::Reason reason) {
// If about to suspend, turn everything off. This covers:
// 1. Clicking power button.
// 2. Close lid.
// Need to specially close the widget immediately here to be able to close
// the UI before device goes to suspend. Otherwise when opening lid after
// lid closed, there may be a flash of the old window before previous
// closing finished.
CloseAllWidgets(/*immediately=*/true);
CloseUi();
} }
void AmbientController::OnAuthScanDone( void AmbientController::OnAuthScanDone(
...@@ -480,7 +507,6 @@ void AmbientController::CloseUi() { ...@@ -480,7 +507,6 @@ void AmbientController::CloseUi() {
DVLOG(1) << __func__; DVLOG(1) << __func__;
ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kClosed); ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kClosed);
GetAmbientBackendModel()->ResetImageFailures();
} }
void AmbientController::ToggleInSessionUi() { void AmbientController::ToggleInSessionUi() {
...@@ -491,7 +517,7 @@ void AmbientController::ToggleInSessionUi() { ...@@ -491,7 +517,7 @@ void AmbientController::ToggleInSessionUi() {
} }
bool AmbientController::IsShown() const { bool AmbientController::IsShown() const {
return ambient_ui_model_.ui_visibility() == AmbientUiVisibility::kShown; return container_view_ && container_view_->IsDrawn();
} }
void AmbientController::AcquireWakeLock() { void AmbientController::AcquireWakeLock() {
...@@ -532,11 +558,16 @@ void AmbientController::ReleaseWakeLock() { ...@@ -532,11 +558,16 @@ void AmbientController::ReleaseWakeLock() {
delayed_lock_timer_.Stop(); delayed_lock_timer_.Stop();
} }
void AmbientController::CloseAllWidgets(bool immediately) { void AmbientController::CloseWidget(bool immediately) {
for (auto* root_window_controller : if (!container_view_)
RootWindowController::root_window_controllers()) { return;
root_window_controller->CloseAmbientWidget(immediately);
} if (immediately)
container_view_->GetWidget()->CloseNow();
else
container_view_->GetWidget()->Close();
container_view_ = nullptr;
} }
void AmbientController::OnLockScreenInactivityTimeoutPrefChanged() { void AmbientController::OnLockScreenInactivityTimeoutPrefChanged() {
...@@ -600,7 +631,7 @@ AmbientBackendModel* AmbientController::GetAmbientBackendModel() { ...@@ -600,7 +631,7 @@ AmbientBackendModel* AmbientController::GetAmbientBackendModel() {
} }
void AmbientController::OnImagesReady() { void AmbientController::OnImagesReady() {
CreateAndShowWidgets(); CreateAndShowWidget();
} }
void AmbientController::OnImagesFailed() { void AmbientController::OnImagesFailed() {
...@@ -608,24 +639,27 @@ void AmbientController::OnImagesFailed() { ...@@ -608,24 +639,27 @@ void AmbientController::OnImagesFailed() {
CloseUi(); CloseUi();
} }
std::unique_ptr<views::Widget> AmbientController::CreateWidget( std::unique_ptr<AmbientContainerView> AmbientController::CreateContainerView() {
aura::Window* container) { DCHECK(!container_view_);
auto container_view = std::make_unique<AmbientContainerView>(&delegate_);
auto* widget_delegate = new AmbientWidgetDelegate(); auto container = std::make_unique<AmbientContainerView>(&delegate_);
widget_delegate->SetInitiallyFocusedView(container_view.get()); container_view_ = container.get();
return container;
}
void AmbientController::CreateAndShowWidget() {
DCHECK(!container_view_);
views::Widget::InitParams params; views::Widget::InitParams params;
params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
params.name = GetWidgetName(); params.name = GetWidgetName();
params.show_state = ui::SHOW_STATE_FULLSCREEN; params.show_state = ui::SHOW_STATE_FULLSCREEN;
params.parent = container; params.parent = GetWidgetContainer();
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.delegate = new AmbientWidgetDelegate();
params.delegate = widget_delegate;
params.visible_on_all_workspaces = true;
auto widget = std::make_unique<views::Widget>(); views::Widget* widget = new views::Widget;
widget->Init(std::move(params)); widget->Init(std::move(params));
widget->SetContentsView(std::move(container_view)); widget->SetContentsView(CreateContainerView());
widget->SetVisibilityAnimationTransition( widget->SetVisibilityAnimationTransition(
views::Widget::VisibilityTransition::ANIMATE_BOTH); views::Widget::VisibilityTransition::ANIMATE_BOTH);
...@@ -635,16 +669,11 @@ std::unique_ptr<views::Widget> AmbientController::CreateWidget( ...@@ -635,16 +669,11 @@ std::unique_ptr<views::Widget> AmbientController::CreateWidget(
widget->Show(); widget->Show();
return widget;
}
void AmbientController::CreateAndShowWidgets() {
// Hide cursor. // Hide cursor.
Shell::Get()->cursor_manager()->HideCursor(); Shell::Get()->cursor_manager()->HideCursor();
for (auto* root_window_controller :
RootWindowController::root_window_controllers()) { // Requests keyboard focus for |container_view_| to receive keyboard events.
root_window_controller->CreateAmbientWidget(); container_view_->RequestFocus();
}
} }
void AmbientController::StartRefreshingImages() { void AmbientController::StartRefreshingImages() {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define ASH_AMBIENT_AMBIENT_CONTROLLER_H_ #define ASH_AMBIENT_AMBIENT_CONTROLLER_H_
#include <memory> #include <memory>
#include <vector>
#include "ash/ambient/ambient_access_token_controller.h" #include "ash/ambient/ambient_access_token_controller.h"
#include "ash/ambient/ambient_photo_controller.h" #include "ash/ambient/ambient_photo_controller.h"
...@@ -71,9 +70,10 @@ class ASH_EXPORT AmbientController ...@@ -71,9 +70,10 @@ class ASH_EXPORT AmbientController
void OnPowerStatusChanged() override; void OnPowerStatusChanged() override;
// chromeos::PowerManagerClient::Observer: // chromeos::PowerManagerClient::Observer:
void ScreenBrightnessChanged(
const power_manager::BacklightBrightnessChange& change) override;
void ScreenIdleStateChanged( void ScreenIdleStateChanged(
const power_manager::ScreenIdleState& idle_state) override; const power_manager::ScreenIdleState& idle_state) override;
void SuspendImminent(power_manager::SuspendImminent::Reason reason) override;
// fingerprint::mojom::FingerprintObserver: // fingerprint::mojom::FingerprintObserver:
void OnAuthScanDone( void OnAuthScanDone(
...@@ -100,17 +100,13 @@ class ASH_EXPORT AmbientController ...@@ -100,17 +100,13 @@ class ASH_EXPORT AmbientController
void ToggleInSessionUi(); void ToggleInSessionUi();
// Returns true if ambient mode containers are visible or are being // Returns true if the |container_view_| is currently visible.
// constructed.
bool IsShown() const; bool IsShown() const;
void RequestAccessToken( void RequestAccessToken(
AmbientAccessTokenController::AccessTokenCallback callback, AmbientAccessTokenController::AccessTokenCallback callback,
bool may_refresh_token_on_lock = false); bool may_refresh_token_on_lock = false);
// Creates a widget and |AmbientContainerView| for the container.
std::unique_ptr<views::Widget> CreateWidget(aura::Window* container);
AmbientBackendModel* GetAmbientBackendModel(); AmbientBackendModel* GetAmbientBackendModel();
AmbientBackendController* ambient_backend_controller() { AmbientBackendController* ambient_backend_controller() {
...@@ -133,9 +129,14 @@ class ASH_EXPORT AmbientController ...@@ -133,9 +129,14 @@ class ASH_EXPORT AmbientController
void OnImagesReady() override; void OnImagesReady() override;
void OnImagesFailed() override; void OnImagesFailed() override;
// Creates and shows a full-screen widget for each root window to show the // Initializes the |container_view_|. Called in |CreateWidget()| to create the
// ambient UI. // contents view.
void CreateAndShowWidgets(); std::unique_ptr<AmbientContainerView> CreateContainerView();
// TODO(meilinw): reuses the lock-screen widget: b/156531168, b/157175030.
// Creates and shows a full-screen widget responsible for showing
// the ambient UI.
void CreateAndShowWidget();
void StartRefreshingImages(); void StartRefreshingImages();
void StopRefreshingImages(); void StopRefreshingImages();
...@@ -154,17 +155,24 @@ class ASH_EXPORT AmbientController ...@@ -154,17 +155,24 @@ class ASH_EXPORT AmbientController
// Release |wake_lock_|. Unbalanced release call will have no effect. // Release |wake_lock_|. Unbalanced release call will have no effect.
void ReleaseWakeLock(); void ReleaseWakeLock();
void CloseAllWidgets(bool immediately); void CloseWidget(bool immediately);
// Invoked when the Ambient mode prefs state changes. // Invoked when the Ambient mode prefs state changes.
void OnLockScreenInactivityTimeoutPrefChanged(); void OnLockScreenInactivityTimeoutPrefChanged();
void OnLockScreenBackgroundTimeoutPrefChanged(); void OnLockScreenBackgroundTimeoutPrefChanged();
void OnPhotoRefreshIntervalPrefChanged(); void OnPhotoRefreshIntervalPrefChanged();
AmbientContainerView* get_container_view_for_testing() {
return container_view_;
}
AmbientAccessTokenController* access_token_controller_for_testing() { AmbientAccessTokenController* access_token_controller_for_testing() {
return &access_token_controller_; return &access_token_controller_;
} }
// Owned by |RootView| of its parent widget.
AmbientContainerView* container_view_ = nullptr;
AmbientViewDelegateImpl delegate_{this}; AmbientViewDelegateImpl delegate_{this};
AmbientUiModel ambient_ui_model_; AmbientUiModel ambient_ui_model_;
...@@ -192,6 +200,8 @@ class ASH_EXPORT AmbientController ...@@ -192,6 +200,8 @@ class ASH_EXPORT AmbientController
ScopedObserver<ui::UserActivityDetector, ui::UserActivityObserver> ScopedObserver<ui::UserActivityDetector, ui::UserActivityObserver>
user_activity_observer_{this}; user_activity_observer_{this};
bool is_screen_off_ = false;
// Observes user profile prefs for ambient. // Observes user profile prefs for ambient.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "ash/ambient/test/ambient_ash_test_base.h" #include "ash/ambient/test/ambient_ash_test_base.h"
#include "ash/ambient/ui/ambient_container_view.h" #include "ash/ambient/ui/ambient_container_view.h"
#include "ash/public/cpp/ambient/ambient_ui_model.h" #include "ash/public/cpp/ambient/ambient_ui_model.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/power/power_status.h" #include "ash/system/power/power_status.h"
#include "base/run_loop.h" #include "base/run_loop.h"
...@@ -40,14 +39,6 @@ class AmbientControllerTest : public AmbientAshTestBase { ...@@ -40,14 +39,6 @@ class AmbientControllerTest : public AmbientAshTestBase {
AmbientAshTestBase::SetUp(); AmbientAshTestBase::SetUp();
GetSessionControllerClient()->set_show_lock_screen_views(true); GetSessionControllerClient()->set_show_lock_screen_views(true);
} }
bool WidgetsVisible() {
const auto& views = GetContainerViews();
return views.size() > 0 &&
std::all_of(views.cbegin(), views.cend(), [](const auto* view) {
return view->GetWidget()->IsVisible();
});
}
}; };
TEST_F(AmbientControllerTest, ShowAmbientScreenUponLock) { TEST_F(AmbientControllerTest, ShowAmbientScreenUponLock) {
...@@ -60,7 +51,7 @@ TEST_F(AmbientControllerTest, ShowAmbientScreenUponLock) { ...@@ -60,7 +51,7 @@ TEST_F(AmbientControllerTest, ShowAmbientScreenUponLock) {
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_FALSE(GetContainerViews().empty()); EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(), EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown); AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
...@@ -82,7 +73,7 @@ TEST_F(AmbientControllerTest, NotShowAmbientWhenPrefNotEnabled) { ...@@ -82,7 +73,7 @@ TEST_F(AmbientControllerTest, NotShowAmbientWhenPrefNotEnabled) {
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_TRUE(GetContainerViews().empty()); EXPECT_FALSE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(), EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed); AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
...@@ -97,15 +88,14 @@ TEST_F(AmbientControllerTest, HideAmbientScreen) { ...@@ -97,15 +88,14 @@ TEST_F(AmbientControllerTest, HideAmbientScreen) {
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_FALSE(GetContainerViews().empty()); EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(), EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown); AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
HideAmbientScreen(); HideAmbientScreen();
FastForwardTiny(); EXPECT_FALSE(container_view());
EXPECT_TRUE(GetContainerViews().empty());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(), EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kHidden); AmbientUiVisibility::kHidden);
...@@ -119,7 +109,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) { ...@@ -119,7 +109,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) {
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_FALSE(GetContainerViews().empty()); EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(), EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown); AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
...@@ -130,8 +120,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) { ...@@ -130,8 +120,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) {
AmbientUiVisibility::kClosed); AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget. // The view should be destroyed along the widget.
FastForwardTiny(); EXPECT_FALSE(container_view());
EXPECT_TRUE(GetContainerViews().empty());
} }
TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) { TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) {
...@@ -144,7 +133,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) { ...@@ -144,7 +133,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) {
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_FALSE(GetContainerViews().empty()); EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(), EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown); AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
...@@ -154,8 +143,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) { ...@@ -154,8 +143,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) {
AmbientUiVisibility::kClosed); AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget. // The view should be destroyed along the widget.
FastForwardTiny(); EXPECT_FALSE(container_view());
EXPECT_TRUE(GetContainerViews().empty());
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
...@@ -163,8 +151,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) { ...@@ -163,8 +151,7 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) {
AmbientUiVisibility::kClosed); AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget. // The view should be destroyed along the widget.
FastForwardTiny(); EXPECT_FALSE(container_view());
EXPECT_TRUE(GetContainerViews().empty());
} }
TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) { TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) {
...@@ -177,7 +164,7 @@ TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) { ...@@ -177,7 +164,7 @@ TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) {
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_FALSE(GetContainerViews().empty()); EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(), EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown); AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
...@@ -191,8 +178,7 @@ TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) { ...@@ -191,8 +178,7 @@ TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) {
AmbientUiVisibility::kClosed); AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget. // The view should be destroyed along the widget.
FastForwardTiny(); EXPECT_FALSE(container_view());
EXPECT_TRUE(GetContainerViews().empty());
LockScreen(); LockScreen();
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
...@@ -202,7 +188,7 @@ TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) { ...@@ -202,7 +188,7 @@ TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) {
AmbientUiVisibility::kClosed); AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget. // The view should be destroyed along the widget.
EXPECT_TRUE(GetContainerViews().empty()); EXPECT_FALSE(container_view());
} }
TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) { TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) {
...@@ -486,12 +472,11 @@ TEST_F(AmbientControllerTest, ShouldDismissContainerViewOnEvents) { ...@@ -486,12 +472,11 @@ TEST_F(AmbientControllerTest, ShouldDismissContainerViewOnEvents) {
for (const auto& event : events) { for (const auto& event : events) {
ShowAmbientScreen(); ShowAmbientScreen();
FastForwardTiny(); FastForwardTiny();
EXPECT_TRUE(WidgetsVisible()); EXPECT_TRUE(container_view()->GetWidget()->IsVisible());
ambient_controller()->OnUserActivity(event.get()); ambient_controller()->OnUserActivity(event.get());
FastForwardTiny(); EXPECT_FALSE(container_view());
EXPECT_TRUE(GetContainerViews().empty());
// Clean up. // Clean up.
CloseAmbientScreen(); CloseAmbientScreen();
...@@ -502,17 +487,16 @@ TEST_F(AmbientControllerTest, ShouldDismissAndThenComesBack) { ...@@ -502,17 +487,16 @@ TEST_F(AmbientControllerTest, ShouldDismissAndThenComesBack) {
LockScreen(); LockScreen();
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_TRUE(WidgetsVisible()); EXPECT_TRUE(container_view()->GetWidget()->IsVisible());
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::KeyboardCode::VKEY_1, ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::KeyboardCode::VKEY_1,
ui::EF_NONE); ui::EF_NONE);
ambient_controller()->OnUserActivity(&key_event); ambient_controller()->OnUserActivity(&key_event);
FastForwardTiny(); EXPECT_FALSE(container_view());
EXPECT_TRUE(GetContainerViews().empty());
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_TRUE(WidgetsVisible()); EXPECT_TRUE(container_view()->GetWidget()->IsVisible());
} }
TEST_F(AmbientControllerTest, TEST_F(AmbientControllerTest,
...@@ -524,6 +508,9 @@ TEST_F(AmbientControllerTest, ...@@ -524,6 +508,9 @@ TEST_F(AmbientControllerTest,
// Should enter ambient mode when the screen is dimmed. // Should enter ambient mode when the screen is dimmed.
SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false); SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false);
EXPECT_FALSE(IsLocked()); EXPECT_FALSE(IsLocked());
EXPECT_FALSE(ambient_controller()->IsShown());
FastForwardTiny();
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
FastForwardToLockScreen(); FastForwardToLockScreen();
...@@ -545,6 +532,7 @@ TEST_F(AmbientControllerTest, ...@@ -545,6 +532,7 @@ TEST_F(AmbientControllerTest,
// Should enter ambient mode when the screen is dimmed. // Should enter ambient mode when the screen is dimmed.
SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false); SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false);
EXPECT_FALSE(IsLocked()); EXPECT_FALSE(IsLocked());
EXPECT_FALSE(ambient_controller()->IsShown());
FastForwardTiny(); FastForwardTiny();
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
...@@ -573,11 +561,11 @@ TEST_F(AmbientControllerTest, ...@@ -573,11 +561,11 @@ TEST_F(AmbientControllerTest,
SetPowerStateDischarging(); SetPowerStateDischarging();
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
// Should not lock the device but still enter ambient mode when the screen is // Should not lock the device and enter ambient mode when the screen is
// dimmed. // dimmed.
SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false); SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false);
EXPECT_FALSE(IsLocked()); EXPECT_FALSE(IsLocked());
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
...@@ -616,6 +604,7 @@ TEST_F(AmbientControllerTest, ShouldHideAmbientScreenWhenDisplayIsOff) { ...@@ -616,6 +604,7 @@ TEST_F(AmbientControllerTest, ShouldHideAmbientScreenWhenDisplayIsOff) {
// Should not lock the device and enter ambient mode when the screen is // Should not lock the device and enter ambient mode when the screen is
// dimmed. // dimmed.
SetScreenBrightnessAndWait(/*percent=*/50);
SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false); SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false);
EXPECT_FALSE(IsLocked()); EXPECT_FALSE(IsLocked());
...@@ -623,11 +612,13 @@ TEST_F(AmbientControllerTest, ShouldHideAmbientScreenWhenDisplayIsOff) { ...@@ -623,11 +612,13 @@ TEST_F(AmbientControllerTest, ShouldHideAmbientScreenWhenDisplayIsOff) {
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
// Should dismiss ambient mode screen. // Should dismiss ambient mode screen.
SetScreenBrightnessAndWait(/*percent=*/0);
SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/true); SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/true);
FastForwardTiny(); FastForwardTiny();
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
// Screen back on again, should not have ambient screen. // Screen back on again, should not have ambient screen.
SetScreenBrightnessAndWait(/*percent=*/50);
SetScreenIdleStateAndWait(/*dimmed=*/false, /*off=*/false); SetScreenIdleStateAndWait(/*dimmed=*/false, /*off=*/false);
FastForwardTiny(); FastForwardTiny();
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
...@@ -641,6 +632,7 @@ TEST_F(AmbientControllerTest, ...@@ -641,6 +632,7 @@ TEST_F(AmbientControllerTest,
// Should not lock the device and enter ambient mode when the screen is // Should not lock the device and enter ambient mode when the screen is
// dimmed. // dimmed.
SetScreenBrightnessAndWait(/*percent=*/50);
SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false); SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false);
EXPECT_FALSE(IsLocked()); EXPECT_FALSE(IsLocked());
...@@ -652,6 +644,7 @@ TEST_F(AmbientControllerTest, ...@@ -652,6 +644,7 @@ TEST_F(AmbientControllerTest,
EXPECT_TRUE(IsLocked()); EXPECT_TRUE(IsLocked());
// Should dismiss ambient mode screen. // Should dismiss ambient mode screen.
SetScreenBrightnessAndWait(/*percent=*/0);
SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/true); SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/true);
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
...@@ -659,6 +652,7 @@ TEST_F(AmbientControllerTest, ...@@ -659,6 +652,7 @@ TEST_F(AmbientControllerTest,
// Screen back on again, should not have ambient screen, but still has lock // Screen back on again, should not have ambient screen, but still has lock
// screen. // screen.
SetScreenBrightnessAndWait(/*percent=*/50);
SetScreenIdleStateAndWait(/*dimmed=*/false, /*off=*/false); SetScreenIdleStateAndWait(/*dimmed=*/false, /*off=*/false);
EXPECT_TRUE(IsLocked()); EXPECT_TRUE(IsLocked());
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
...@@ -678,7 +672,7 @@ TEST_F(AmbientControllerTest, HideCursor) { ...@@ -678,7 +672,7 @@ TEST_F(AmbientControllerTest, HideCursor) {
FastForwardToLockScreenTimeout(); FastForwardToLockScreenTimeout();
FastForwardTiny(); FastForwardTiny();
EXPECT_FALSE(GetContainerViews().empty()); EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(), EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown); AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown()); EXPECT_TRUE(ambient_controller()->IsShown());
...@@ -689,76 +683,4 @@ TEST_F(AmbientControllerTest, HideCursor) { ...@@ -689,76 +683,4 @@ TEST_F(AmbientControllerTest, HideCursor) {
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
} }
TEST_F(AmbientControllerTest, ShowsOnMultipleDisplays) {
UpdateDisplay("800x600,800x600");
FastForwardTiny();
ShowAmbientScreen();
FastForwardToNextImage();
auto* screen = display::Screen::GetScreen();
EXPECT_EQ(screen->GetNumDisplays(), 2);
EXPECT_EQ(GetContainerViews().size(), 2u);
// Check that each root controller has an ambient widget.
for (auto* ctrl : RootWindowController::root_window_controllers())
EXPECT_TRUE(ctrl->ambient_widget_for_testing() &&
ctrl->ambient_widget_for_testing()->IsVisible());
}
TEST_F(AmbientControllerTest, RespondsToDisplayAdded) {
UpdateDisplay("800x600");
ShowAmbientScreen();
FastForwardToNextImage();
auto* screen = display::Screen::GetScreen();
EXPECT_EQ(screen->GetNumDisplays(), 1);
EXPECT_EQ(GetContainerViews().size(), 1u);
UpdateDisplay("800x600,800x600");
FastForwardTiny();
EXPECT_TRUE(WidgetsVisible());
EXPECT_EQ(screen->GetNumDisplays(), 2);
EXPECT_EQ(GetContainerViews().size(), 2u);
for (auto* ctrl : RootWindowController::root_window_controllers())
EXPECT_TRUE(ctrl->ambient_widget_for_testing() &&
ctrl->ambient_widget_for_testing()->IsVisible());
}
TEST_F(AmbientControllerTest, HandlesDisplayRemoved) {
UpdateDisplay("800x600,800x600");
FastForwardTiny();
ShowAmbientScreen();
FastForwardToNextImage();
auto* screen = display::Screen::GetScreen();
EXPECT_EQ(screen->GetNumDisplays(), 2);
EXPECT_EQ(GetContainerViews().size(), 2u);
EXPECT_TRUE(WidgetsVisible());
// Changing to one screen will destroy the widget on the non-primary screen.
UpdateDisplay("800x600");
FastForwardTiny();
EXPECT_EQ(screen->GetNumDisplays(), 1);
EXPECT_EQ(GetContainerViews().size(), 1u);
EXPECT_TRUE(WidgetsVisible());
}
TEST_F(AmbientControllerTest, ClosesAmbientBeforeSuspend) {
LockScreen();
FastForwardToLockScreenTimeout();
EXPECT_TRUE(ambient_controller()->IsShown());
SimulateSystemSuspendAndWait(power_manager::SuspendImminent::Reason::
SuspendImminent_Reason_LID_CLOSED);
EXPECT_FALSE(ambient_controller()->IsShown());
FastForwardToLockScreenTimeout();
// Ambient mode should not resume after suspend.
EXPECT_FALSE(ambient_controller()->IsShown());
}
} // namespace ash } // namespace ash
...@@ -20,13 +20,11 @@ ...@@ -20,13 +20,11 @@
#include "ash/public/cpp/ambient/ambient_prefs.h" #include "ash/public/cpp/ambient/ambient_prefs.h"
#include "ash/public/cpp/ambient/ambient_ui_model.h" #include "ash/public/cpp/ambient/ambient_ui_model.h"
#include "ash/public/cpp/ambient/fake_ambient_backend_controller_impl.h" #include "ash/public/cpp/ambient/fake_ambient_backend_controller_impl.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/threading/scoped_blocking_call.h" #include "base/threading/scoped_blocking_call.h"
...@@ -35,11 +33,9 @@ ...@@ -35,11 +33,9 @@
#include "chromeos/dbus/power/fake_power_manager_client.h" #include "chromeos/dbus/power/fake_power_manager_client.h"
#include "chromeos/dbus/power/power_manager_client.h" #include "chromeos/dbus/power/power_manager_client.h"
#include "chromeos/dbus/power_manager/idle.pb.h" #include "chromeos/dbus/power_manager/idle.pb.h"
#include "ui/display/screen.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_unittest_util.h" #include "ui/gfx/image/image_unittest_util.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/widget/widget.h"
namespace ash { namespace ash {
namespace { namespace {
...@@ -216,46 +212,36 @@ void AmbientAshTestBase::SetScreenIdleStateAndWait(bool is_screen_dimmed, ...@@ -216,46 +212,36 @@ void AmbientAshTestBase::SetScreenIdleStateAndWait(bool is_screen_dimmed,
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
std::vector<views::View*> void AmbientAshTestBase::SetScreenBrightnessAndWait(double percent) {
AmbientAshTestBase::GetMediaStringViewTextContainers() { power_manager::BacklightBrightnessChange change;
std::vector<views::View*> result; change.set_percent(percent);
for (auto* view : GetMediaStringViews())
result.push_back(view->media_text_container_for_testing()); chromeos::FakePowerManagerClient::Get()->SendScreenBrightnessChanged(change);
return result; base::RunLoop().RunUntilIdle();
} }
views::View* AmbientAshTestBase::GetMediaStringViewTextContainer() { views::View* AmbientAshTestBase::GetMediaStringViewTextContainer() {
return GetMediaStringView()->media_text_container_for_testing(); return GetMediaStringView()->media_text_container_for_testing();
} }
std::vector<views::Label*> AmbientAshTestBase::GetMediaStringViewTextLabels() {
std::vector<views::Label*> result;
for (auto* view : GetMediaStringViews())
result.push_back(view->media_text_label_for_testing());
return result;
}
views::Label* AmbientAshTestBase::GetMediaStringViewTextLabel() { views::Label* AmbientAshTestBase::GetMediaStringViewTextLabel() {
return GetMediaStringView()->media_text_label_for_testing(); return GetMediaStringView()->media_text_label_for_testing();
} }
void AmbientAshTestBase::SimulateMediaMetadataChanged( void AmbientAshTestBase::SimulateMediaMetadataChanged(
media_session::MediaMetadata metadata) { media_session::MediaMetadata metadata) {
for (auto* view : GetMediaStringViews()) GetMediaStringView()->MediaSessionMetadataChanged(metadata);
view->MediaSessionMetadataChanged(metadata);
} }
void AmbientAshTestBase::SimulateMediaPlaybackStateChanged( void AmbientAshTestBase::SimulateMediaPlaybackStateChanged(
media_session::mojom::MediaPlaybackState state) { media_session::mojom::MediaPlaybackState state) {
for (auto* media_string_view : GetMediaStringViews()) { // Creates media session info.
// Creates media session info. media_session::mojom::MediaSessionInfoPtr session_info(
media_session::mojom::MediaSessionInfoPtr session_info( media_session::mojom::MediaSessionInfo::New());
media_session::mojom::MediaSessionInfo::New()); session_info->playback_state = state;
session_info->playback_state = state;
// Simulate media session info changed.
// Simulate media session info changed. GetMediaStringView()->MediaSessionInfoChanged(std::move(session_info));
media_string_view->MediaSessionInfoChanged(std::move(session_info));
}
} }
void AmbientAshTestBase::SetPhotoViewImageSize(int width, int height) { void AmbientAshTestBase::SetPhotoViewImageSize(int width, int height) {
...@@ -265,36 +251,17 @@ void AmbientAshTestBase::SetPhotoViewImageSize(int width, int height) { ...@@ -265,36 +251,17 @@ void AmbientAshTestBase::SetPhotoViewImageSize(int width, int height) {
image_decoder->SetImageSize(width, height); image_decoder->SetImageSize(width, height);
} }
std::vector<AmbientBackgroundImageView*>
AmbientAshTestBase::GetAmbientBackgroundImageViews() {
std::vector<AmbientBackgroundImageView*> result;
for (auto* view : GetContainerViews()) {
auto* background_image_view =
view->GetViewByID(AmbientViewID::kAmbientBackgroundImageView);
result.push_back(
static_cast<AmbientBackgroundImageView*>(background_image_view));
}
return result;
}
AmbientBackgroundImageView* AmbientBackgroundImageView*
AmbientAshTestBase::GetAmbientBackgroundImageView() { AmbientAshTestBase::GetAmbientBackgroundImageView() {
return static_cast<AmbientBackgroundImageView*>( DCHECK(container_view());
GetContainerView()->GetViewByID(kAmbientBackgroundImageView)); return static_cast<AmbientBackgroundImageView*>(container_view()->GetViewByID(
} AmbientViewID::kAmbientBackgroundImageView));
std::vector<MediaStringView*> AmbientAshTestBase::GetMediaStringViews() {
std::vector<MediaStringView*> result;
for (auto* view : GetContainerViews()) {
auto* media_string_view = view->GetViewByID(kAmbientMediaStringView);
result.push_back(static_cast<MediaStringView*>(media_string_view));
}
return result;
} }
MediaStringView* AmbientAshTestBase::GetMediaStringView() { MediaStringView* AmbientAshTestBase::GetMediaStringView() {
DCHECK(container_view());
return static_cast<MediaStringView*>( return static_cast<MediaStringView*>(
GetContainerView()->GetViewByID(kAmbientMediaStringView)); container_view()->GetViewByID(AmbientViewID::kAmbientMediaStringView));
} }
void AmbientAshTestBase::FastForwardToLockScreenTimeout() { void AmbientAshTestBase::FastForwardToLockScreenTimeout() {
...@@ -400,30 +367,8 @@ AmbientPhotoController* AmbientAshTestBase::photo_controller() { ...@@ -400,30 +367,8 @@ AmbientPhotoController* AmbientAshTestBase::photo_controller() {
return ambient_controller()->ambient_photo_controller(); return ambient_controller()->ambient_photo_controller();
} }
std::vector<AmbientContainerView*> AmbientAshTestBase::GetContainerViews() { AmbientContainerView* AmbientAshTestBase::container_view() {
std::vector<AmbientContainerView*> result; return ambient_controller()->get_container_view_for_testing();
for (auto* ctrl : RootWindowController::root_window_controllers()) {
auto* widget = ctrl->ambient_widget_for_testing();
if (widget) {
auto* view = widget->GetContentsView();
DCHECK(view && view->GetID() == kAmbientContainerView);
result.push_back(static_cast<AmbientContainerView*>(view));
}
}
return result;
}
AmbientContainerView* AmbientAshTestBase::GetContainerView() {
auto* widget =
Shell::GetPrimaryRootWindowController()->ambient_widget_for_testing();
if (widget) {
auto* container_view = widget->GetContentsView();
DCHECK(container_view && container_view->GetID() == kAmbientContainerView);
return static_cast<AmbientContainerView*>(container_view);
}
return nullptr;
} }
AmbientAccessTokenController* AmbientAshTestBase::token_controller() { AmbientAccessTokenController* AmbientAshTestBase::token_controller() {
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector>
#include "ash/ambient/ambient_access_token_controller.h" #include "ash/ambient/ambient_access_token_controller.h"
#include "ash/ambient/ambient_controller.h" #include "ash/ambient/ambient_controller.h"
...@@ -15,7 +14,6 @@ ...@@ -15,7 +14,6 @@
#include "ash/ambient/ui/ambient_background_image_view.h" #include "ash/ambient/ui/ambient_background_image_view.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "services/media_session/public/mojom/media_session.mojom.h" #include "services/media_session/public/mojom/media_session.mojom.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace views { namespace views {
...@@ -66,16 +64,8 @@ class AmbientAshTestBase : public AshTestBase { ...@@ -66,16 +64,8 @@ class AmbientAshTestBase : public AshTestBase {
void SimulateSystemSuspendAndWait( void SimulateSystemSuspendAndWait(
power_manager::SuspendImminent::Reason reason); power_manager::SuspendImminent::Reason reason);
// Return all media string view text containers. There is one per display.
std::vector<views::View*> GetMediaStringViewTextContainers();
// Return the media string view text container for the ambient mode container
// on the default display.
views::View* GetMediaStringViewTextContainer(); views::View* GetMediaStringViewTextContainer();
// Return all media string view text labels. There is one per display.
std::vector<views::Label*> GetMediaStringViewTextLabels();
// Return the media string view text label for the ambient mode container on
// the default display.
views::Label* GetMediaStringViewTextLabel(); views::Label* GetMediaStringViewTextLabel();
// Simulates the system starting to resume. // Simulates the system starting to resume.
...@@ -86,6 +76,9 @@ class AmbientAshTestBase : public AshTestBase { ...@@ -86,6 +76,9 @@ class AmbientAshTestBase : public AshTestBase {
// Wait until the event has been processed. // Wait until the event has been processed.
void SetScreenIdleStateAndWait(bool is_screen_dimmed, bool is_off); void SetScreenIdleStateAndWait(bool is_screen_dimmed, bool is_off);
// Simulates a screen brightness changed event.
void SetScreenBrightnessAndWait(double percent);
void SimulateMediaMetadataChanged(media_session::MediaMetadata metadata); void SimulateMediaMetadataChanged(media_session::MediaMetadata metadata);
void SimulateMediaPlaybackStateChanged( void SimulateMediaPlaybackStateChanged(
...@@ -127,24 +120,17 @@ class AmbientAshTestBase : public AshTestBase { ...@@ -127,24 +120,17 @@ class AmbientAshTestBase : public AshTestBase {
base::TimeDelta GetRefreshTokenDelay(); base::TimeDelta GetRefreshTokenDelay();
// Returns the ambient image view for each display.
std::vector<AmbientBackgroundImageView*> GetAmbientBackgroundImageViews();
// Returns the AmbientBackgroundImageView for the default display.
AmbientBackgroundImageView* GetAmbientBackgroundImageView(); AmbientBackgroundImageView* GetAmbientBackgroundImageView();
// Returns the media string views for displaying ongoing media info. // Returns the media string view for displaying ongoing media info.
std::vector<MediaStringView*> GetMediaStringViews();
// Returns the media string view for the default display.
MediaStringView* GetMediaStringView(); MediaStringView* GetMediaStringView();
AmbientController* ambient_controller(); AmbientController* ambient_controller();
AmbientPhotoController* photo_controller(); AmbientPhotoController* photo_controller();
// Returns the top-level views which contains all the ambient components. // Returns the top-level view which contains all the ambient components.
std::vector<AmbientContainerView*> GetContainerViews(); AmbientContainerView* container_view();
// Returns the top level ambient container view for the primary root window.
AmbientContainerView* GetContainerView();
AmbientAccessTokenController* token_controller(); AmbientAccessTokenController* token_controller();
......
...@@ -18,18 +18,15 @@ using AmbientContainerViewTest = AmbientAshTestBase; ...@@ -18,18 +18,15 @@ using AmbientContainerViewTest = AmbientAshTestBase;
// Tests that AmbientContainerView window should be fullscreen. // Tests that AmbientContainerView window should be fullscreen.
TEST_F(AmbientContainerViewTest, WindowFullscreenSize) { TEST_F(AmbientContainerViewTest, WindowFullscreenSize) {
ShowAmbientScreen(); ShowAmbientScreen();
for (const auto* container : GetContainerViews()) { views::Widget* widget = container_view()->GetWidget();
const views::Widget* widget = container->GetWidget();
gfx::Rect root_window_bounds =
gfx::Rect root_window_bounds = display::Screen::GetScreen()
display::Screen::GetScreen() ->GetDisplayNearestWindow(widget->GetNativeWindow()->GetRootWindow())
->GetDisplayNearestWindow( .bounds();
widget->GetNativeWindow()->GetRootWindow()) gfx::Rect container_window_bounds =
.bounds(); widget->GetNativeWindow()->GetBoundsInScreen();
gfx::Rect container_window_bounds = EXPECT_EQ(root_window_bounds, container_window_bounds);
widget->GetNativeWindow()->GetBoundsInScreen();
EXPECT_EQ(root_window_bounds, container_window_bounds);
}
// Clean up. // Clean up.
CloseAmbientScreen(); CloseAmbientScreen();
......
...@@ -74,7 +74,7 @@ GlanceableInfoView::GlanceableInfoView(AmbientViewDelegate* delegate) ...@@ -74,7 +74,7 @@ GlanceableInfoView::GlanceableInfoView(AmbientViewDelegate* delegate)
DCHECK(delegate); DCHECK(delegate);
SetID(AmbientViewID::kAmbientGlanceableInfoView); SetID(AmbientViewID::kAmbientGlanceableInfoView);
auto* backend_model = delegate_->GetAmbientBackendModel(); auto* backend_model = delegate_->GetAmbientBackendModel();
scoped_backend_model_observer_.Observe(backend_model); backend_model->AddObserver(this);
InitLayout(); InitLayout();
...@@ -84,7 +84,9 @@ GlanceableInfoView::GlanceableInfoView(AmbientViewDelegate* delegate) ...@@ -84,7 +84,9 @@ GlanceableInfoView::GlanceableInfoView(AmbientViewDelegate* delegate)
} }
} }
GlanceableInfoView::~GlanceableInfoView() = default; GlanceableInfoView::~GlanceableInfoView() {
delegate_->GetAmbientBackendModel()->RemoveObserver(this);
}
const char* GlanceableInfoView::GetClassName() const { const char* GlanceableInfoView::GetClassName() const {
return "GlanceableInfoView"; return "GlanceableInfoView";
......
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
#ifndef ASH_AMBIENT_UI_GLANCEABLE_INFO_VIEW_H_ #ifndef ASH_AMBIENT_UI_GLANCEABLE_INFO_VIEW_H_
#define ASH_AMBIENT_UI_GLANCEABLE_INFO_VIEW_H_ #define ASH_AMBIENT_UI_GLANCEABLE_INFO_VIEW_H_
#include "ash/ambient/model/ambient_backend_model.h"
#include "ash/ambient/model/ambient_backend_model_observer.h" #include "ash/ambient/model/ambient_backend_model_observer.h"
#include "base/scoped_observation.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace views { namespace views {
...@@ -55,9 +53,6 @@ class GlanceableInfoView : public views::View, ...@@ -55,9 +53,6 @@ class GlanceableInfoView : public views::View,
// Owned by |AmbientController|. // Owned by |AmbientController|.
AmbientViewDelegate* const delegate_ = nullptr; AmbientViewDelegate* const delegate_ = nullptr;
base::ScopedObservation<AmbientBackendModel, AmbientBackendModelObserver>
scoped_backend_model_observer_{this};
}; };
} // namespace ash } // namespace ash
......
...@@ -269,8 +269,7 @@ TEST_F(MediaStringViewTest, HasNoMaskLayerWithShortText) { ...@@ -269,8 +269,7 @@ TEST_F(MediaStringViewTest, HasNoMaskLayerWithShortText) {
media_session::mojom::MediaPlaybackState::kPlaying); media_session::mojom::MediaPlaybackState::kPlaying);
SimulateMediaMetadataChanged(metadata); SimulateMediaMetadataChanged(metadata);
// Force re-layout. // Force re-layout.
for (auto* view : GetContainerViews()) container_view()->Layout();
view->Layout();
EXPECT_LT(GetMediaStringViewTextLabel()->GetPreferredSize().width(), EXPECT_LT(GetMediaStringViewTextLabel()->GetPreferredSize().width(),
kMediaStringMaxWidthDip); kMediaStringMaxWidthDip);
...@@ -289,8 +288,7 @@ TEST_F(MediaStringViewTest, HasMaskLayerWithLongText) { ...@@ -289,8 +288,7 @@ TEST_F(MediaStringViewTest, HasMaskLayerWithLongText) {
media_session::mojom::MediaPlaybackState::kPlaying); media_session::mojom::MediaPlaybackState::kPlaying);
SimulateMediaMetadataChanged(metadata); SimulateMediaMetadataChanged(metadata);
// Force re-layout. // Force re-layout.
for (auto* view : GetContainerViews()) container_view()->Layout();
view->Layout();
EXPECT_GT(GetMediaStringViewTextLabel()->GetPreferredSize().width(), EXPECT_GT(GetMediaStringViewTextLabel()->GetPreferredSize().width(),
kMediaStringMaxWidthDip); kMediaStringMaxWidthDip);
...@@ -309,8 +307,7 @@ TEST_F(MediaStringViewTest, MaskLayerShouldUpdate) { ...@@ -309,8 +307,7 @@ TEST_F(MediaStringViewTest, MaskLayerShouldUpdate) {
media_session::mojom::MediaPlaybackState::kPlaying); media_session::mojom::MediaPlaybackState::kPlaying);
SimulateMediaMetadataChanged(metadata); SimulateMediaMetadataChanged(metadata);
// Force re-layout. // Force re-layout.
for (auto* view : GetContainerViews()) container_view()->Layout();
view->Layout();
EXPECT_LT(GetMediaStringViewTextLabel()->GetPreferredSize().width(), EXPECT_LT(GetMediaStringViewTextLabel()->GetPreferredSize().width(),
kMediaStringMaxWidthDip); kMediaStringMaxWidthDip);
...@@ -322,8 +319,7 @@ TEST_F(MediaStringViewTest, MaskLayerShouldUpdate) { ...@@ -322,8 +319,7 @@ TEST_F(MediaStringViewTest, MaskLayerShouldUpdate) {
SimulateMediaMetadataChanged(metadata); SimulateMediaMetadataChanged(metadata);
// Force re-layout. // Force re-layout.
for (auto* view : GetContainerViews()) container_view()->Layout();
view->Layout();
EXPECT_GT(GetMediaStringViewTextLabel()->GetPreferredSize().width(), EXPECT_GT(GetMediaStringViewTextLabel()->GetPreferredSize().width(),
kMediaStringMaxWidthDip); kMediaStringMaxWidthDip);
...@@ -335,8 +331,7 @@ TEST_F(MediaStringViewTest, MaskLayerShouldUpdate) { ...@@ -335,8 +331,7 @@ TEST_F(MediaStringViewTest, MaskLayerShouldUpdate) {
SimulateMediaMetadataChanged(metadata); SimulateMediaMetadataChanged(metadata);
// Force re-layout. // Force re-layout.
for (auto* view : GetContainerViews()) container_view()->Layout();
view->Layout();
EXPECT_LT(GetMediaStringViewTextLabel()->GetPreferredSize().width(), EXPECT_LT(GetMediaStringViewTextLabel()->GetPreferredSize().width(),
kMediaStringMaxWidthDip); kMediaStringMaxWidthDip);
......
...@@ -44,7 +44,9 @@ PhotoView::PhotoView(AmbientViewDelegate* delegate) : delegate_(delegate) { ...@@ -44,7 +44,9 @@ PhotoView::PhotoView(AmbientViewDelegate* delegate) : delegate_(delegate) {
Init(); Init();
} }
PhotoView::~PhotoView() = default; PhotoView::~PhotoView() {
delegate_->GetAmbientBackendModel()->RemoveObserver(this);
}
const char* PhotoView::GetClassName() const { const char* PhotoView::GetClassName() const {
return "PhotoView"; return "PhotoView";
...@@ -80,7 +82,7 @@ void PhotoView::Init() { ...@@ -80,7 +82,7 @@ void PhotoView::Init() {
image_views_[1]->layer()->SetOpacity(0.0f); image_views_[1]->layer()->SetOpacity(0.0f);
auto* model = delegate_->GetAmbientBackendModel(); auto* model = delegate_->GetAmbientBackendModel();
scoped_backend_model_observer_.Observe(model); model->AddObserver(this);
UpdateImage(model->GetCurrentImage()); UpdateImage(model->GetCurrentImage());
} }
......
...@@ -7,12 +7,10 @@ ...@@ -7,12 +7,10 @@
#include <memory> #include <memory>
#include "ash/ambient/model/ambient_backend_model.h"
#include "ash/ambient/model/ambient_backend_model_observer.h" #include "ash/ambient/model/ambient_backend_model_observer.h"
#include "ash/ambient/ui/ambient_background_image_view.h" #include "ash/ambient/ui/ambient_background_image_view.h"
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/scoped_observation.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -68,9 +66,6 @@ class ASH_EXPORT PhotoView : public views::View, ...@@ -68,9 +66,6 @@ class ASH_EXPORT PhotoView : public views::View,
// The index of |image_views_| to update the next image. // The index of |image_views_| to update the next image.
int image_index_ = 0; int image_index_ = 0;
base::ScopedObservation<AmbientBackendModel, AmbientBackendModelObserver>
scoped_backend_model_observer_{this};
}; };
} // namespace ash } // namespace ash
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "ash/accessibility/accessibility_panel_layout_manager.h" #include "ash/accessibility/accessibility_panel_layout_manager.h"
#include "ash/accessibility/touch_exploration_controller.h" #include "ash/accessibility/touch_exploration_controller.h"
#include "ash/accessibility/touch_exploration_manager.h" #include "ash/accessibility/touch_exploration_manager.h"
#include "ash/ambient/ambient_controller.h"
#include "ash/app_menu/app_menu_model_adapter.h" #include "ash/app_menu/app_menu_model_adapter.h"
#include "ash/focus_cycler.h" #include "ash/focus_cycler.h"
#include "ash/high_contrast/high_contrast_controller.h" #include "ash/high_contrast/high_contrast_controller.h"
...@@ -97,7 +96,6 @@ ...@@ -97,7 +96,6 @@
#include "ui/views/controls/menu/menu_runner.h" #include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/view_model.h" #include "ui/views/view_model.h"
#include "ui/views/view_model_utils.h" #include "ui/views/view_model_utils.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/capture_controller.h" #include "ui/wm/core/capture_controller.h"
#include "ui/wm/core/coordinate_conversion.h" #include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/core/visibility_controller.h" #include "ui/wm/core/visibility_controller.h"
...@@ -651,7 +649,6 @@ void RootWindowController::Shutdown() { ...@@ -651,7 +649,6 @@ void RootWindowController::Shutdown() {
touch_exploration_manager_.reset(); touch_exploration_manager_.reset();
wallpaper_widget_controller_.reset(); wallpaper_widget_controller_.reset();
CloseAmbientWidget(/*immediately=*/true);
CloseChildWindows(); CloseChildWindows();
aura::Window* root_window = GetRootWindow(); aura::Window* root_window = GetRootWindow();
...@@ -818,27 +815,6 @@ void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) { ...@@ -818,27 +815,6 @@ void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) {
status_area_widget->UpdateAfterLoginStatusChange(status); status_area_widget->UpdateAfterLoginStatusChange(status);
} }
void RootWindowController::CreateAmbientWidget() {
DCHECK(!ambient_widget_);
auto* ambient_controller = Shell::Get()->ambient_controller();
if (ambient_controller && ambient_controller->IsShown()) {
ambient_widget_ = ambient_controller->CreateWidget(
GetRootWindow()->GetChildById(kShellWindowId_AmbientModeContainer));
}
}
void RootWindowController::CloseAmbientWidget(bool immediately) {
if (ambient_widget_) {
if (immediately)
ambient_widget_->CloseNow();
else
ambient_widget_->CloseWithReason(views::Widget::ClosedReason::kLostFocus);
}
ambient_widget_.reset();
}
AccessibilityPanelLayoutManager* AccessibilityPanelLayoutManager*
RootWindowController::GetAccessibilityPanelLayoutManagerForTest() { RootWindowController::GetAccessibilityPanelLayoutManagerForTest() {
return GetAccessibilityPanelLayoutManager(); return GetAccessibilityPanelLayoutManager();
...@@ -907,8 +883,6 @@ void RootWindowController::Init(RootWindowType root_window_type) { ...@@ -907,8 +883,6 @@ void RootWindowController::Init(RootWindowType root_window_type) {
Shell::Get()->session_controller()->IsUserSessionBlocked()); Shell::Get()->session_controller()->IsUserSessionBlocked());
root_window_layout_manager_->OnWindowResized(); root_window_layout_manager_->OnWindowResized();
CreateAmbientWidget();
// Explicitly update the desks controller before notifying the ShellObservers. // Explicitly update the desks controller before notifying the ShellObservers.
// This is to make sure the desks' states are correct before clients are // This is to make sure the desks' states are correct before clients are
// updated. // updated.
......
...@@ -30,8 +30,7 @@ class WindowTreeHost; ...@@ -30,8 +30,7 @@ class WindowTreeHost;
namespace views { namespace views {
class MenuRunner; class MenuRunner;
class Widget; }
} // namespace views
namespace wm { namespace wm {
class ScopedCaptureClient; class ScopedCaptureClient;
...@@ -223,11 +222,6 @@ class ASH_EXPORT RootWindowController { ...@@ -223,11 +222,6 @@ class ASH_EXPORT RootWindowController {
// Called when the login status changes after login (such as lock/unlock). // Called when the login status changes after login (such as lock/unlock).
void UpdateAfterLoginStatusChange(LoginStatus status); void UpdateAfterLoginStatusChange(LoginStatus status);
void CreateAmbientWidget();
void CloseAmbientWidget(bool immediately);
views::Widget* ambient_widget_for_testing() { return ambient_widget_.get(); }
// Returns accessibility panel layout manager for this root window. // Returns accessibility panel layout manager for this root window.
AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManagerForTest(); AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManagerForTest();
...@@ -311,8 +305,6 @@ class ASH_EXPORT RootWindowController { ...@@ -311,8 +305,6 @@ class ASH_EXPORT RootWindowController {
std::unique_ptr<LockScreenActionBackgroundController> std::unique_ptr<LockScreenActionBackgroundController>
lock_screen_action_background_controller_; lock_screen_action_background_controller_;
std::unique_ptr<views::Widget> ambient_widget_;
// Whether child windows have been closed during shutdown. Exists to avoid // Whether child windows have been closed during shutdown. Exists to avoid
// calling related cleanup code more than once. // calling related cleanup code more than once.
bool did_close_child_windows_ = false; bool did_close_child_windows_ = false;
......
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