Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: ash/system/chromeos/power/power_event_observer_unittest.cc

Issue 2296003002: ABANDONED: chromeos: Resume displays when suspend is cancelled. (Closed)
Patch Set: fix comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/chromeos/power/power_event_observer.cc ('k') | chromeos/dbus/fake_power_manager_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/chromeos/power/power_event_observer_unittest.cc
diff --git a/ash/system/chromeos/power/power_event_observer_unittest.cc b/ash/system/chromeos/power/power_event_observer_unittest.cc
index 15c9c6a970f4b4dceaac05fe0b21b8ede591f04f..63dedbce6962b2b46c0cf72ba540c3faa2eca38f 100644
--- a/ash/system/chromeos/power/power_event_observer_unittest.cc
+++ b/ash/system/chromeos/power/power_event_observer_unittest.cc
@@ -8,12 +8,16 @@
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
+#include "base/run_loop.h"
#include "base/time/time.h"
#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/power_manager_client.h"
+#include "chromeos/dbus/fake_power_manager_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/compositor/compositor.h"
+#include "ui/display/chromeos/display_configurator.h"
+#include "ui/display/chromeos/test/action_logger.h"
+#include "ui/display/chromeos/test/test_native_display_delegate.h"
namespace ash {
@@ -25,6 +29,13 @@ class PowerEventObserverTest : public test::AshTestBase {
// test::AshTestBase::SetUp() overrides:
void SetUp() override {
test::AshTestBase::SetUp();
+
+ // Reset any state left in chromeos::FakePowerManagerClient by previous
+ // tests.
+ power_manager_client_ = static_cast<chromeos::FakePowerManagerClient*>(
+ chromeos::DBusThreadManager::Get()->GetPowerManagerClient());
+ power_manager_client_->Reset();
+
observer_.reset(new PowerEventObserver());
}
@@ -44,6 +55,7 @@ class PowerEventObserverTest : public test::AshTestBase {
return result;
}
+ chromeos::FakePowerManagerClient* power_manager_client_; // Non-owned.
std::unique_ptr<PowerEventObserver> observer_;
private:
@@ -51,22 +63,20 @@ class PowerEventObserverTest : public test::AshTestBase {
};
TEST_F(PowerEventObserverTest, LockBeforeSuspend) {
- chromeos::PowerManagerClient* client =
- chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
- ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
+ ASSERT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks());
// Check that the observer requests a suspend-readiness callback when it hears
// that the system is about to suspend.
SetCanLockScreen(true);
SetShouldLockScreenBeforeSuspending(true);
observer_->SuspendImminent();
- EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks());
+ EXPECT_EQ(1, power_manager_client_->GetNumPendingSuspendReadinessCallbacks());
// It should run the callback when it hears that the screen is locked and the
// lock screen animations have completed.
observer_->ScreenIsLocked();
observer_->OnLockAnimationsComplete();
- EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
+ EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks());
// If the system is already locked, no callback should be requested.
observer_->SuspendDone(base::TimeDelta());
@@ -74,14 +84,14 @@ TEST_F(PowerEventObserverTest, LockBeforeSuspend) {
observer_->ScreenIsLocked();
observer_->OnLockAnimationsComplete();
observer_->SuspendImminent();
- EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
+ EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks());
// It also shouldn't request a callback if it isn't instructed to lock the
// screen.
observer_->SuspendDone(base::TimeDelta());
SetShouldLockScreenBeforeSuspending(false);
observer_->SuspendImminent();
- EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks());
+ EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks());
}
TEST_F(PowerEventObserverTest, SetInvisibleBeforeSuspend) {
@@ -139,10 +149,8 @@ TEST_F(PowerEventObserverTest, DelayResuspendForLockAnimations) {
SetCanLockScreen(true);
SetShouldLockScreenBeforeSuspending(true);
- chromeos::PowerManagerClient* client =
- chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
observer_->SuspendImminent();
- EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks());
+ EXPECT_EQ(1, power_manager_client_->GetNumPendingSuspendReadinessCallbacks());
observer_->ScreenIsLocked();
observer_->SuspendDone(base::TimeDelta());
@@ -152,11 +160,58 @@ TEST_F(PowerEventObserverTest, DelayResuspendForLockAnimations) {
// observer has not run the callback that it got from the first suspend
// request. The real PowerManagerClient would reset its internal counter in
// this situation but the stub client is not that smart.
- EXPECT_EQ(2, client->GetNumPendingSuspendReadinessCallbacks());
+ EXPECT_EQ(2, power_manager_client_->GetNumPendingSuspendReadinessCallbacks());
observer_->OnLockAnimationsComplete();
- EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks());
+ EXPECT_EQ(1, power_manager_client_->GetNumPendingSuspendReadinessCallbacks());
EXPECT_EQ(0, GetNumVisibleCompositors());
}
+TEST_F(PowerEventObserverTest, SuspendAndResumeDisplays) {
+ // Configure ui::DisplayConfigurator to do asynchronous configuration.
+ ui::test::ActionLogger logger;
+ ui::test::TestNativeDisplayDelegate* delegate =
+ new ui::test::TestNativeDisplayDelegate(&logger);
+ delegate->set_run_async(true);
+ ui::DisplayConfigurator* configurator =
+ Shell::GetInstance()->display_configurator();
+ configurator->SetDelegateForTesting(
+ std::unique_ptr<ui::NativeDisplayDelegate>(delegate));
+
+ // Start a suspend attempt and let the async display-suspending task run.
+ observer_->SuspendImminent();
+ EXPECT_TRUE(configurator->displays_suspended_for_test());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(configurator->displays_suspended_for_test());
+
+ // When the system resumes, the displays should be resumed.
+ observer_->SuspendDone(base::TimeDelta());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(configurator->displays_suspended_for_test());
+
+ // Now, start another suspend attempt but abort it before the
+ // display-suspending task runs (http://crbug.com/620208). The displays should
+ // still be in the suspended state, since the async task is running and might
+ // undo any resuming that's done at this time.
+ observer_->SuspendImminent();
+ EXPECT_TRUE(configurator->displays_suspended_for_test());
+ observer_->SuspendDone(base::TimeDelta());
+ EXPECT_TRUE(configurator->displays_suspended_for_test());
+
+ // When the task finally completes, the displays should be resumed.
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(configurator->displays_suspended_for_test());
+
+ // Start suspending and then cancel immediately again.
+ observer_->SuspendImminent();
+ observer_->SuspendDone(base::TimeDelta());
+ EXPECT_TRUE(configurator->displays_suspended_for_test());
+
+ // This time, suspend again before the display-resuming task has a chance to
+ // run. The displays should remain suspended.
+ observer_->SuspendImminent();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(configurator->displays_suspended_for_test());
+}
+
} // namespace ash
« no previous file with comments | « ash/system/chromeos/power/power_event_observer.cc ('k') | chromeos/dbus/fake_power_manager_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698