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

Unified Diff: chromeos/dbus/power_manager_client_unittest.cc

Issue 2403733003: chromeos: Avoid crash on synchronous suspend readiness call. (Closed)
Patch Set: Created 4 years, 2 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 | « chromeos/dbus/power_manager_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/power_manager_client_unittest.cc
diff --git a/chromeos/dbus/power_manager_client_unittest.cc b/chromeos/dbus/power_manager_client_unittest.cc
index 6614d6c7da76ca620cea404f079f4532ed78c3a5..1d2f2bd273e73a4c30b092cfa355c46524fe6188 100644
--- a/chromeos/dbus/power_manager_client_unittest.cc
+++ b/chromeos/dbus/power_manager_client_unittest.cc
@@ -96,6 +96,9 @@ class TestObserver : public PowerManagerClient::Observer {
void set_take_suspend_readiness_callback(bool take_callback) {
take_suspend_readiness_callback_ = take_callback;
}
+ void set_run_suspend_readiness_callback_immediately(bool run) {
+ run_suspend_readiness_callback_immediately_ = run;
+ }
// Runs |suspend_readiness_callback_|.
bool RunSuspendReadinessCallback() WARN_UNUSED_RESULT {
@@ -113,6 +116,8 @@ class TestObserver : public PowerManagerClient::Observer {
num_suspend_imminent_++;
if (take_suspend_readiness_callback_)
suspend_readiness_callback_ = client_->GetSuspendReadinessCallback();
+ if (run_suspend_readiness_callback_immediately_)
+ CHECK(RunSuspendReadinessCallback());
}
void SuspendDone(const base::TimeDelta& sleep_duration) override {
num_suspend_done_++;
@@ -121,6 +126,8 @@ class TestObserver : public PowerManagerClient::Observer {
num_dark_suspend_imminent_++;
if (take_suspend_readiness_callback_)
suspend_readiness_callback_ = client_->GetSuspendReadinessCallback();
+ if (run_suspend_readiness_callback_immediately_)
+ CHECK(RunSuspendReadinessCallback());
}
private:
@@ -136,6 +143,11 @@ class TestObserver : public PowerManagerClient::Observer {
// GetSuspendReadinessCallback() method?
bool take_suspend_readiness_callback_ = false;
+ // Should SuspendImminent() and DarkSuspendImminent() run the suspend
+ // readiness callback synchronously after taking it? Only has an effect if
+ // |take_suspend_readiness_callback_| is true.
+ bool run_suspend_readiness_callback_immediately_ = false;
+
// Callback returned by |client_|'s GetSuspendReadinessCallback() method.
base::Closure suspend_readiness_callback_;
@@ -520,4 +532,38 @@ TEST_F(PowerManagerClientTest, DarkSuspendImminentWhileCallbackPending) {
dark_callback.Run();
}
+// Tests that PowerManagerClient handles a single observer that requests a
+// suspend-readiness callback and then runs it synchronously from within
+// SuspendImminent() instead of running it asynchronously:
+// http://crosbug.com/p/58295
+TEST_F(PowerManagerClientTest, SyncCallbackWithSingleObserver) {
+ TestObserver observer(client_.get());
+ observer.set_take_suspend_readiness_callback(true);
+ observer.set_run_suspend_readiness_callback_immediately(true);
+
+ const int kSuspendId = 1;
+ ExpectSuspendReadiness(kHandleSuspendReadiness, kSuspendId, kSuspendDelayId);
+ EmitSuspendImminentSignal(kSuspendImminent, kSuspendId);
+ EmitSuspendDoneSignal(kSuspendId);
+}
+
+// Tests the case where one observer reports suspend readiness by running its
+// callback before a second observer even gets notified about the suspend
+// attempt. We shouldn't report suspend readiness until the second observer has
+// been notified and confirmed readiness.
+TEST_F(PowerManagerClientTest, SyncCallbackWithMultipleObservers) {
+ TestObserver observer1(client_.get());
+ observer1.set_take_suspend_readiness_callback(true);
+ observer1.set_run_suspend_readiness_callback_immediately(true);
+
+ TestObserver observer2(client_.get());
+ observer2.set_take_suspend_readiness_callback(true);
+
+ const int kSuspendId = 1;
+ EmitSuspendImminentSignal(kSuspendImminent, kSuspendId);
+ ExpectSuspendReadiness(kHandleSuspendReadiness, kSuspendId, kSuspendDelayId);
+ EXPECT_TRUE(observer2.RunSuspendReadinessCallback());
+ EmitSuspendDoneSignal(kSuspendId);
+}
+
} // namespace chromeos
« no previous file with comments | « chromeos/dbus/power_manager_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698